OPAL (Object Oriented Parallel Accelerator Library)  2.2.0
OPAL
RNGStream.cpp
Go to the documentation of this file.
1 #include "Sample/RNGStream.h"
2 
3 #include <iostream>
4 
6 unsigned int RNGStream::globalSeed_sm = 42;
7 unsigned int RNGStream::numGlobalInstances_sm = 0;
8 
10  if (globalInstance_sm == NULL)
12 
14  return globalInstance_sm;
15 }
16 
18  return new RNGStream(seed);
19 }
20 
22  if (generator->isGlobal_m) {
24 
25  if (numGlobalInstances_sm == 0) {
26  delete generator;
27  }
28  } else {
29  delete generator;
30  }
31 
32  generator = NULL;
33  return;
34 }
35 
36 void RNGStream::setGlobalSeed(unsigned int seed) {
38 
39  if (globalInstance_sm != NULL)
40  globalInstance_sm->RNGenerator_m.seed(seed);
41 }
42 
43 unsigned int RNGStream::getGlobalSeed() {
44  return globalSeed_sm;
45 }
46 
47 std::mt19937_64 & RNGStream::getGenerator() {
48  return RNGenerator_m;
49 }
RNGStream()
Definition: RNGStream.h:25
int seed
The current random seed.
Definition: Options.cpp:41
static unsigned int numGlobalInstances_sm
Definition: RNGStream.h:40
bool isGlobal_m
Definition: RNGStream.h:42
static RNGStream * globalInstance_sm
Definition: RNGStream.h:38
std::mt19937_64 & getGenerator()
Definition: RNGStream.cpp:47
std::mt19937_64 RNGenerator_m
Definition: RNGStream.h:41
static void setGlobalSeed(unsigned int seed)
Definition: RNGStream.cpp:36
static unsigned int getGlobalSeed()
Definition: RNGStream.cpp:43
static unsigned int globalSeed_sm
Definition: RNGStream.h:39
static void deleteInstance(RNGStream *&generator)
Definition: RNGStream.cpp:21
static RNGStream * getInstance()
Definition: RNGStream.cpp:9