OPALX (Object Oriented Parallel Accelerator Library for Exascal) MINIorX
OPALX
ParticleBinning Namespace Reference

Classes

class  AdaptBins
 A class that bins particles in energy bins and allows for adaptive runtime rebinning. More...
struct  DeviceViewTraits
 Traits class to extract host and device view types from a given ViewType. More...
struct  DeviceViewTraits< true, ViewType >
 Specialization of DeviceViewTraits for when DualView is used. More...
struct  DeviceViewTraits< false, ViewType >
 Specialization of DeviceViewTraits for when DualView is not used. More...
class  Histogram
 Template class providing adaptive particle histogram binning with support for Kokkos Views and DualViews. More...
struct  CoordinateSelector
 Example struct used to access the binning variable for each particle. More...
struct  ArrayReduction
 A templated structure for performing array-based reductions in parallel computations. More...
struct  ReductionVariantHelper
 Primary template for generating std::variant types containing ArrayReduction specializations. More...
struct  ReductionVariantHelper< SizeType, IndexType, std::integer_sequence< IndexType, Sizes... > >
 Specialized template that expands std::integer_sequence to create a variant of ArrayReduction types. More...
struct  HostArrayReduction
 Host-only array reduction structure for dynamic array sizes in Kokkos::parallel_reduce. More...

Typedefs

template<typename SizeType, typename IndexType>
using ReductionVariant = typename ReductionVariantHelper<SizeType, IndexType, std::make_integer_sequence<IndexType, maxArrSize<IndexType>>>::type
 Type alias for a std::variant containing all possible ArrayReduction types up to maxArrSize.

Enumerations

enum class  HistoReductionMode { Standard , ParallelReduce , TeamBased , HostOnly }

Functions

template<typename bin_index_type>
HistoReductionMode determineHistoReductionMode (HistoReductionMode modePreference, bin_index_type binCount)
 Determines the appropriate histogram reduction mode based on user preference, bin count, and execution environment.
template<typename ViewType>
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 ...-sum view.
template<typename ValueType, typename SizeType, typename HashType>
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.
template<typename SizeType, typename IndexType, IndexType N>
ReductionVariant< SizeType, IndexType > createReductionObjectHelper (IndexType binCount)
 Recursive helper function to create ArrayReduction objects with compile-time size matching.
template<typename SizeType, typename IndexType>
ReductionVariant< SizeType, IndexType > createReductionObject (IndexType binCount)
 Factory function to create ArrayReduction objects with runtime-specified size.
template<typename T, unsigned Dim>
T vnorm (const VField_t< T, Dim > &field, int p=2)
 Computes the (p)-norm of a vector field (for debugging purpose).

Variables

template<typename IndexType>
constexpr IndexType maxArrSize = 5
 Maximum allowed array size for compile-time array reduction types.
template<typename SizeType, typename IndexType>
IndexType HostArrayReduction< SizeType, IndexType >::binCountStatic = 10
 Static member initialization for the array size variable.

Class Documentation

◆ ParticleBinning::DeviceViewTraits

struct ParticleBinning::DeviceViewTraits
template<bool UseDualView, typename ViewType>
struct ParticleBinning::DeviceViewTraits< UseDualView, ViewType >

Traits class to extract host and device view types from a given ViewType.

This primary template is specialized based on the UseDualView boolean flag.

Template Parameters
UseDualViewFlag indicating whether Kokkos::DualView is used.
ViewTypeThe original view type (e.g., Kokkos::View or Kokkos::DualView).

Definition at line 20 of file BinHisto.h.

Inheritance diagram for ParticleBinning::DeviceViewTraits< UseDualView, ViewType >:
Collaboration diagram for ParticleBinning::DeviceViewTraits< UseDualView, ViewType >:

◆ ParticleBinning::DeviceViewTraits< true, ViewType >

struct ParticleBinning::DeviceViewTraits< true, ViewType >
template<typename ViewType>
struct ParticleBinning::DeviceViewTraits< true, ViewType >

