File indexing completed on 2026-11-27 10:26:36
0001
0002
0003
0004
0005
0006
0007 #pragma once
0008
0009 #include <type_traits>
0010
0011 #include "corecel/Macros.hh"
0012 #include "corecel/Types.hh"
0013 #include "corecel/data/ObserverPtr.hh"
0014 #include "corecel/math/Algorithms.hh"
0015 #include "corecel/sys/ThreadId.hh"
0016
0017 #include "../CoreStateCounters.hh"
0018
0019 namespace celeritas
0020 {
0021 namespace detail
0022 {
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036 struct InitializeCountersExecutor
0037 {
0038
0039
0040 ObserverPtr<CoreStateCounters, MemSpace::native> counters;
0041 size_type num_pending{};
0042
0043
0044
0045 CELER_FORCEINLINE_FUNCTION void operator()(ThreadId tid) const
0046 {
0047 CELER_EXPECT(tid == ThreadId{0});
0048
0049 counters->num_generated = 0;
0050 counters->num_cut = 0;
0051 counters->num_errored = 0;
0052 counters->num_pending = num_pending;
0053 }
0054 };
0055
0056
0057
0058
0059
0060
0061
0062
0063
0064
0065
0066
0067
0068 template<typename CounterType>
0069 struct AddPendingExecutor
0070 {
0071
0072
0073 ObserverPtr<CoreStateCounters, MemSpace::native> counters;
0074 CounterType num_photons;
0075
0076
0077
0078
0079 CELER_FORCEINLINE_FUNCTION void operator()(ThreadId tid) const
0080 {
0081 CELER_EXPECT(tid == ThreadId{0});
0082
0083 size_type temp_num_photons{};
0084 if constexpr (std::is_integral_v<CounterType>)
0085 {
0086
0087 temp_num_photons = num_photons;
0088 }
0089 else
0090 {
0091
0092 temp_num_photons = *num_photons;
0093 }
0094 counters->num_pending += temp_num_photons;
0095 }
0096 };
0097
0098
0099
0100
0101
0102
0103
0104
0105 struct AddPrimariesCountExecutor
0106 {
0107
0108
0109 ObserverPtr<CoreStateCounters, MemSpace::native> counters;
0110 size_type num_primaries{};
0111
0112
0113
0114 CELER_FORCEINLINE_FUNCTION void operator()(ThreadId tid) const
0115 {
0116 CELER_EXPECT(tid == ThreadId{0});
0117 CELER_EXPECT(num_primaries > 0);
0118
0119 counters->num_initializers += num_primaries;
0120 counters->num_generated += num_primaries;
0121 counters->num_pending = 0;
0122 }
0123 };
0124
0125
0126
0127
0128
0129 struct UpdateActiveExecutor
0130 {
0131
0132
0133 ObserverPtr<CoreStateCounters, MemSpace::native> counters;
0134 size_type state_size{};
0135
0136
0137
0138 CELER_FORCEINLINE_FUNCTION void operator()(ThreadId tid) const
0139 {
0140 CELER_EXPECT(tid == ThreadId{0});
0141 CELER_EXPECT(state_size >= counters->num_vacancies);
0142
0143 size_type num_new_tracks
0144 = min(counters->num_vacancies, counters->num_initializers);
0145
0146
0147 counters->num_initializers -= num_new_tracks;
0148 counters->num_vacancies -= num_new_tracks;
0149
0150
0151 counters->num_active = state_size - counters->num_vacancies;
0152
0153 CELER_ENSURE(counters->num_active <= state_size);
0154 }
0155 };
0156
0157
0158
0159
0160
0161
0162
0163
0164 struct UpdateAliveExecutor
0165 {
0166
0167
0168 ObserverPtr<CoreStateCounters, MemSpace::native> counters;
0169 size_type state_size;
0170
0171
0172
0173
0174 CELER_FORCEINLINE_FUNCTION void operator()(ThreadId tid) const
0175 {
0176 CELER_EXPECT(tid == ThreadId{0});
0177 CELER_EXPECT(state_size >= counters->num_vacancies);
0178
0179 counters->num_alive = state_size - counters->num_vacancies;
0180 }
0181 };
0182
0183
0184
0185
0186
0187
0188
0189
0190
0191 struct UpdateSecondariesCountExecutor
0192 {
0193
0194
0195 ObserverPtr<CoreStateCounters, MemSpace::native> counters;
0196 ObserverPtr<size_type, MemSpace::native> secondary_count;
0197 size_type state_size{};
0198
0199
0200
0201 CELER_FORCEINLINE_FUNCTION void operator()(ThreadId tid) const
0202 {
0203 CELER_EXPECT(tid == ThreadId{0});
0204 CELER_EXPECT(secondary_count);
0205 CELER_EXPECT(state_size >= counters->num_vacancies);
0206
0207 size_type num_secondaries = *secondary_count;
0208 counters->num_secondaries = num_secondaries;
0209 counters->num_initializers += num_secondaries;
0210 counters->num_alive = state_size - counters->num_vacancies;
0211 }
0212 };
0213
0214
0215 }
0216 }