CASToR  3.2
Tomographic Reconstruction (PET/SPECT/CT)
Public Types | Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes | Static Private Attributes | List of all members
sRandomNumberGenerator Class Reference

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>

Collaboration diagram for sRandomNumberGenerator:
Collaboration graph

Public Types

typedef mt19937 Engine
 
typedef uniform_real_distribution< HPFLTNBDistribution
 
typedef mt19937 Engine
 
typedef uniform_real_distribution< HPFLTNBDistribution
 

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...
 
EngineGetExtraGenerator (int a_nb=0)
 Get the not thread safe additional random generator, for use various sequential parts of an otherwise multithreaded code. More...
 
EngineGetGenerator ()
 Get the random generator for the current thread. More...
 
void SetVerbose (int a_verboseLevel)
 Set verbosity level. More...
 
int Initialize (int a_nbThreads, int a_nbExtra)
 
int Initialize (int64_t a_seed, int a_nbThreads, int a_nbExtra)
 
HPFLTNB GenerateRdmNber ()
 
HPFLTNB GenerateExtraRdmNber (int a_nb=0)
 
EngineGetExtraGenerator (int a_nb=0)
 
EngineGetGenerator ()
 
void SetVerbose (int a_verboseLevel)
 

Static Public Member Functions

static sRandomNumberGeneratorGetInstance ()
 Instanciate the singleton object and Initialize member variables if not already done, return a pointer to this object otherwise. More...
 
static sRandomNumberGeneratorGetInstance ()
 

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 &)
 
 sRandomNumberGenerator ()
 
 ~sRandomNumberGenerator ()
 
 sRandomNumberGenerator (sRandomNumberGenerator const &)
 
void operator= (sRandomNumberGenerator const &)
 

Private Attributes

int m_verbose
 
vector< Enginemp_Engines
 
vector< Enginemp_extraEngines
 
Distribution mp_Distribution
 
int64_t m_seed
 

Static Private Attributes

static sRandomNumberGeneratormp_Instance = NULL
 

Detailed Description

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 19 of file code/include/management/sRandomNumberGenerator.hh.

Member Typedef Documentation

◆ Distribution [1/2]

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 41 of file code/include/management/sRandomNumberGenerator.hh.

◆ Distribution [2/2]

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 41 of file include/management/sRandomNumberGenerator.hh.

◆ Engine [1/2]

Engine using C++11 Mersenne Twister pseudo-random generator of 32-bit numbers

Definition at line 40 of file include/management/sRandomNumberGenerator.hh.

◆ Engine [2/2]

Engine using C++11 Mersenne Twister pseudo-random generator of 32-bit numbers

Definition at line 40 of file code/include/management/sRandomNumberGenerator.hh.

Constructor & Destructor Documentation

◆ sRandomNumberGenerator() [1/4]

sRandomNumberGenerator::sRandomNumberGenerator ( )
private

Constructor of sRandomNumberGenerator. Do nothing by default as it is a singleton clasee.

Definition at line 103 of file code/include/management/sRandomNumberGenerator.hh.

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

◆ ~sRandomNumberGenerator() [1/2]

sRandomNumberGenerator::~sRandomNumberGenerator ( )
private

Destructor of sRandomNumberGenerator. Do nothing by default.

Definition at line 39 of file code/src/management/sRandomNumberGenerator.cc.

Here is the caller graph for this function:

◆ sRandomNumberGenerator() [2/4]

sRandomNumberGenerator::sRandomNumberGenerator ( sRandomNumberGenerator const &  )
private

◆ sRandomNumberGenerator() [3/4]

sRandomNumberGenerator::sRandomNumberGenerator ( )
private

◆ ~sRandomNumberGenerator() [2/2]

sRandomNumberGenerator::~sRandomNumberGenerator ( )
private

◆ sRandomNumberGenerator() [4/4]

sRandomNumberGenerator::sRandomNumberGenerator ( sRandomNumberGenerator const &  )
private

Member Function Documentation

◆ GenerateExtraRdmNber() [1/2]

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.

Parameters
a_nbindex of the extra non threaded rng
Returns
HPFLTNB random number

Definition at line 230 of file code/src/management/sRandomNumberGenerator.cc.

Here is the caller graph for this function:

◆ GenerateExtraRdmNber() [2/2]

HPFLTNB sRandomNumberGenerator::GenerateExtraRdmNber ( int  a_nb = 0)

◆ GenerateRdmNber() [1/2]

HPFLTNB sRandomNumberGenerator::GenerateRdmNber ( )

Generate a random number for the thread which index is recovered from the OpenMP function.

