Random Manager¶
The RandomManager in NEST provides three RNG types (rank-synchronized, VP-synchronized, VP-specific) to manage parallel random number generation, ensuring reproducibility and thread safety. It supports various algorithms (e.g., Mersenne Twister, Philox) and allows configuration of seeds and types, initializing RNGs with unique seeds derived from base values and seeder constants for consistent yet independent streams across processes and threads.
-
class RandomManager : public nest::ManagerInterface¶
Manage the kernel’s random number generators.
This manager provides one random number generator per thread plus the global RNG. It also handles selection of RNG type and seeding.
Public Functions
-
virtual void initialize(const bool) override¶
Register available RNG types, set default RNG type and create RNGs.
-
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
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
-
virtual void get_status(DictionaryDatum&) override¶
Retrieve the status of the manager.
See also
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 RngPtr get_rank_synced_rng() const¶
Get rank-synchronized random number generator.
The rank-synchronized generator provides identical random number sequences on all MPI ranks. It may be used only by the master thread on each rank and must be used in lock-step across all ranks. Synchronization is checked by MPI exchange at certain points during a simulation.
-
inline RngPtr get_vp_synced_rng(size_t tid) const¶
Get VP-synchronized random number generator.
The kernel maintains one instance of a synchronized random number generator for each thread (and thus, across ranks, for each VP). The purpose of these synchronized generators is to provide identical random number sequences on each VP while VPs execute in parallel. All VPs (ie all threads on all ranks) must use the generators in lock-step to maintain synchrony. Synchronization is checked by MPI exchange at certain points during a simulation.
- Parameters:
tid – ID of thread requesting generator
-
inline RngPtr get_vp_specific_rng(size_t tid) const¶
Get VP-specific random number generator.
Each VP (thread) can use this RNG freely and will receive an independent random number sequence.
-
void check_rng_synchrony() const¶
Confirm that rank- and thread-synchronized RNGs are in sync.
- Throws:
KernelException – if RNGs are out of sync.
-
template<typename RNG_TYPE>
void register_rng_type(const std::string &name)¶ Register new random number generator type with manager.
This allows NEST modules to add new RNG types.
- Parameters:
RNG_TYPE – Class fulfilling requirements of C++ RNG.
-
virtual void initialize(const bool) override¶