Specialization of DeviceViewTraits for when DualView is used.

Definition at line 26 of file BinHisto.h.

Inheritance diagram for ParticleBinning::DeviceViewTraits< true, ViewType >:
Collaboration diagram for ParticleBinning::DeviceViewTraits< true, ViewType >:
Class Members
typedef typename t_dev d_type typename ViewType::t_dev
typedef typename t_host h_type typename ViewType::t_host

◆ ParticleBinning::DeviceViewTraits< false, ViewType >

struct ParticleBinning::DeviceViewTraits< false, ViewType >
template<typename ViewType>
struct ParticleBinning::DeviceViewTraits< false, ViewType >

Specialization of DeviceViewTraits for when DualView is not used.

Definition at line 35 of file BinHisto.h.

Inheritance diagram for ParticleBinning::DeviceViewTraits< false, ViewType >:
Collaboration diagram for ParticleBinning::DeviceViewTraits< false, ViewType >:
Class Members
typedef ViewType d_type ViewType
typedef ViewType h_type ViewType

◆ ParticleBinning::ReductionVariantHelper

struct ParticleBinning::ReductionVariantHelper
template<typename SizeType, typename IndexType, typename Sequence>
struct ParticleBinning::ReductionVariantHelper< SizeType, IndexType, Sequence >

Primary template for generating std::variant types containing ArrayReduction specializations.

This template is not used directly but serves as the base for the specialized version. It works in conjunction with std::integer_sequence to generate a variant containing ArrayReduction types with sizes from 1 to maxArrSize.

This is necessary to pre-compile types for histogram reduction on device.

Template Parameters
SizeTypeThe type used for array elements in the reduction operations.
IndexTypeThe type used for array indexing.
SequenceA std::integer_sequence type that will be expanded in the specialization.

Definition at line 97 of file ParallelReduceTools.h.

Inheritance diagram for ParticleBinning::ReductionVariantHelper< SizeType, IndexType, Sequence >:
Collaboration diagram for ParticleBinning::ReductionVariantHelper< SizeType, IndexType, Sequence >:

◆ ParticleBinning::ReductionVariantHelper< SizeType, IndexType, std::integer_sequence< IndexType, Sizes... > >

struct ParticleBinning::ReductionVariantHelper< SizeType, IndexType, std::integer_sequence< IndexType, Sizes... > >
template<typename SizeType, typename IndexType, IndexType... Sizes>
struct ParticleBinning::ReductionVariantHelper< SizeType, IndexType, std::integer_sequence< IndexType, Sizes... > >

Specialized template that expands std::integer_sequence to create a variant of ArrayReduction types.

This specialization takes a std::integer_sequence and expands it into a std::variant containing ArrayReduction types with consecutive sizes. Each size in the sequence is incremented by 1 to create ArrayReduction<SizeType, IndexType, Sizes + 1>.

Template Parameters
SizeTypeThe type used for array elements in the reduction operations.
IndexTypeThe type used for array indexing.
Sizes...Parameter pack of integer values from the std::integer_sequence.

Definition at line 111 of file ParallelReduceTools.h.

Inheritance diagram for ParticleBinning::ReductionVariantHelper< SizeType, IndexType, std::integer_sequence< IndexType, Sizes... > >:
Collaboration diagram for ParticleBinning::ReductionVariantHelper< SizeType, IndexType, std::integer_sequence< IndexType, Sizes... > >:
Class Members
typedef variant< ArrayReduction< SizeType, IndexType, Sizes+1 >... > type std::variant<ArrayReduction<SizeType, IndexType, Sizes + 1>...>

Typedef Documentation

◆ ReductionVariant

template<typename SizeType, typename IndexType>
using ParticleBinning::ReductionVariant = typename ReductionVariantHelper<SizeType, IndexType, std::make_integer_sequence<IndexType, maxArrSize<IndexType>>>::type

