File indexing completed on 2025-09-17 08:53:46
0001
0002
0003
0004
0005
0006
0007 #pragma once
0008
0009 #include "corecel/Types.hh"
0010 #include "corecel/random/data/RngData.hh"
0011 #include "corecel/random/engine/RngEngine.hh"
0012 #include "corecel/sys/ThreadId.hh"
0013 #include "celeritas/Types.hh"
0014
0015 namespace celeritas
0016 {
0017 namespace detail
0018 {
0019
0020
0021
0022
0023 class RngReseedExecutor
0024 {
0025 public:
0026 using ParamsCRef = NativeCRef<RngParamsData>;
0027 using StateRef = NativeRef<RngStateData>;
0028
0029 public:
0030
0031 inline CELER_FUNCTION
0032 RngReseedExecutor(ParamsCRef const&, StateRef const&, UniqueEventId id);
0033
0034
0035 inline CELER_FUNCTION void operator()(TrackSlotId tid) const;
0036
0037
0038 CELER_FORCEINLINE_FUNCTION void operator()(ThreadId tid) const
0039 {
0040 return (*this)(TrackSlotId{tid.unchecked_get()});
0041 }
0042
0043 private:
0044 ParamsCRef const params_;
0045 StateRef const state_;
0046 UniqueEventId::size_type stride_;
0047 };
0048
0049
0050
0051
0052
0053
0054
0055 CELER_FUNCTION RngReseedExecutor::RngReseedExecutor(ParamsCRef const& params,
0056 StateRef const& state,
0057 UniqueEventId id)
0058 : params_{params}, state_{state}, stride_{id.unchecked_get() * state.size()}
0059 {
0060 CELER_EXPECT(params_ && state_);
0061 CELER_EXPECT(id);
0062 static_assert(sizeof(ull_int) == sizeof(UniqueEventId::size_type));
0063 }
0064
0065
0066
0067
0068
0069 CELER_FUNCTION void RngReseedExecutor::operator()(TrackSlotId tid) const
0070 {
0071 CELER_EXPECT(tid < state_.size());
0072 RngEngine::Initializer_t init;
0073 init.seed = params_.seed;
0074 init.subsequence = stride_ + tid.unchecked_get();
0075
0076 RngEngine engine(params_, state_, tid);
0077 engine = init;
0078 }
0079
0080
0081 }
0082 }