34 template <
typename bin_index_type>
38 if (std::is_same<Kokkos::DefaultExecutionSpace, Kokkos::DefaultHostExecutionSpace>::value)
41#ifdef OPALX_DEVICE_COMPILATION
45 "ParticleBinning::determineHistoReductionMode",
46 "HistoReductionMode::HostOnly is not supported when OPALX_DEVICE_COMPILATION "
57 return modePreference;
88 template <
typename bunch_type>
91 using value_type =
typename bunch_type::Layout_t::value_type;
131 KOKKOS_INLINE_FUNCTION
135 return value / sqrt(1 + value * value);
148 template <
typename bunch_type>
150 using value_type =
typename bunch_type::Layout_t::value_type;
161 KOKKOS_INLINE_FUNCTION
164 return sqrt(1 + value * value);
181 template <
typename ViewType>
182 void computeFixSum(
const ViewType& input_view,
const ViewType& post_sum_view) {
183 using execution_space =
typename ViewType::execution_space;
184 using size_type =
typename ViewType::size_type;
185 using value_type =
typename ViewType::value_type;
188 if (post_sum_view.extent(0) != input_view.extent(0) + 1) {
189 Inform m(
"computePostSum");
190 m << level4 <<
"Output view must have size input_view.extent(0) + 1" << endl;
195 Kokkos::parallel_for(
196 "InitPostSum", Kokkos::RangePolicy<execution_space>(0, 1),
197 KOKKOS_LAMBDA(
const size_type) { post_sum_view(0) = 0; });
200 Kokkos::parallel_scan(
201 "ComputePostSum", Kokkos::RangePolicy<execution_space>(0, input_view.extent(0)),
203 partial_sum += input_view(i);
205 post_sum_view(i + 1) = partial_sum;
222 template <
typename ValueType,
typename SizeType,
typename HashType>
223 bool viewIsSorted(
const Kokkos::View<ValueType*> view, HashType indices, SizeType npart) {
225 Kokkos::parallel_reduce(
226 "CheckSorted", npart - 1,
227 KOKKOS_LAMBDA(
const SizeType& i,
bool& update) {
228 if (view(indices(i)) > view(indices(i + 1))) update =
false;
230 Kokkos::LAnd<bool>(sorted));
ippl::detail::size_type size_type
Container_t::bin_index_type bin_index_type
void computeFixSum(const ViewType &input_view, const ViewType &post_sum_view)
Computes the post- or prefix-sum of the input view and stores the result in the .....
HistoReductionMode determineHistoReductionMode(HistoReductionMode modePreference, bin_index_type binCount)
Determines the appropriate histogram reduction mode based on user preference, bin count,...
bool viewIsSorted(const Kokkos::View< ValueType * > view, HashType indices, SizeType npart)
Checks if the elements in a Kokkos::View are sorted in non-decreasing order.
Example struct used to access the binning variable for each particle.
position_view_type data_arr
Kokkos view of the particle data array.
KOKKOS_INLINE_FUNCTION value_type operator()(const size_type &i) const
Returns the value of the binning variable for a given particle index.
void updateDataArr(bunch_type &bunch)
Updates the data array view with the latest particle data.
typename bunch_type::particle_position_type::view_type position_view_type
Type representing the view of particle positions.
const int axis
Index of the coordinate axis to use for binning.
CoordinateSelector(int axis_)
Constructs a CoordinateSelector for a specific axis.
typename bunch_type::size_type size_type
Type representing the size of the particle bunch.
typename bunch_type::Layout_t::value_type value_type
Type representing the value of the binning variable (e.g., position or velocity).
Selects the gamma factor for binning.
typename bunch_type::size_type size_type
void updateDataArr(bunch_type &bunch)
position_view_type data_arr
typename bunch_type::particle_position_type::view_type position_view_type
typename bunch_type::Layout_t::value_type value_type
KOKKOS_INLINE_FUNCTION value_type operator()(const size_type &i) const