Tpetra parallel linear algebra  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Tpetra_Details_Random.hpp
1 // @HEADER
2 // *****************************************************************************
3 // Tpetra: Templated Linear Algebra Services Package
4 //
5 // Copyright 2008 NTESS and the Tpetra contributors.
6 // SPDX-License-Identifier: BSD-3-Clause
7 // *****************************************************************************
8 // @HEADER
9 
10 #ifndef TPETRA_DETAILS_RANDOM_HPP
11 #define TPETRA_DETAILS_RANDOM_HPP
12 
13 #include "TpetraCore_config.h"
14 #include "Kokkos_Random.hpp"
15 
16 namespace Tpetra {
17 namespace Details {
18 
19 template<class ExecutionSpace>
20 class Static_Random_XorShift64_Pool {
21 public:
22  // The resetPool function will re-initialize the pool based on the system RNG and the MPI rank.
23  // On GPU architectures, this will likely involve non-trivial host-to-device transfers.
24  static void resetPool(int mpi_rank);
25 
26  // The isSet function returns true if resetPool has been callled.
27  static bool isSet();
28  // The getPool function will return the existing pool.
29  static Kokkos::Random_XorShift64_Pool<ExecutionSpace> & getPool();
30 };
31 
32 
33 #ifdef KOKKOS_ENABLE_CUDA
34 template<>
35 class Static_Random_XorShift64_Pool<typename Kokkos::CudaSpace::execution_space> {
36 public:
37  static void resetPool(int mpi_rank);
38  static bool isSet();
39  static Kokkos::Random_XorShift64_Pool<typename Kokkos::CudaSpace::execution_space> & getPool();
40 };
41 #endif // KOKKOS_ENABLE_CUDA
42 
43 
44 #ifdef KOKKOS_ENABLE_HIP
45 template<>
46 class Static_Random_XorShift64_Pool<typename Kokkos::HIPSpace::execution_space> {
47 public:
48  static void resetPool(int mpi_rank);
49  static bool isSet();
50  static Kokkos::Random_XorShift64_Pool<typename Kokkos::HIPSpace::execution_space> & getPool();
51 };
52 #endif // KOKKOS_ENABLE_HIP
53 
54 
55 #ifdef KOKKOS_ENABLE_SYCL
56 template<>
57 class Static_Random_XorShift64_Pool<typename Kokkos::Experimental::SYCLDeviceUSMSpace::execution_space> {
58 public:
59  static void resetPool(int mpi_rank);
60  static bool isSet();
61  static Kokkos::Random_XorShift64_Pool<typename Kokkos::Experimental::SYCLDeviceUSMSpace::execution_space> & getPool();
62 };
63 #endif // KOKKOS_ENABLE_SYCL
64 
65 #ifdef KOKKOS_ENABLE_OPENMP
66 template<>
67 class Static_Random_XorShift64_Pool<typename Kokkos::OpenMP> {
68 public:
69  static void resetPool(int mpi_rank);
70  static bool isSet();
71  static Kokkos::Random_XorShift64_Pool<typename Kokkos::OpenMP> & getPool();
72 };
73 #endif // KOKKOS_ENABLE_OPENMP
74 
75 #ifdef KOKKOS_ENABLE_SERIAL
76 template<>
77 class Static_Random_XorShift64_Pool<typename Kokkos::Serial> {
78 public:
79  static void resetPool(int mpi_rank);
80  static bool isSet();
81  static Kokkos::Random_XorShift64_Pool<typename Kokkos::Serial> & getPool();
82 };
83 #endif // KOKKOS_ENABLE_SERIAL
84 
85 } // namespace Details
86 } // namespace Tpetra
87 
88 #endif // TPETRA_DETAILS_RANDOM_HPP