SpECTRE  v2026.04.01
Loading...
Searching...
No Matches
Parallel::ReductionDatum< T, InvokeCombine, InvokeFinal, InvokeFinalExtraArgsIndices > Struct Template Reference

The data to be reduced, and invokables to be called whenever two reduction messages are combined and after the reduction has been completed. More...

#include <Reduction.hpp>

Public Types

using value_type = T
using invoke_combine = InvokeCombine
using invoke_final = InvokeFinal
using invoke_final_extra_args_indices = InvokeFinalExtraArgsIndices

Public Attributes

value

Detailed Description

template<class T, class InvokeCombine, class InvokeFinal = funcl::Identity, class InvokeFinalExtraArgsIndices = std::index_sequence<>>
struct Parallel::ReductionDatum< T, InvokeCombine, InvokeFinal, InvokeFinalExtraArgsIndices >

The data to be reduced, and invokables to be called whenever two reduction messages are combined and after the reduction has been completed.

InvokeCombine is a binary invokable that maps (T current_state, T element) -> T, where the current_state is the result of reductions so far. The InvokeFinal is an n-ary that takes as its first argument a T result_of_reduction and is invoked once after the reduction is completed. The additional arguments correspond to the resultant data of earlier ReductionDatum template parameters in the ReductionData, and are identified via the InvokeFinalExtraArgsIndices, which must be a std::index_sequence. Specifically, say you want the third ReductionDatum's InvokeFinal to be passed the first ReductionDatum then std::index_sequence<0> would be passed for InvokeFinalExtraArgsIndices. Here is an example of computing the RMS error of the evolved variables u and v:

using RmsRed = Parallel::ReductionDatum<double, funcl::Plus<>,
funcl::Sqrt<funcl::Divides<>>,
std::index_sequence<0>>;
Parallel::ReductionData<Parallel::ReductionDatum<size_t, funcl::Plus<>>,
RmsRed, RmsRed>
error_reduction{3, square(1.0e-3), square(1.0e-4)};
my_proxy, array_proxy);

with the receiving action:

struct ProcessErrorNorms {
template <typename ParallelComponent, typename DbTags, typename Metavariables,
typename ArrayIndex>
static void apply(db::DataBox<DbTags>& /*box*/,
const Parallel::GlobalCache<Metavariables>& /*cache*/,
const ArrayIndex& /*array_index*/, const int points,
const double error_u, const double error_v) {
SPECTRE_PARALLEL_REQUIRE(number_of_1d_array_elements * 3 == points);
error_u, sqrt(number_of_1d_array_elements * square(1.0e-3) / points)));
error_v, sqrt(number_of_1d_array_elements * square(1.0e-4) / points)));
}
};

The documentation for this struct was generated from the following file:
  • src/Parallel/Reduction.hpp