Reduction operations#

Overview#

MPL supports various communication operations that perform a reduction operation over all processes within a communicator. The reduction operation is passed as an argument to the communicator class method that realizes to communication operation. The reduction operation can be given by a user-defined two-arguments functor class, a lambda function, e.g.,

comm.reduce([](auto a, auto b) { return a + b; }, ...);

or by any of the template classes as documented below.

Class documentation#

Maximum#

Perform the reduction operation

\[y = \max (x_1, x_2)\]
template<typename T>
struct max#

Function object for calculating the maximum of two values in reduction operations as communicator::reduce.

Template Parameters:

T – data type of the reduction operation’s arguments and its result

Public Functions

inline T operator()(const T &x, const T &y) const#
Parameters:
  • x – first argument

  • y – second argument

Returns:

maximum of the two arguments

Minimum#

Perform the reduction operation

\[y = \min (x_1, x_2)\]
template<typename T>
struct min#

Function object for calculating the minimum of two values in reduction operations as communicator::reduce.

Template Parameters:

T – data type of the reduction operation’s arguments and its result

Public Functions

inline T operator()(const T &x, const T &y) const#
Parameters:
  • x – first argument

  • y – second argument

Returns:

minimum of the two arguments

Addition#

Perform the reduction operation

\[y = x_1 + x_2\]
template<typename T>
struct plus#

Function object for calculating the sum of two values in reduction operations as communicator::reduce.

Template Parameters:

T – data type of the reduction operation’s arguments and its result

Public Functions

inline T operator()(const T &x, const T &y) const#
Parameters:
  • x – first argument

  • y – second argument

Returns:

sum of the two arguments

Multiplication#

Perform the reduction operation

\[y = x_1 \cdot x_2\]
template<typename T>
struct multiplies#

Function object for calculating the product of two values in reduction operations as communicator::reduce.

Template Parameters:

T – data type of the reduction operation’s arguments and its result

Public Functions

inline T operator()(const T &x, const T &y) const#
Parameters:
  • x – first argument

  • y – second argument

Returns:

product of the two arguments

Logical conjunction#

Perform the reduction operation

\[y = x_1 \land x_2\]
template<typename T>
struct logical_and#

Function object for calculating the logical conjunction of two values in reduction operations as communicator::reduce.

Template Parameters:

T – data type of the reduction operation’s arguments and its result

Public Functions

inline T operator()(const T &x, const T &y) const#
Parameters:
  • x – first argument

  • y – second argument

Returns:

logical conjunction of the two arguments

Logical disjunction#

Perform the reduction operation

\[y = x_1 \lor x_2\]
template<typename T>
struct logical_or#

Function object for calculating the logical (inclusive) disjunction of two values in reduction operations as communicator::reduce.

Template Parameters:

T – data type of the reduction operation’s arguments and its result

Public Functions

inline T operator()(const T &x, const T &y) const#
Parameters:
  • x – first argument

  • y – second argument

Returns:

logical (inclusive) disjunction of the two arguments

Exclusive disjunction#

Perform the reduction operation

\[y = x_1 \oplus x_2\]
template<typename T>
struct logical_xor#

Function object for calculating the logical exclusive disjunction of two values in reduction operations as communicator::reduce.

Template Parameters:

T – data type of the reduction operation’s arguments and its result

Public Functions

inline T operator()(const T &x, const T &y) const#
Parameters:
  • x – first argument

  • y – second argument

Returns:

logical exclusive disjunction of the two arguments

Bitwise and#

Perform for integer arguments the bitwise reduction operation

\[y = x_1 \land x_2\]
template<typename T>
struct bit_and#

Function object for calculating the bitwise conjunction of two values in reduction operations as communicator::reduce.

Template Parameters:

T – data type of the reduction operation’s arguments and its result

Public Functions

inline T operator()(const T &x, const T &y) const#
Parameters:
  • x – first argument

  • y – second argument

Returns:

bitwise conjunction of the two arguments

