10 #include "sRandomNumberGenerator.hh" 52 if(
m_verbose >=3)
Cout(
"sRandomNumberGenerator::Initialize ..."<< endl);
58 std::random_device rd;
64 int mpi_rank_temp = 0;
65 int mpi_size_temp = 0;
66 MPI_Comm_rank(MPI_COMM_WORLD, &mpi_rank_temp);
67 MPI_Comm_size(MPI_COMM_WORLD, &mpi_size_temp);
70 int64_t temp_seed = -1;
79 for (
int p=0; p<mpi_size_temp; p++)
83 Cout(
"sRandomNumberGenerator::Seed for rank " << p <<
" is " <<
m_seed << endl);
88 MPI_Send(&
m_seed, 1, MPI_LONG, p, 0, MPI_COMM_WORLD);
94 MPI_Status* status = NULL;
95 MPI_Recv(&
m_seed, 1, MPI_LONG, 0, 0, MPI_COMM_WORLD, status);
98 MPI_Barrier(MPI_COMM_WORLD);
105 for (
int th=0; th<a_nbThreads; th++)
107 seed = initialGenerator();
108 if (
m_verbose>=3)
Cout(
"sRandomNumberGenerator::Initialize() -> Seed for thread " << th <<
" : " << seed << endl);
112 for(
int ex=0; ex<a_nbExtra; ex++)
114 seed = initialGenerator();
115 if(
m_verbose>=3)
Cout(
"sRandomNumberGenerator::Initialize() - >Seed for additional nonthreaded generator "<<ex<<
" : " << seed << endl);
131 if(
m_verbose >=3)
Cout(
"sRandomNumberGenerator::Initialize with provided seed "<<a_seed<< endl);
138 Cout(
"***** sRandomNumberGenerator::Initialize()-> Error : seed for RNG should be >=0 !" << endl);
146 int mpi_rank_temp = 0;
147 int mpi_size_temp = 0;
148 MPI_Comm_rank(MPI_COMM_WORLD, &mpi_rank_temp);
149 MPI_Comm_size(MPI_COMM_WORLD, &mpi_size_temp);
152 int64_t temp_seed = -1;
158 if (mpi_rank_temp==0)
160 Engine mpi_generator(a_seed);
161 for (
int p=0; p<mpi_size_temp; p++)
165 Cout(
"sRandomNumberGenerator::Seed for rank "<<p<<
" is "<<
m_seed<<
""<< endl);
170 MPI_Send(&
m_seed, 1, MPI_LONG, p, 0, MPI_COMM_WORLD);
176 MPI_Status* status = NULL;
177 MPI_Recv(&
m_seed, 1, MPI_LONG, 0, 0, MPI_COMM_WORLD, status);
179 MPI_Barrier(MPI_COMM_WORLD);
186 for(
int th=0; th<a_nbThreads; th++)
188 seed = initialGenerator();
190 if (
m_verbose>=3)
Cout(
"sRandomNumberGenerator::Initialize() -> Seed for thread " << th <<
" : " << seed << endl);
193 for(
int ex=0; ex<a_nbExtra; ex++)
195 seed = initialGenerator();
197 if (
m_verbose>=3)
Cout(
"sRandomNumberGenerator::Initialize() -> Seed for additional nonthreaded random generator "<<ex<<
" : " << seed << endl);
212 #ifdef CASTOR_VERBOSE 213 if (
m_verbose >=4)
Cout(
"sRandomNumberGenerator::GenerateRdmNber..." << endl);
218 id = omp_get_thread_num();
232 #ifdef CASTOR_VERBOSE 233 if(
m_verbose >=4)
Cout(
"sRandomNumberGenerator::GenerateExtraRdmNber..."<< endl);
247 #ifdef CASTOR_VERBOSE 248 if(
m_verbose >=4)
Cout(
"sRandomNumberGenerator::GetExtraGenerator..."<< endl);
262 #ifdef CASTOR_VERBOSE 263 if(
m_verbose >=4)
Cout(
"sRandomNumberGenerator::GetGenerator..."<< endl);
268 id = omp_get_thread_num();
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.
vector< Engine > mp_Engines
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 ...
Distribution mp_Distribution
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...
vector< Engine > mp_extraEngines
static sRandomNumberGenerator * mp_Instance
~sRandomNumberGenerator()
Destructor of sRandomNumberGenerator. Do nothing by default.