MPI_Alltoall is a collective operation in which all processes send the same amount of data to each other, and receive the same amount of data from each other. The operation of this routine can be represented as follows, where each process performs 2n (n being the number of processes in communicator \fIcomm\fP) independent point-to-point communications (including communication with itself).
.sp
.nf
MPI_Comm_size(\fIcomm\fP, &n);
for (i = 0, i < n; i++)
MPI_Send(\fIsendbuf\fP + i * \fIsendcount\fP * extent(\fIsendtype\fP),
\fIsendcount\fP, \fIsendtype\fP, i, ..., \fIcomm\fP);
for (i = 0, i < n; i++)
MPI_Recv(\fIrecvbuf\fP + i * \fIrecvcount\fP * extent(\fIrecvtype\fP),
\fIrecvcount\fP, \fIrecvtype\fP, i, ..., \fIcomm\fP);
.fi
.sp
Each process breaks up its local \fIsendbuf\fP into n blocks \- each
containing \fIsendcount\fP elements of type \fIsendtype\fP \- and
divides its \fIrecvbuf\fP similarly according to \fIrecvcount\fP and
\fIrecvtype\fP. Process j sends the k-th block of its local
\fIsendbuf\fP to process k, which places the data in the j-th block of
its local \fIrecvbuf\fP. The amount of data sent must be equal to the
amount of data received, pairwise, between every pair of processes.
WHEN COMMUNICATOR IS AN INTER-COMMUNICATOR
.sp
When the communicator is an inter-communicator, the gather operation occurs in two phases. The data is gathered from all the members of the first group and received by all the members of the second group. Then the data is gathered from all the members of the second group and received by all the members of the first. The operation exhibits a symmetric, full-duplex behavior.
.sp
The first group defines the root process. The root process uses MPI_ROOT as the value of \fIroot\fR. All other processes in the first group use MPI_PROC_NULL as the value of \fIroot\fR. All processes in the second group use the rank of the root process in the first group as the value of \fIroot\fR.
.sp
When the communicator is an intra-communicator, these groups are the same, and the operation occurs in a single phase.
When the communicator is an intracommunicator, you can perform an all-to-all operation in-place (the output buffer is used as the input buffer). Use the variable MPI_IN_PLACE as the value of \fIsendbuf\fR. In this case, \fIsendcount\fR and \fIsendtype\fR are ignored. The input data of each process is assumed to be in the area where that process would receive its own contribution to the receive buffer.