Sparse representation of local nodes. More...
#include <sparse_node_array.h>
Classes | |
| class | NodeEntry |
| Entry representing individual node. More... | |
Public Types | |
| typedef BlockVector< SparseNodeArray::NodeEntry >::const_iterator | const_iterator |
| Iterator inherited from BlockVector. | |
Public Member Functions | |
| SparseNodeArray () | |
| Create empty sparse node array. | |
| size_t | size () const |
| Return size of container. | |
| void | clear () |
| Clear the array. | |
| void | add_local_node (Node &) |
| Add single local node. | |
| void | set_max_node_id (size_t) |
| Set max node ID to maximum in network. | |
| size_t | get_max_node_id () const |
| Globally largest node ID. | |
| Node * | get_node_by_node_id (size_t) const |
| Return pointer to node or nullptr if node is not local. | |
| Node * | get_node_by_index (size_t) const |
| Lookup node based on index into container. | |
| const_iterator | begin () const |
| Constant iterators for safe iteration of SparseNodeArray. | |
| const_iterator | end () const |
Private Member Functions | |
| bool | is_consistent_ () const |
Private Attributes | |
| BlockVector< NodeEntry > | nodes_ |
| stores local node information | |
| size_t | global_max_node_id_ |
| globally largest node ID | |
| size_t | local_min_node_id_ |
| smallest local node ID | |
| size_t | local_max_node_id_ |
| largest local node ID | |
| double | left_scale_ |
| scale factor for left side of array | |
| double | right_scale_ |
| scale factor for right side of array | |
| size_t | split_node_id_ |
| Globally smallest node ID in right side of array. | |
| size_t | split_idx_ |
| Array index of first element in right side of array. | |
| bool | have_split_ |
| Mark whether split has happened during network construction. | |
| bool | left_side_has_proxies_ |
| Proxy status of nodes on left side of array. | |
Sparse representation of local nodes.
SparseNodeArray maps node IDs of thread-local nodes to Node*. It provides a const iterator interface for iteration over all local nodes, lookup by node ID and lookup by numeric index into local nodes. The latter is provided to support HPC synapses using TargetIdentifierIndex representation.
For efficient lookup, all normal nodes (with proxies) need to be created together and all devices need to be created together. It does not matter which are created first. If nodes and devices are created alternatingly, lookup performance may suffer significantly if many devices are present. This mainly affects network connection.
As nodes are added to an initially empty SparseNodeArray, the array tracks whether nodes have proxies or not. Array lookup is split at the point of the first proxy/no-proxy (or no-proxy/proxy) transition between nodes. In the no-proxy region, where all nodes are represented locally, Node IDs are mapped directly to array indices. In the proxy region, they are scaled by 1/n_vp.
To reliably reject requests for node IDs beyond the globally maximal node ID, the latter must be set explicitly. A SparseNodeArray is said to be in consistent state if the global maximal node ID has been set. Once add_local_node() is called, the array is not in consistent state until the global maximal node ID is set again. This is indicated by setting the max_node_id_ == 0. Looking up nodes while the array is not in a consistent state triggers an assertion.
To also support cases in which users alternate creation of nodes with and without proxies or use nodes with special behavior (e.g., MUSIC nodes), we perform a linear search from the estimated location of the node in the array.
The following invariants hold when the array is in consistent state:
| typedef BlockVector<SparseNodeArray::NodeEntry>::const_iterator nest::SparseNodeArray::const_iterator |
Iterator inherited from BlockVector.
| nest::SparseNodeArray::SparseNodeArray | ( | ) |
Create empty sparse node array.
| void nest::SparseNodeArray::add_local_node | ( | Node & | node | ) |
Add single local node.
References nest::Node::get_node_id(), nest::VPManager::get_num_virtual_processes(), global_max_node_id_, nest::Node::has_proxies(), have_split_, nest::kernel(), left_scale_, left_side_has_proxies_, local_max_node_id_, local_min_node_id_, nodes_, right_scale_, split_idx_, and nest::KernelManager::vp_manager.
|
inline |
Constant iterators for safe iteration of SparseNodeArray.
References nodes_.
Referenced by nest::OneToOneBuilder::connect_(), nest::AllToAllBuilder::connect_(), nest::FixedInDegreeBuilder::connect_(), nest::BernoulliBuilder::connect_(), nest::PoissonBuilder::connect_(), nest::SPManager::get_synaptic_elements(), and nest::SimulationManager::update_().
| void nest::SparseNodeArray::clear | ( | ) |
Clear the array.
References global_max_node_id_, have_split_, left_scale_, left_side_has_proxies_, local_max_node_id_, local_min_node_id_, nodes_, right_scale_, split_idx_, and split_node_id_.
|
inline |
References nodes_.
Referenced by nest::OneToOneBuilder::connect_(), nest::AllToAllBuilder::connect_(), nest::FixedInDegreeBuilder::connect_(), nest::BernoulliBuilder::connect_(), nest::PoissonBuilder::connect_(), nest::SPManager::get_synaptic_elements(), and nest::SimulationManager::update_().
|
inline |
Globally largest node ID.
References global_max_node_id_.
|
inline |
Lookup node based on index into container.
References nodes_.
| Node * nest::SparseNodeArray::get_node_by_node_id | ( | size_t | node_id | ) | const |
Return pointer to node or nullptr if node is not local.
References global_max_node_id_, is_consistent_(), left_scale_, local_max_node_id_, local_min_node_id_, nodes_, right_scale_, split_idx_, and split_node_id_.
|
inlineprivate |
References global_max_node_id_, and nodes_.
Referenced by get_node_by_node_id().
| void nest::SparseNodeArray::set_max_node_id | ( | size_t | node_id | ) |
Set max node ID to maximum in network.
This also sets split_node_id_ to max node ID + 1 as long as we have not split.
References global_max_node_id_, have_split_, local_max_node_id_, and split_node_id_.
|
inline |
Return size of container.
This is the number of local nodes.
References nodes_.
|
private |
globally largest node ID
Referenced by add_local_node(), clear(), get_max_node_id(), get_node_by_node_id(), is_consistent_(), and set_max_node_id().
|
private |
Mark whether split has happened during network construction.
False as long as only one kind of neuron has been added.
Referenced by add_local_node(), clear(), and set_max_node_id().
|
private |
scale factor for left side of array
Referenced by add_local_node(), clear(), and get_node_by_node_id().
|
private |
Proxy status of nodes on left side of array.
Referenced by add_local_node(), and clear().
|
private |
largest local node ID
Referenced by add_local_node(), clear(), get_node_by_node_id(), and set_max_node_id().
|
private |
smallest local node ID
Referenced by add_local_node(), clear(), and get_node_by_node_id().
|
private |
stores local node information
Referenced by add_local_node(), begin(), clear(), end(), get_node_by_index(), get_node_by_node_id(), is_consistent_(), and size().
|
private |
scale factor for right side of array
Referenced by add_local_node(), clear(), and get_node_by_node_id().
|
private |
Array index of first element in right side of array.
Referenced by add_local_node(), clear(), and get_node_by_node_id().
|
private |
Globally smallest node ID in right side of array.
Referenced by clear(), get_node_by_node_id(), and set_max_node_id().