BioDynaMo  v1.05.117-b1949764
Public Types | Public Member Functions | Protected Member Functions | Protected Attributes | Private Member Functions | Private Attributes | Friends | List of all members
bdm::Scheduler Class Reference

#include <scheduler.h>

Collaboration diagram for bdm::Scheduler:
[legend]

Public Types

using Clock = std::chrono::high_resolution_clock
 

Public Member Functions

 Scheduler ()
 
virtual ~Scheduler ()
 
void Simulate (uint64_t steps)
 Simulate steps number of iterations. More...
 
void SimulateUntil (const std::function< bool()> &exit_condition)
 
void FinalizeInitialization () const
 
uint64_t GetSimulatedSteps () const
 This function returns the number of simulated steps (=iterations). More...
 
real_t GetSimulatedTime () const
 
void ScheduleOp (Operation *op, OpType op_type=OpType::kSchedule)
 
void UnscheduleOp (Operation *op)
 
std::vector< Operation * > GetOps (const std::string &name)
 
void SetAgentFilters (const std::vector< Functor< bool, Agent * > * > &filters)
 
const std::vector< Functor< bool, Agent * > * > & GetAgentFilters () const
 
RootAdaptorGetRootVisualization ()
 
TimingAggregatorGetOpTimes ()
 
void PrintInfo (std::ostream &out) const
 

Protected Member Functions

virtual void Execute ()
 

Protected Attributes

uint64_t total_steps_ = 0
 
real_t simulated_time_ = 0.0
 

Private Member Functions

void Backup ()
 Backup the simulation. Backup interval based on Param::backup_interval More...
 
bool Restore (uint64_t *steps)
 
void UpdateSimulatedTime ()
 
void Initialize (uint64_t steps=0)
 
template<typename Lambda >
void ForEachOperationInList (const std::vector< Operation * > &operations, Lambda lambda) const
 Runs a lambda for each operation in the specified list of operations. More...
 
template<typename Lambda >
void ForEachScheduledOperation (Lambda lambda)
 Runs a lambda for each scheduled operation. More...
 
template<typename Lambda >
void ForEachOperation (Lambda lambda)
 Runs a lambda for each operation that is executed in the Execute() call. More...
 
std::vector< std::string > GetListOfScheduledAgentOps () const
 Return a list of AgentOperations that are scheduled. More...
 
std::vector< std::string > GetListOfScheduledStandaloneOps () const
 Return a list of StandAloneOperations that are scheduled. More...
 
void SetUpOps ()
 
void TearDownOps ()
 
void RunScheduledOps ()
 
void RunPreScheduledOps () const
 
void RunAgentOps (Functor< bool, Agent * > *filter) const
 
void RunPostScheduledOps () const
 
void ScheduleOps ()
 

Private Attributes

friend SchedulerTest
 
SimulationBackupbackup_ = nullptr
 
uint64_t restore_point_
 
std::chrono::time_point< Clocklast_backup_ = Clock::now()
 
RootAdaptorroot_visualization_ = nullptr
 
ProgressBarprogress_bar_ = nullptr
 
std::vector< Operation * > all_ops_
 
std::vector< std::pair< OpType, Operation * > > schedule_ops_
 List of operations that are to be added in the upcoming timestep. More...
 
std::vector< Operation * > unschedule_ops_
 List of operations that are to be removed in the upcoming timestep. More...
 
std::vector< Operation * > scheduled_standalone_ops_
 List of operations will be executed as a stand-alone operation. More...
 
std::vector< Operation * > scheduled_agent_ops_
 List of operations will be executed on all agents. More...
 
std::vector< std::string > protected_op_names_
 List of operations that cannot be affected by the user. More...
 
std::vector< Operation * > pre_scheduled_ops_
 
std::vector< Operation * > post_scheduled_ops_
 
TimingAggregator op_times_
 Tracks operations' execution times. More...
 
std::vector< Functor< bool, Agent * > * > agent_filters_
 

Friends

void RunAgentsTest (Param::MappedDataArrayMode, uint64_t, bool, bool)
 

Detailed Description

Definition at line 45 of file scheduler.h.

Member Typedef Documentation

◆ Clock

using bdm::Scheduler::Clock = std::chrono::high_resolution_clock

Definition at line 47 of file scheduler.h.

Constructor & Destructor Documentation

◆ Scheduler()

bdm::Scheduler::Scheduler ( )

Definition at line 36 of file scheduler.cc.

◆ ~Scheduler()

bdm::Scheduler::~Scheduler ( )
virtual

Definition at line 121 of file scheduler.cc.

Member Function Documentation

◆ Backup()

void bdm::Scheduler::Backup ( )
private

Backup the simulation. Backup interval based on Param::backup_interval

Definition at line 420 of file scheduler.cc.

◆ Execute()

void bdm::Scheduler::Execute ( )
protectedvirtual

Executes one step. This design makes testing more convenient

Definition at line 354 of file scheduler.cc.

◆ FinalizeInitialization()

