![]()
Definition
MPI_Iallreduce is the non-blocking version of MPI_Allreduce; it is the means by which MPI processes can apply a reduction calculation and make the reduction result available to all MPI processes involved. Unlike MPI_Allreduce however, MPI_Iallreduce returns immediately, before the reduction is guaranteed to be complete. The user must therefore explicitly wait (MPI_Wait) or test (MPI_Test) for the completion of MPI_Iallreduce before safely reusing the buffers passed. Also, MPI_Iallreduce is a collective operation; it must be called by every MPI process in the communicator given. Predefined operations are: MPI_MIN, MPI_MAX, MPI_BOR, MPI_BXOR, MPI_LOR, MPI_LXOR, MPI_BAND, MPI_LAND, MPI_SUM and MPI_PROD. Other variants of MPI_Iallreduce are MPI_Allreduce, MPI_Reduce, MPI_Ireduce. Refer to MPI_Allreduce to see the blocking counterpart of MPI_Iallreduce.
![]()
Parameters
- send_buffer
- A pointer on the buffer to send for reduction.
- receive_buffer
- A pointer on the buffer in which store the result of the reduction.
- count
- The number of elements in the send buffer, which is identical to that in the receive buffer as well.
- datatype
- The type of a buffer element.
- operation
- The operation to apply to combine messages received in the reduction. This operation must be associative, and commutative for predefined operations while user-defined operations may be non-commutative.
- communicator
- The communicator in which the reduction takes place.
- request
- The variable in which store the handler on the non-blocking operation.
![]()
Returned value
The error code returned from the non-blocking reduction.
- MPI_SUCCESS
- The routine successfully completed.
#include <stdio.h>
#include <stdlib.h>
#include <mpi.h>
/**
* @brief Illustrates how to use a non-blocking all-reduce.
* @details This application consists of a sum all-reduction; every MPI process
* sends its rank for reduction before the sum of these ranks is stored in the
* receive buffer of each MPI process. It can be visualised as follows:
*
* +-----------+ +-----------+ +-----------+ +-----------+
* | Process 0 | | Process 1 | | Process 2 | | Process 3 |
* +-+-------+-+ +-+-------+-+ +-+-------+-+ +-+-------+-+
* | Value | | Value | | Value | | Value |
* | 0 | | 1 | | 2 | | 3 |
* +-------+ +----+--+ +--+----+ +-------+
* \ | | /
* \ | | /
* \ | | /
* \ | | /
* +-----+-----+-----+-----+
* |
* +---+---+
* | SUM |
* +---+---+
* | 6 |
* +-------+
* |
* +-----+-----+-----+-----+
* / | | \
* / | | \
* / | | \
* / | | \
* +-------+ +----+--+ +--+----+ +-------+
* | 6 | | 6 | | 6 | | 6 |
* +-+-------+-+ +-+-------+-+ +-+-------+-+ +-+-------+-+
* | Process 0 | | Process 1 | | Process 2 | | Process 3 |
* +-----------+ +-----------+ +-----------+ +-----------+
**/
int main(int argc, char* argv[])
{
MPI_Init(&argc, &argv);
// Get the size of the communicator
int size = 0;
MPI_Comm_size(MPI_COMM_WORLD, &size);
if(size != 4)
{
printf("This application is meant to be run with 4 MPI processes.\n");
MPI_Abort(MPI_COMM_WORLD, EXIT_FAILURE);
}
// Get my rank
int my_rank;
MPI_Comm_rank(MPI_COMM_WORLD, &my_rank);
// Each MPI process sends its rank to reduction, root MPI process collects the result
int reduction_result = 0;
MPI_Request request;
MPI_Iallreduce(&my_rank, &reduction_result, 1, MPI_INT, MPI_SUM, MPI_COMM_WORLD, &request);
// Do some other job
printf("Process %d issued the MPI_Iallreduce and has moved on, printing this message.\n", my_rank);
// Wait for the MPI_Iallreduce to complete
MPI_Wait(&request, MPI_STATUS_IGNORE);
printf("[MPI Process %d] The sum of all ranks is %d.\n", my_rank, reduction_result);
MPI_Finalize();
return EXIT_SUCCESS;
}
![]()
Definition
MPI_Iallreduce is the non-blocking version of MPI_Allreduce; it is the means by which MPI processes can apply a reduction calculation and make the reduction result available to all MPI processes involved. Unlike MPI_Allreduce however, MPI_Iallreduce returns immediately, before the reduction is guaranteed to be complete. The user must therefore explicitly wait (MPI_Wait) or test (MPI_Test) for the completion of MPI_Iallreduce before safely reusing the buffers passed. Also, MPI_Iallreduce is a collective operation; it must be called by every MPI process in the communicator given. Predefined operations are: MPI_MIN, MPI_MAX, MPI_BOR, MPI_BXOR, MPI_LOR, MPI_LXOR, MPI_BAND, MPI_LAND, MPI_SUM and MPI_PROD. Other variants of MPI_Iallreduce are MPI_Allreduce, MPI_Reduce, MPI_Ireduce. Refer to MPI_Allreduce to see the blocking counterpart of MPI_Iallreduce.
SUBROUTINE MPI_Iallreduce(send_buffer, receive_buffer, count, datatype, operation, communicator, request, ierror)
<type> :: send_buffer(*)
<type> :: receive_buffer(*)
INTEGER :: count
INTEGER :: datatype
INTEGER :: operation
INTEGER :: communicator
INTEGER :: request
INTEGER :: ierror
![]()
Parameters
- send_buffer
- The buffer to send for reduction.
- receive_buffer
- The buffer in which store the result of the reduction.
- count
- The number of elements in the send buffer, which is identical to that in the receive buffer as well.
- datatype
- The type of a buffer element.
- operation
- The operation to apply to combine messages received in the reduction. This operation must be associative, and commutative for predefined operations while user-defined operations may be non-commutative.
- communicator
- The communicator in which the reduction takes place.
- request
- The variable in which store the handler on the non-blocking operation.
- ierror
- The error code returned from the non-blocking reduction.
!> @brief Illustrates how to use a non-blocking all-reduce.
!> @details This application consists of a sum all-reduction every MPI process
!> sends its rank for reduction before the sum of these ranks is stored in the
!> receive buffer of each MPI process. It can be visualised as follows:
!>
!> +-----------+ +-----------+ +-----------+ +-----------+
!> | Process 0 | | Process 1 | | Process 2 | | Process 3 |
!> +-+-------+-+ +-+-------+-+ +-+-------+-+ +-+-------+-+
!> | Value | | Value | | Value | | Value |
!> | 0 | | 1 | | 2 | | 3 |
!> +-------+ +----+--+ +--+----+ +-------+
!> \ | | /
!> \ | | /
!> \ | | /
!> \ | | /
!> +-----+-----+-----+-----+
!> |
!> +---+---+
!> | SUM |
!> +---+---+
!> | 6 |
!> +-------+
!> |
!> +-----+-----+-----+-----+
!> / | | \
!> / | | \
!> / | | \
!> / | | \
!> +-------+ +----+--+ +--+----+ +-------+
!> | 6 | | 6 | | 6 | | 6 |
!> +-+-------+-+ +-+-------+-+ +-+-------+-+ +-+-------+-+
!> | Process 0 | | Process 1 | | Process 2 | | Process 3 |
!> +-----------+ +-----------+ +-----------+ +-----------+
PROGRAM main
USE mpi
IMPLICIT NONE
INTEGER :: ierror
INTEGER :: size
INTEGER :: my_rank
INTEGER :: reduction_result = 0
INTEGER :: request
CALL MPI_Init(ierror)
! Get the size of the communicator
CALL MPI_Comm_size(MPI_COMM_WORLD, size, ierror)
IF (size .NE. 4) THEN
WRITE(*,'(A)') 'This application is meant to be run with 4 MPI processes.'
CALL MPI_Abort(MPI_COMM_WORLD, 0, ierror)
END IF
! Get my rank
CALL MPI_Comm_rank(MPI_COMM_WORLD, my_rank, ierror)
! Each MPI process sends its rank to reduction, root MPI process collects the result
CALL MPI_Iallreduce(my_rank, reduction_result, 1, MPI_INTEGER, MPI_SUM, MPI_COMM_WORLD, request, ierror)
! Do some other job
WRITE(*,'(A,I0,A)') 'Process ', my_rank, ' issued the MPI_Iallreduce and has moved on, printing this message.'
! Wait for the MPI_Iallreduce to complete
CALL MPI_Wait(request, MPI_STATUS_IGNORE, ierror)
WRITE(*,'(A,I0,A,I0,A)') '[MPI Process ', my_rank, '] The sum of all ranks is ', reduction_result, '.'
CALL MPI_Finalize(ierror)
END PROGRAM main
![]()
Definition
MPI_Iallreduce is the non-blocking version of MPI_Allreduce; it is the means by which MPI processes can apply a reduction calculation and make the reduction result available to all MPI processes involved. Unlike MPI_Allreduce however, MPI_Iallreduce returns immediately, before the reduction is guaranteed to be complete. The user must therefore explicitly wait (MPI_Wait) or test (MPI_Test) for the completion of MPI_Iallreduce before safely reusing the buffers passed. Also, MPI_Iallreduce is a collective operation; it must be called by every MPI process in the communicator given. Predefined operations are: MPI_MIN, MPI_MAX, MPI_BOR, MPI_BXOR, MPI_LOR, MPI_LXOR, MPI_BAND, MPI_LAND, MPI_SUM and MPI_PROD. Other variants of MPI_Iallreduce are MPI_Allreduce, MPI_Reduce, MPI_Ireduce. Refer to MPI_Allreduce to see the blocking counterpart of MPI_Iallreduce.
SUBROUTINE MPI_Iallreduce(send_buffer, receive_buffer, count, datatype, operation, communicator, request, ierror)
TYPE(*), DIMENSION(..), INTENT(IN), ASYNCHRONOUS :: send_buffer
TYPE(*), DIMENSION(..), ASYNCHRONOUS :: receive_buffer
TYPE(INTEGER), INTENT(IN) :: count
TYPE(MPI_Datatype), INTENT(IN) :: datatype
TYPE(MPI_Op), INTENT(IN) :: operation
TYPE(MPI_Comm), INTENT(IN) :: communicator
TYPE(MPI_Request), INTENT(OUT) :: request
INTEGER, OPTIONAL, INTENT(OUT) :: ierror
![]()
Parameters
- send_buffer
- The buffer to send for reduction.
- receive_buffer
- The buffer in which store the result of the reduction.
- count
- The number of elements in the send buffer, which is identical to that in the receive buffer as well.
- datatype
- The type of a buffer element.
- operation
- The operation to apply to combine messages received in the reduction. This operation must be associative, and commutative for predefined operations while user-defined operations may be non-commutative.
- communicator
- The communicator in which the reduction takes place.
- request
- The variable in which store the handler on the non-blocking operation.
- ierror [Optional]
- The error code returned from the non-blocking reduction.
!> @brief Illustrates how to use a non-blocking all-reduce.
!> @details This application consists of a sum all-reduction every MPI process
!> sends its rank for reduction before the sum of these ranks is stored in the
!> receive buffer of each MPI process. It can be visualised as follows:
!>
!> +-----------+ +-----------+ +-----------+ +-----------+
!> | Process 0 | | Process 1 | | Process 2 | | Process 3 |
!> +-+-------+-+ +-+-------+-+ +-+-------+-+ +-+-------+-+
!> | Value | | Value | | Value | | Value |
!> | 0 | | 1 | | 2 | | 3 |
!> +-------+ +----+--+ +--+----+ +-------+
!> \ | | /
!> \ | | /
!> \ | | /
!> \ | | /
!> +-----+-----+-----+-----+
!> |
!> +---+---+
!> | SUM |
!> +---+---+
!> | 6 |
!> +-------+
!> |
!> +-----+-----+-----+-----+
!> / | | \
!> / | | \
!> / | | \
!> / | | \
!> +-------+ +----+--+ +--+----+ +-------+
!> | 6 | | 6 | | 6 | | 6 |
!> +-+-------+-+ +-+-------+-+ +-+-------+-+ +-+-------+-+
!> | Process 0 | | Process 1 | | Process 2 | | Process 3 |
!> +-----------+ +-----------+ +-----------+ +-----------+
PROGRAM main
USE mpi_f08
IMPLICIT NONE
INTEGER :: size
INTEGER :: my_rank
INTEGER :: reduction_result = 0
TYPE(MPI_Request) :: request
CALL MPI_Init()
! Get the size of the communicator
CALL MPI_Comm_size(MPI_COMM_WORLD, size)
IF (size .NE. 4) THEN
WRITE(*,'(A)') 'This application is meant to be run with 4 MPI processes.'
CALL MPI_Abort(MPI_COMM_WORLD, 0)
END IF
! Get my rank
CALL MPI_Comm_rank(MPI_COMM_WORLD, my_rank)
! Each MPI process sends its rank to reduction, root MPI process collects the result
CALL MPI_Iallreduce(my_rank, reduction_result, 1, MPI_INTEGER, MPI_SUM, MPI_COMM_WORLD, request)
! Do some other job
WRITE(*,'(A,I0,A)') 'Process ', my_rank, ' issued the MPI_Iallreduce and has moved on, printing this message.'
! Wait for the MPI_Iallreduce to complete
CALL MPI_Wait(request, MPI_STATUS_IGNORE)
WRITE(*,'(A,I0,A,I0,A)') '[MPI Process ', my_rank, '] The sum of all ranks is ', reduction_result, '.'
CALL MPI_Finalize()
END PROGRAM main