BioDynaMo  v1.05.120-25dc9790
Public Member Functions | Static Public Member Functions | Protected Attributes | List of all members
bdm::experimental::CopyExecutionContext Class Reference

#include <copy_execution_context.h>

Inheritance diagram for bdm::experimental::CopyExecutionContext:
[legend]
Collaboration diagram for bdm::experimental::CopyExecutionContext:
[legend]

Public Member Functions

 CopyExecutionContext (const std::shared_ptr< ThreadSafeAgentUidMap > &map, std::shared_ptr< std::vector< std::vector< Agent * >>> agents)
 
 ~CopyExecutionContext () override
 
void SetupIterationAll (const std::vector< ExecutionContext * > &all_exec_ctxts) override
 
void TearDownAgentOpsAll (const std::vector< ExecutionContext * > &all_exec_ctxts) override
 
void Execute (Agent *agent, AgentHandle ah, const std::vector< Operation * > &operations) override
 
- Public Member Functions inherited from bdm::InPlaceExecutionContext
 InPlaceExecutionContext (const std::shared_ptr< ThreadSafeAgentUidMap > &map)
 
 ~InPlaceExecutionContext () override
 
void SetupIterationAll (const std::vector< ExecutionContext * > &all_exec_ctxts) override
 
void TearDownIterationAll (const std::vector< ExecutionContext * > &all_exec_ctxts) override
 
void SetupAgentOpsAll (const std::vector< ExecutionContext * > &all_exec_ctxts) override
 
void TearDownAgentOpsAll (const std::vector< ExecutionContext * > &all_exec_ctxts) override
 
void Execute (Agent *agent, AgentHandle ah, const std::vector< Operation * > &operations) override
 
void ForEachNeighbor (Functor< void, Agent * > &lambda, const Agent &query, void *criteria) override
 
void ForEachNeighbor (Functor< void, Agent *, real_t > &lambda, const Agent &query, real_t squared_radius) override
 
void ForEachNeighbor (Functor< void, Agent *, real_t > &lambda, const Real3 &query_position, real_t squared_radius) override
 
void AddAgent (Agent *new_agent) override
 Adds the agent to the simulation (threadsafe, takes ownership). Note that we avoid the use of smart pointers for the agents to avoid unnecessary overhead during construction of the agent (performance argument). usage example: More...
 
void RemoveAgent (const AgentUid &uid) override
 
AgentGetAgent (const AgentUid &uid) override
 
const AgentGetConstAgent (const AgentUid &uid) override
 
- Public Member Functions inherited from bdm::ExecutionContext
virtual ~ExecutionContext ()=default
 

Static Public Member Functions

static void Use (Simulation *sim)
 Use the CopyExecutionContext for simulation sim. More...
 

Protected Attributes

std::shared_ptr< std::vector< std::vector< Agent * > > > agents_
 
- Protected Attributes inherited from bdm::InPlaceExecutionContext
std::shared_ptr< ThreadSafeAgentUidMapnew_agent_map_
 Lookup table AgentUid -> AgentPointer for new created agents. More...
 
ThreadInfotinfo_
 
std::vector< Agent * > new_agents_
 Pointer to new agents. More...
 
std::vector< AgentUidremove_
 
std::atomic_flag mutex_ = ATOMIC_FLAG_INIT
 prevent race conditions for cached Agents More...
 
std::vector< std::pair< Agent *, real_t > > neighbor_cache_
 
real_t cached_squared_search_radius_ = 0.0
 The radius that was used to cache neighbors in neighbor_cache_ More...
 
bool cache_neighbors_ = false
 Cache the value of Param::cache_neighbors. More...
 

Additional Inherited Members

- Protected Member Functions inherited from bdm::InPlaceExecutionContext
bool IsNeighborCacheValid (real_t query_squared_radius) const
 
virtual void AddAgentsToRm (const std::vector< ExecutionContext * > &all_exec_ctxts)
 
virtual void RemoveAgentsFromRm (const std::vector< ExecutionContext * > &all_exec_ctxts)
 

Detailed Description

This execution context derives from InPlaceExecutionContext and replaces the logic when agent updates will be visible to other agents. The remaining implementation is the same as in InPlaceExecutionContext. The CopyExecutionContext creates and updates a copy of an agent. The changes to this copy are committed at the end of the iteration.
Thus, all agents see the same agent state if they read attributes from their neighbors. The value of the neighbor attributes will be from the last iteration.
NB: This execution context does not support neighbor modification, Param::ExecutionOrder::kForEachOpForEachAgent, and agent filter Scheduler::SetAgentFilters.

Definition at line 37 of file copy_execution_context.h.

Constructor & Destructor Documentation

◆ CopyExecutionContext()

bdm::experimental::CopyExecutionContext::CopyExecutionContext ( const std::shared_ptr< ThreadSafeAgentUidMap > &  map,
std::shared_ptr< std::vector< std::vector< Agent * >>>  agents 
)
explicit

Definition at line 38 of file copy_execution_context.cc.

◆ ~CopyExecutionContext()

bdm::experimental::CopyExecutionContext::~CopyExecutionContext ( )
overridedefault

Member Function Documentation

◆ Execute()

void bdm::experimental::CopyExecutionContext::Execute ( Agent agent,
AgentHandle  ah,
const std::vector< Operation * > &  operations 
)
overridevirtual

Execute a series of operations on an agent in the order given in the argument

Implements bdm::ExecutionContext.

Definition at line 87 of file copy_execution_context.cc.

◆ SetupIterationAll()

void bdm::experimental::CopyExecutionContext::SetupIterationAll ( const std::vector< ExecutionContext * > &  all_exec_ctxts)
overridevirtual

This function is called at the beginning of each iteration to setup all execution contexts. This function is not thread-safe. NB: Invalidates references and pointers to agents.

Implements bdm::ExecutionContext.

Definition at line 58 of file copy_execution_context.cc.

◆ TearDownAgentOpsAll()

void bdm::experimental::CopyExecutionContext::TearDownAgentOpsAll ( const std::vector< ExecutionContext * > &  all_exec_ctxts)
overridevirtual

This function is called after all agent operations were executed.
This function is not thread-safe.
NB: Invalidates references and pointers to agents.

Implements bdm::ExecutionContext.

Definition at line 77 of file copy_execution_context.cc.

◆ Use()

void bdm::experimental::CopyExecutionContext::Use ( Simulation sim)
static

Use the CopyExecutionContext for simulation sim.

Definition at line 24 of file copy_execution_context.cc.

Member Data Documentation

◆ agents_

std::shared_ptr<std::vector<std::vector<Agent*> > > bdm::experimental::CopyExecutionContext::agents_
protected

Pointer container for all agents shared between all CopyExecutionContext instances of a simulation.

Definition at line 60 of file copy_execution_context.h.


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