OPALX (Object Oriented Parallel Accelerator Library for Exascal) MINIorX
OPALX
ParticleBinning::HostArrayReduction< SizeType, IndexType > Struct Template Reference

Host-only array reduction structure for dynamic array sizes in Kokkos::parallel_reduce. More...

#include <ParallelReduceTools.h>

Collaboration diagram for ParticleBinning::HostArrayReduction< SizeType, IndexType >:

Public Member Functions

 HostArrayReduction ()
 Default constructor that allocates and zero-initializes the array.
 HostArrayReduction (const HostArrayReduction &rhs)
 Copy constructor that performs a deep copy of the array from another instance.
 ~HostArrayReduction ()
 Destructor that deallocates the dynamically allocated array.
HostArrayReductionoperator= (const HostArrayReduction &rhs)
 Assignment operator that performs a deep copy of the array from another instance.
HostArrayReductionoperator+= (const HostArrayReduction &src)
 Element-wise addition operator that adds the elements of another HostArrayReduction instance.

Public Attributes

SizeType * the_array
 Pointer to the dynamically allocated array for reduction operations.

Static Public Attributes

static IndexType binCountStatic
 Static variable defining the array size for all instances of this template specialization.

Detailed Description

template<typename SizeType, typename IndexType>
struct ParticleBinning::HostArrayReduction< SizeType, IndexType >

Host-only array reduction structure for dynamic array sizes in Kokkos::parallel_reduce.

This structure provides array-based reduction functionality specifically only for host execution. Unlike ArrayReduction which uses compile-time fixed sizes, HostArrayReduction uses dynamically allocated arrays with runtime-determined sizes. This approach offers better performance than team-based reductions on host systems (low concurrency) while maintaining flexibility for arbitrary bin counts (way more efficient than pure atomics).

Template Parameters
SizeTypeThe type used for the elements of the array.
IndexTypeThe type used for indexing and array size specification.
Note
This structure is conditionally compiled and only available when KOKKOS_ENABLE_CUDA is not defined.
All instances of this class share the same array size through the static binCountStatic member.

Usage Example (ReducerType is a specialization of HostArrayReduction):

Kokkos::parallel_reduce("initLocalHist", bunch_m->getLocalNum(),
KOKKOS_LAMBDA(const size_type& i, ReducerType& update) {
bin_index_type ndx = binIndex(i); // Determine the bin index for this particle
update.the_array[ndx]++; // Increment the corresponding bin count in the reduction array
}, Kokkos::Sum<ReducerType>(to_reduce)
);
ippl::detail::size_type size_type

Definition at line 217 of file ParallelReduceTools.h.

Constructor & Destructor Documentation

◆ HostArrayReduction() [1/2]

template<typename SizeType, typename IndexType>
ParticleBinning::HostArrayReduction< SizeType, IndexType >::HostArrayReduction ( )
inline

Default constructor that allocates and zero-initializes the array.

Definition at line 236 of file ParallelReduceTools.h.

References binCountStatic, and the_array.

Referenced by HostArrayReduction(), operator+=(), and operator=().

Here is the caller graph for this function:

◆ HostArrayReduction() [2/2]

template<typename SizeType, typename IndexType>
ParticleBinning::HostArrayReduction< SizeType, IndexType >::HostArrayReduction ( const HostArrayReduction< SizeType, IndexType > & rhs)
inline

Copy constructor that performs a deep copy of the array from another instance.

Parameters
rhsThe instance to copy from.

Definition at line 246 of file ParallelReduceTools.h.

References binCountStatic, HostArrayReduction(), and the_array.

Here is the call graph for this function:

◆ ~HostArrayReduction()

template<typename SizeType, typename IndexType>
ParticleBinning::HostArrayReduction< SizeType, IndexType >::~HostArrayReduction ( )
inline

Destructor that deallocates the dynamically allocated array.

Definition at line 254 of file ParallelReduceTools.h.

References the_array.

Member Function Documentation

◆ operator+=()

template<typename SizeType, typename IndexType>
HostArrayReduction & ParticleBinning::HostArrayReduction< SizeType, IndexType >::operator+= ( const HostArrayReduction< SizeType, IndexType > & src)
inline

Element-wise addition operator that adds the elements of another HostArrayReduction instance.

Parameters
srcThe source instance to add to this instance.
Returns
Reference to this instance after addition.

Definition at line 276 of file ParallelReduceTools.h.

References binCountStatic, HostArrayReduction(), and the_array.

Here is the call graph for this function:

◆ operator=()

template<typename SizeType, typename IndexType>
HostArrayReduction & ParticleBinning::HostArrayReduction< SizeType, IndexType >::operator= ( const HostArrayReduction< SizeType, IndexType > & rhs)
inline

Assignment operator that performs a deep copy of the array from another instance.

Parameters
rhsThe instance to copy from.
Returns
Reference to this instance after assignment.

Definition at line 262 of file ParallelReduceTools.h.

References binCountStatic, HostArrayReduction(), and the_array.

Here is the call graph for this function:

Member Data Documentation

◆ binCountStatic

template<typename SizeType, typename IndexType>
IndexType ParticleBinning::HostArrayReduction< SizeType, IndexType >::binCountStatic
static

Static variable defining the array size for all instances of this template specialization.

Note
This value is set outside when the classed is used, typically before any instances are created.
Warning
Changing this value after object creation may lead to inconsistent behavior.

Definition at line 230 of file ParallelReduceTools.h.

Referenced by HostArrayReduction(), HostArrayReduction(), operator+=(), and operator=().

◆ the_array

template<typename SizeType, typename IndexType>
SizeType* ParticleBinning::HostArrayReduction< SizeType, IndexType >::the_array

Pointer to the dynamically allocated array for reduction operations.

Definition at line 222 of file ParallelReduceTools.h.

Referenced by HostArrayReduction(), HostArrayReduction(), operator+=(), operator=(), and ~HostArrayReduction().


The documentation for this struct was generated from the following file: