Block-Structured AMR Software Framework
Loading...
Searching...
No Matches
Reductions and Scans

Performance-portable reduction and scan operations in AMReX. More...

Classes

struct  amrex::ReduceOpSum
 
struct  amrex::ReduceOpMin
 
struct  amrex::ReduceOpMax
 
struct  amrex::ReduceOpLogicalAnd
 
struct  amrex::ReduceOpLogicalOr
 
class  amrex::ReduceData< Ts >
 
class  amrex::ReduceOps< Ps >
 
class  amrex::Reducer< Ops, Ts >
 Class for local reductions (e.g., sum, min and max). More...
 

Functions

template<typename T , typename N , std::enable_if_t< std::is_integral_v< N >, int > = 0>
amrex::Reduce::Sum (N n, T const *v, T init_val=0)
 Compute the sum of an array of values.
 
template<typename T , typename N , typename F , std::enable_if_t< std::is_integral_v< N > &&!std::is_same_v< T *, std::decay_t< F > >, int > = 0>
amrex::Reduce::Sum (N n, F const &f, T init_val=0)
 Compute the sum of values generated by a callable.
 
template<typename T , typename N , std::enable_if_t< std::is_integral_v< N >, int > = 0>
amrex::Reduce::Min (N n, T const *v, T init_val=std::numeric_limits< T >::max())
 Compute the minimum of an array of values.
 
template<typename T , typename N , typename F , std::enable_if_t< std::is_integral_v< N > &&!std::is_same_v< T *, std::decay_t< F > >, int > = 0>
amrex::Reduce::Min (N n, F const &f, T init_val=std::numeric_limits< T >::max())
 Compute the minimum of values generated by a callable.
 
template<typename T , typename N , std::enable_if_t< std::is_integral_v< N >, int > = 0>
amrex::Reduce::Max (N n, T const *v, T init_val=std::numeric_limits< T >::lowest())
 Compute the maximum of an array of values.
 
template<typename T , typename N , typename F , std::enable_if_t< std::is_integral_v< N > &&!std::is_same_v< T *, std::decay_t< F > >, int > = 0>
amrex::Reduce::Max (N n, F const &f, T init_val=std::numeric_limits< T >::lowest())
 Compute the maximum of values generated by a callable.
 
template<typename T , typename N , std::enable_if_t< std::is_integral_v< N >, int > = 0>
std::pair< T, T > amrex::Reduce::MinMax (N n, T const *v)
 Compute the minimum and maximum of an array of values.
 
template<typename T , typename N , typename F , std::enable_if_t< std::is_integral_v< N > &&!std::is_same_v< T *, std::decay_t< F > >, int > = 0>
std::pair< T, T > amrex::Reduce::MinMax (N n, F const &f)
 Compute the minimum and maximum of values generated by a callable.
 
template<typename T , typename N , typename P , std::enable_if_t< std::is_integral_v< N >, int > = 0>
bool amrex::Reduce::AnyOf (N n, T const *v, P const &pred)
 Test whether any element in an array satisfies a unary predicate.
 
template<typename P , int dim>
bool amrex::Reduce::AnyOf (BoxND< dim > const &box, P const &pred)
 Test whether the predicate is true for any index in a Box.
 
template<typename T , typename N , typename FIN , typename FOUT , typename TYPE , typename M = std::enable_if_t<std::is_integral_v<N> && (std::is_same_v<std::decay_t<TYPE>,Type::Inclusive> || std::is_same_v<std::decay_t<TYPE>,Type::Exclusive>)>>
amrex::Scan::PrefixSum (N n, FIN const &fin, FOUT const &fout, TYPE, RetSum a_ret_sum=retSum)
 
template<typename N , typename T , typename M = std::enable_if_t<std::is_integral_v<N>>>
amrex::Scan::InclusiveSum (N n, T const *in, T *out, RetSum a_ret_sum=retSum)
 Inclusive sum.
 
template<typename N , typename T , typename M = std::enable_if_t<std::is_integral_v<N>>>
amrex::Scan::ExclusiveSum (N n, T const *in, T *out, RetSum a_ret_sum=retSum)
 Exclusive sum.
 
