...one of the most highly
regarded and expertly designed C++ library projects in the
world.
— Herb Sutter and Andrei
Alexandrescu, C++
Coding Standards
boost::mpi::reduce — Combine the values stored by each process into a single value at the root.
// In header: <boost/mpi/collectives.hpp> template<typename T, typename Op> void reduce(const communicator & comm, const T & in_value, T & out_value, Op op, int root); template<typename T, typename Op> void reduce(const communicator & comm, const T & in_value, Op op, int root); template<typename T, typename Op> void reduce(const communicator & comm, const T * in_values, int n, T * out_values, Op op, int root); template<typename T, typename Op> void reduce(const communicator & comm, const T * in_values, int n, Op op, int root);
reduce
is a collective algorithm that combines the values stored by each process into a single value at the root
. The values can be combined arbitrarily, specified via a function object. The type T
of the values may be any type that is serializable or has an associated MPI data type. One can think of this operation as a gather
to the root
, followed by an std::accumulate()
over the gathered values and using the operation op
.
When the type T
has an associated MPI data type, this routine invokes MPI_Reduce
to perform the reduction. If possible, built-in MPI operations will be used; otherwise, reduce()
will create a custom MPI_Op for the call to MPI_Reduce.
Parameters: |
|