From 641bf72f2030f78d1ecfbbedc60704f4215d9662 Mon Sep 17 00:00:00 2001 From: Tim Mattox Date: Wed, 1 Mar 2017 11:52:33 -0500 Subject: [PATCH] lib kokkos: Enable deterministic use of Random_XorShift*_Pool. Add support for lock-free and deterministic use of Random_XorShift*_Pool by giving state_idx selection and lock responsibility up to the application. Done by an overload of get_state() to take sate_idx as an argument that the appplication guarantees is concurrently unique and within the range of num_states that the application passed to init(). In other words, this allows the RNG state to be associated with some application specific index, rather than a runtime arbitrary thread ID, and thus the application can control which work is performed using which RNG in a deterministic manner, regardless of which thread performs the work. --- lib/kokkos/algorithms/src/Kokkos_Random.hpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/lib/kokkos/algorithms/src/Kokkos_Random.hpp b/lib/kokkos/algorithms/src/Kokkos_Random.hpp index 2fb6b553c2..a0d666183c 100644 --- a/lib/kokkos/algorithms/src/Kokkos_Random.hpp +++ b/lib/kokkos/algorithms/src/Kokkos_Random.hpp @@ -752,6 +752,12 @@ namespace Kokkos { return Random_XorShift64(state_(i),i); } + // NOTE: state_idx MUST be unique and less than num_states + KOKKOS_INLINE_FUNCTION + Random_XorShift64 get_state(const int state_idx) const { + return Random_XorShift64(state_(state_idx),state_idx); + } + KOKKOS_INLINE_FUNCTION void free_state(const Random_XorShift64& state) const { state_(state.state_idx_) = state.state_; @@ -1006,6 +1012,12 @@ namespace Kokkos { return Random_XorShift1024(state_,p_(i),i); }; + // NOTE: state_idx MUST be unique and less than num_states + KOKKOS_INLINE_FUNCTION + Random_XorShift1024 get_state(const int state_idx) const { + return Random_XorShift1024(state_,p_(state_idx),state_idx); + } + KOKKOS_INLINE_FUNCTION void free_state(const Random_XorShift1024& state) const { for(int i = 0; i<16; i++)