void bdm::Scheduler::FinalizeInitialization ( ) const

Finalize simulation initialization or manual changes between Simulate calls.
All Simulate calls do this automatically, but sometimes it is useful to do it manually (e.g.for tutorials).

Definition at line 153 of file scheduler.cc.

◆ ForEachOperation()

template<typename Lambda >
void bdm::Scheduler::ForEachOperation ( Lambda  lambda)
inlineprivate

Runs a lambda for each operation that is executed in the Execute() call.

Definition at line 194 of file scheduler.h.

◆ ForEachOperationInList()

template<typename Lambda >
void bdm::Scheduler::ForEachOperationInList ( const std::vector< Operation * > &  operations,
Lambda  lambda 
) const
inlineprivate

Runs a lambda for each operation in the specified list of operations.

Definition at line 178 of file scheduler.h.

◆ ForEachScheduledOperation()

template<typename Lambda >
void bdm::Scheduler::ForEachScheduledOperation ( Lambda  lambda)
inlineprivate

Runs a lambda for each scheduled operation.

Definition at line 187 of file scheduler.h.

◆ GetAgentFilters()

const std::vector< Functor< bool, Agent * > * > & bdm::Scheduler::GetAgentFilters ( ) const

Definition at line 245 of file scheduler.cc.

◆ GetListOfScheduledAgentOps()

std::vector< std::string > bdm::Scheduler::GetListOfScheduledAgentOps ( ) const
private

Return a list of AgentOperations that are scheduled.

Definition at line 202 of file scheduler.cc.

◆ GetListOfScheduledStandaloneOps()

std::vector< std::string > bdm::Scheduler::GetListOfScheduledStandaloneOps ( ) const
private

Return a list of StandAloneOperations that are scheduled.

Definition at line 210 of file scheduler.cc.

◆ GetOps()

std::vector< Operation * > bdm::Scheduler::GetOps ( const std::string &  name)

Returns a vector of operations with the given name. If the name is in the list of proected ops, this function returns an empty vector.

Definition at line 218 of file scheduler.cc.

◆ GetOpTimes()

TimingAggregator * bdm::Scheduler::GetOpTimes ( )

Definition at line 162 of file scheduler.cc.

◆ GetRootVisualization()

RootAdaptor* bdm::Scheduler::GetRootVisualization ( )
inline

Definition at line 102 of file scheduler.h.

◆ GetSimulatedSteps()

uint64_t bdm::Scheduler::GetSimulatedSteps ( ) const

This function returns the number of simulated steps (=iterations).

Definition at line 158 of file scheduler.cc.

◆ GetSimulatedTime()

real_t bdm::Scheduler::GetSimulatedTime ( ) const

This function returns the time that has been simulated until this point of the simulation.

Definition at line 160 of file scheduler.cc.

◆ Initialize()

void bdm::Scheduler::Initialize ( uint64_t  steps = 0)
private

Definition at line 458 of file scheduler.cc.

◆ PrintInfo()

void bdm::Scheduler::PrintInfo ( std::ostream &  out) const

Prints an overview of all pre-scheduled, agent, standalone, and post-scheduled operations. For each iteration, the scheduler executes these operations in the order that they appear in the output. Additionally, the output shows a column "frequency" with values $n_i$ indicating that a certain operation $i$ is only executed every $n_i$-th time.

Definition at line 371 of file scheduler.cc.

◆ Restore()

bool bdm::Scheduler::Restore ( uint64_t *  steps)
private

Restore the simulation if requested at the right time

Parameters
stepsnumber of simulation steps for a Simulate call
Returns
if Simulate should return early

Definition at line 435 of file scheduler.cc.

◆ RunAgentOps()

void bdm::Scheduler::RunAgentOps ( Functor< bool, Agent * > *  filter) const
private

Definition at line 288 of file scheduler.cc.

◆ RunPostScheduledOps()

void bdm::Scheduler::RunPostScheduledOps ( ) const
private

Definition at line 346 of file scheduler.cc.

◆ RunPreScheduledOps()

void bdm::Scheduler::RunPreScheduledOps ( ) const
private

Definition at line 279 of file scheduler.cc.

◆ RunScheduledOps()

void bdm::Scheduler::RunScheduledOps ( )
private

Definition at line 324 of file scheduler.cc.

◆ ScheduleOp()

void bdm::Scheduler::ScheduleOp ( Operation op,
OpType  op_type = OpType::kSchedule 
)

Adds the given operation to the list of to be scheduled operations. Scheduler takes over ownership of the object op. NB: Don't pass stack objects to this function.

Definition at line 164 of file scheduler.cc.

◆ ScheduleOps()

void bdm::Scheduler::ScheduleOps ( )
private

Definition at line 505 of file scheduler.cc.

◆ SetAgentFilters()

void bdm::Scheduler::SetAgentFilters ( const std::vector< Functor< bool, Agent * > * > &  filters)