template<class InIter , class OutIter >
OutIter amrex::Gpu::inclusive_scan (InIter begin, InIter end, OutIter result)
 
template<class InIter , class OutIter >
OutIter amrex::Gpu::exclusive_scan (InIter begin, InIter end, OutIter result)
 

Detailed Description

Performance-portable reduction and scan operations in AMReX.

These interfaces provide reductions (e.g., sum, min, max) and scan operations (prefix sums) over index spaces and ranges on both CPUs and GPUs. They do not use MPI and operate on data local to the process.

Key functions and classes include:

Function Documentation

◆ AnyOf() [1/2]

template<typename P , int dim>
bool amrex::Reduce::AnyOf ( BoxND< dim > const &  box,
P const &  pred 
)

Test whether the predicate is true for any index in a Box.

Note that this is local test that does not involve MPI.

Template Parameters
Pcallable type
dimdimension of the box
Parameters
boxindex region for the loop
predcallable object with the signature of bool(int,int,int).
Returns
the test result.

◆ AnyOf() [2/2]

template<typename T , typename N , typename P , std::enable_if_t< std::is_integral_v< N >, int > = 0>
bool amrex::Reduce::AnyOf ( n,
T const *  v,
P const &  pred 
)

Test whether any element in an array satisfies a unary predicate.

Note that this is local test that does not involve MPI.

Template Parameters
Tvalue type of the elements.
Nintegral index type.
Ppredicate type
Parameters
nnumber of elements to test.
vpointer to the input data array.
predunary predicate object.
Returns
the test result.

◆ exclusive_scan()

template<class InIter , class OutIter >
OutIter amrex::Gpu::exclusive_scan ( InIter  begin,
InIter  end,
OutIter  result 
)

◆ ExclusiveSum()

template<typename N , typename T , typename M = std::enable_if_t<std::is_integral_v<N>>>
T amrex::Scan::ExclusiveSum ( n,
T const *  in,
T *  out,
RetSum  a_ret_sum = retSum 
)

Exclusive sum.

Parameters
nnumber of elements
ininput
outoutput
a_ret_sumcontrol the return value
Returns
return the total sum if a_ret_sum is true

◆ inclusive_scan()

template<class InIter , class OutIter >
OutIter amrex::Gpu::inclusive_scan ( InIter  begin,
InIter  end,
OutIter  result 
)

◆ InclusiveSum()

template<typename N , typename T , typename M = std::enable_if_t<std::is_integral_v<N>>>
T amrex::Scan::InclusiveSum ( n,
T const *  in,
T *  out,
RetSum  a_ret_sum = retSum 
)

Inclusive sum.

Parameters
nnumber of elements
ininput
outoutput
a_ret_sumcontrol the return value
Returns
return the total sum if a_ret_sum is true

◆ Max() [1/2]

template<typename T , typename N , typename F , std::enable_if_t< std::is_integral_v< N > &&!std::is_same_v< T *, std::decay_t< F > >, int > = 0>
T amrex::Reduce::Max ( n,
F const &  f,
init_val = std::numeric_limits<T>::lowest() 
)

Compute the maximum of values generated by a callable.

Note that this is local reduction that does not involve MPI.

Template Parameters
Tvalue type of the reduction.
Nintegral index type.
Fcallable type with the signature T(N).
Parameters
nnumber of elements to reduce.
fcallable object invoked as f(i). For GPU builds, this needs to be a device lambda function or functor.
init_valinitial value (default: std::numeric_limits<T>::lowest()).
Returns
the maximum.

◆ Max() [2/2]

template<typename T , typename N , std::enable_if_t< std::is_integral_v< N >, int > = 0>
T amrex::Reduce::Max ( n,
T const *  v,
init_val = std::numeric_limits<T>::lowest() 
)

Compute the maximum of an array of values.

Note that this is local reduction that does not involve MPI.

Template Parameters
Tvalue type of the reduction.
Nintegral index type.
Parameters
nnumber of elements to reduce.
vpointer to the input data array.
init_valinitial value (default: std::numeric_limits<T>::lowest()).
Returns
the maximum.

◆ Min() [1/2]

