NEST main@f146f75
Loading...
Searching...
No Matches
nest::NodeCollectionComposite Class Reference

Subclass for the composite NodeCollection type. More...

#include <node_collection.h>

Inheritance diagram for nest::NodeCollectionComposite:
[legend]
Collaboration diagram for nest::NodeCollectionComposite:
[legend]

Public Member Functions

 NodeCollectionComposite (const NodeCollectionPrimitive &, size_t, size_t, size_t)
 Create a composite from a primitive, with boundaries and step length.
 NodeCollectionComposite (const NodeCollectionComposite &, size_t, size_t, size_t)
 Creates a new composite from another, with boundaries and step length.
 NodeCollectionComposite (const std::vector< NodeCollectionPrimitive > &)
 Create a composite from a vector of primitives.
 NodeCollectionComposite (const NodeCollectionComposite &)=default
 Composite copy constructor.
std::ostream & print_me (std::ostream &) const override
 Print out the contents of the NodeCollection in a pretty and informative way.
size_t operator[] (const size_t) const override
 Get the node ID in the specified index in the NodeCollection.
NodeCollectionPTR operator+ (NodeCollectionPTR rhs) const override
 Addition operator.
NodeCollectionPTR operator+ (const NodeCollectionPrimitive &rhs) const
bool operator== (const NodeCollectionPTR rhs) const override
const_iterator begin (NodeCollectionPTR=NodeCollectionPTR(nullptr)) const override
 Method to get an iterator representing the beginning of the NodeCollection.
const_iterator thread_local_begin (NodeCollectionPTR=NodeCollectionPTR(nullptr)) const override
 Return iterator stepping from first node on the thread it is called on over nodes on that thread.
const_iterator rank_local_begin (NodeCollectionPTR=NodeCollectionPTR(nullptr)) const override
 Method to get an iterator representing the beginning of the NodeCollection.
const_iterator end (NodeCollectionPTR=NodeCollectionPTR(nullptr)) const override
 Method to get an iterator representing the end of the NodeCollection.
size_t size () const override
 Returns total number of node IDs in the composite.
size_t stride () const override
 Returns the stride between node IDs in the composite.
bool contains (const size_t node_id) const override
 Check if the NodeCollection contains a specified node ID.
NodeCollectionPTR slice (size_t start, size_t end, size_t step=1) const override
 Slices the NodeCollection to the boundaries, with an optional step parameter.
void set_metadata (NodeCollectionMetadataPTR) override
 Sets the metadata of the NodeCollection.
NodeCollectionMetadataPTR get_metadata () const override
 Gets the metadata of the NodeCollection.
bool is_range () const override
bool empty () const override
 Checks if the NodeCollection has no elements.
long get_nc_index (const size_t) const override
 Returns index of node with given node ID in NodeCollection.
bool has_proxies () const override
 Returns whether the NodeCollection contains any nodes with proxies or not.
bool all_connect_as_neurons () const override
 Returns true if all elements connect as neurons.
bool all_connect_as_devices () const override
 Returns true if all elements connect as devices.
Public Member Functions inherited from nest::NodeCollection
 NodeCollection ()
 Initializer gets current fingerprint from the kernel.
virtual ~NodeCollection ()=default
bool valid () const
 Check to see if the fingerprint of the NodeCollection matches that of the kernel.
virtual bool operator!= (NodeCollectionPTR) const
 Check if two NodeCollections are equal.
std::vector< size_t > to_array (const std::string &selection) const
 Method that creates a vector filled with node IDs from the NodeCollection; for debugging.
void get_metadata_status (Dictionary &) const
 Collect metadata into dictionary.
size_t get_first () const
 return the first stored ID (i.e, ID at index zero) inside the NodeCollection
size_t get_last () const
 return the last stored ID inside the NodeCollection

Private Types

typedef size_t(* gid_to_phase_fcn_) (size_t)
 Type for lambda-helper function used by {rank, thread, specific}_local_begin.

