CASToR
2.0
Tomographic Reconstruction (PET/SPECT/CT)
|
Singleton class that generate a thread-safe random generator number for openMP
As singleton, it can be called from any class requiring RNGs.
More...
#include <sRandomNumberGenerator.hh>
Public Types | |
typedef mt19937 | Engine |
typedef uniform_real_distribution < HPFLTNB > | Distribution |
Public Member Functions | |
int | Initialize (int a_nbThreads, int a_nbExtra) |
Instantiate pseudo random number generators, one per thread by default, and additional extra ones if requested. More... | |
int | Initialize (int64_t a_seed, int a_nbThreads, int a_nbExtra) |
Instantiate pseudo random number generators, one per thread by default, and additional extra ones if requested, starting from the user-provided seed. More... | |
HPFLTNB | GenerateRdmNber () |
Generate a random number for the thread which index is recovered from the OpenMP function. More... | |
HPFLTNB | GenerateExtraRdmNber (int a_nb=0) |
Generate a random number using the specified additional not thread safe random generator, for use in sequential parts of an otherwise multithreaded code. More... | |
Engine & | GetExtraGenerator (int a_nb=0) |
Get the not thread safe additional random generator, for use various sequential parts of an otherwise multithreaded code. More... | |
void | SetVerbose (int a_verboseLevel) |
Set verbosity level. More... | |
Static Public Member Functions | |
static sRandomNumberGenerator * | GetInstance () |
Instanciate the singleton object and Initialize member variables if not already done, return a pointer to this object otherwise. More... | |
Private Member Functions | |
sRandomNumberGenerator () | |
Constructor of sRandomNumberGenerator. Do nothing by default as it is a singleton clasee. More... | |
~sRandomNumberGenerator () | |
Destructor of sRandomNumberGenerator. Do nothing by default. More... | |
sRandomNumberGenerator (sRandomNumberGenerator const &) | |
void | operator= (sRandomNumberGenerator const &) |
Private Attributes | |
int | m_verbose |
vector< Engine > | mp_Engines |
vector< Engine > | mp_extraEngines |
Distribution | mp_Distribution |
int64_t | m_seed |
Static Private Attributes | |
static sRandomNumberGenerator * | mp_Instance = NULL |
Singleton class that generate a thread-safe random generator number for openMP
As singleton, it can be called from any class requiring RNGs.
Definition at line 42 of file sRandomNumberGenerator.hh.
typedef uniform_real_distribution<HPFLTNB> sRandomNumberGenerator::Distribution |
Distribution which produces random floating-point values i, uniformly distributed on the interval [a, b)
Definition at line 64 of file sRandomNumberGenerator.hh.
typedef mt19937 sRandomNumberGenerator::Engine |
Engine using C++11 Mersenne Twister pseudo-random generator of 32-bit numbers
Definition at line 63 of file sRandomNumberGenerator.hh.
|
private |
Constructor of sRandomNumberGenerator. Do nothing by default as it is a singleton clasee.
Definition at line 120 of file sRandomNumberGenerator.hh.
|
private |
Destructor of sRandomNumberGenerator. Do nothing by default.
Definition at line 62 of file sRandomNumberGenerator.cc.
|
private |
HPFLTNB sRandomNumberGenerator::GenerateExtraRdmNber | ( | int | a_nb = 0 | ) |
Generate a random number using the specified additional not thread safe random generator, for use in sequential parts of an otherwise multithreaded code.
a_nb | index of the extra non threaded rng |
Definition at line 253 of file sRandomNumberGenerator.cc.
HPFLTNB sRandomNumberGenerator::GenerateRdmNber | ( | ) |
Generate a random number for the thread which index is recovered from the OpenMP function.
Definition at line 233 of file sRandomNumberGenerator.cc.
sRandomNumberGenerator::Engine & sRandomNumberGenerator::GetExtraGenerator | ( | int | a_nb = 0 | ) |
Get the not thread safe additional random generator, for use various sequential parts of an otherwise multithreaded code.
a_nb | index of the extra non threaded rng |
Definition at line 268 of file sRandomNumberGenerator.cc.
|
inlinestatic |
Instanciate the singleton object and Initialize member variables if not already done, return a pointer to this object otherwise.
Definition at line 53 of file sRandomNumberGenerator.hh.
int sRandomNumberGenerator::Initialize | ( | int | a_nbThreads, |
int | a_nbExtra | ||
) |
Instantiate pseudo random number generators, one per thread by default, and additional extra ones if requested.
a_nbThreads | : number of generators intended for usage in threads (one per thread) |
a_nbExtra | : number of additional generators intended for other usage (not thread safe) |
The generators for each thread and each MPI instance should be independent. The initial seed is generated by the true random generator and used to seed a temporary PRNG, which generates seeds for all final PRNGs. If MPI is used, an additional level of temporary generators is inserted, to ensure randomness.
Definition at line 73 of file sRandomNumberGenerator.cc.
int sRandomNumberGenerator::Initialize | ( | int64_t | a_seed, |
int | a_nbThreads, | ||
int | a_nbExtra | ||
) |
Instantiate pseudo random number generators, one per thread by default, and additional extra ones if requested, starting from the user-provided seed.
a_seed | : initial seed |
a_nbThreads | : number of generators intended for usage in threads (one per thread) |
a_nbExtra | : number of additional generators intended for other usage (not thread safe) |
The generators for each thread and each MPI instance should be independent. The user-provided seed is fed to a temporary PRNG, which generates seeds for all final PRNGs. If MPI is used, an additional level of temporary generators is inserted, to ensure randomness.
Definition at line 152 of file sRandomNumberGenerator.cc.
|
private |
|
inline |
Set verbosity level.
a_verboseLevel |
Definition at line 120 of file sRandomNumberGenerator.hh.
|
private |
Initial seed, that will start the initialization process for all the final pseudo random generators
Definition at line 149 of file sRandomNumberGenerator.hh.
|
private |
Verbosity Level
Definition at line 145 of file sRandomNumberGenerator.hh.
|
private |
Uniform distribution
Definition at line 148 of file sRandomNumberGenerator.hh.
|
private |
Multithreaded of mt199937 Engines (1 by thread)
Definition at line 146 of file sRandomNumberGenerator.hh.
|
private |
Additional non threaded mt199937 Engines if requested
Definition at line 147 of file sRandomNumberGenerator.hh.
|
staticprivate |
Unique instance of the singleton class
Definition at line 144 of file sRandomNumberGenerator.hh.