BioDynaMo  v1.05.0-137fdb15
Classes | Public Member Functions | Protected Member Functions | Protected Attributes | Private Member Functions | Private Attributes | Friends | List of all members
bdm::ResourceManager Class Reference

#include <resource_manager.h>

Collaboration diagram for bdm::ResourceManager:
[legend]

Classes

struct  ParallelRemovalAuxData
 

Public Member Functions

 ResourceManager (TRootIOCtor *r)
 
 ResourceManager ()
 
virtual ~ResourceManager ()
 
ResourceManageroperator= (ResourceManager &&other) noexcept
 
void RebuildAgentUidMap ()
 
AgentGetAgent (const AgentUid &uid)
 
AgentGetAgent (AgentHandle ah)
 
AgentHandle GetAgentHandle (const AgentUid &uid)
 
void SwapAgents (std::vector< std::vector< Agent * >> *agents)
 
void AddDiffusionGrid (DiffusionGrid *dgrid)
 
void AddContinuum (Continuum *cm)
 
void RemoveDiffusionGrid (size_t substance_id)
 
void RemoveContinuum (size_t continuum_id)
 
DiffusionGridGetDiffusionGrid (size_t substance_id) const
 
ContinuumGetContinuum (size_t continuum_id) const
 Return the continuum model which holds the substance of specified id. More...
 
DiffusionGridGetDiffusionGrid (const std::string &substance_name) const
 
ContinuumGetContinuum (const std::string &continuum_name) const
 
template<typename TFunctor >
void ForEachDiffusionGrid (TFunctor &&f) const
 
template<typename TFunctor >
void ForEachContinuum (TFunctor &&f) const
 
size_t GetNumAgents (int numa_node=-1) const
 
size_t GetAgentVectorCapacity (int numa_node)
 
virtual void ForEachAgent (const std::function< void(Agent *)> &function, Functor< bool, Agent * > *filter=nullptr)
 
virtual void ForEachAgent (const std::function< void(Agent *, AgentHandle)> &function, Functor< bool, Agent * > *filter=nullptr)
 
virtual void ForEachAgentParallel (Functor< void, Agent * > &function, Functor< bool, Agent * > *filter=nullptr)
 
virtual void ForEachAgentParallel (Operation &op, Functor< bool, Agent * > *filter=nullptr)
 
virtual void ForEachAgentParallel (Functor< void, Agent *, AgentHandle > &function, Functor< bool, Agent * > *filter=nullptr)
 
virtual void ForEachAgentParallel (uint64_t chunk, Functor< void, Agent *, AgentHandle > &function, Functor< bool, Agent * > *filter=nullptr)
 
void Reserve (size_t capacity)
 
uint64_t GrowAgentContainer (size_t additional, size_t numa_node)
 
bool ContainsAgent (const AgentUid &uid) const
 
void ClearAgents ()
 
virtual void LoadBalance ()
 
void DebugNuma () const
 
void AddAgent (Agent *agent, typename AgentHandle::NumaNode_t numa_node=0)
 
void ResizeAgentUidMap ()
 
virtual void EndOfIteration ()
 
virtual void AddAgents (typename AgentHandle::NumaNode_t numa_node, uint64_t offset, const std::vector< Agent * > &new_agents)
 
void RemoveAgent (const AgentUid &uid)
 
void RemoveAgents (const std::vector< std::vector< AgentUid > * > &uids)
 
const TypeIndexGetTypeIndex () const
 

Protected Member Functions

void MarkEnvironmentOutOfSync ()
 

Protected Attributes

AgentUidMap< AgentHandleuid_ah_map_ = AgentUidMap<AgentHandle>(100u)
 Maps an AgentUid to its storage location in agents_
. More...
 
std::vector< std::vector< Agent * > > agents_
 Pointer container for all agents. More...
 
std::vector< std::vector< Agent * > > agents_lb_
 Container used during load balancing. More...
 
ThreadInfothread_info_ = ThreadInfo::GetInstance()
 
TypeIndextype_index_ = nullptr
 
ParallelRemovalAuxData parallel_remove_
 auxiliary data required for parallel agent removal More...
 

Private Member Functions

 BDM_CLASS_DEF_NV (ResourceManager, 2)
 

Private Attributes

std::unordered_map< uint64_t, Continuum * > continuum_models_
 Maps a continuum ID to the pointer to the continuum models. More...
 

Friends

class SimulationBackup
 
