Canoe
Comprehensive Atmosphere N' Ocean Engine
schedulers.hpp
Go to the documentation of this file.
1 #ifndef SRC_SCHEDULERS_HPP_
2 #define SRC_SCHEDULERS_HPP_
3 
4 // C/C++
5 #include <unordered_map>
6 #include <utility>
7 #include <vector>
8 
9 class MeshBlock;
10 class ParameterInput;
11 
12 using IntegrationStage = std::pair<int, int>;
13 using TaskFunc = bool (*)(MeshBlock *, IntegrationStage);
14 
15 struct TaskInfo {
16  bool done = false;
17  int load = 0;
18  std::vector<TaskFunc> deps;
19 };
20 
21 class Scheduler {
22  public:
24  explicit Scheduler(MeshBlock *pmb);
25  virtual ~Scheduler() {}
26 
28  bool DoTask(TaskFunc func);
29  bool CheckDone(std::vector<TaskFunc> const &deps);
30  void AddTasks(std::vector<TaskFunc> const &tasks);
31 
32  protected:
33  std::unordered_map<TaskFunc, TaskInfo> tasks_;
36 
37  private:
38  MeshBlock *pmy_block_;
39 };
40 
41 using SchedulerPtr = std::shared_ptr<Scheduler>;
42 
44  public:
45  static SchedulerPtr Create(MeshBlock *pmb, ParameterInput *pin);
46 };
47 
48 #endif // SRC_SCHEDULERS_HPP_
static SchedulerPtr Create(MeshBlock *pmb, ParameterInput *pin)
Definition: schedulers.cpp:54
IntegrationStage current_stage_
Definition: schedulers.hpp:35
MeshBlock * pmy_block_
Definition: schedulers.hpp:38
Scheduler(MeshBlock *pmb)
constructor and destructor
Definition: schedulers.cpp:11
bool DoTask(TaskFunc func)
functions
Definition: schedulers.cpp:13
std::unordered_map< TaskFunc, TaskInfo > tasks_
Definition: schedulers.hpp:33
bool CheckDone(std::vector< TaskFunc > const &deps)
Definition: schedulers.cpp:18
virtual ~Scheduler()
Definition: schedulers.hpp:25
TaskFunc current_task_
Definition: schedulers.hpp:34
void AddTasks(std::vector< TaskFunc > const &tasks)
Definition: schedulers.cpp:43
bool(*)(MeshBlock *, IntegrationStage) TaskFunc
Definition: schedulers.hpp:13
std::pair< int, int > IntegrationStage
Definition: schedulers.hpp:12
std::shared_ptr< Scheduler > SchedulerPtr
Definition: schedulers.hpp:41
bool done
Definition: schedulers.hpp:16
std::vector< TaskFunc > deps
Definition: schedulers.hpp:18