Private Member Functions

void merge_parts_ (std::vector< NodeCollectionPrimitive > &parts) const
 Goes through the vector of primitives, merging as much as possible.
std::pair< size_t, size_t > specific_local_begin_ (size_t period, size_t phase, size_t start_part, size_t start_offset, gid_to_phase_fcn_ period_first_node) const
 Abstraction of {rank, thread}_local_begin.
bool valid_idx_ (const size_t part_idx, const size_t element_idx) const
 Return true if part_idx/element_idx pair indicates element of collection.
std::pair< size_t, size_t > find_next_part_ (size_t part_idx, size_t element_idx, size_t n=1) const
 Find next part and offset in it after moving beyond previous part, based on stride.

Static Private Member Functions

static size_t gid_to_vp_ (size_t gid)
 helper for thread_local_begin/compsite_update_indices
static size_t gid_to_rank_ (size_t gid)
 helper for rank_local_begin/compsite_update_indices

Private Attributes

std::vector< NodeCollectionPrimitive > parts_
 Primitives forming composite.
size_t size_
 Total number of node IDs, takes into account slicing.
size_t stride_
 Step length, set when slicing.
size_t first_part_
 Primitive to start at, set when slicing.
size_t first_elem_
 Element to start at, set when slicing.
size_t last_part_
 Last entry of parts_ belonging to sliced NC.
size_t last_elem_
 Last entry of parts_[last_part_] belonging to sliced NC.
bool is_sliced_
 Whether the NodeCollectionComposite is sliced.
std::vector< size_t > cumul_abs_size_
 Cumulative size of parts.
std::vector< size_t > first_in_part_
 Local index to first element in each part when slicing is taken into account, or invalid_index.

Friends

class nc_const_iterator

Additional Inherited Members

Public Types inherited from nest::NodeCollection
using const_iterator = nc_const_iterator
Static Public Member Functions inherited from nest::NodeCollection
static NodeCollectionPTR create (const size_t node_id)
 Create a NodeCollection from a single node ID.
static NodeCollectionPTR create (const Node *node)
 Create a NodeCollection from a single node pointer.
static NodeCollectionPTR create (const std::vector< size_t > &node_ids)
 Create a NodeCollection from an array of node IDs.

Detailed Description

Subclass for the composite NodeCollection type.

The composite type contains a collection of primitives which are not contiguous and homogeneous with each other. If the composite is sliced, it also holds information about what index to start at, one past the index to end at, and the step. The endpoint is one past the last valid node.