std::ostream & operator<< (std::ostream &os, const ResourceManager &rm)
 

Detailed Description

ResourceManager stores agents and continuum models and provides methods to add, remove, and access them. Agents are uniquely identified by their AgentUid, and AgentHandle. An AgentHandle might change during the simulation.

Definition at line 53 of file resource_manager.h.

Constructor & Destructor Documentation

◆ ResourceManager() [1/2]

bdm::ResourceManager::ResourceManager ( TRootIOCtor *  r)
inlineexplicit

Definition at line 55 of file resource_manager.h.

◆ ResourceManager() [2/2]

bdm::ResourceManager::ResourceManager ( )

Definition at line 30 of file resource_manager.cc.

◆ ~ResourceManager()

bdm::ResourceManager::~ResourceManager ( )
virtual

Definition at line 45 of file resource_manager.cc.

Member Function Documentation

◆ AddAgent()

void bdm::ResourceManager::AddAgent ( Agent agent,
typename AgentHandle::NumaNode_t  numa_node = 0 
)
inline

NB: This method is not thread-safe! This function might invalidate agent references pointing into the ResourceManager. AgentPointer are not affected.

Definition at line 393 of file resource_manager.h.

◆ AddAgents()

virtual void bdm::ResourceManager::AddAgents ( typename AgentHandle::NumaNode_t  numa_node,
uint64_t  offset,
const std::vector< Agent * > &  new_agents 
)
inlinevirtual

Adds new_agents to agents_[numa_node]. offset specifies the index at which the first element is inserted. Agents are inserted consecutively. This methos is thread safe only if insertion intervals do not overlap!

Definition at line 427 of file resource_manager.h.

◆ AddContinuum()

void bdm::ResourceManager::AddContinuum ( Continuum cm)
inline

Definition at line 124 of file resource_manager.h.

◆ AddDiffusionGrid()

void bdm::ResourceManager::AddDiffusionGrid ( DiffusionGrid dgrid)
inline

Definition at line 119 of file resource_manager.h.

◆ BDM_CLASS_DEF_NV()

bdm::ResourceManager::BDM_CLASS_DEF_NV ( ResourceManager  ,
 
)
private

◆ ClearAgents()

void bdm::ResourceManager::ClearAgents ( )
inline

Remove all agents NB: This method is not thread-safe! This function invalidates agent references pointing into the ResourceManager. AgentPointer are not affected.

Definition at line 371 of file resource_manager.h.

◆ ContainsAgent()

bool bdm::ResourceManager::ContainsAgent ( const AgentUid uid) const
inline

Returns true if an agent with the given uid is stored in this ResourceManager.

Definition at line 363 of file resource_manager.h.

◆ DebugNuma()

void bdm::ResourceManager::DebugNuma ( ) const

◆ EndOfIteration()

virtual void bdm::ResourceManager::EndOfIteration ( )
inlinevirtual

Definition at line 421 of file resource_manager.h.

◆ ForEachAgent() [1/2]

virtual void bdm::ResourceManager::ForEachAgent ( const std::function< void(Agent *)> &  function,
Functor< bool, Agent * > *  filter = nullptr 
)
inlinevirtual

Call a function for all or a subset of agents in the simulation.

Parameters
functionthat will be called for each agent
filterif specified, function will only be called for agents for which filter(agent) evaluates to true.

/code{.cpp} rm->ForEachAgent([](Agent* a) { std::cout << a->GetUid() << std::endl; }); /endcode

Definition at line 278 of file resource_manager.h.

◆ ForEachAgent() [2/2]

virtual void bdm::ResourceManager::ForEachAgent ( const std::function< void(Agent *, AgentHandle)> &  function,
Functor< bool, Agent * > *  filter = nullptr 
)
inlinevirtual

Definition at line 289 of file resource_manager.h.

◆ ForEachAgentParallel() [1/4]

void bdm::ResourceManager::ForEachAgentParallel ( Functor< void, Agent * > &  function,
Functor< bool, Agent * > *  filter = nullptr 
)
virtual

Call a function for all or a subset of agents in the simulation.

Parameters
functionthat will be called for each agent
filterif specified, function will only be called for agents for which filter(agent) evaluates to true. Function invocations are parallelized.
Uses static scheduling.
See also
ForEachAgent

Definition at line 92 of file resource_manager.cc.

◆ ForEachAgentParallel() [2/4]