Bitwise or#

Perform for integer arguments the bitwise reduction operation

\[y = x_1 \lor x_2\]
template<typename T>
struct bit_or#

Function object for calculating the bitwise (inclusive) disjunction of two values in reduction operations as communicator::reduce.

Template Parameters:

T – data type of the reduction operation’s arguments and its result

Public Functions

inline T operator()(const T &x, const T &y) const#
Parameters:
  • x – first argument

  • y – second argument

Returns:

bitwise (inclusive) disjunction of the two arguments

Bitwise exclusive-or#

Perform for integer arguments the bitwise reduction operation

\[y = x_1 \oplus x_2\]
template<typename T>
struct bit_xor#

Function object for calculating the bitwise exclusive disjunction of two values in reduction operations as communicator::reduce.

Template Parameters:

T – data type of the reduction operation’s arguments and its result

Public Functions

inline T operator()(const T &x, const T &y) const#
Parameters:
  • x – first argument

  • y – second argument

Returns:

bitwise exclusive disjunction of the two arguments

Operator traits#

The application of some reduction operations can be performed more efficiently by exploiting the commutativity properties of the employed reduction operation. Partial template specializations of the class mpl::op_traits provide information about the commutativity properties of the reduction operation. Users may provide further user-defined specializations of mpl::op_traits for user-defined operators.

template<typename F>
struct op_traits#

Traits class for storing meta information about reduction operations.

Template Parameters:

F – function object type

Public Static Attributes

static constexpr bool is_commutative = false#

Is true if reduction operation specified in the template parameter F is commutative.

template<typename T>
struct op_traits<max<T>>#

Specialization of traits class op_traits for storing meta information about the max reduction operation.

Public Static Attributes

static constexpr bool is_commutative = true#

The max reduction operation is commutative.

template<typename T>
struct op_traits<min<T>>#

Specialization of traits class op_traits for storing meta information about the min reduction operation.

Public Static Attributes

static constexpr bool is_commutative = true#

The min reduction operation is commutative.

template<typename T>
struct op_traits<plus<T>>#

Specialization of traits class op_traits for storing meta information about the plus reduction operation.

Public Static Attributes

static constexpr bool is_commutative = true#

The plus reduction operation is commutative.

template<typename T>
struct op_traits<multiplies<T>>#

Specialization of traits class op_traits for storing meta information about the multiplies reduction operation.

Public Static Attributes

static constexpr bool is_commutative = true#

The multiplies reduction operation is commutative.

template<typename T>
struct op_traits<logical_and<T>>#

Specialization of traits class op_traits for storing meta information about the logical_and reduction operation.

Public Static Attributes

static constexpr bool is_commutative = true#

The logical_and reduction operation is commutative.

template<typename T>
struct op_traits<logical_or<T>>#

Specialization of traits class op_traits for storing meta information about the logical_or reduction operation.

Public Static Attributes

static constexpr bool is_commutative = true#

The logical_or reduction operation is commutative.

template<typename T>
struct op_traits<logical_xor<T>>#

Specialization of traits class op_traits for storing meta information about the logical_xor reduction operation.

Public Static Attributes

static constexpr bool is_commutative = true#

The logical_xor reduction operation is commutative.

template<typename T>
struct op_traits<bit_and<T>>#

Specialization of traits class op_traits for storing meta information about the bit_and reduction operation.

Public Static Attributes

static constexpr bool is_commutative = true#

The bit_and reduction operation is commutative.

template<typename T>
struct op_traits<bit_or<T>>#

Specialization of traits class op_traits for storing meta information about the bit_or reduction operation.

Public Static Attributes

static constexpr bool is_commutative = true#

The bit_or reduction operation is commutative.

template<typename T>
struct op_traits<bit_xor<T>>#

Specialization of traits class op_traits for storing meta information about the bit_xor reduction operation.

Public Static Attributes

static constexpr bool is_commutative = true#

The bit_xor reduction operation is commutative.