OPAL (Object Oriented Parallel Accelerator Library)  2021.1.99
OPAL
RNGStream.cpp
Go to the documentation of this file.
1 //
2 // Class RNGStream
3 // This class takes care of RNG generator instances.
4 //
5 // Copyright (c) 2018, Christof Metzger-Kraus, Open Sourcerer
6 // All rights reserved
7 //
8 // This file is part of OPAL.
9 //
10 // OPAL is free software: you can redistribute it and/or modify
11 // it under the terms of the GNU General Public License as published by
12 // the Free Software Foundation, either version 3 of the License, or
13 // (at your option) any later version.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with OPAL. If not, see <https://www.gnu.org/licenses/>.
17 //
18 #include "Sample/RNGStream.h"
19 
20 #include <iostream>
21 
23 unsigned int RNGStream::globalSeed_sm = 42;
24 unsigned int RNGStream::numGlobalInstances_sm = 0;
25 
27  if (globalInstance_sm == NULL)
29 
31  return globalInstance_sm;
32 }
33 
35  return new RNGStream(seed);
36 }
37 
39  if (generator->isGlobal_m) {
41 
42  if (numGlobalInstances_sm == 0) {
43  delete generator;
44  }
45  } else {
46  delete generator;
47  }
48 
49  generator = NULL;
50  return;
51 }
52 
53 void RNGStream::setGlobalSeed(unsigned int seed) {
55 
56  if (globalInstance_sm != NULL)
58 }
59 
60 unsigned int RNGStream::getGlobalSeed() {
61  return globalSeed_sm;
62 }
63 
64 std::mt19937_64 & RNGStream::getGenerator() {
65  return RNGenerator_m;
66 }
int seed
The current random seed.
Definition: Options.cpp:37
static RNGStream * getInstance()
Definition: RNGStream.cpp:26
static void deleteInstance(RNGStream *&generator)
Definition: RNGStream.cpp:38
static unsigned int getGlobalSeed()
Definition: RNGStream.cpp:60
bool isGlobal_m
Definition: RNGStream.h:59
static void setGlobalSeed(unsigned int seed)
Definition: RNGStream.cpp:53
static RNGStream * globalInstance_sm
Definition: RNGStream.h:55
RNGStream()
Definition: RNGStream.h:42
static unsigned int numGlobalInstances_sm
Definition: RNGStream.h:57
std::mt19937_64 RNGenerator_m
Definition: RNGStream.h:58
static unsigned int globalSeed_sm
Definition: RNGStream.h:56
std::mt19937_64 & getGenerator()
Definition: RNGStream.cpp:64