Type alias for a std::variant containing all possible ArrayReduction types up to maxArrSize.

This alias creates a variant that can hold ArrayReduction objects with sizes from 1 to maxArrSize. It uses ReductionVariantHelper with std::make_integer_sequence to generate all variants type at compile time.

Template Parameters
SizeTypeThe type used for array elements in the reduction operations.
IndexTypeThe type used for array indexing and size specification.

Definition at line 126 of file ParallelReduceTools.h.

Enumeration Type Documentation

◆ HistoReductionMode

Enumerator
Standard 
ParallelReduce 
TeamBased 
HostOnly 

Definition at line 11 of file ParallelReduceTools.h.

Function Documentation

◆ computeFixSum()

template<typename ViewType>
void ParticleBinning::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 ...-sum view.

Template Parameters
SizeTypeThe type of the elements in the input and ...-sum views.
Parameters
input_viewThe input view containing the elements to be summed.
post_sum_viewThe output view where the ...-sum results will be stored. It must have a size of input_view.extent(0) + 1.
postSumIf true, the post-sum is computed; otherwise, the prefix-sum is computed.
Exceptions
`ippl::Comm->abort();`if the size of the post_sum_view is not equal to input_view.extent(0) + 1.

Definition at line 140 of file BinningTools.h.

Referenced by ParticleBinning::Histogram< size_type, bin_index_type, value_type, true >::initPostSum().

Here is the caller graph for this function:

◆ createReductionObject()

template<typename SizeType, typename IndexType>
ReductionVariant< SizeType, IndexType > ParticleBinning::createReductionObject ( IndexType binCount)

Factory function to create ArrayReduction objects with runtime-specified size.

This function provides an interface for creating ArrayReduction objects where the array size is determined at runtime. It internally uses compile-time template recursion to match the runtime binCount with the template specialization.

This allows using "runtime sized arrays" as reducer objects inside a Kokkos kernel on device.

Template Parameters
SizeTypeThe type used for array elements in the reduction operations.
IndexTypeThe type used for array indexing.
Parameters
binCountThe desired number of bins for the reduction array (must be $\leq$ maxArrSize).
Returns
ReductionVariant containing the ArrayReduction object with the specified size.
Exceptions
`std::out_of_range`If binCount exceeds maxArrSize or is less than 1.

Example usage (also see implementation of AdaptBins::initLocalHisto()):

