Skip to content

Commit 69beb8b

Browse files
Put RNG in SM for gamma interactions
1 parent ccc606d commit 69beb8b

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

examples/Example19/gammas.cu

+12-4
Original file line numberDiff line numberDiff line change
@@ -135,10 +135,18 @@ __device__ void GammaInteraction(int const globalSlot, SOAData const &soaData, i
135135
const int theMCIndex = MCIndex[lvolID];
136136
const auto energy = currentTrack.energy;
137137

138-
auto survive = [&] { activeQueue->push_back(globalSlot); };
138+
__shared__ std::byte rngSM[ThreadsPerBlock * sizeof(RanluxppDouble)];
139139

140-
RanluxppDouble newRNG{currentTrack.rngState.Branch()};
141-
G4HepEmRandomEngine rnge{&currentTrack.rngState};
140+
auto &rngState = reinterpret_cast<RanluxppDouble *>(rngSM)[threadIdx.x];
141+
rngState = currentTrack.rngState;
142+
143+
auto survive = [&] {
144+
currentTrack.rngState = rngState;
145+
activeQueue->push_back(globalSlot);
146+
};
147+
148+
RanluxppDouble newRNG{rngState.Branch()};
149+
G4HepEmRandomEngine rnge{&rngState};
142150

143151
if constexpr (ProcessIndex == 0) {
144152
// Invoke gamma conversion to e-/e+ pairs, if the energy is above the threshold.
@@ -169,7 +177,7 @@ __device__ void GammaInteraction(int const globalSlot, SOAData const &soaData, i
169177

170178
positron.InitAsSecondary(/*parent=*/currentTrack);
171179
// Reuse the RNG state of the dying track.
172-
positron.rngState = currentTrack.rngState;
180+
positron.rngState = rngState;
173181
positron.energy = posKinEnergy;
174182
positron.dir.Set(dirSecondaryPos[0], dirSecondaryPos[1], dirSecondaryPos[2]);
175183

0 commit comments

Comments
 (0)