CASToR  3.0
Tomographic Reconstruction (PET/SPECT/CT)
sRandomNumberGenerator.hh
Go to the documentation of this file.
1 /*
2 This file is part of CASToR.
3 
4  CASToR is free software: you can redistribute it and/or modify it under the
5  terms of the GNU General Public License as published by the Free Software
6  Foundation, either version 3 of the License, or (at your option) any later
7  version.
8 
9  CASToR is distributed in the hope that it will be useful, but WITHOUT ANY
10  WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11  FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
12  details.
13 
14  You should have received a copy of the GNU General Public License along with
15  CASToR (in file GNU_GPL.TXT). If not, see <http://www.gnu.org/licenses/>.
16 
17 Copyright 2017-2019 all CASToR contributors listed below:
18 
19  --> Didier BENOIT, Claude COMTAT, Marina FILIPOVIC, Thibaut MERLIN, Mael MILLARDET, Simon STUTE, Valentin VIELZEUF
20 
21 This is CASToR version 3.0.
22 */
23 
30 #ifndef SRANDOMNUMBERGENERATOR_HH
31 #define SRANDOMNUMBERGENERATOR_HH 1
32 
33 #include "gVariables.hh"
34 #include "sOutputManager.hh"
35 
42 {
43  // -------------------------------------------------------------------
44  // Constructor & Destructor
45  public:
53  {
54  if (mp_Instance == NULL) mp_Instance = new sRandomNumberGenerator();
55  return mp_Instance;
56  }
57 
58 
59  // -------------------------------------------------------------------
60  // Public member functions
61  public:
62  typedef mt19937 Engine;
63  typedef uniform_real_distribution<HPFLTNB> Distribution;
75  int Initialize(int a_nbThreads, int a_nbExtra);
76 
88  int Initialize(int64_t a_seed, int a_nbThreads, int a_nbExtra);
105  HPFLTNB GenerateExtraRdmNber(int a_nb = 0);
113  Engine& GetExtraGenerator(int a_nb = 0);
119  void SetVerbose(int a_verboseLevel) {m_verbose = a_verboseLevel;};
120 
121 
122  // -------------------------------------------------------------------
123  // Private member functions
124  private:
135  // Prevent the compiler generating methods of copy the object :
137  void operator=(sRandomNumberGenerator const&);
138 
139 
140  // -------------------------------------------------------------------
141  // Data members
142  private:
144  int m_verbose;
145  vector<Engine> mp_Engines;
146  vector<Engine> mp_extraEngines;
147  Distribution mp_Distribution;
148  int64_t m_seed;
149 };
150 
151 #endif
152 
This header file is mainly used to declare some macro definitions and all includes needed from the st...
static sRandomNumberGenerator * GetInstance()
Instanciate the singleton object and Initialize member variables if not already done, return a pointer to this object otherwise.
#define HPFLTNB
Definition: gVariables.hh:83
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.
void operator=(sRandomNumberGenerator const &)
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.
static sRandomNumberGenerator * mp_Instance
~sRandomNumberGenerator()
Destructor of sRandomNumberGenerator. Do nothing by default.