10#include "Tpetra_Details_Random.hpp"
11#include "Teuchos_TestForException.hpp"
18unsigned int getSeedFromRank(
int mpi_rank) {
24 uint64_t myRank =
static_cast<uint64_t
>(mpi_rank);
25 uint64_t seed64 =
static_cast<uint64_t
> (std::rand ()) + myRank + 17311uLL;
26 unsigned int seed =
static_cast<unsigned int> (seed64&0xffffffff);
30#ifdef KOKKOS_ENABLE_CUDA
31Kokkos::Random_XorShift64_Pool<typename Kokkos::CudaSpace::execution_space> * cuda_pool_=
nullptr;
33void finalize_cuda_pool() {
34 if(cuda_pool_ !=
nullptr) {
42#ifdef KOKKOS_ENABLE_HIP
43Kokkos::Random_XorShift64_Pool<typename Kokkos::HIPSpace::execution_space> * hip_pool_=
nullptr;
45void finalize_hip_pool() {
46 if(hip_pool_ !=
nullptr) {
53#ifdef KOKKOS_ENABLE_SYCL
54Kokkos::Random_XorShift64_Pool<typename Kokkos::Experimental::SYCLDeviceUSMSpace::execution_space> * sycl_pool_=
nullptr;
56void finalize_sycl_pool() {
57 if(sycl_pool_ !=
nullptr) {
65#ifdef KOKKOS_ENABLE_OPENMP
66Kokkos::Random_XorShift64_Pool<Kokkos::OpenMP> * openmp_pool_=
nullptr;
68void finalize_openmp_pool() {
69 if(openmp_pool_ !=
nullptr) {
71 openmp_pool_ =
nullptr;
77#ifdef KOKKOS_ENABLE_SERIAL
78Kokkos::Random_XorShift64_Pool<Kokkos::Serial> * serial_pool_=
nullptr;
80void finalize_serial_pool() {
81 if(serial_pool_ !=
nullptr) {
83 serial_pool_ =
nullptr;
92#ifdef KOKKOS_ENABLE_CUDA
94Static_Random_XorShift64_Pool<typename Kokkos::CudaSpace::execution_space>::
95resetPool(
int mpi_rank) {
96 using pool_type = Kokkos::Random_XorShift64_Pool<typename Kokkos::CudaSpace::execution_space>;
101 Kokkos::push_finalize_hook(finalize_cuda_pool);
103 cuda_pool_ =
new pool_type(getSeedFromRank(mpi_rank));
107Static_Random_XorShift64_Pool<typename Kokkos::CudaSpace::execution_space>::
109 return cuda_pool_!=
nullptr;
112Kokkos::Random_XorShift64_Pool<typename Kokkos::CudaSpace::execution_space> &
113Static_Random_XorShift64_Pool<typename Kokkos::CudaSpace::execution_space>::
115 TEUCHOS_TEST_FOR_EXCEPTION(!isSet(),std::runtime_error,
"Tpetra::Details::Static_Random_XorShift64_Pool: resetPool() must be called before getPool");
122#ifdef KOKKOS_ENABLE_HIP
124Static_Random_XorShift64_Pool<typename Kokkos::HIPSpace::execution_space>::
125resetPool(
int mpi_rank) {
126 using pool_type = Kokkos::Random_XorShift64_Pool<typename Kokkos::HIPSpace::execution_space>;
131 Kokkos::push_finalize_hook(finalize_hip_pool);
133 hip_pool_ =
new pool_type(getSeedFromRank(mpi_rank));
137Static_Random_XorShift64_Pool<typename Kokkos::HIPSpace::execution_space>::
139 return hip_pool_!=
nullptr;
142Kokkos::Random_XorShift64_Pool<typename Kokkos::HIPSpace::execution_space> &
143Static_Random_XorShift64_Pool<typename Kokkos::HIPSpace::execution_space>::
145 TEUCHOS_TEST_FOR_EXCEPTION(!isSet(),std::runtime_error,
"Tpetra::Details::Static_Random_XorShift64_Pool: resetPool() must be called before getPool");
152#ifdef KOKKOS_ENABLE_SYCL
154Static_Random_XorShift64_Pool<typename Kokkos::Experimental::SYCLDeviceUSMSpace::execution_space>::
155resetPool(
int mpi_rank) {
156 using pool_type = Kokkos::Random_XorShift64_Pool<typename Kokkos::Experimental::SYCLDeviceUSMSpace::execution_space>;
161 Kokkos::push_finalize_hook(finalize_sycl_pool);
163 sycl_pool_ =
new pool_type(getSeedFromRank(mpi_rank));
167Static_Random_XorShift64_Pool<typename Kokkos::Experimental::SYCLDeviceUSMSpace::execution_space>::
169 return sycl_pool_!=
nullptr;
172Kokkos::Random_XorShift64_Pool<typename Kokkos::Experimental::SYCLDeviceUSMSpace::execution_space> &
173Static_Random_XorShift64_Pool<typename Kokkos::Experimental::SYCLDeviceUSMSpace::execution_space>::
175 TEUCHOS_TEST_FOR_EXCEPTION(!isSet(),std::runtime_error,
"Tpetra::Details::Static_Random_XorShift64_Pool: resetPool() must be called before getPool");
182#ifdef KOKKOS_ENABLE_OPENMP
184Static_Random_XorShift64_Pool<Kokkos::OpenMP>::
185resetPool(
int mpi_rank) {
186 using pool_type = Kokkos::Random_XorShift64_Pool<Kokkos::OpenMP>;
191 Kokkos::push_finalize_hook(finalize_openmp_pool);
193 openmp_pool_ =
new pool_type(getSeedFromRank(mpi_rank));
197Static_Random_XorShift64_Pool<Kokkos::OpenMP>::
199 return openmp_pool_!=
nullptr;
202Kokkos::Random_XorShift64_Pool<Kokkos::OpenMP> &
203Static_Random_XorShift64_Pool<Kokkos::OpenMP>::
205 TEUCHOS_TEST_FOR_EXCEPTION(!isSet(),std::runtime_error,
"Tpetra::Details::Static_Random_XorShift64_Pool: resetPool() must be called before getPool");
206 return *openmp_pool_;
212#ifdef KOKKOS_ENABLE_SERIAL
214Static_Random_XorShift64_Pool<Kokkos::Serial>::
215resetPool(
int mpi_rank) {
216 using pool_type = Kokkos::Random_XorShift64_Pool<Kokkos::Serial>;
221 Kokkos::push_finalize_hook(finalize_serial_pool);
223 serial_pool_ =
new pool_type(getSeedFromRank(mpi_rank));
227Static_Random_XorShift64_Pool<Kokkos::Serial>::
229 return serial_pool_!=
nullptr;
232Kokkos::Random_XorShift64_Pool<Kokkos::Serial> &
233Static_Random_XorShift64_Pool<Kokkos::Serial>::
235 TEUCHOS_TEST_FOR_EXCEPTION(!isSet(),std::runtime_error,
"Tpetra::Details::Static_Random_XorShift64_Pool: resetPool() must be called before getPool");
236 return *serial_pool_;
Nonmember function that computes a residual Computes R = B - A * X.
Namespace Tpetra contains the class and methods constituting the Tpetra library.