template<typename T , typename N , typename F , std::enable_if_t< std::is_integral_v< N > &&!std::is_same_v< T *, std::decay_t< F > >, int > = 0>
T amrex::Reduce::Min ( n,
F const &  f,
init_val = std::numeric_limits<T>::max() 
)

Compute the minimum of values generated by a callable.

Note that this is local reduction that does not involve MPI.

Template Parameters
Tvalue type of the reduction.
Nintegral index type.
Fcallable type with the signature T(N).
Parameters
nnumber of elements to reduce.
fcallable object invoked as f(i). For GPU builds, this needs to be a device lambda function or functor.
init_valinitial value (default: std::numeric_limits<T>::max()).
Returns
the minimum.

◆ Min() [2/2]

template<typename T , typename N , std::enable_if_t< std::is_integral_v< N >, int > = 0>
T amrex::Reduce::Min ( n,
T const *  v,
init_val = std::numeric_limits<T>::max() 
)

Compute the minimum of an array of values.

Note that this is local reduction that does not involve MPI.

Template Parameters
Tvalue type of the reduction.
Nintegral index type.
Parameters
nnumber of elements to reduce.
vpointer to the input data array.
init_valinitial value (default: std::numeric_limits<T>::max()).
Returns
the minimum.

◆ MinMax() [1/2]

template<typename T , typename N , typename F , std::enable_if_t< std::is_integral_v< N > &&!std::is_same_v< T *, std::decay_t< F > >, int > = 0>
std::pair< T, T > amrex::Reduce::MinMax ( n,
F const &  f 
)

Compute the minimum and maximum of values generated by a callable.

Note that this is local reduction that does not involve MPI.

Template Parameters
Tvalue type of the reduction.
Nintegral index type.
Fcallable type with the signature T(N).
Parameters
nnumber of elements to reduce.
fcallable object invoked as f(i). For GPU builds, this needs to be a device lambda function or functor.
Returns
the pair of minimum and maximum.

◆ MinMax() [2/2]

template<typename T , typename N , std::enable_if_t< std::is_integral_v< N >, int > = 0>
std::pair< T, T > amrex::Reduce::MinMax ( n,
T const *  v 
)

Compute the minimum and maximum of an array of values.

Note that this is local reduction that does not involve MPI.

Template Parameters
Tvalue type of the reduction.
Nintegral index type.
Parameters
nnumber of elements to reduce.
vpointer to the input data array.
Returns
the pair of minimum and maximum.

◆ PrefixSum()

template<typename T , typename N , typename FIN , typename FOUT , typename TYPE , typename M = std::enable_if_t<std::is_integral_v<N> && (std::is_same_v<std::decay_t<TYPE>,Type::Inclusive> || std::is_same_v<std::decay_t<TYPE>,Type::Exclusive>)>>
T amrex::Scan::PrefixSum ( n,
FIN const &  fin,
FOUT const &  fout,
TYPE  ,
RetSum  a_ret_sum = retSum 
)

◆ Sum() [1/2]

template<typename T , typename N , typename F , std::enable_if_t< std::is_integral_v< N > &&!std::is_same_v< T *, std::decay_t< F > >, int > = 0>
T amrex::Reduce::Sum ( n,
F const &  f,
init_val = 0 
)

Compute the sum of values generated by a callable.

Note that this is local reduction that does not involve MPI.

Template Parameters
Tvalue type of the reduction.
Nintegral index type.
Fcallable type with the signature T(N).
Parameters
nnumber of elements to reduce.
fcallable object invoked as f(i). For GPU builds, this needs to be a device lambda function or functor.
init_valinitial value (default: 0).
Returns
the sum.

◆ Sum() [2/2]

template<typename T , typename N , std::enable_if_t< std::is_integral_v< N >, int > = 0>
T amrex::Reduce::Sum ( n,
T const *  v,
init_val = 0 
)

Compute the sum of an array of values.

Note that this is local reduction that does not involve MPI.

Template Parameters
Tvalue type of the reduction.
Nintegral index type.
Parameters
nnumber of elements to reduce.
vpointer to the input data array.
init_valinitial value (default: 0).
Returns
the sum.