CASToR  3.2
Tomographic Reconstruction (PET/SPECT/CT)
code/include/management/sRandomNumberGenerator.hh
Go to the documentation of this file.
1 
8 #ifndef SRANDOMNUMBERGENERATOR_HH
9 #define SRANDOMNUMBERGENERATOR_HH 1
10 
11 #include "gVariables.hh"
12 #include "sOutputManager.hh"
13 
20 {
21  // -------------------------------------------------------------------
22  // Constructor & Destructor
23  public:
31  {
32  if (mp_Instance == NULL) mp_Instance = new sRandomNumberGenerator();
33  return mp_Instance;
34  }
35 
36 
37  // -------------------------------------------------------------------
38  // Public member functions
39  public:
40  typedef mt19937 Engine;
41  typedef uniform_real_distribution<HPFLTNB> Distribution;
53  int Initialize(int a_nbThreads, int a_nbExtra);
54 
66  int Initialize(int64_t a_seed, int a_nbThreads, int a_nbExtra);
83  HPFLTNB GenerateExtraRdmNber(int a_nb = 0);
91  Engine& GetExtraGenerator(int a_nb = 0);
97  Engine& GetGenerator();
103  void SetVerbose(int a_verboseLevel) {m_verbose = a_verboseLevel;};
104 
105 
106  // -------------------------------------------------------------------
107  // Private member functions
108  private:
119  // Prevent the compiler generating methods of copy the object :
121  void operator=(sRandomNumberGenerator const&);
122 
123 
124  // -------------------------------------------------------------------
125  // Data members
126  private:
128  int m_verbose;
129  vector<Engine> mp_Engines;
130  vector<Engine> mp_extraEngines;
131  Distribution mp_Distribution;
132  int64_t m_seed;
133 };
134 
135 #endif
136 
static sRandomNumberGenerator * GetInstance()
Instanciate the singleton object and Initialize member variables if not already done, return a pointer to this object otherwise.
Engine & GetExtraGenerator(int a_nb=0)
Get the not thread safe additional random generator, for use various sequential parts of an otherwise...
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.
void SetVerbose(int a_verboseLevel)
Set verbosity level.
This header file is mainly used to declare some macro definitions and all includes needed from the st...
void operator=(sRandomNumberGenerator const &)
Engine & GetGenerator()
Get the random generator for the current thread.
int Initialize(int a_nbThreads, int a_nbExtra)
Instantiate pseudo random number generators, one per thread by default, and additional extra ones if ...
sRandomNumberGenerator()
Constructor of sRandomNumberGenerator. Do nothing by default as it is a singleton clasee...
HPFLTNB GenerateRdmNber()
Generate a random number for the thread which index is recovered from the OpenMP function.
Singleton class that generate a thread-safe random generator number for openMP As singleton...
uniform_real_distribution< HPFLTNB > Distribution
Declaration of class sOutputManager.
~sRandomNumberGenerator()
Destructor of sRandomNumberGenerator. Do nothing by default.