OpenMPCD
Uniform0e1i.hpp
Go to the documentation of this file.
1 /**
2  * @file
3  * Defines the `OpenMPCD::CUDA::Random::Distributions::Uniform0e1i` class.
4  */
5 
6 #ifndef OPENMPCD_CUDA_RANDOM_DISTRIBUTIONS_UNIFORM0E1I_HPP
7 #define OPENMPCD_CUDA_RANDOM_DISTRIBUTIONS_UNIFORM0E1I_HPP
8 
12 
13 
14 namespace OpenMPCD
15 {
16 namespace CUDA
17 {
18 namespace Random
19 {
20 
21 /**
22  * Distributions for the generation of random numbers.
23  */
24 namespace Distributions
25 {
26 
27 /**
28  * The uniform distribution in the left-open interval \f$ (0, 1] \f$.
29  *
30  * The value \f$ 0 \f$ does not lie within the range of possible values, but
31  * \f$ 1 \f$ does.
32  *
33  * @tparam T The underlying data type, which must be `float` or `double`.
34  */
35 template<typename T>
37 {
38 public:
39  /**
40  * Generates a random value sampled from the distribution.
41  *
42  * @tparam RNG The random number generator type.
43  *
44  * @param[in] rng The random number generator instance.
45  */
46  template<typename RNG>
48  T operator()(RNG& rng) const;
49 
50  /**
51  * Generates two random values sampled from the distribution.
52  *
53  * @tparam RNG The random number generator type.
54  *
55  * @param[in] rng
56  * The random number generator instance.
57  * @param[out] r1
58  * Pointer to where the first random number should be stored;
59  * must not be `nullptr`.
60  * @param[out] r2
61  * Pointer to where the second random number should be stored;
62  * must not be `nullptr`.
63  */
64  template<typename RNG>
66  void operator()(RNG& rng, T* const r1, T* const r2) const;
67 }; //class Uniform0e1i
68 
69 ///@cond
70 template<> template<typename RNG>
72 float Uniform0e1i<float>::operator()(RNG& rng) const
73 {
74  return curand_uniform(rng.getState());
75 }
76 
77 template<> template<typename RNG>
79 double Uniform0e1i<double>::operator()(RNG& rng) const
80 {
81  return curand_uniform_double(rng.getState());
82 }
83 
84 
85 template<typename T> template<typename RNG>
88  RNG& rng, T* const r1, T* const r2) const
89 {
90  OPENMPCD_DEBUG_ASSERT(r1 != NULL);
91  OPENMPCD_DEBUG_ASSERT(r2 != NULL);
92 
93  *r1 = operator()(rng);
94  *r2 = operator()(rng);
95 }
96 
97 template<> template<>
99 void Uniform0e1i<double>::operator()<Generators::Philox4x32_10>(
100  Generators::Philox4x32_10& rng, double* const r1, double* const r2) const
101 {
102  OPENMPCD_DEBUG_ASSERT(r1 != NULL);
103  OPENMPCD_DEBUG_ASSERT(r2 != NULL);
104 
105  const double2 result = curand_uniform2_double(rng.getState());
106  *r1 = result.x;
107  *r2 = result.y;
108 }
109 ///@endcond
110 
111 } //namespace Distributions
112 } //namespace Random
113 } //namespace CUDA
114 } //namespace OpenMPCD
115 
116 
117 #endif //OPENMPCD_CUDA_RANDOM_DISTRIBUTIONS_UNIFORM0E1I_HPP
OpenMPCD::CUDA::Random::Distributions::Uniform0e1i::operator()
OPENMPCD_CUDA_DEVICE T operator()(RNG &rng) const
Generates a random value sampled from the distribution.
OPENMPCD_DEBUG_ASSERT
#define OPENMPCD_DEBUG_ASSERT(assertion)
Asserts that the given expression evaluates to true, but only if OPENMPCD_DEBUG is defined.
Definition: OPENMPCD_DEBUG_ASSERT.hpp:88
OPENMPCD_CUDA_DEVICE
#define OPENMPCD_CUDA_DEVICE
Denotes a function to be callable from a CUDA Device.
Definition: Macros.hpp:25
Philox4x32-10.hpp
OpenMPCD::CUDA::Random::Distributions::Uniform0e1i
The uniform distribution in the left-open interval .
Definition: Uniform0e1i.hpp:36
OpenMPCD::RNG
boost::mt11213b RNG
The random number generator type.
Definition: Types.hpp:18
OPENMPCD_DEBUG_ASSERT.hpp
Macros.hpp