1 /* ---------------------------------------------------------------------- 2 SPARTA - Stochastic PArallel Rarefied-gas Time-accurate Analyzer 3 http://sparta.sandia.gov 4 Steve Plimpton, sjplimp@sandia.gov, Michael Gallis, magalli@sandia.gov 5 Sandia National Laboratories 6 7 Copyright (2014) Sandia Corporation. Under the terms of Contract 8 DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains 9 certain rights in this software. This software is distributed under 10 the GNU General Public License. 11 12 See the README file in the top-level SPARTA directory. 13 ------------------------------------------------------------------------- */ 14 15 #ifndef RAND_POOL_WRAP_H 16 #define RAND_POOL_WRAP_H 17 18 #include "pointers.h" 19 #include "kokkos_type.h" 20 #include "random_knuth.h" 21 #include "error.h" 22 23 namespace SPARTA_NS { 24 25 struct RandWrap { 26 class RanKnuth* rng; 27 28 KOKKOS_INLINE_FUNCTION RandWrapRandWrap29 RandWrap() { 30 rng = NULL; 31 } 32 33 KOKKOS_INLINE_FUNCTION drandRandWrap34 double drand() { 35 return rng->uniform(); 36 } 37 38 KOKKOS_INLINE_FUNCTION normalRandWrap39 double normal() { 40 return rng->gaussian(); 41 } 42 }; 43 44 class RandPoolWrap : protected Pointers { 45 public: 46 RandPoolWrap(int, class SPARTA *); 47 ~RandPoolWrap(); 48 void destroy(); 49 void init(RanKnuth*); 50 51 KOKKOS_INLINE_FUNCTION get_state()52 RandWrap get_state() const 53 { 54 #ifdef SPARTA_KOKKOS_GPU 55 error->all(FLERR,"Cannot use Knuth RNG with GPUs"); 56 #endif 57 58 RandWrap rand_wrap; 59 60 typedef Kokkos::Experimental::UniqueToken< 61 DeviceType, Kokkos::Experimental::UniqueTokenScope::Global> unique_token_type; 62 63 unique_token_type unique_token; 64 int tid = unique_token.acquire(); 65 rand_wrap.rng = random_thr[tid]; 66 unique_token.release(tid); 67 68 return rand_wrap; 69 } 70 71 KOKKOS_INLINE_FUNCTION free_state(RandWrap)72 void free_state(RandWrap) const 73 { 74 75 } 76 77 private: 78 class RanKnuth **random_thr; 79 int nthreads; 80 }; 81 82 } 83 84 #endif 85 86 /* ERROR/WARNING messages: 87 88 */ 89