75 if(
m_verbose >=3)
Cout(
"sRandomNumberGenerator::Initialize ..."<< endl);
81 std::random_device rd;
87 int mpi_rank_temp = 0;
88 int mpi_size_temp = 0;
89 MPI_Comm_rank(MPI_COMM_WORLD, &mpi_rank_temp);
90 MPI_Comm_size(MPI_COMM_WORLD, &mpi_size_temp);
93 int64_t temp_seed = -1;
102 for (
int p=0; p<mpi_size_temp; p++)
106 Cout(
"sRandomNumberGenerator::Seed for rank " << p <<
" is " <<
m_seed << endl);
111 MPI_Send(&
m_seed, 1, MPI_LONG, p, 0, MPI_COMM_WORLD);
117 MPI_Status* status = NULL;
118 MPI_Recv(&
m_seed, 1, MPI_LONG, 0, 0, MPI_COMM_WORLD, status);
121 MPI_Barrier(MPI_COMM_WORLD);
128 for (
int th=0; th<a_nbThreads; th++)
130 seed = initialGenerator();
131 if (
m_verbose>=3)
Cout(
"sRandomNumberGenerator::Initialize() -> Seed for thread " << th <<
" : " << seed << endl);
135 for(
int ex=0; ex<a_nbExtra; ex++)
137 seed = initialGenerator();
138 if(
m_verbose>=3)
Cout(
"sRandomNumberGenerator::Initialize() - >Seed for additional nonthreaded generator "<<ex<<
" : " << seed << endl);
154 if(
m_verbose >=3)
Cout(
"sRandomNumberGenerator::Initialize with provided seed "<<a_seed<< endl);
161 Cout(
"***** sRandomNumberGenerator::Initialize()-> Error : seed for RNG should be >=0 !" << endl);
169 int mpi_rank_temp = 0;
170 int mpi_size_temp = 0;
171 MPI_Comm_rank(MPI_COMM_WORLD, &mpi_rank_temp);
172 MPI_Comm_size(MPI_COMM_WORLD, &mpi_size_temp);
175 int64_t temp_seed = -1;
181 if (mpi_rank_temp==0)
183 Engine mpi_generator(a_seed);
184 for (
int p=0; p<mpi_size_temp; p++)
188 Cout(
"sRandomNumberGenerator::Seed for rank "<<p<<
" is "<<
m_seed<<
""<< endl);
193 MPI_Send(&
m_seed, 1, MPI_LONG, p, 0, MPI_COMM_WORLD);
199 MPI_Status* status = NULL;
200 MPI_Recv(&
m_seed, 1, MPI_LONG, 0, 0, MPI_COMM_WORLD, status);
202 MPI_Barrier(MPI_COMM_WORLD);
209 for(
int th=0; th<a_nbThreads; th++)
211 seed = initialGenerator();
213 if (
m_verbose>=3)
Cout(
"sRandomNumberGenerator::Initialize() -> Seed for thread " << th <<
" : " << seed << endl);
216 for(
int ex=0; ex<a_nbExtra; ex++)
218 seed = initialGenerator();
220 if (
m_verbose>=3)
Cout(
"sRandomNumberGenerator::Initialize() -> Seed for additional nonthreaded random generator "<<ex<<
" : " << seed << endl);
235 #ifdef CASTOR_VERBOSE
236 if (
m_verbose >=4)
Cout(
"sRandomNumberGenerator::GenerateRdmNber..." << endl);
241 id = omp_get_thread_num();
255 #ifdef CASTOR_VERBOSE
256 if(
m_verbose >=4)
Cout(
"sRandomNumberGenerator::GenerateExtraRdmNber..."<< endl);
270 #ifdef CASTOR_VERBOSE
271 if(
m_verbose >=4)
Cout(
"sRandomNumberGenerator::GetExtraGenerator..."<< endl);
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.
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...
Declaration of class sRandomNumberGenerator.
vector< Engine > mp_Engines
vector< Engine > mp_extraEngines
static sRandomNumberGenerator * mp_Instance
~sRandomNumberGenerator()
Destructor of sRandomNumberGenerator. Do nothing by default.