4#include "Kokkos_Macros.hpp"
5#include <Kokkos_Random.hpp>
6#include <common/common.hpp>
7#include <common/traits.hpp>
47 KOKKOS_INLINE_FUNCTION
auto
54 using gen_t =
typename pool_type::generator_type;
55 using Functor =
decltype(functor);
56 static_assert(std::is_invocable_v<Functor, gen_t&>
57 && !std::is_invocable_v<Functor, gen_t>,
58 "Functor must accept generator by reference only");
60 auto gen = pool.get_state();
61 const auto result = functor(gen);
67#define SAMPLE_RANDOM_VARIABLES(_random_pool_, ...) \
68 auto _generator_state_ = _random_pool_.get_state(); \
70 _random_pool_.free_state(_generator_state_);
88 template <
class Archive>
98 template <
class Archive>
107 template <FloatingPo
intType T>
108 KOKKOS_INLINE_FUNCTION T
114 template <FloatingPo
intType T>
115 KOKKOS_INLINE_FUNCTION T
123 if constexpr (std::is_same_v<T, float>)
127 else if constexpr (std::is_same_v<T, double>)
135 [[deprecated]] [[nodiscard]] Kokkos::View<double*, ComputeSpace>
136 double_uniform(
size_t n_sample,
double a = 0.,
double b = 1.)
const;
138 template <FloatingPo
intType T,
size_t n_r>
139 Kokkos::View<T[n_r], ComputeSpace>
142 Kokkos::View<T[n_r], ComputeSpace> A(
"random");
147 template <
size_t n_r>
148 [[deprecated]] KOKKOS_INLINE_FUNCTION std::array<double, n_r>
155 [[nodiscard]] KOKKOS_INLINE_FUNCTION uint64_t
160 random_pool, [a, b](
auto& gen) {
return gen.urand64(a, b); });
173 template <
typename random_pool_t,
size_t n_r,
size_t... I>
174 KOKKOS_INLINE_FUNCTION std::array<double, n_r>
176 std::index_sequence<I...> )
const
179 auto generator = pool.get_state();
180 std::array<double, n_r> res
181 = { { (
static_cast<void>(I), generator.drand(0., 1.))... } };
182 pool.free_state(generator);
187 template <
class ExecutionSpace,
190 class IndexType = int64_t,
191 const std::size_t CHUNK_SIZE>
196 typename ViewType::const_value_type begin,
197 typename ViewType::const_value_type end)
199 int64_t LDA = a.extent(0);
203 Kokkos::parallel_for(
204 "Kokkos::fill_random",
205 Kokkos::RangePolicy<ExecutionSpace>(
206 exec, 0, (LDA + (CHUNK_SIZE - 1)) / CHUNK_SIZE),
207 Kokkos::Impl::fill_random_functor_begin_end<ViewType,
KOKKOS_INLINE_FUNCTION uint64_t uniform_u(uint64_t a, uint64_t b) const
Definition prng.hpp:156
KOKKOS_INLINE_FUNCTION T uniform() const
Definition prng.hpp:109
KOKKOS_INLINE_FUNCTION T uniform(T a, T b) const
Definition prng.hpp:116
KOKKOS_INLINE_FUNCTION std::array< double, n_r > generate_uniform_impl(random_pool_t pool, std::index_sequence< I... >) const
Definition prng.hpp:175
auto get_seed() const
Definition prng.hpp:166
MC::pool_type pool_type
Definition prng.hpp:78
void load(Archive &ar)
Load data from ar for deserialization.
Definition prng.hpp:100
pool_type::generator_type generator_type
Definition prng.hpp:79
KOKKOS_INLINE_FUNCTION std::array< double, n_r > double_uniform() const
Definition prng.hpp:149
pool_type random_pool
Definition prng.hpp:163
void save(Archive &ar) const
Save data into ar for serialization.
Definition prng.hpp:90
Kokkos::View< T[n_r], ComputeSpace > random_view() const
Definition prng.hpp:140
std::size_t seed
Definition prng.hpp:172
Namespace that contains classes and structures related to Monte Carlo (MC) simulations.
Definition alias.hpp:16
void fill_random(const ExecutionSpace &exec, ViewType a, RandomPool g, typename ViewType::const_value_type begin, typename ViewType::const_value_type end)
Definition prng.hpp:193
KOKKOS_INLINE_FUNCTION auto sample_random_variables(const pool_type &pool, auto &&functor)
Definition prng.hpp:48
pool_type get_pool(std::size_t seed=0)
Definition prng.cpp:29
gen_pool_type< Kokkos::DefaultExecutionSpace > pool_type
Definition alias.hpp:100
uint64_t master_seed()
Definition prng.cpp:23
uint64_t next_splitmix64(uint64_t &x) noexcept
Definition prng.cpp:13