NEST main@caf0ae8
 
Loading...
Searching...
No Matches
nest::SparseNodeArray Class Reference

Sparse representation of local nodes. More...

#include <sparse_node_array.h>

Collaboration diagram for nest::SparseNodeArray:
[legend]

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.
 

Detailed Description

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:

  1. Entries are sorted by strictly increasing node ID (nid).
  2. All entries with index i < split_idx_ belong to the left part of the array, all remaining entries to the right part.
  3. All entries with node ID nid < split_node_id_ belong to the left part of the array, all remaining entries to the right part.
  4. nodes_[0].get_node()->has_proxies() == nodes_[i].get_node()->has_proxies() for 0 <= i < lookup_split_idx_
Note
  • The last invariant simply means that all nodes in the left part of the array have the same value of has_proxies().

Member Typedef Documentation

◆ const_iterator

Constructor & Destructor Documentation

◆ SparseNodeArray()

nest::SparseNodeArray::SparseNodeArray ( )

Create empty sparse node array.

Member Function Documentation

◆ add_local_node()

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.

Here is the call graph for this function:

◆ begin()

SparseNodeArray::const_iterator nest::SparseNodeArray::begin ( ) const
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_().

Here is the caller graph for this function:

◆ clear()

◆ end()

SparseNodeArray::const_iterator nest::SparseNodeArray::end ( ) const
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_().

Here is the caller graph for this function:

◆ get_max_node_id()

size_t nest::SparseNodeArray::get_max_node_id ( ) const
inline

Globally largest node ID.

References global_max_node_id_.

◆ get_node_by_index()

Node * nest::SparseNodeArray::get_node_by_index ( size_t  idx) const
inline

Lookup node based on index into container.

Note
Required for target lookup by HPC synapses.

References nodes_.

◆ get_node_by_node_id()

Node * nest::SparseNodeArray::get_node_by_node_id ( size_t  node_id) const

Return pointer to node or nullptr if node is not local.

Note
The caller is responsible for providing proper proxy-node pointers for non-local nodes.

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_.

Here is the call graph for this function:

◆ is_consistent_()

bool nest::SparseNodeArray::is_consistent_ ( ) const
inlineprivate

References global_max_node_id_, and nodes_.

Referenced by get_node_by_node_id().

Here is the caller graph for this function:

◆ set_max_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.

Note
Must be called by any method adding nodes to the network at end of each batch of nodes added.

References global_max_node_id_, have_split_, local_max_node_id_, and split_node_id_.

◆ size()

size_t nest::SparseNodeArray::size ( ) const
inline

Return size of container.

This is the number of local nodes.

See also
get_max_node_id()

References nodes_.

Member Data Documentation

◆ global_max_node_id_

size_t nest::SparseNodeArray::global_max_node_id_
private

◆ have_split_

bool nest::SparseNodeArray::have_split_
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().

◆ left_scale_

double nest::SparseNodeArray::left_scale_
private

scale factor for left side of array

Referenced by add_local_node(), clear(), and get_node_by_node_id().

◆ left_side_has_proxies_

bool nest::SparseNodeArray::left_side_has_proxies_
private

Proxy status of nodes on left side of array.

Referenced by add_local_node(), and clear().

◆ local_max_node_id_

size_t nest::SparseNodeArray::local_max_node_id_
private

largest local node ID

Referenced by add_local_node(), clear(), get_node_by_node_id(), and set_max_node_id().

◆ local_min_node_id_

size_t nest::SparseNodeArray::local_min_node_id_
private

smallest local node ID

Referenced by add_local_node(), clear(), and get_node_by_node_id().

◆ nodes_

BlockVector< NodeEntry > nest::SparseNodeArray::nodes_
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().

◆ right_scale_

double nest::SparseNodeArray::right_scale_
private

scale factor for right side of array

Referenced by add_local_node(), clear(), and get_node_by_node_id().

◆ split_idx_

size_t nest::SparseNodeArray::split_idx_
private

Array index of first element in right side of array.

Referenced by add_local_node(), clear(), and get_node_by_node_id().

◆ split_node_id_

size_t nest::SparseNodeArray::split_node_id_
private

Globally smallest node ID in right side of array.

  • Is updated by set_max_node_id()
  • Is global_max_node_id_ + 1 as long as right side is empty.

Referenced by clear(), get_node_by_node_id(), and set_max_node_id().


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