void bdm::ResourceManager::ForEachAgentParallel ( Functor< void, Agent *, AgentHandle > &  function,
Functor< bool, Agent * > *  filter = nullptr 
)
virtual

Definition at line 59 of file resource_manager.cc.

◆ ForEachAgentParallel() [3/4]

void bdm::ResourceManager::ForEachAgentParallel ( Operation op,
Functor< bool, Agent * > *  filter = nullptr 
)
virtual

Call an operation for all or a subset of agents in the simulation. Function invocations are parallelized.
Uses static scheduling.

See also
ForEachAgent

Definition at line 98 of file resource_manager.cc.

◆ ForEachAgentParallel() [4/4]

void bdm::ResourceManager::ForEachAgentParallel ( uint64_t  chunk,
Functor< void, Agent *, AgentHandle > &  function,
Functor< bool, Agent * > *  filter = nullptr 
)
virtual

Call a function for all or a subset of agents in the simulation. Function invocations are parallelized.
Uses dynamic scheduling and work stealing. Batch size controlled by chunk.

Parameters
chunknumber of agents that are assigned to a thread (batch size)
See also
ForEachAgent

Definition at line 104 of file resource_manager.cc.

◆ ForEachContinuum()

template<typename TFunctor >
void bdm::ResourceManager::ForEachContinuum ( TFunctor &&  f) const
inline

Execute the given functor for all continuum models /code{.cpp} rm->ForEachContinuum([](Continuum* cm) { ... }); /endcode

Definition at line 246 of file resource_manager.h.

◆ ForEachDiffusionGrid()

template<typename TFunctor >
void bdm::ResourceManager::ForEachDiffusionGrid ( TFunctor &&  f) const
inline

Execute the given functor for all diffusion grids /code{.cpp} rm->ForEachDiffusionGrid([](DiffusionGrid* dgrid) { ... }); /endcode

Definition at line 230 of file resource_manager.h.

◆ GetAgent() [1/2]

Agent* bdm::ResourceManager::GetAgent ( AgentHandle  ah)
inline

Definition at line 111 of file resource_manager.h.

◆ GetAgent() [2/2]

Agent* bdm::ResourceManager::GetAgent ( const AgentUid uid)
inline

Definition at line 103 of file resource_manager.h.

◆ GetAgentHandle()

AgentHandle bdm::ResourceManager::GetAgentHandle ( const AgentUid uid)
inline

Definition at line 115 of file resource_manager.h.

◆ GetAgentVectorCapacity()

size_t bdm::ResourceManager::GetAgentVectorCapacity ( int  numa_node)

Definition at line 579 of file resource_manager.cc.

◆ GetContinuum() [1/2]

Continuum* bdm::ResourceManager::GetContinuum ( const std::string &  continuum_name) const
inline

Return the continuum model which holds the substance of specified name Caution: using this function in a tight loop will result in a slow simulation. Use GetContinuum(size_t) in those cases.

Definition at line 209 of file resource_manager.h.

◆ GetContinuum() [2/2]

Continuum* bdm::ResourceManager::GetContinuum ( size_t  continuum_id) const
inline

Return the continuum model which holds the substance of specified id.

Definition at line 177 of file resource_manager.h.

◆ GetDiffusionGrid() [1/2]

DiffusionGrid* bdm::ResourceManager::GetDiffusionGrid ( const std::string &  substance_name) const
inline

Return the diffusion grid which holds the substance of specified name. Calls back to GetContinuum(std::string) and checks with dynamic_cast if substance_name corresponds to a DiffusionGrid implementation. Caution: using this function in a tight loop will result in a slow simulation. Use GetDiffusionGrid(size_t) in those cases.

Definition at line 195 of file resource_manager.h.

◆ GetDiffusionGrid() [2/2]

DiffusionGrid* bdm::ResourceManager::GetDiffusionGrid ( size_t  substance_id) const
inline

Return the diffusion grid which holds the substance of specified id. Calls back to GetContinuum() to get the continuum model and used a dynamic_cast to check if the implementation is a DiffusionGrid.

Definition at line 165 of file resource_manager.h.

◆ GetNumAgents()

size_t bdm::ResourceManager::GetNumAgents ( int  numa_node = -1) const
inline

Returns the total number of agents if numa_node == -1 Otherwise the number of agents in the specific numa node

Definition at line 254 of file resource_manager.h.

◆ GetTypeIndex()

const TypeIndex* bdm::ResourceManager::GetTypeIndex ( ) const
inline

