BioDynaMo
v1.05.120-25dc9790
|
#include <in_place_exec_ctxt.h>
Classes | |
struct | ThreadSafeAgentUidMap |
Public Member Functions | |
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 |
Agent * | GetAgent (const AgentUid &uid) override |
const Agent * | GetConstAgent (const AgentUid &uid) override |
Public Member Functions inherited from bdm::ExecutionContext | |
virtual | ~ExecutionContext ()=default |
Protected Member Functions | |
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) |
Protected Attributes | |
std::shared_ptr< ThreadSafeAgentUidMap > | new_agent_map_ |
Lookup table AgentUid -> AgentPointer for new created agents. More... | |
ThreadInfo * | tinfo_ |
std::vector< Agent * > | new_agents_ |
Pointer to new agents. More... | |
std::vector< AgentUid > | remove_ |
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... | |
Private Attributes | |
std::vector< AgentPointer<> > | critical_region_ |
Used to determine which agents must not be updated from different threads. More... | |
std::vector< AgentPointer<> > | critical_region_2_ |
Used to determine which agents must not be updated from different threads. More... | |
std::vector< Spinlock * > | locks_ |
Friends | |
class | Environment |
class | in_place_exec_ctxt_detail::InPlaceExecutionContext_NeighborCacheValidity_Test |
This execution context updates agents in place.
Let's assume we have two agents A, B
in our simulation that we want to update to the next timestep A*, B*
. If we have one thread it will first update A
and afterwards B
and write the updates directly to the same data structure. Therefore, before we start updating B
the array looks like this: A*, B
. B
already observes the updated A
.
Operations in method Execute
are executed in order given by the user. Subsequent operations observe the changes of earlier operations.
In-place updates can lead to race conditions if agents not only modify themselves, but also neighbors. Therefore, a protection mechanism has been added.
Param::thread_safety_mechanism
New agents will only be visible at the next iteration. Definition at line 54 of file in_place_exec_ctxt.h.
|
explicit |
Definition at line 113 of file in_place_exec_ctxt.cc.
|
override |
Definition at line 120 of file in_place_exec_ctxt.cc.
|
overridevirtual |
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
:
or
new_agent | The agent to be added to the simulation |
Implements bdm::ExecutionContext.
Definition at line 232 of file in_place_exec_ctxt.cc.
|
protectedvirtual |
Definition at line 319 of file in_place_exec_ctxt.cc.
|
overridevirtual |
Execute a series of operations on an agent in the order given in the argument
Implements bdm::ExecutionContext.
Definition at line 148 of file in_place_exec_ctxt.cc.
|
overridevirtual |
Applies the lambda lambda
for each neighbor of the given query
agent within the given criteria
. Does not support caching.
Implements bdm::ExecutionContext.
Definition at line 251 of file in_place_exec_ctxt.cc.
|
overridevirtual |
Applies the lambda lambda
for each neighbor of the given query
agent within the given search radius squared_radius
Implements bdm::ExecutionContext.
Definition at line 260 of file in_place_exec_ctxt.cc.
|
overridevirtual |
Applies the lambda lambda
for each neighbor of the given query_position
within the given search radius sqrt(squared_radius)
Implements bdm::ExecutionContext.
Definition at line 290 of file in_place_exec_ctxt.cc.
Implements bdm::ExecutionContext.
Definition at line 300 of file in_place_exec_ctxt.cc.
Implements bdm::ExecutionContext.
Definition at line 311 of file in_place_exec_ctxt.cc.
|
protected |
Check whether or not the neighbors in neighbor_cache_
were queried with the same squared radius (cached_squared_search_radius_
) as currently being queried with (query_squared_radius_
)
Definition at line 237 of file in_place_exec_ctxt.cc.
|
overridevirtual |
Implements bdm::ExecutionContext.
Definition at line 315 of file in_place_exec_ctxt.cc.
|
protectedvirtual |
Definition at line 356 of file in_place_exec_ctxt.cc.
|
overridevirtual |
This function is called before all agent operations are executed.
This function is not thread-safe. NB: Invalidates references and pointers to agents.
Implements bdm::ExecutionContext.
Definition at line 142 of file in_place_exec_ctxt.cc.
|
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 126 of file in_place_exec_ctxt.cc.
|
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 145 of file in_place_exec_ctxt.cc.
|
overridevirtual |
This function is called at the end of each iteration to tear down all execution contexts. This function is not thread-safe.
NB: Invalidates references and pointers to agents.
Implements bdm::ExecutionContext.
Definition at line 133 of file in_place_exec_ctxt.cc.
|
friend |
Definition at line 136 of file in_place_exec_ctxt.h.
|
friend |
Definition at line 138 of file in_place_exec_ctxt.h.
|
protected |
Cache the value of Param::cache_neighbors.
Definition at line 158 of file in_place_exec_ctxt.h.
|
protected |
The radius that was used to cache neighbors in neighbor_cache_
Definition at line 156 of file in_place_exec_ctxt.h.
|
private |
Used to determine which agents must not be updated from different threads.
Definition at line 173 of file in_place_exec_ctxt.h.
|
private |
Used to determine which agents must not be updated from different threads.
Definition at line 175 of file in_place_exec_ctxt.h.
|
private |
Definition at line 177 of file in_place_exec_ctxt.h.
|
protected |
prevent race conditions for cached Agents
Definition at line 152 of file in_place_exec_ctxt.h.
Definition at line 154 of file in_place_exec_ctxt.h.
|
protected |
Lookup table AgentUid -> AgentPointer for new created agents.
Definition at line 140 of file in_place_exec_ctxt.h.
|
protected |
Pointer to new agents.
Definition at line 145 of file in_place_exec_ctxt.h.
|
protected |
Contains unique ids of agents that will be removed at the end of each iteration. AgentUids are separated by numa node.
Definition at line 149 of file in_place_exec_ctxt.h.
|
protected |
Definition at line 142 of file in_place_exec_ctxt.h.