IPPL (Independent Parallel Particle Layer)
IPPL
Loading...
Searching...
No Matches
Randu.h
Go to the documentation of this file.
1// Struct Randu
2// This struct can be used for sampling uniform distribution function
3// on bounded domain.
4//
5#ifndef IPPL_RANDU_H
6#define IPPL_RANDU_H
7
9#include "Random/Utility.h"
10
11namespace ippl {
12 namespace random {
13
25 template <typename T, unsigned Dim>
26 struct randu {
27 using view_type =
29 using GeneratorPool = typename Kokkos::Random_XorShift64_Pool<>;
30
31 // Output View for the random numbers
33
34 // The GeneratorPool
36
39
48 KOKKOS_INLINE_FUNCTION randu(view_type v_, GeneratorPool rand_pool_, T* rmin_p,
49 T* rmax_p)
50 : v(v_)
51 , rand_pool(rand_pool_) {
52 for (unsigned int i = 0; i < Dim; i++) {
53 rmin[i] = rmin_p[i];
54 rmax[i] = rmax_p[i];
55 }
56 }
57
58 KOKKOS_INLINE_FUNCTION randu(view_type v_, GeneratorPool rand_pool_)
59 : v(v_)
60 , rand_pool(rand_pool_) {
61 for (unsigned int i = 0; i < Dim; i++) {
62 rmin[i] = 0.0;
63 rmax[i] = 1.0;
64 }
65 }
66
72 KOKKOS_INLINE_FUNCTION void operator()(const size_t i) const {
73 // Get a random number state from the pool for the active thread
74 typename GeneratorPool::generator_type rand_gen = rand_pool.get_state();
75
76 for (unsigned d = 0; d < Dim; ++d) {
77 v(i)[d] = rand_gen.drand(rmin[d], rmax[d]);
78 }
79
80 // Give the state back, which will allow another thread to acquire it
81 rand_pool.free_state(rand_gen);
82 }
83 };
84 } // namespace random
85} // namespace ippl
86
87#endif
constexpr unsigned Dim
Definition Archive.h:20
KOKKOS_INLINE_FUNCTION randu(view_type v_, GeneratorPool rand_pool_, T *rmin_p, T *rmax_p)
Constructor for the randu functor.
Definition Randu.h:48
KOKKOS_INLINE_FUNCTION randu(view_type v_, GeneratorPool rand_pool_)
Definition Randu.h:58
typename Kokkos::Random_XorShift64_Pool<> GeneratorPool
Definition Randu.h:29
typename ippl::detail::ViewType< ippl::Vector< double, Dim >, 1 >::view_type view_type
Definition Randu.h:27
GeneratorPool rand_pool
Definition Randu.h:35
view_type v
Definition Randu.h:32
KOKKOS_INLINE_FUNCTION void operator()(const size_t i) const
Operator to generate random numbers.
Definition Randu.h:72