1#ifndef PARALLEL_REDUCE_TOOLS_H
2#define PARALLEL_REDUCE_TOOLS_H
37 template<
typename SizeType,
typename IndexType, IndexType N>
41 KOKKOS_INLINE_FUNCTION
43 for (IndexType i = 0; i < N; i++ ) {
the_array[i] = 0; }
45 KOKKOS_INLINE_FUNCTION
49 KOKKOS_INLINE_FUNCTION
56 KOKKOS_INLINE_FUNCTION
80 template<
typename IndexType>
96 template<
typename SizeType,
typename IndexType,
typename Sequence>
110 template<
typename SizeType,
typename IndexType, IndexType... Sizes>
112 using type = std::variant<ArrayReduction<SizeType, IndexType, Sizes + 1>...>;
125 template<
typename SizeType,
typename IndexType>
147 template<
typename SizeType,
typename IndexType, IndexType N>
150 throw std::out_of_range(
"binCount is out of the allowed range");
151 }
else if (binCount == N) {
185 template<
typename SizeType,
typename IndexType>
216 template<
typename SizeType,
typename IndexType>
232#ifndef KOKKOS_ENABLE_CUDA
287 KOKKOS_INLINE_FUNCTION
289 Kokkos::abort(
"Error: HostArrayReduction is not supported on CUDA!\n Note: It exists only for compilation compatibility.");
309 template<
typename SizeType,
typename IndexType>
321 template<
typename T,
unsigned Dim>
324 ippl::parallel_reduce(
"VectorFieldNormReduce", field.getFieldRangePolicy(),
325 KOKKOS_LAMBDA(
const ippl::RangePolicy<Dim>::index_array_type& idx,
T& loc_sum) {
326 ippl::Vector<T, Dim> e = apply(field, idx);
327 loc_sum += std::pow(e.dot(e), p/2.0);
328 }, Kokkos::Sum<T>(sum));
329 return std::pow(sum, 1.0/p);
347 template<
typename SizeType,
typename IndexType, IndexType N>
358 template<
typename SizeType,
typename IndexType>
ippl::Field< ippl::Vector< T, Dim >, Dim, ViewArgs... > VField_t
ReductionVariant< SizeType, IndexType > createReductionObject(IndexType binCount)
Factory function to create ArrayReduction objects with runtime-specified size.
ReductionVariant< SizeType, IndexType > createReductionObjectHelper(IndexType binCount)
Recursive helper function to create ArrayReduction objects with compile-time size matching.
constexpr IndexType maxArrSize
Maximum allowed array size for compile-time array reduction types.
typename ReductionVariantHelper< SizeType, IndexType, std::make_integer_sequence< IndexType, maxArrSize< IndexType > > >::type ReductionVariant
Type alias for a std::variant containing all possible ArrayReduction types up to maxArrSize.
std::variant< ArrayReduction< SizeType, IndexType, Sizes+1 >... > type
T vnorm(const VField_t< T, Dim > &field, int p=2)
Computes the (p)-norm of a vector field (for debugging purpose).
Primary template for generating std::variant types containing ArrayReduction specializations.
A templated structure for performing array-based reductions in parallel computations.
KOKKOS_INLINE_FUNCTION ArrayReduction()
KOKKOS_INLINE_FUNCTION ArrayReduction & operator=(const ArrayReduction &rhs)
KOKKOS_INLINE_FUNCTION ArrayReduction & operator+=(const ArrayReduction &src)
KOKKOS_INLINE_FUNCTION ArrayReduction(const ArrayReduction &rhs)
Host-only array reduction structure for dynamic array sizes in Kokkos::parallel_reduce.
HostArrayReduction & operator=(const HostArrayReduction &rhs)
Assignment operator that performs a deep copy of the array from another instance.
~HostArrayReduction()
Destructor that deallocates the dynamically allocated array.
SizeType * the_array
Pointer to the dynamically allocated array for reduction operations.
HostArrayReduction(const HostArrayReduction &rhs)
Copy constructor that performs a deep copy of the array from another instance.
HostArrayReduction & operator+=(const HostArrayReduction &src)
Element-wise addition operator that adds the elements of another HostArrayReduction instance.
static IndexType binCountStatic
Static variable defining the array size for all instances of this template specialization.
HostArrayReduction()
Default constructor that allocates and zero-initializes the array.
static KOKKOS_FORCEINLINE_FUNCTION ParticleBinning::ArrayReduction< SizeType, IndexType, N > sum()
static KOKKOS_FORCEINLINE_FUNCTION ParticleBinning::HostArrayReduction< SizeType, IndexType > sum()