15 #ifndef CORE_MULTI_SIMULATION_MULTI_SIMULATION_MANAGER_H_
16 #define CORE_MULTI_SIMULATION_MULTI_SIMULATION_MANAGER_H_
40 namespace experimental {
42 static const unsigned int kMaster = 0;
44 enum Status { kBusy, kAvail };
45 enum Tag { kReady, kResult, kTask, kKill };
49 class MultiSimulationManager {
53 explicit MultiSimulationManager(
54 int ws, Param *default_params,
55 std::function<
void(Param *, TimeSeries *)> simulate);
57 void WriteTimingsToFile();
59 void IngestData(
const std::string &data_file);
61 ~MultiSimulationManager();
64 void RecordTiming(
int worker, TimingAggregator *agg);
67 void KillAllWorkers();
70 void GetTimingsFromWorkers();
75 friend struct ParticleSwarm;
78 int GetFirstAvailableWorker();
81 void ChangeStatusWorker(
int worker, Status s);
85 void ForAllWorkers(
const std::function<
void(
int w)> &lambda);
87 vector<Status> availability_;
90 Param *default_params_;
91 std::function<void(Param *, TimeSeries *)> simulate_;
92 std::vector<TimingAggregator> timings_;
99 explicit Worker(
int myrank,
100 std::function<
void(Param *, TimeSeries *)> simulate);
102 template <
typename T>
104 Log::Info(
"MultiSimulationManager",
"[W", myrank_,
"]: ", s);
112 void IncrementTaskCount();
115 unsigned int task_count_ = 0;
116 std::function<void(Param *, TimeSeries *)> simulate_;
117 TimingAggregator ta_;
125 #endif // CORE_MULTI_SIMULATION_MULTI_SIMULATION_MANAGER_H_