Stride Reference Manual  1.0
Runner.h
Go to the documentation of this file.
1 
2 #include <vector>
3 #include <string>
4 #include <map>
5 #include <memory>
6 #include <thread>
7 #include <boost/property_tree/ptree.hpp>
8 #include <boost/property_tree/xml_parser.hpp>
9 #include <boost/filesystem/path.hpp>
10 #include <boost/bimap.hpp>
11 #include "sim/Coordinator.h"
13 #include "vis/ClusterSaver.h"
14 #include "sim/SimulatorRunMode.h"
15 #include "sim/Simulator.h"
16 #include "sim/AsyncSimulator.h"
18 
19 #ifdef MPI_USED
20 
21 #include <mpi.h>
22 
23 #endif
24 
25 
26 namespace stride {
27 namespace run {
28 
30  SimulatorWorldrank(const std::string& name, int rank) : world_rank(rank) {
31  strcpy(simulator_name, name.c_str());
32  }
33 
34  char simulator_name[20];
36 };
37 
39 class Runner {
40 public:
41  // The different steps we do:
42  static void setup();
43 
44  Runner(const std::vector<std::string>& overrides_list, const std::string& config_file,
45  const RunMode& mode, int timestep);
46 
47  void printInfo();
48 
49  void initSimulators();
50 
51  void run();
52 
53  boost::property_tree::ptree getConfig();
54 
55  boost::property_tree::ptree getRegionsConfig(const std::vector<string>& names);
56 
57  void write(std::ostream& out, const boost::property_tree::ptree&);
58 
59 private:
60  void parseConfig(); // done by constructor
61  void initOutputs(Simulator& sim);
62 
63  std::shared_ptr<Simulator> addLocalSimulator(const string& name, const boost::property_tree::ptree& config);
64 
65  std::shared_ptr<AsyncSimulator> addRemoteSimulator(const string& name, const boost::property_tree::ptree& config);
66 
67  void initMpi();
68 
69  void makeSetupStruct();
70 
71  boost::filesystem::path hdf5Path(const string& name);
72 
73  std::map<std::string, std::string> m_overrides;
74  std::string m_config_file;
76  bool m_uses_mpi = false;
77  bool m_is_master = true;
79 
80  // MPI related attributes
83  shared_ptr<RemoteSimulatorReceiver> m_local_receiver;
86  boost::bimap<string, int> m_worldranks;
87  #ifdef MPI_USED
88  MPI_Datatype m_setup_message;
89  #endif
90 
91  boost::property_tree::ptree m_config;
92  std::map<std::string, boost::property_tree::ptree> m_region_configs;
93  std::vector<std::string> m_region_order;
94 
95  std::map<std::string, shared_ptr<Simulator>> m_local_simulators;
96  //std::map<std::string, shared_ptr<RemoteSimulatorSender>> m_remote_senders;
97  std::map<std::string, shared_ptr<AsyncSimulator>> m_async_simulators;
98  std::shared_ptr<Coordinator> m_coord;
99 
100  // Some important configuration keys, used a lot
101  std::string m_name;
102  boost::filesystem::path m_output_dir;
103  std::string m_travel_schedule;
104 
105  std::map<std::string, std::shared_ptr<Hdf5Saver>> m_hdf5_savers;
106  std::map<std::string, std::shared_ptr<ClusterSaver>> m_vis_savers;
107 };
108 
110 /*
111 class SimulatorRunner {
112 public:
113  SimulatorRunner(const shared_ptr<Simulator>& sim, const shared_ptr<Hdf5Saver>& saver):
114  m_sim(sim), m_saver(saver) {}
115 
116  shared_ptr<Simulator> m_sim;
117  shared_ptr<Hdf5Saver> m_saver;
118 };
119  */
120 
121 }
122 }
std::string m_name
Definition: Runner.h:101
SimulatorWorldrank(const std::string &name, int rank)
Definition: Runner.h:30
string m_processor_name
Definition: Runner.h:85
std::map< std::string, std::string > m_overrides
Definition: Runner.h:73
boost::filesystem::path m_output_dir
Definition: Runner.h:102
std::map< std::string, std::shared_ptr< Hdf5Saver > > m_hdf5_savers
Definition: Runner.h:105
std::map< std::string, shared_ptr< AsyncSimulator > > m_async_simulators
Definition: Runner.h:97
Helper for parsing the config, and starting the simulators.
Definition: Runner.h:39
Time Dependent Person DataType.
Definition: NoBehaviour.h:17
std::shared_ptr< Coordinator > m_coord
Definition: Runner.h:98
void run(T generator, const string &prefix)
Definition: popgen/main.cpp:15
std::map< std::string, std::shared_ptr< ClusterSaver > > m_vis_savers
Definition: Runner.h:106
std::map< std::string, boost::property_tree::ptree > m_region_configs
Definition: Runner.h:92
std::map< std::string, shared_ptr< Simulator > > m_local_simulators
Definition: Runner.h:95
Header for the Simulator class.
std::string m_travel_schedule
Definition: Runner.h:103
std::vector< std::string > m_region_order
Definition: Runner.h:93
thread m_listen_thread
Definition: Runner.h:84
Main class that contains and direct the virtual world.
Definition: Simulator.h:64
shared_ptr< RemoteSimulatorReceiver > m_local_receiver
Definition: Runner.h:83
std::string m_config_file
Definition: Runner.h:74
Header file for the Saver class for the checkpointing functionality.
boost::property_tree::ptree m_config
Definition: Runner.h:91
boost::bimap< string, int > m_worldranks
Definition: Runner.h:86
RunMode m_mode
Definition: Runner.h:75