CASToR  2.0
Tomographic Reconstruction (PET/SPECT/CT)
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
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-2018 all CASToR contributors listed below:
18 
19  --> current contributors: Thibaut MERLIN, Simon STUTE, Didier BENOIT, Claude COMTAT, Marina FILIPOVIC, Mael MILLARDET
20  --> past contributors: Valentin VIELZEUF
21 
22 This is CASToR version 2.0.
23 */
24 
31 #ifndef SRANDOMNUMBERGENERATOR_HH
32 #define SRANDOMNUMBERGENERATOR_HH 1
33 
34 #include "gVariables.hh"
35 #include "sOutputManager.hh"
36 
43 {
44  // -------------------------------------------------------------------
45  // Constructor & Destructor
46  public:
54  {
55  if (mp_Instance == NULL) mp_Instance = new sRandomNumberGenerator();
56  return mp_Instance;
57  }
58 
59 
60  // -------------------------------------------------------------------
61  // Public member functions
62  public:
63  typedef mt19937 Engine;
64  typedef uniform_real_distribution<HPFLTNB> Distribution;
76  int Initialize(int a_nbThreads, int a_nbExtra);
77 
89  int Initialize(int64_t a_seed, int a_nbThreads, int a_nbExtra);
106  HPFLTNB GenerateExtraRdmNber(int a_nb = 0);
114  Engine& GetExtraGenerator(int a_nb = 0);
120  void SetVerbose(int a_verboseLevel) {m_verbose = a_verboseLevel;};
121 
122 
123  // -------------------------------------------------------------------
124  // Private member functions
125  private:
136  // Prevent the compiler generating methods of copy the object :
138  void operator=(sRandomNumberGenerator const&);
139 
140 
141  // -------------------------------------------------------------------
142  // Data members
143  private:
145  int m_verbose;
146  vector<Engine> mp_Engines;
147  vector<Engine> mp_extraEngines;
149  int64_t m_seed;
150 };
151 
152 #endif
153 
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.