Evolutionary Algorithm for Adaptive Phase Estimation  1.0.2
rng.h
1 #ifndef RNG_H
2 #define RNG_H
3 #if HAVE_CONFIG_H
4 #include <config.h>
5 #endif
6 #ifdef CUDA
7 #include <curand.h>
8 #endif
9 
10 using namespace std;
11 
16 class RngBase {
17  public:
18  RngBase(bool _gaussian): gaussian(_gaussian) {};
19  ~RngBase() {};
20  double next_rand(const double mean, const double dev) {
21  return 0.0;
22  };
23 
24  protected:
25  bool gaussian;
26  };
27 
31 class RngSimple: public RngBase {
32  public:
33  RngSimple(bool _gaussian, int n_random_numbers, int seed, int rank);
34  ~RngSimple();
35  double next_rand(const double mean, const double dev);
36  };
37 
42 class RngVectorized: public RngBase {
43  public:
44  RngVectorized(bool _gaussian): RngBase(_gaussian) {};
45  ~RngVectorized() {};
46  double next_rand(const double mean, const double dev);
47  };
48 
49 #ifdef CUDA
50 
53 class RngGpu: public RngVectorized {
54  public:
55  RngGpu(bool _gaussian, int n_random_numbers, int seed, int rank);
56  ~RngGpu();
57  double next_rand(const double mean, const double dev);
58 
59  private:
60  double *random_numbers;
61  int n_random_numbers;
62  int index_random_numbers;
63 
64  double *dev_random_numbers;
65  curandGenerator_t gen;
66  };
67 
68 #define Rng RngGpu
69 
70 #elif defined(VSL)
71 
75 class RngVsl: public RngVectorized {
76  public:
77  RngVsl(bool _gaussian, int n_random_numbers, int seed, int rank);
78  ~RngVsl();
79  double next_rand(const double mean, const double dev);
80 
81  private:
82  double *random_numbers;
83  int n_random_numbers;
84  int index_random_numbers;
85  };
86 #define Rng RngVsl
87 
88 #else
89 
90 #define Rng RngSimple
91 
92 #endif
93 
94 #endif // RNG_H
Rng class store methods for generating random numbers using RngBase as its base class....
Definition: rng.h:16
RngVectorized generates random numbers into vectors in order to reduce the computational overhead....
Definition: rng.h:42
RngSimple generates random numbers from C++ build-in pseudo-random number generator.
Definition: rng.h:31