std::visit(
[&](auto& reducer_arr) {
executeInitLocalHistoReduction(reducer_arr);
);
ReductionVariant< SizeType, IndexType > createReductionObject(IndexType binCount)
Factory function to create ArrayReduction objects with runtime-specified size.

Definition at line 186 of file ParallelReduceTools.h.

References createReductionObjectHelper().

Here is the call graph for this function:

◆ createReductionObjectHelper()

template<typename SizeType, typename IndexType, IndexType N>
ReductionVariant< SizeType, IndexType > ParticleBinning::createReductionObjectHelper ( IndexType binCount)

Recursive helper function to create ArrayReduction objects with compile-time size matching.

This function uses compile-time recursion to find and instantiate the correct ArrayReduction type based on the requested binCount. It recursively increments the template parameter N until it matches binCount, then returns the appropriate ArrayReduction instance.

Template Parameters
SizeTypeThe type used for array elements in the reduction operations.
IndexTypeThe type used for array indexing.
NCurrent array size being tested in the recursive search.
Parameters
binCountThe desired number of bins for the reduction array.
Returns
ReductionVariant containing the ArrayReduction object with size matching binCount.
Exceptions
`std::out_of_range`If binCount exceeds maxArrSize.
Note
This function should not be called directly. Use createReductionObject() instead and use std::visit to access the reducer.

Definition at line 148 of file ParallelReduceTools.h.

References createReductionObjectHelper(), and maxArrSize.

Referenced by createReductionObject(), and createReductionObjectHelper().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ determineHistoReductionMode()

template<typename bin_index_type>
HistoReductionMode ParticleBinning::determineHistoReductionMode ( HistoReductionMode modePreference,
bin_index_type binCount )

Determines the appropriate histogram reduction mode based on user preference, bin count, and execution environment.

This function selects the optimal histogram reduction method. If the code is compiled with a host execution space (e.g., Serial or OpenMP), it forces the reduction mode to HistoReductionMode::HostOnly, disregarding the user's preference. Otherwise, if the user preference is HistoReductionMode::Standard, it automatically chooses between ParallelReduce or TeamBased based on the binCount. If a specific preference is provided (not Standard), that preference is respected.

Parameters
modePreferenceThe user's preferred reduction mode.
  • Standard to select a mode based on bin count.

  • ParallelReduce, TeamBased, or HostOnly to force a specific mode.

Returns
HistoReductionMode The selected histogram reduction mode:
  • HostOnly if the default execution space is a host space.

  • ParallelReduce if binCount is within maxArrSize<bin_index_type>.

  • TeamBased if binCount exceeds maxArrSize<bin_index_type>.

  • Otherwise, respects the specified modePreference.

Note
If compiled for a host-only execution environment, the returned mode will always be HistoReductionMode::HostOnly, regardless of modePreference.
See also
HistoReductionMode

Definition at line 33 of file BinningTools.h.

References HostOnly, maxArrSize, ParallelReduce, Standard, and TeamBased.

◆ viewIsSorted()

template<typename ValueType, typename SizeType, typename HashType>
bool ParticleBinning::viewIsSorted ( const Kokkos::View< ValueType * > view,
HashType indices,
SizeType npart )

Checks if the elements in a Kokkos::View are sorted in non-decreasing order.

Template Parameters
ValueTypeThe type of the elements in the Kokkos::View so be checked.
SizeTypeThe type used for indexing and size.
Parameters
viewThe Kokkos::View containing the elements to be checked.
indicesArgsort of view.
npartThe number of elements in the view to be checked.
Returns
true if the elements are sorted in non-decreasing order, false otherwise.
Note
This function does not leverage short circuiting.

Definition at line 182 of file BinningTools.h.

◆ vnorm()

template<typename T, unsigned Dim>
T ParticleBinning::vnorm ( const VField_t< T, Dim > & field,
int p = 2 )

Computes the (p)-norm of a vector field (for debugging purpose).

Parameters
fieldThe input vector field.
pThe order of the norm (default is 2 for Euclidean norm).
Returns
The computed (p)-norm of the vector field.

Definition at line 322 of file ParallelReduceTools.h.

Variable Documentation

◆ HostArrayReduction< SizeType, IndexType >::binCountStatic

template<typename SizeType, typename IndexType>
IndexType ParticleBinning::HostArrayReduction< SizeType, IndexType >::binCountStatic = 10

Static member initialization for the array size variable.

This line provides the definition and default initialization for the static member binCountStatic. The default value of 10 serves as a place holder and should be overridden based on the required histogram size.

Template Parameters
SizeTypeThe type used for array elements.
IndexTypeThe type used for indexing and size specification.
Note
This must be defined outside the class template for proper static member initialization.
The value should be set appropriately before creating any HostArrayReduction instances.
This is only used in the host version of the code.

Definition at line 310 of file ParallelReduceTools.h.

◆ maxArrSize

template<typename IndexType>
IndexType ParticleBinning::maxArrSize = 5
constexpr

Maximum allowed array size for compile-time array reduction types.

This constexpr variable defines the upper limit for statically-sized array reductions that are used in parallel histogram reductions. For small histograms, this is prefereable to pure atomics. However, for large values, compile time is increased significantly.

Template Parameters
IndexTypeThe type used for array indexing and size specification.
Note
5 is empirically chosen, since in real world applications the team-based reduction is usually enough.

Definition at line 81 of file ParallelReduceTools.h.

Referenced by createReductionObjectHelper(), and determineHistoReductionMode().