Canoe
Comprehensive Atmosphere N' Ocean Engine
schedulers.cpp
Go to the documentation of this file.
1 
4 // athena
5 #include <athena/mesh/mesh.hpp>
6 #include <athena/parameter_input.hpp>
7 
8 // canoe
9 #include "schedulers.hpp"
10 
11 Scheduler::Scheduler(MeshBlock* pmb) : pmy_block_(pmb) {}
12 
14  current_task_ = func;
15  return func(pmy_block_, current_stage_);
16 }
17 
18 bool Scheduler::CheckDone(std::vector<TaskFunc> const& deps) {
19  if (deps.empty()) return true;
20 
21  tasks_[current_task_].deps = deps;
22 
23  for (auto& dep_task : deps) {
24  auto it = tasks_.find(dep_task);
25 
26  // find dependent task
27  if (it != tasks_.end()) {
28  if (it->second.done) continue;
29  } else { // register task, initialize to todo
30  tasks_[dep_task] = {false, {}};
31  }
32 
33  TaskFunc parent_task = current_task_;
34  tasks_[dep_task].done = DoTask(dep_task);
35  current_task_ = parent_task;
36 
37  if (!tasks_[dep_task].done) return false;
38  }
39 
40  return true;
41 }
42 
43 void Scheduler::AddTasks(std::vector<TaskFunc> const& tasks) {
44  for (auto& task : tasks) {
45  auto it = tasks_.find(task);
46 
47  // did not find task
48  if (it == tasks_.end()) {
49  tasks_[task] = {false, {}};
50  }
51  }
52 }
53 
54 SchedulerPtr SchedulerFactory::Create(MeshBlock* pmb, ParameterInput* pin) {
55  SchedulerPtr scheduler;
56  scheduler = std::make_shared<Scheduler>(pmb);
57  return scheduler;
58 }
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
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::shared_ptr< Scheduler > SchedulerPtr
Definition: schedulers.hpp:41