10 #ifndef TPETRA_DETAILS_RANDOM_DEF_HPP
11 #define TPETRA_DETAILS_RANDOM_DEF_HPP
13 #include "Tpetra_Details_Random_decl.hpp"
14 #include "Teuchos_TestForException.hpp"
15 #include "Kokkos_Random.hpp"
21 template<
class ExecutionSpace>
22 void finalize_pool() {
23 using PoolClass = Static_Random_XorShift64_Pool<ExecutionSpace>;
24 if(PoolClass::pool_ !=
nullptr) {
25 delete PoolClass::pool_;
27 PoolClass::pool_=
nullptr;
33 template<
class ExecutionSpace>
34 unsigned int Static_Random_XorShift64_Pool<ExecutionSpace>::getSeedFromRank(
int mpi_rank) {
40 uint64_t myRank =
static_cast<uint64_t
>(mpi_rank);
41 uint64_t seed64 =
static_cast<uint64_t
> (std::rand ()) + myRank + 17311uLL;
42 unsigned int seed =
static_cast<unsigned int> (seed64&0xffffffff);
47 template<
class ExecutionSpace>
48 void Static_Random_XorShift64_Pool<ExecutionSpace>::
49 resetPool(
int mpi_rank) {
50 using pool_type = Kokkos::Random_XorShift64_Pool<ExecutionSpace>;
55 Kokkos::push_finalize_hook(finalize_pool<ExecutionSpace>);
57 pool_ =
new Kokkos::Random_XorShift64_Pool<ExecutionSpace>(getSeedFromRank(mpi_rank));
60 template<
class ExecutionSpace>
61 bool Static_Random_XorShift64_Pool<ExecutionSpace>::
63 return pool_!=
nullptr;
66 template<
class ExecutionSpace>
67 Kokkos::Random_XorShift64_Pool<ExecutionSpace> & Static_Random_XorShift64_Pool<ExecutionSpace>::
69 TEUCHOS_TEST_FOR_EXCEPTION(!isSet(),std::runtime_error,
"Tpetra::Details::Static_Random_XorShift64_Pool: resetPool() must be called before getPool");
86 #define TPETRA_DETAILS_RANDOM_INSTANT(NODE) \
87 template<> Kokkos::Random_XorShift64_Pool<typename NODE::execution_space>* Details::Static_Random_XorShift64_Pool<typename NODE::execution_space>::pool_ = nullptr; \
88 template class Details::Static_Random_XorShift64_Pool<typename NODE::execution_space>;
92 #endif // TPETRA_DETAILS_RANDOM_DEF_HPP