OPALX (Object Oriented Parallel Accelerator Library for Exascal) master (dc2a29eed580)
OPALX
Loading...
Searching...
No Matches
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 >:
Collaboration graph

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 = 10
 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 OPALX_DEVICE_COMPILATION 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
Container_t::bin_index_type bin_index_type

Definition at line 237 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 257 of file ParallelReduceTools.h.

References ParticleBinning::HostArrayReduction< SizeType, IndexType >::binCountStatic, and ParticleBinning::HostArrayReduction< SizeType, IndexType >::the_array.

◆ 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 269 of file ParallelReduceTools.h.

References ParticleBinning::HostArrayReduction< SizeType, IndexType >::binCountStatic, and ParticleBinning::HostArrayReduction< SizeType, IndexType >::the_array.

◆ ~HostArrayReduction()

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

Destructor that deallocates the dynamically allocated array.

Definition at line 279 of file ParallelReduceTools.h.

References ParticleBinning::HostArrayReduction< SizeType, IndexType >::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 304 of file ParallelReduceTools.h.

References ParticleBinning::HostArrayReduction< SizeType, IndexType >::binCountStatic, and ParticleBinning::HostArrayReduction< SizeType, IndexType >::the_array.

◆ 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 287 of file ParallelReduceTools.h.

References ParticleBinning::HostArrayReduction< SizeType, IndexType >::binCountStatic, and ParticleBinning::HostArrayReduction< SizeType, IndexType >::the_array.

Member Data Documentation

◆ binCountStatic

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

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

Static member initialization for the array size variable.

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.

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 251 of file ParallelReduceTools.h.

Referenced by ParticleBinning::HostArrayReduction< SizeType, IndexType >::HostArrayReduction(), ParticleBinning::HostArrayReduction< SizeType, IndexType >::HostArrayReduction(), ParticleBinning::HostArrayReduction< SizeType, IndexType >::operator+=(), and ParticleBinning::HostArrayReduction< SizeType, IndexType >::operator=().

◆ the_array


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