forked from lijiext/lammps
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.
This commit is contained in:
parent
6e26358ec3
commit
641bf72f20
|
@ -752,6 +752,12 @@ namespace Kokkos {
|
|||
return Random_XorShift64<DeviceType>(state_(i),i);
|
||||
}
|
||||
|
||||
// NOTE: state_idx MUST be unique and less than num_states
|
||||
KOKKOS_INLINE_FUNCTION
|
||||
Random_XorShift64<DeviceType> get_state(const int state_idx) const {
|
||||
return Random_XorShift64<DeviceType>(state_(state_idx),state_idx);
|
||||
}
|
||||
|
||||
KOKKOS_INLINE_FUNCTION
|
||||
void free_state(const Random_XorShift64<DeviceType>& state) const {
|
||||
state_(state.state_idx_) = state.state_;
|
||||
|
@ -1006,6 +1012,12 @@ namespace Kokkos {
|
|||
return Random_XorShift1024<DeviceType>(state_,p_(i),i);
|
||||
};
|
||||
|
||||
// NOTE: state_idx MUST be unique and less than num_states
|
||||
KOKKOS_INLINE_FUNCTION
|
||||
Random_XorShift1024<DeviceType> get_state(const int state_idx) const {
|
||||
return Random_XorShift1024<DeviceType>(state_,p_(state_idx),state_idx);
|
||||
}
|
||||
|
||||
KOKKOS_INLINE_FUNCTION
|
||||
void free_state(const Random_XorShift1024<DeviceType>& state) const {
|
||||
for(int i = 0; i<16; i++)
|
||||
|
|
Loading…
Reference in New Issue