Note
To avoid creating copies of Primitives (not sure that saves much), Composite keeps primitives as they are. These are called parts. It then sets markers
Note
  • Any part after first_part_ but before last_part_ will always be in the NC in its entirety.
  • A composite node collection is never empty (in that case it would be replaced with a Primitive. Therefore, there is always at least one part with one element.

Member Typedef Documentation

◆ gid_to_phase_fcn_

typedef size_t(* nest::NodeCollectionComposite::gid_to_phase_fcn_) (size_t)
private

Type for lambda-helper function used by {rank, thread, specific}_local_begin.

Constructor & Destructor Documentation

◆ NodeCollectionComposite() [1/4]

nest::NodeCollectionComposite::NodeCollectionComposite ( const NodeCollectionPrimitive & primitive,
size_t start,
size_t end,
size_t stride )

Create a composite from a primitive, with boundaries and step length.

Let the slicing be given by b:e:s for brevity. Then the elements of the sliced composite will be given by

b, b + s, ..., b + j s < e <=> b, b + s, ..., b + j s ≤ e - 1 <=> j ≤ floor( ( e - 1 - b ) / s )

Since j = 0 is included in the sequence above, the sliced node collection has 1 + floor( ( e - 1 - b ) / s ) elements. Flooring is implemented via integer division.

Parameters
primitivePrimitive to be converted
startOffset in the primitive to begin at.
endOffset in the primitive, one past the node to end at.
stepLength to step in the primitive.

References end(), parts_, and stride().

Referenced by find_next_part_(), NodeCollectionComposite(), NodeCollectionComposite(), operator+(), operator==(), and slice().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ NodeCollectionComposite() [2/4]

nest::NodeCollectionComposite::NodeCollectionComposite ( const NodeCollectionComposite & composite,
size_t start,
size_t end,
size_t stride )

Creates a new composite from another, with boundaries and step length.

This constructor is used only when slicing.

Since we do not allow slicing of sliced node collections with step > 1, the underlying node collections all have step one and we can calculate the size of the sliced node collection as described in the constructor taking a NodeCollectionPrimitive as argument.

Parameters
compositeComposite to slice.
startIndex in the composite to begin at.
endIndex in the composite one past the node to end at.
stepLength to step in the composite.

References begin(), cumul_abs_size_, end(), first_elem_, first_in_part_, first_part_, is_sliced_, last_elem_, last_part_, nc_const_iterator, NodeCollectionComposite(), parts_, size(), size_, stride(), and stride_.

Here is the call graph for this function:

◆ NodeCollectionComposite() [3/4]

nest::NodeCollectionComposite::NodeCollectionComposite ( const std::vector< NodeCollectionPrimitive > & parts)
explicit

Create a composite from a vector of primitives.

Since primitives by definition contain contiguous elements, the size of the composite collection is the sum of the size of its parts.

Parameters
partsVector of primitives.

References cumul_abs_size_, first_elem_, first_in_part_, first_part_, is_sliced_, last_elem_, last_part_, parts_, nest::primitive_sort_op, size_, and stride_.

◆ NodeCollectionComposite() [4/4]

nest::NodeCollectionComposite::NodeCollectionComposite ( const NodeCollectionComposite & )
default

Composite copy constructor.

Parameters
compComposite to be copied.

References end(), and NodeCollectionComposite().

Here is the call graph for this function:

Member Function Documentation

◆ all_connect_as_devices()

bool nest::NodeCollectionComposite::all_connect_as_devices ( ) const
overridevirtual

Returns true if all elements connect as devices.

This includes most devices, but not globally receiving devices, e.g., the volume transmitter.

Note
There are nodes that neither connect as neurons nor devices.

Implements nest::NodeCollection.

References all_connect_as_devices(), and parts_.

Referenced by all_connect_as_devices().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ all_connect_as_neurons()

bool nest::NodeCollectionComposite::all_connect_as_neurons ( ) const
overridevirtual

Returns true if all elements connect as neurons.

This includes neurons with proxies and devices such as the volume transmitter.

Note
There are nodes that neither connect as neurons nor devices.

Implements nest::NodeCollection.

References all_connect_as_neurons(), and parts_.

Referenced by all_connect_as_neurons().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ begin()

NodeCollection::const_iterator nest::NodeCollectionComposite::begin ( NodeCollectionPTR = NodeCollectionPTR(nullptr)) const
inlineoverridevirtual

Method to get an iterator representing the beginning of the NodeCollection.

Returns
an iterator representing the beginning of the NodeCollection

Implements nest::NodeCollection.

References first_elem_, first_part_, nc_const_iterator, and stride_.

Referenced by NodeCollectionComposite(), operator[](), and print_me().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ contains()

bool nest::NodeCollectionComposite::contains ( const size_t node_id) const
inlineoverridevirtual

Check if the NodeCollection contains a specified node ID.

Parameters
node_idnode ID to see if exists in the NodeCollection
Returns
true if the NodeCollection contains the node ID, false otherwise

Implements nest::NodeCollection.

References get_nc_index().

Here is the call graph for this function:

◆ empty()

bool nest::NodeCollectionComposite::empty ( ) const
inlineoverridevirtual

Checks if the NodeCollection has no elements.

Returns
true if the NodeCollection is empty, false otherwise

Implements nest::NodeCollection.

◆ end()

NodeCollection::const_iterator nest::NodeCollectionComposite::end ( NodeCollectionPTR = NodeCollectionPTR(nullptr)) const
inlineoverridevirtual

Method to get an iterator representing the end of the NodeCollection.

Parameters
offsetIndex of element NC that iterator points to
Returns
an iterator representing the end of the NodeCollection, taking offset into account

Implements nest::NodeCollection.

References nest::nc_const_iterator::END, last_elem_, last_part_, and nc_const_iterator.

Referenced by NodeCollectionComposite(), NodeCollectionComposite(), NodeCollectionComposite(), print_me(), rank_local_begin(), slice(), and thread_local_begin().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ find_next_part_()

std::pair< size_t, size_t > nest::NodeCollectionComposite::find_next_part_ ( size_t part_idx,
size_t element_idx,
size_t n = 1 ) const
private

Find next part and offset in it after moving beyond previous part, based on stride.

Parameters
part_idxPart for current iterator position
element_idxElement for current iterator position
nNumber of node collection elements we advance by (ie argument that was passed to to operator+(n))
Returns
New part-offset tuple pointing into new part, or invalid_index tuple.

References NodeCollectionComposite().

Here is the call graph for this function:

◆ get_metadata()

NodeCollectionMetadataPTR nest::NodeCollectionComposite::get_metadata ( ) const
inlineoverridevirtual

Gets the metadata of the NodeCollection.

Returns
A Metadata pointer

Implements nest::NodeCollection.

References parts_.

Referenced by operator+(), and operator+().

Here is the caller graph for this function:

◆ get_nc_index()

long nest::NodeCollectionComposite::get_nc_index ( const size_t ) const
overridevirtual

Returns index of node with given node ID in NodeCollection.

Index here is into the sliced node collection, so that nc[ nc.get_nc_index( gid )].node_id == gid.

Returns
Index of node with given node ID; -1 if node not in NodeCollection.

Implements nest::NodeCollection.

References cumul_abs_size_, first_elem_, first_part_, get_nc_index(), is_sliced_, last_elem_, last_part_, parts_, size(), and stride_.

Referenced by contains(), and get_nc_index().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ gid_to_rank_()

size_t nest::NodeCollectionComposite::gid_to_rank_ ( size_t gid)
staticprivate

helper for rank_local_begin/compsite_update_indices

References gid_to_rank_(), and nest::kernel().

Referenced by nest::nc_const_iterator::advance_local_iter_to_new_part_(), gid_to_rank_(), and rank_local_begin().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ gid_to_vp_()

size_t nest::NodeCollectionComposite::gid_to_vp_ ( size_t gid)
staticprivate

helper for thread_local_begin/compsite_update_indices

References gid_to_vp_(), and nest::kernel().

Referenced by nest::nc_const_iterator::advance_local_iter_to_new_part_(), gid_to_vp_(), and thread_local_begin().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ has_proxies()

bool nest::NodeCollectionComposite::has_proxies ( ) const
overridevirtual

Returns whether the NodeCollection contains any nodes with proxies or not.

Returns
true if any nodes in the NodeCollection have proxies, false otherwise.

Implements nest::NodeCollection.

References has_proxies(), and parts_.

Referenced by has_proxies().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ is_range()

bool nest::NodeCollectionComposite::is_range ( ) const
inlineoverridevirtual

Implements nest::NodeCollection.

◆ merge_parts_()

void nest::NodeCollectionComposite::merge_parts_ ( std::vector< NodeCollectionPrimitive > & parts) const
private

Goes through the vector of primitives, merging as much as possible.

Parameters
partsVector of primitives to be merged.

References merge_parts_().

Referenced by merge_parts_(), operator+(), and operator+().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ operator+() [1/2]

NodeCollectionPTR nest::NodeCollectionComposite::operator+ ( const NodeCollectionPrimitive & rhs) const

References get_metadata(), nest::NodeCollectionPrimitive::get_metadata(), merge_parts_(), operator+(), parts_, and nest::primitive_sort_op.

Here is the call graph for this function:

◆ operator+() [2/2]

NodeCollectionPTR nest::NodeCollectionComposite::operator+ ( NodeCollectionPTR rhs) const
overridevirtual

Addition operator.

Joins this composite with another NodeCollection. The resulting NodeCollection is sorted and merged, and converted to a primitive if possible.

Parameters
rhsNodeCollection to add to this composite
Returns
a NodeCollection pointer to either a primitive or a composite.

Implements nest::NodeCollection.

References get_metadata(), is_sliced_, last_elem_, last_part_, merge_parts_(), NodeCollectionComposite(), operator+(), parts_, nest::primitive_sort_op, stride_, and nest::NodeCollection::valid().

Referenced by operator+(), and operator+().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ operator==()

bool nest::NodeCollectionComposite::operator== ( const NodeCollectionPTR rhs) const
overridevirtual

Implements nest::NodeCollection.

References NodeCollectionComposite(), operator==(), parts_, and size_.

Referenced by operator==().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ operator[]()

size_t nest::NodeCollectionComposite::operator[] ( const size_t ) const
overridevirtual

Get the node ID in the specified index in the NodeCollection.

Parameters
idxIndex in the NodeCollection
Returns
a node ID

Implements nest::NodeCollection.

References begin(), is_sliced_, operator[](), and parts_.

Referenced by operator[]().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ print_me()

std::ostream & nest::NodeCollectionComposite::print_me ( std::ostream & ) const
overridevirtual

Print out the contents of the NodeCollection in a pretty and informative way.

Note
Important for resolution from NodeCollectionPTR to subclasses.

Implements nest::NodeCollection.

References begin(), end(), is_sliced_, nest::kernel(), nest::NodeIDTriple::model_id, nc_const_iterator, nest::NodeIDTriple::node_id, parts_, print_me(), and stride_.

Referenced by print_me().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ rank_local_begin()

NodeCollection::const_iterator nest::NodeCollectionComposite::rank_local_begin ( NodeCollectionPTR = NodeCollectionPTR(nullptr)) const
overridevirtual

Method to get an iterator representing the beginning of the NodeCollection.

Returns
an iterator representing the beginning of the NodeCollection, in an MPI-parallel context.

Implements nest::NodeCollection.

References end(), first_elem_, first_part_, gid_to_rank_(), nest::kernel(), nc_const_iterator, nest::nc_const_iterator::RANK_LOCAL, rank_local_begin(), specific_local_begin_(), and stride_.

Referenced by rank_local_begin().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ set_metadata()

void nest::NodeCollectionComposite::set_metadata ( NodeCollectionMetadataPTR )
inlineoverridevirtual

Sets the metadata of the NodeCollection.

Parameters
metaA Metadata pointer

Implements nest::NodeCollection.

References parts_.

◆ size()

size_t nest::NodeCollectionComposite::size ( ) const
inlineoverridevirtual

Returns total number of node IDs in the composite.

Implements nest::NodeCollection.

References size_.

Referenced by get_nc_index(), NodeCollectionComposite(), slice(), and specific_local_begin_().

Here is the caller graph for this function:

◆ slice()

NodeCollectionPTR nest::NodeCollectionComposite::slice ( size_t start,
size_t end,
size_t stride = 1 ) const
overridevirtual

Slices the NodeCollection to the boundaries, with an optional step parameter.

Note that the boundaries being specified are inclusive.

Parameters
startIndex of the NodeCollection to start at
endOne past the index of the NodeCollection to stop at
strideNumber of places between node IDs to skip. Defaults to 1
Returns
a NodeCollection pointer to the new, sliced NodeCollection.

Implements nest::NodeCollection.

References end(), FULL_LOGGING_ONLY, nest::kernel(), NodeCollectionComposite(), size(), slice(), stride(), and nest::NodeCollection::valid().

Referenced by slice().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ specific_local_begin_()

std::pair< size_t, size_t > nest::NodeCollectionComposite::specific_local_begin_ ( size_t period,
size_t phase,
size_t start_part,
size_t start_offset,
gid_to_phase_fcn_ period_first_node ) const
private

Abstraction of {rank, thread}_local_begin.

Parameters
periodnumber of ranks or virtual processes
phasecalling rank or virtual process
start_partbegin seach in this part of the collection
start_offsetbegin search from this offset in start_part
period_first_nodefunction converting gid to rank or thread
Returns
{ part_index, part_offset } — values are invalid_index if no solution found

References first_in_part_, first_index(), FULL_LOGGING_ONLY, nest::kernel(), last_elem_, last_part_, parts_, size(), specific_local_begin_(), and stride_.

Referenced by rank_local_begin(), specific_local_begin_(), and thread_local_begin().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ stride()

size_t nest::NodeCollectionComposite::stride ( ) const
inlineoverridevirtual

Returns the stride between node IDs in the composite.

Implements nest::NodeCollection.

References stride_.

Referenced by NodeCollectionComposite(), NodeCollectionComposite(), and slice().

Here is the caller graph for this function:

◆ thread_local_begin()

NodeCollection::const_iterator nest::NodeCollectionComposite::thread_local_begin ( NodeCollectionPTR = NodeCollectionPTR(nullptr)) const
overridevirtual

Return iterator stepping from first node on the thread it is called on over nodes on that thread.

Returns
an iterator representing the beginning of the NodeCollection, in a parallel context.

Implements nest::NodeCollection.

References end(), first_elem_, first_part_, gid_to_vp_(), nest::kernel(), nc_const_iterator, specific_local_begin_(), stride_, nest::nc_const_iterator::THREAD_LOCAL, and thread_local_begin().

Referenced by thread_local_begin().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ valid_idx_()

bool nest::NodeCollectionComposite::valid_idx_ ( const size_t part_idx,
const size_t element_idx ) const
inlineprivate

Return true if part_idx/element_idx pair indicates element of collection.

References last_elem_, and last_part_.

◆ nc_const_iterator

friend class nc_const_iterator
friend

Member Data Documentation

◆ cumul_abs_size_

std::vector< size_t > nest::NodeCollectionComposite::cumul_abs_size_
private

Cumulative size of parts.

Referenced by get_nc_index(), NodeCollectionComposite(), and NodeCollectionComposite().

◆ first_elem_

size_t nest::NodeCollectionComposite::first_elem_
private

◆ first_in_part_

std::vector< size_t > nest::NodeCollectionComposite::first_in_part_
private

Local index to first element in each part when slicing is taken into account, or invalid_index.

Referenced by NodeCollectionComposite(), NodeCollectionComposite(), and specific_local_begin_().

◆ first_part_

size_t nest::NodeCollectionComposite::first_part_
private

◆ is_sliced_

bool nest::NodeCollectionComposite::is_sliced_
private

◆ last_elem_

size_t nest::NodeCollectionComposite::last_elem_
private

Last entry of parts_[last_part_] belonging to sliced NC.

Referenced by end(), get_nc_index(), NodeCollectionComposite(), NodeCollectionComposite(), operator+(), specific_local_begin_(), and valid_idx_().

◆ last_part_

size_t nest::NodeCollectionComposite::last_part_
private

Last entry of parts_ belonging to sliced NC.

Referenced by end(), get_nc_index(), NodeCollectionComposite(), NodeCollectionComposite(), operator+(), specific_local_begin_(), and valid_idx_().

◆ parts_

◆ size_

size_t nest::NodeCollectionComposite::size_
private

Total number of node IDs, takes into account slicing.

Referenced by NodeCollectionComposite(), NodeCollectionComposite(), operator==(), and size().

◆ stride_

size_t nest::NodeCollectionComposite::stride_
private

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