VP Manager

The VPManager in NEST coordinates virtual processes (VPs) for parallel execution, distributing computational tasks across threads and MPI ranks. It maps node IDs to VPs, ensures thread safety, and manages MPI rank assignments to enable efficient distributed simulations. The manager provides VP-to-thread and MPI rank conversions to synchronize parallel operations.

class VPManager : public nest::ManagerInterface

Public Functions

virtual void initialize(const bool) override

Prepare manager for operation.

After this method has completed, the manager should be completely initialized and “ready for action”.

See also

finalize()

Note

Initialization of any given manager may depend on other managers having been initialized before. KernelManager::initialize() is responsible for calling the initialization routines on the specific managers in correct order.

Parameters:

adjust_number_of_threads_or_rng_only – Pass true if calling from kernel_manager::change_number_of_threads() or RandomManager::get_status() to limit operations to those necessary for thread adjustment or switch or re-seeding of RNG.

virtual void finalize(const bool) override

Take down manager after operation.

After this method has completed, all dynamic data structures created by the manager shall be deallocated and containers emptied. Plain variables need not be reset.

See also

initialize()

Note

Finalization of any given manager may depend on other managers not having been finalized yet. KernelManager::finalize() is responsible for calling the initialization routines on the specific managers in correct order, i.e., the opposite order of initialize() calls.

Parameters:

adjust_number_of_threads_or_rng_only – Pass true if calling from kernel_manager::change_number_of_threads() to limit operations to those necessary for thread adjustment.

virtual void set_status(const DictionaryDatum&) override

Set the status of the manager.

See also

get_status()

virtual void get_status(DictionaryDatum&) override

Retrieve the status of the manager.

See also

set_status()

Note

This would ideally be a const function. However, some managers delay the update of internal variables up to the point where they are needed (e.g., before reporting their values to the user, or before simulate is called). An example for this pattern is the call to update_delay_extrema_() right at the beginning of ConnectionManager::get_status().

inline size_t get_thread_id() const

Gets ID of local thread.

Returns thread ID if OpenMP is installed and zero otherwise.

void set_num_threads(const size_t n_threads)

Set the number of threads by setting the internal variable n_threads_, the corresponding value in the Communicator, and the OpenMP number of threads.

inline size_t get_num_threads() const

Get number of threads.

This function returns the total number of threads per process.

size_t get_OMP_NUM_THREADS() const

Get OMP_NUM_THREADS environment variable.

Note

Returns 0 if OMP_NUM_THREADS is not set.

inline bool is_node_id_vp_local(const size_t node_id) const

Returns true if the given global node exists on this vp.

inline size_t node_id_to_lid(const size_t node_id) const

Returns thread local index of a given global node.

inline size_t lid_to_node_id(const size_t lid) const

Returns the node ID of a given local index.

inline size_t get_vp() const

Returns virtual process index.

inline size_t node_id_to_vp(const size_t node_id) const

Return a thread number for a given global node id.

Each node has a default thread on which it will run. The thread is defined by the relation: t = (node_id div P) mod T, where P is the number of simulation processes and T the number of threads. This may be used by Network::add_node() if the user has not specified anything.

inline size_t vp_to_thread(const size_t vp) const

Convert a given VP ID to the corresponding thread ID.

inline size_t thread_to_vp(const size_t tid) const

Convert a given thread ID to the corresponding VP ID.

inline bool is_local_vp(const size_t tid) const

Return true, if the given VP is on the local machine.

inline size_t get_num_virtual_processes() const

Returns the number of virtual processes.

inline void assert_single_threaded() const

Fails if NEST is in thread-parallel section.

inline void assert_thread_parallel() const

Fails if NEST is not in thread-parallel section.

inline size_t get_num_assigned_ranks_per_thread() const

Returns the number of processes that are taken care of by a single thread while processing MPI buffers in a multithreaded environment.

inline AssignedRanks get_assigned_ranks(const size_t tid)

Returns assigned ranks per thread to fill MPI buffers.

Thread tid is responsible for all ranks in [assigned_ranks.begin, assigned_ranks.end), which are in total assigned_ranks.size and at most assigned_ranks.max_size