Returns
a random generated number in [0. ; 1.)
Returns
a random generated number in [0. ; 1.)

Definition at line 210 of file code/src/management/sRandomNumberGenerator.cc.

Here is the caller graph for this function:

◆ GenerateRdmNber() [2/2]

HPFLTNB sRandomNumberGenerator::GenerateRdmNber ( )

◆ GetExtraGenerator() [1/2]

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.

Parameters
a_nbindex of the extra non threaded rng
Returns
HPFLTNB random number

Definition at line 245 of file code/src/management/sRandomNumberGenerator.cc.

◆ GetExtraGenerator() [2/2]

Engine& sRandomNumberGenerator::GetExtraGenerator ( int  a_nb = 0)

◆ GetGenerator() [1/2]

Engine& sRandomNumberGenerator::GetGenerator ( )

◆ GetGenerator() [2/2]

sRandomNumberGenerator::Engine & sRandomNumberGenerator::GetGenerator ( )

Get the random generator for the current thread.

Returns
Engine& random generator

Definition at line 260 of file code/src/management/sRandomNumberGenerator.cc.

Here is the caller graph for this function:

◆ GetInstance() [1/2]

static sRandomNumberGenerator * sRandomNumberGenerator::GetInstance ( )
inlinestatic

Instanciate the singleton object and Initialize member variables if not already done, return a pointer to this object otherwise.

Returns
instance of the sRandomNumberGenerator singleton

Definition at line 30 of file code/include/management/sRandomNumberGenerator.hh.

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

◆ GetInstance() [2/2]

static sRandomNumberGenerator* sRandomNumberGenerator::GetInstance ( )
inlinestatic

Definition at line 30 of file include/management/sRandomNumberGenerator.hh.

Here is the call graph for this function:

◆ Initialize() [1/4]

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.

Parameters
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.

Returns
0 if success, positive value otherwise

Definition at line 50 of file code/src/management/sRandomNumberGenerator.cc.

Here is the caller graph for this function:

◆ Initialize() [2/4]

int sRandomNumberGenerator::Initialize ( int  a_nbThreads,
int  a_nbExtra 
)

◆ Initialize() [3/4]

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.

Parameters
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.

Returns
0 if success, positive value otherwise

Definition at line 129 of file code/src/management/sRandomNumberGenerator.cc.

◆ Initialize() [4/4]

int sRandomNumberGenerator::Initialize ( int64_t  a_seed,
int  a_nbThreads,
int  a_nbExtra 
)

◆ operator=() [1/2]

void sRandomNumberGenerator::operator= ( sRandomNumberGenerator const &  )
private
Here is the caller graph for this function:

◆ operator=() [2/2]

void sRandomNumberGenerator::operator= ( sRandomNumberGenerator const &  )
private

◆ SetVerbose() [1/2]

void sRandomNumberGenerator::SetVerbose ( int  a_verboseLevel)
inline

Set verbosity level.

Parameters
a_verboseLevel

Definition at line 103 of file code/include/management/sRandomNumberGenerator.hh.

Here is the caller graph for this function:

◆ SetVerbose() [2/2]

void sRandomNumberGenerator::SetVerbose ( int  a_verboseLevel)
inline

Definition at line 103 of file include/management/sRandomNumberGenerator.hh.

Here is the call graph for this function:

Member Data Documentation

◆ m_seed

int64_t sRandomNumberGenerator::m_seed
private

Initial seed, that will start the initialization process for all the final pseudo random generators

Definition at line 132 of file code/include/management/sRandomNumberGenerator.hh.

◆ m_verbose

int sRandomNumberGenerator::m_verbose
private

Verbosity Level

Definition at line 128 of file code/include/management/sRandomNumberGenerator.hh.

◆ mp_Distribution

Distribution sRandomNumberGenerator::mp_Distribution
private

Uniform distribution

Definition at line 131 of file code/include/management/sRandomNumberGenerator.hh.

◆ mp_Engines

vector< Engine > sRandomNumberGenerator::mp_Engines
private

Multithreaded of mt199937 Engines (1 by thread)

Definition at line 129 of file code/include/management/sRandomNumberGenerator.hh.

◆ mp_extraEngines

vector< Engine > sRandomNumberGenerator::mp_extraEngines
private

Additional non threaded mt199937 Engines if requested

Definition at line 130 of file code/include/management/sRandomNumberGenerator.hh.

◆ mp_Instance

sRandomNumberGenerator * sRandomNumberGenerator::mp_Instance = NULL
staticprivate

Unique instance of the singleton class

Definition at line 127 of file code/include/management/sRandomNumberGenerator.hh.


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