NEST main@caf0ae8
 
Loading...
Searching...
No Matches
random_manager.h
Go to the documentation of this file.
1/*
2 * random_manager.h
3 *
4 * This file is part of NEST.
5 *
6 * Copyright (C) 2004 The NEST Initiative
7 *
8 * NEST is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation, either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * NEST is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with NEST. If not, see <http://www.gnu.org/licenses/>.
20 *
21 */
22
23#ifndef RANDOM_MANAGER_H
24#define RANDOM_MANAGER_H
25
26// Generated includes:
27#include "config.h"
28
29// C++ includes:
30#include <string>
31#include <vector>
32
33// Includes from libnestutil:
34#include "manager_interface.h"
35
36// Includes from nestkernel:
37#include "nest_types.h"
38#include "random_generators.h"
39
40namespace nest
41{
42
50{
51public:
53 ~RandomManager() override;
54
58 void initialize( const bool ) override;
59 void finalize( const bool ) override;
60 void set_status( const Dictionary& ) override;
61 void get_status( Dictionary& ) override;
62
72
85 RngPtr get_vp_synced_rng( size_t tid ) const;
86
93 RngPtr get_vp_specific_rng( size_t tid ) const;
94
100 void check_rng_synchrony() const;
101
109 template < typename RNG_TYPE >
110 void register_rng_type( const std::string& name );
111
112private:
114 std::map< std::string, BaseRandomGeneratorFactory* > rng_types_;
115
117 std::string current_rng_type_;
118
120 std::uint32_t base_seed_;
121
124
126 std::vector< RngPtr > vp_synced_rngs_;
127
129 std::vector< RngPtr > vp_specific_rngs_;
130
132 static const std::string DEFAULT_RNG_TYPE_;
133
135 static const std::uint32_t DEFAULT_BASE_SEED_;
136
138 static const std::uint32_t RANK_SYNCED_SEEDER_;
139
141 static const std::uint32_t THREAD_SYNCED_SEEDER_;
142
144 static const std::uint32_t THREAD_SPECIFIC_SEEDER_;
145};
146
147inline RngPtr
152
153inline RngPtr
155{
156 assert( tid < static_cast< size_t >( vp_specific_rngs_.size() ) );
157 return vp_synced_rngs_[ tid ];
158}
159
160inline RngPtr
162{
163 assert( tid < static_cast< size_t >( vp_specific_rngs_.size() ) );
164 return vp_specific_rngs_[ tid ];
165}
166
167} // namespace nest
168
169#endif /* RANDOM_MANAGER_H */
Dictionary class for interface to Python and C++ API.
Definition dictionary.h:213
Base class for RNG engine wrappers.
Definition random_generators.h:67
Interface for kernel manager classes.
Definition manager_interface.h:46
Manage the kernel's random number generators.
Definition random_manager.h:50
std::map< std::string, BaseRandomGeneratorFactory * > rng_types_
Available RNG types.
Definition random_manager.h:114
void get_status(Dictionary &) override
Retrieve the status of the manager.
Definition random_manager.cpp:132
std::vector< RngPtr > vp_synced_rngs_
Random number generators synchronized across VPs.
Definition random_manager.h:126
void finalize(const bool) override
Take down manager after operation.
Definition random_manager.cpp:104
RandomManager()
Definition random_manager.cpp:55
static const std::uint32_t DEFAULT_BASE_SEED_
Base seed used by default.
Definition random_manager.h:135
void initialize(const bool) override
Register available RNG types, set default RNG type and create RNGs.
Definition random_manager.cpp:67
RngPtr rank_synced_rng_
Random number generator synchronized across ranks.
Definition random_manager.h:123
std::uint32_t base_seed_
Base seed used when RNGs were last created.
Definition random_manager.h:120
RngPtr get_vp_synced_rng(size_t tid) const
Get VP-synchronized random number generator.
Definition random_manager.h:154
static const std::string DEFAULT_RNG_TYPE_
RNG type used by default.
Definition random_manager.h:132
~RandomManager() override
Definition random_manager.cpp:62
static const std::uint32_t THREAD_SYNCED_SEEDER_
Thread-synchronized seed-sequence initializer component.
Definition random_manager.h:141
void check_rng_synchrony() const
Confirm that rank- and thread-synchronized RNGs are in sync.
Definition random_manager.cpp:184
RngPtr get_rank_synced_rng() const
Get rank-synchronized random number generator.
Definition random_manager.h:148
static const std::uint32_t THREAD_SPECIFIC_SEEDER_
Thread-specific seed-sequence initializer component.
Definition random_manager.h:144
std::string current_rng_type_
Name of currently used RNG type.
Definition random_manager.h:117
void set_status(const Dictionary &) override
Set the status of the manager.
Definition random_manager.cpp:146
void register_rng_type(const std::string &name)
Register new random number generator type with manager.
Definition random_manager.cpp:227
std::vector< RngPtr > vp_specific_rngs_
Random number generators specific to VPs.
Definition random_manager.h:129
RngPtr get_vp_specific_rng(size_t tid) const
Get VP-specific random number generator.
Definition random_manager.h:161
static const std::uint32_t RANK_SYNCED_SEEDER_
Rank-synchronized seed-sequence initializer component.
Definition random_manager.h:138
Namespace for the NEST simulation kernel.
Definition beta_normalization_factor.h:33