7.9.6. All-Reduce

PreviousUpNext
Up: Global Reduction Operations Next: MPI Process-Local Reduction Previous: Example of User-Defined Reduce

MPI includes a variant of the reduce operations where the result is returned to all MPI processes in a group. MPI requires that all MPI processes from the same group participating in these operations receive identical results.

MPI_ALLREDUCE(sendbuf, recvbuf, count, datatype, op, comm)
IN sendbufstarting address of send buffer (choice)
OUT recvbufstarting address of receive buffer (choice)
IN countnumber of elements in send buffer (non-negative integer)
IN datatypedatatype of elements of send buffer (handle)
IN opoperation (handle)
IN commcommunicator (handle)
C binding
int MPI_Allreduce(const void *sendbuf, void *recvbuf, int count, MPI_Datatype datatype, MPI_Op op, MPI_Comm comm)
int MPI_Allreduce_c(const void *sendbuf, void *recvbuf, MPI_Count count, MPI_Datatype datatype, MPI_Op op, MPI_Comm comm)
Fortran 2008 binding
MPI_Allreduce(sendbuf, recvbuf, count, datatype, op, comm, ierror)

TYPE(*), DIMENSION(..), INTENT(IN) :: sendbuf
TYPE(*), DIMENSION(..) :: recvbuf
INTEGER, INTENT(IN) :: count
TYPE(MPI_Datatype), INTENT(IN) :: datatype
TYPE(MPI_Op), INTENT(IN) :: op
TYPE(MPI_Comm), INTENT(IN) :: comm
INTEGER, OPTIONAL, INTENT(OUT) :: ierror
MPI_Allreduce(sendbuf, recvbuf, count, datatype, op, comm, ierror) !(_c)

TYPE(*), DIMENSION(..), INTENT(IN) :: sendbuf
TYPE(*), DIMENSION(..) :: recvbuf
INTEGER(KIND=MPI_COUNT_KIND), INTENT(IN) :: count
TYPE(MPI_Datatype), INTENT(IN) :: datatype
TYPE(MPI_Op), INTENT(IN) :: op
TYPE(MPI_Comm), INTENT(IN) :: comm
INTEGER, OPTIONAL, INTENT(OUT) :: ierror
Fortran binding
MPI_ALLREDUCE(SENDBUF, RECVBUF, COUNT, DATATYPE, OP, COMM, IERROR)

<type> SENDBUF(*), RECVBUF(*)
INTEGER COUNT, DATATYPE, OP, COMM, IERROR

If comm is an intra-communicator, MPI_ALLREDUCE behaves the same as MPI_REDUCE except that the result appears in the receive buffer of all the group members.


Advice to implementors.

The all-reduce operations can be implemented as a reduce, followed by a broadcast. However, a direct implementation can lead to better performance. ( End of advice to implementors.)
The ``in place'' option for intra-communicators is specified by passing the value MPI_IN_PLACE to the argument sendbuf at all processes. value MPI_IN_PLACE to the argument sendbuf at all MPI processes. In this case, the input data is taken at each MPI process from the receive buffer, where it will be replaced by the output data.

If comm is an inter-communicator, then the result of the reduction of the data provided by MPI processes in group A is stored at each MPI process in group B, and vice versa. Both groups should provide count and datatype arguments that specify the same type signature.

The following example uses an intra-communicator.


Example A routine that computes the product of a vector and an array that are distributed across a group of MPI processes and returns the answer at all nodes (see also Example Predefined Reduction Operations).

Image file


PreviousUpNext
Up: Global Reduction Operations Next: MPI Process-Local Reduction Previous: Example of User-Defined Reduce


Return to MPI-4.1 Standard Index
Return to MPI Forum Home Page

(Unofficial) MPI-4.1 of November 2, 2023
HTML Generated on November 19, 2023