Definition at line 487 of file resource_manager.h.

◆ GrowAgentContainer()

uint64_t bdm::ResourceManager::GrowAgentContainer ( size_t  additional,
size_t  numa_node 
)
inline

Resize agents_[numa_node] such that it holds current + additional elements after this call. Returns the size after

Definition at line 349 of file resource_manager.h.

◆ LoadBalance()

void bdm::ResourceManager::LoadBalance ( )
virtual

Reorder agents such that, agents are distributed to NUMA nodes. Nearby agents will be moved to the same NUMA node.

Definition at line 239 of file resource_manager.cc.

◆ MarkEnvironmentOutOfSync()

void bdm::ResourceManager::MarkEnvironmentOutOfSync ( )
protected

Adding and removing agents does not immediately reflect in the state of the environment. This function sets a flag in the envrionment such that it is aware of the changes.

Definition at line 588 of file resource_manager.cc.

◆ operator=()

ResourceManager& bdm::ResourceManager::operator= ( ResourceManager &&  other)
inlinenoexcept

Definition at line 61 of file resource_manager.h.

◆ RebuildAgentUidMap()

void bdm::ResourceManager::RebuildAgentUidMap ( )
inline

Definition at line 90 of file resource_manager.h.

◆ RemoveAgent()

void bdm::ResourceManager::RemoveAgent ( const AgentUid uid)
inline

Removes the agent with the given uid.
NB: This method is not thread-safe! This function invalidates agent references pointing into the ResourceManager. AgentPointer are not affected.

Definition at line 455 of file resource_manager.h.

◆ RemoveAgents()

void bdm::ResourceManager::RemoveAgents ( const std::vector< std::vector< AgentUid > * > &  uids)

Definition at line 339 of file resource_manager.cc.

◆ RemoveContinuum()

void bdm::ResourceManager::RemoveContinuum ( size_t  continuum_id)
inline

Definition at line 151 of file resource_manager.h.

◆ RemoveDiffusionGrid()

void bdm::ResourceManager::RemoveDiffusionGrid ( size_t  substance_id)
inline

Definition at line 146 of file resource_manager.h.

◆ Reserve()

void bdm::ResourceManager::Reserve ( size_t  capacity)
inline

Reserves enough memory to hold capacity number of agents for each numa domain.

Definition at line 337 of file resource_manager.h.

◆ ResizeAgentUidMap()

void bdm::ResourceManager::ResizeAgentUidMap ( )
inline

Definition at line 409 of file resource_manager.h.

◆ SwapAgents()

void bdm::ResourceManager::SwapAgents ( std::vector< std::vector< Agent * >> *  agents)

Definition at line 584 of file resource_manager.cc.

Friends And Related Function Documentation

◆ operator<<

std::ostream& operator<< ( std::ostream &  os,
const ResourceManager rm 
)
friend

Definition at line 524 of file resource_manager.h.

◆ SimulationBackup

friend class SimulationBackup
friend

Definition at line 514 of file resource_manager.h.

Member Data Documentation

◆ agents_

std::vector<std::vector<Agent*> > bdm::ResourceManager::agents_
protected

Pointer container for all agents.

Definition at line 498 of file resource_manager.h.

◆ agents_lb_

std::vector<std::vector<Agent*> > bdm::ResourceManager::agents_lb_
protected

Container used during load balancing.

Definition at line 500 of file resource_manager.h.

◆ continuum_models_

std::unordered_map<uint64_t, Continuum*> bdm::ResourceManager::continuum_models_
private

Maps a continuum ID to the pointer to the continuum models.

Definition at line 519 of file resource_manager.h.

◆ parallel_remove_

ParallelRemovalAuxData bdm::ResourceManager::parallel_remove_
protected

auxiliary data required for parallel agent removal

Definition at line 512 of file resource_manager.h.

◆ thread_info_

ThreadInfo* bdm::ResourceManager::thread_info_ = ThreadInfo::GetInstance()
protected

Definition at line 502 of file resource_manager.h.

◆ type_index_

TypeIndex* bdm::ResourceManager::type_index_ = nullptr
protected

Definition at line 504 of file resource_manager.h.

◆ uid_ah_map_

AgentUidMap<AgentHandle> bdm::ResourceManager::uid_ah_map_ = AgentUidMap<AgentHandle>(100u)
protected

Maps an AgentUid to its storage location in agents_
.

Definition at line 496 of file resource_manager.h.


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