In applications like matrix transposes or Fast Fourier Transforms (FFTs), an MPI_Alltoall call is very helpful. This is an extension to MPI_Allgather where each process sends distinct data to each receiver. The j-th block from process i is received by process j and stored in the i-th block. A graphic representation of the MPI_Alltoall is shown below:

matrix illustration of Alltoall. In this representation, processes are the 5 rows and data are the 5 columns. The units of data are labeled A, B, C, D and E for the columns with a subscript (0 to 4) that represents the original process (row). For example, the first process contains A_0, B_0, C_0, D_0 and E_0. After the all-to-all operation, all the A-parts of the original data are on the first process, all the B-parts of the data are on the second process, and so on. In effect, the process-by-data matrix is transposed.
Matrix illustration of Alltoall.

Just as with Allgatherv, the MPI_Alltoallv extension allows these blocks of data to vary in size among different pairs of senders and receivers. The syntax of MPI_Alltoall and MPI_Alltoallv is as follows:

Alltoall and Alltoallv Syntax
int MPI_Alltoall(void *sbuf, int scount, \
     MPI_Datatype stype, void *rbuf, int rcount, \
     MPI_Datatype rtype, MPI_Comm comm)

int MPI_Alltoallv(void *sbuf, int *scounts, \
     int *sdispls, MPI_Datatype stype, void *rbuf, \
     int *rcounts, int *rdispls, MPI_Datatype rtype, \
     MPI_Comm comm)
MPI_ALLTOALL(sbuf, scount, stype, rbuf, rcount, rtype, comm, ierr)

MPI_ALLTOALLV(sbuf, scounts, sdispls, stype, rbuf, rcounts,
     rdispls, rtype, comm, ierr)
Alltoall[v] parameters:
sbuf
is the starting address of the send buffer
scount[s]
is the [array of the] number of elements to send to each process
[sdispls]
is an array specifying the displacements of data relative to sbuf
stype
is the data type of send buffer elements
rbuf
is the address of the receive buffer
rcount[s]
is [an array containing] the number of elements to be received from each process
[rdispls]
is an array specifying the displacements of data relative to rbuf
rtype
is the data type of the receive buffer elements
comm
is the group communicator
Info: Alltoall vs. Allgather specifications

Alltoall has the same specification as Allgather, except sbuf must contain scount*NPROC elements.

 
©   Cornell University  |  Center for Advanced Computing  |  Copyright Statement  |  Inclusivity Statement