Agent operations are executed for each filter in agent_filters_.
By default no filter is specified which means that all agent operations will be executed for each agents in the simulation.

Definition at line 239 of file scheduler.cc.

◆ SetUpOps()

void bdm::Scheduler::SetUpOps ( )
private

Definition at line 263 of file scheduler.cc.

◆ Simulate()

void bdm::Scheduler::Simulate ( uint64_t  steps)

Simulate steps number of iterations.

Definition at line 130 of file scheduler.cc.

◆ SimulateUntil()

void bdm::Scheduler::SimulateUntil ( const std::function< bool()> &  exit_condition)

Simulate until exit_condition evaluates to true.
The condition will be tested at the beginning of an iteration.
e.g. simulate until there are 1000 agents in the simulation

scheduler->SimulateUntil([](){
   auto* rm = Simulation::GetActive()->GetResourceManager();
   return rm->GetNumAgents() >= 1000;
});

NB: Automated backups and restores are not yet supported if the simulation uses this simulate function. TODO(lukas)

Definition at line 144 of file scheduler.cc.

◆ TearDownOps()

void bdm::Scheduler::TearDownOps ( )
private

Definition at line 271 of file scheduler.cc.

◆ UnscheduleOp()

void bdm::Scheduler::UnscheduleOp ( Operation op)

Definition at line 174 of file scheduler.cc.

◆ UpdateSimulatedTime()

void bdm::Scheduler::UpdateSimulatedTime ( )
private

Definition at line 451 of file scheduler.cc.

Friends And Related Function Documentation

◆ RunAgentsTest

void RunAgentsTest ( Param::MappedDataArrayMode  ,
uint64_t  ,
bool  ,
bool   
)
friend

Member Data Documentation

◆ agent_filters_

std::vector<Functor<bool, Agent*>*> bdm::Scheduler::agent_filters_
private

Agent operations are executed for each filter in agent_filters_.
By default no filter is specified which means that all agent operations will be executed for each agents in the simulation.

Definition at line 159 of file scheduler.h.

◆ all_ops_

std::vector<Operation*> bdm::Scheduler::all_ops_
private

List of all operations that have been add either as default or by a call to Scheduler::ScheduleOp. Scheduler::UnscheduleOp doesn't remove the operation from this list.

Definition at line 136 of file scheduler.h.

◆ backup_

SimulationBackup* bdm::Scheduler::backup_ = nullptr
private

Definition at line 126 of file scheduler.h.

◆ last_backup_

std::chrono::time_point<Clock> bdm::Scheduler::last_backup_ = Clock::now()
private

Definition at line 128 of file scheduler.h.

◆ op_times_

TimingAggregator bdm::Scheduler::op_times_
private

Tracks operations' execution times.

Definition at line 154 of file scheduler.h.

◆ post_scheduled_ops_

std::vector<Operation*> bdm::Scheduler::post_scheduled_ops_
private

Definition at line 152 of file scheduler.h.

◆ pre_scheduled_ops_

std::vector<Operation*> bdm::Scheduler::pre_scheduled_ops_
private

Definition at line 149 of file scheduler.h.

◆ progress_bar_

ProgressBar* bdm::Scheduler::progress_bar_ = nullptr
private

Definition at line 130 of file scheduler.h.

◆ protected_op_names_

std::vector<std::string> bdm::Scheduler::protected_op_names_
private

List of operations that cannot be affected by the user.

Definition at line 146 of file scheduler.h.

◆ restore_point_

uint64_t bdm::Scheduler::restore_point_
private

Definition at line 127 of file scheduler.h.

◆ root_visualization_

RootAdaptor* bdm::Scheduler::root_visualization_ = nullptr
private

Definition at line 129 of file scheduler.h.

◆ schedule_ops_

std::vector<std::pair<OpType, Operation*> > bdm::Scheduler::schedule_ops_
private

List of operations that are to be added in the upcoming timestep.

Definition at line 138 of file scheduler.h.

◆ scheduled_agent_ops_

std::vector<Operation*> bdm::Scheduler::scheduled_agent_ops_
private

List of operations will be executed on all agents.

Definition at line 144 of file scheduler.h.

◆ scheduled_standalone_ops_

std::vector<Operation*> bdm::Scheduler::scheduled_standalone_ops_
private

List of operations will be executed as a stand-alone operation.

Definition at line 142 of file scheduler.h.

◆ SchedulerTest

friend bdm::Scheduler::SchedulerTest
private

Definition at line 124 of file scheduler.h.

◆ simulated_time_

real_t bdm::Scheduler::simulated_time_ = 0.0
protected

Definition at line 116 of file scheduler.h.

◆ total_steps_

uint64_t bdm::Scheduler::total_steps_ = 0
protected

Definition at line 115 of file scheduler.h.

◆ unschedule_ops_

std::vector<Operation*> bdm::Scheduler::unschedule_ops_
private

List of operations that are to be removed in the upcoming timestep.

Definition at line 140 of file scheduler.h.


The documentation for this class was generated from the following files: