4#include "Kokkos_Macros.hpp"
5#include <Kokkos_Random.hpp>
6#include <common/common.hpp>
7#include <common/traits.hpp>
51 using gen_t =
typename pool_type::generator_type;
52 using Functor =
decltype(functor);
53 static_assert(std::is_invocable_v<Functor, gen_t&> &&
54 !std::is_invocable_v<Functor, gen_t>,
55 "Functor must accept generator by reference only");
57 auto gen = pool.get_state();
58 const auto result = functor(gen);
64#define SAMPLE_RANDOM_VARIABLES(_random_pool_, ...) \
65 auto _generator_state_ = _random_pool_.get_state(); \
67 _random_pool_.free_state(_generator_state_);
78 explicit KPRNG(
size_t _seed = 0);
80 template <FloatingPo
intType T> KOKKOS_INLINE_FUNCTION T
uniform()
const
85 template <FloatingPo
intType T>
86 KOKKOS_INLINE_FUNCTION T
uniform(T a, T b)
const
93 if constexpr (std::is_same_v<T, float>)
97 else if constexpr (std::is_same_v<T, double>)
105 [[deprecated]] [[nodiscard]] Kokkos::View<double*, ComputeSpace>
106 double_uniform(
size_t n_sample,
double a = 0.,
double b = 1.)
const;
108 template <FloatingPo
intType T,
size_t n_r>
111 Kokkos::View<T[n_r], ComputeSpace> A(
"random");
116 template <
size_t n_r>
117 [[deprecated]] KOKKOS_INLINE_FUNCTION std::array<double, n_r>
124 [[nodiscard]] KOKKOS_INLINE_FUNCTION uint64_t
uniform_u(uint64_t a,
129 random_pool, [a, b](
auto& gen) {
return gen.urand64(a, b); });
141 template <
typename random_pool_t,
size_t n_r,
size_t... I>
142 KOKKOS_INLINE_FUNCTION std::array<double, n_r>
144 std::index_sequence<I...> )
const
147 auto generator = pool.get_state();
148 std::array<double, n_r> res = {
149 {(
static_cast<void>(I), generator.drand(0., 1.))...}};
150 pool.free_state(generator);
KOKKOS_INLINE_FUNCTION uint64_t uniform_u(uint64_t a, uint64_t b) const
Definition prng.hpp:124
KOKKOS_INLINE_FUNCTION T uniform() const
Definition prng.hpp:80
KOKKOS_INLINE_FUNCTION T uniform(T a, T b) const
Definition prng.hpp:86
KOKKOS_INLINE_FUNCTION std::array< double, n_r > generate_uniform_impl(random_pool_t pool, std::index_sequence< I... >) const
Definition prng.hpp:143
auto get_seed() const
Definition prng.hpp:134
MC::pool_type pool_type
Definition prng.hpp:75
KPRNG(size_t _seed=0)
Definition prng.cpp:24
pool_type::generator_type generator_type
Definition prng.hpp:76
KOKKOS_INLINE_FUNCTION std::array< double, n_r > double_uniform() const
Definition prng.hpp:118
pool_type random_pool
Definition prng.hpp:132
Kokkos::View< T[n_r], ComputeSpace > random_view() const
Definition prng.hpp:109
std::size_t seed
Definition prng.hpp:140
Namespace that contains classes and structures related to Monte Carlo (MC) simulations.
Definition alias.hpp:15
KOKKOS_INLINE_FUNCTION auto sample_random_variables(const pool_type &pool, auto &&functor)
Definition prng.hpp:44
pool_type get_pool(std::size_t seed=0)
Definition prng.cpp:10
gen_pool_type< Kokkos::DefaultExecutionSpace > pool_type
Definition alias.hpp:40