BioDynaMo  v1.03.58-27764645
Classes | Public Member Functions | Protected Member Functions | Protected 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 RemoveDiffusionGrid (size_t substance_id)
 
DiffusionGridGetDiffusionGrid (size_t substance_id) const
 Return the diffusion grid which holds the substance of specified id. More...
 
DiffusionGridGetDiffusionGrid (const std::string &substance_name) const
 
template<typename TFunctor >
void ForEachDiffusionGrid (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 ()
 
 BDM_CLASS_DEF_NV (ResourceManager, 2)
 

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...
 
std::unordered_map< uint64_t, DiffusionGrid * > diffusion_grids_
 Maps a diffusion grid ID to the pointer to the diffusion grid. More...
 
ThreadInfothread_info_ = ThreadInfo::GetInstance()
 
TypeIndextype_index_ = nullptr
 
ParallelRemovalAuxData parallel_remove_
 auxiliary data required for parallel agent removal More...
 

Friends

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

Detailed Description

ResourceManager stores agents and diffusion grids 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 52 of file resource_manager.h.

Constructor & Destructor Documentation

◆ ResourceManager() [1/2]

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

Definition at line 54 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 321 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 355 of file resource_manager.h.

◆ AddDiffusionGrid()

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

Definition at line 118 of file resource_manager.h.

◆ BDM_CLASS_DEF_NV()

bdm::ResourceManager::BDM_CLASS_DEF_NV ( ResourceManager  ,
 
)
protected

◆ 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 299 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 291 of file resource_manager.h.

◆ DebugNuma()

void bdm::ResourceManager::DebugNuma ( ) const

◆ EndOfIteration()

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

Definition at line 349 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.

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

Definition at line 206 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 217 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.

◆ ForEachDiffusionGrid()

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

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

Definition at line 176 of file resource_manager.h.

◆ GetAgent() [1/2]

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

Definition at line 110 of file resource_manager.h.

◆ GetAgent() [2/2]

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

Definition at line 102 of file resource_manager.h.

◆ GetAgentHandle()

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

Definition at line 114 of file resource_manager.h.

◆ GetAgentVectorCapacity()

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

Definition at line 579 of file resource_manager.cc.

◆ 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 Caution: using this function in a tight loop will result in a slow simulation. Use GetDiffusionGrid(size_t) in those cases.

Definition at line 157 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.

Definition at line 143 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 184 of file resource_manager.h.

◆ GetTypeIndex()

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

Definition at line 415 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 277 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 60 of file resource_manager.h.

◆ RebuildAgentUidMap()

void bdm::ResourceManager::RebuildAgentUidMap ( )
inline

Definition at line 89 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 383 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.

◆ RemoveDiffusionGrid()

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

Definition at line 131 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 265 of file resource_manager.h.

◆ ResizeAgentUidMap()

void bdm::ResourceManager::ResizeAgentUidMap ( )
inline

Definition at line 337 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 449 of file resource_manager.h.

◆ SimulationBackup

friend class SimulationBackup
friend

Definition at line 444 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 426 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 428 of file resource_manager.h.

◆ diffusion_grids_

std::unordered_map<uint64_t, DiffusionGrid*> bdm::ResourceManager::diffusion_grids_
protected

Maps a diffusion grid ID to the pointer to the diffusion grid.

Definition at line 430 of file resource_manager.h.

◆ parallel_remove_

ParallelRemovalAuxData bdm::ResourceManager::parallel_remove_
protected

auxiliary data required for parallel agent removal

Definition at line 442 of file resource_manager.h.

◆ thread_info_

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

Definition at line 432 of file resource_manager.h.

◆ type_index_

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

Definition at line 434 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 424 of file resource_manager.h.


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