MPI_ALLTOALL_INIT(3)

πŸ“¦
version 5.0.10 Β· 4 versions
, in ubuntu stonking

✨ MPI_ALLTOALL_INIT ✨

okay bestie, welcome to the Open MPI manual, and specifically the page for MPI_Alltoall, MPI_Ialltoall, and MPI_Alltoall_init. it's giving "everyone talks to everyone" energy and honestly? iconic. let's get into it πŸ’…


πŸ’– NAME πŸ’–

MPI_Alltoall, MPI_Ialltoall, MPI_Alltoall_init β€” all processes send data to all processes 🫢


πŸŽ€ SYNTAX πŸŽ€

✨ C Syntax ✨

#include <mpi.h>

int MPI_Alltoall(const void *sendbuf, int sendcount,
     MPI_Datatype sendtype, void *recvbuf, int recvcount,
     MPI_Datatype recvtype, MPI_Comm comm)

int MPI_Ialltoall(const void *sendbuf, int sendcount,
     MPI_Datatype sendtype, void *recvbuf, int recvcount,
     MPI_Datatype recvtype, MPI_Comm comm, MPI_Request *request)

int MPI_Alltoall_init(const void *sendbuf, int sendcount,
     MPI_Datatype sendtype, void *recvbuf, int recvcount,
     MPI_Datatype recvtype, MPI_Comm comm, MPI_Info info, MPI_Request *request)

🌸 Fortran Syntax 🌸

USE MPI
! or the older form: INCLUDE 'mpif.h'
MPI_ALLTOALL(SENDBUF, SENDCOUNT, SENDTYPE, RECVBUF, RECVCOUNT,
     RECVTYPE, COMM, IERROR)

     <type>  SENDBUF(*), RECVBUF(*)
     INTEGER SENDCOUNT, SENDTYPE, RECVCOUNT, RECVTYPE
     INTEGER COMM, IERROR

MPI_IALLTOALL(SENDBUF, SENDCOUNT, SENDTYPE, RECVBUF, RECVCOUNT,
     RECVTYPE, COMM, REQUEST, IERROR)

     <type>  SENDBUF(*), RECVBUF(*)
     INTEGER SENDCOUNT, SENDTYPE, RECVCOUNT, RECVTYPE
     INTEGER COMM, REQUEST, IERROR

MPI_ALLTOALL_INIT(SENDBUF, SENDCOUNT, SENDTYPE, RECVBUF, RECVCOUNT,
     RECVTYPE, COMM, INFO, REQUEST, IERROR)

     <type>  SENDBUF(*), RECVBUF(*)
     INTEGER SENDCOUNT, SENDTYPE, RECVCOUNT, RECVTYPE
     INTEGER COMM, INFO, REQUEST, IERROR

πŸ¦‹ Fortran 2008 Syntax πŸ¦‹

USE mpi_f08
MPI_Alltoall(sendbuf, sendcount, sendtype, recvbuf, recvcount, recvtype,
             comm, ierror)

     TYPE(*), DIMENSION(..), INTENT(IN) :: sendbuf
     TYPE(*), DIMENSION(..) :: recvbuf
     INTEGER, INTENT(IN) :: sendcount, recvcount
     TYPE(MPI_Datatype), INTENT(IN) :: sendtype, recvtype
     TYPE(MPI_Comm), INTENT(IN) :: comm
     INTEGER, OPTIONAL, INTENT(OUT) :: ierror

MPI_Ialltoall(sendbuf, sendcount, sendtype, recvbuf, recvcount, recvtype,
             comm, request, ierror)

     TYPE(*), DIMENSION(..), INTENT(IN), ASYNCHRONOUS :: sendbuf
     TYPE(*), DIMENSION(..), ASYNCHRONOUS :: recvbuf
     INTEGER, INTENT(IN) :: sendcount, recvcount
     TYPE(MPI_Datatype), INTENT(IN) :: sendtype, recvtype
     TYPE(MPI_Comm), INTENT(IN) :: comm
     TYPE(MPI_Request), INTENT(OUT) :: request
     INTEGER, OPTIONAL, INTENT(OUT) :: ierror

MPI_Alltoall_init(sendbuf, sendcount, sendtype, recvbuf, recvcount, recvtype,
                     comm, info, request, ierror)

     TYPE(*), DIMENSION(..), INTENT(IN), ASYNCHRONOUS :: sendbuf
     TYPE(*), DIMENSION(..), ASYNCHRONOUS :: recvbuf
     INTEGER, INTENT(IN) :: sendcount, recvcount
     TYPE(MPI_Datatype), INTENT(IN) :: sendtype, recvtype
     TYPE(MPI_Comm), INTENT(IN) :: comm
     TYPE(MPI_Info), INTENT(IN) :: info
     TYPE(MPI_Request), INTENT(OUT) :: request
     INTEGER, OPTIONAL, INTENT(OUT) :: ierror

πŸ’œ INPUT PARAMETERS πŸ’œ

  • sendbuf β€” where your send buffer starts (choice). the launch pad bestie πŸš€
  • sendcount β€” how many elements you're sending to each process (integer).
  • sendtype β€” the datatype of the stuff in your send buffer (handle).
  • recvcount β€” how many elements you're receiving from each process (integer).
  • recvtype β€” the datatype of the stuff landing in your receive buffer (handle).
  • comm β€” the communicator the data gets exchanged over (handle).
  • info β€” Info (handle, persistent only)

🫢 OUTPUT PARAMETERS 🫢

  • recvbuf β€” where your receive buffer starts (choice).
  • request β€” Request (handle, non-blocking only).
  • ierror β€” Fortran only: error status (integer).

🌈 DESCRIPTION 🌈

MPI_Alltoall is a collective operation where all processes send the same amount of data to each other, and receive the same amount of data from each other. mutual exchange. no cap. πŸ’ž

the way this routine works can be written out like the snippet below, where each process does 2n independent point-to-point communications (n = the number of processes in communicator comm), and yes that includes talking to itself. self-care communication fr 😌

MPI_Comm_size(comm, &n);
for (i = 0, i < n; i++)
    MPI_Send(sendbuf + i * sendcount * extent(sendtype),
        sendcount, sendtype, i, ..., comm);
for (i = 0, i < n; i++)
    MPI_Recv(recvbuf + i * recvcount * extent(recvtype),
        recvcount, recvtype, i, ..., comm);

each process chops up its local sendbuf into n blocks β€” every block holding sendcount elements of type sendtype β€” and splits its recvbuf the same way, according to recvcount and recvtype. process j sends the k-th block of its local sendbuf to process k, and process k drops that data into the j-th block of its local recvbuf. the amount of data sent has to equal the amount of data received, pairwise, between every pair of processes. balance is everything ✨

πŸ‘‘ WHEN COMMUNICATOR IS AN INTER-COMMUNICATOR πŸ‘‘

when the communicator is an inter-communicator, the gather operation happens in two phases. first, the data gets gathered from all the members of the first group and received by all the members of the second group. then, the data gets gathered from all the members of the second group and received by all the members of the first. the operation is giving symmetric, full-duplex behavior, honestly very demure, very mindful. πŸŽ€

the first group defines the root process. the root process uses MPI_ROOT as the value of root. all other processes in the first group use MPI_PROC_NULL as the value of root. all processes in the second group use the rank of the root process in the first group as the value of root.

when the communicator is an intra-communicator, these groups are the same, and the operation happens in a single phase. one and done πŸ’…


⭐ USE OF IN-PLACE OPTION ⭐

when the communicator is an intracommunicator, you can do an all-to-all operation in-place (aka the output buffer is doubling as the input buffer, we love a multitasker ✨). just use the variable MPI_IN_PLACE as the value of sendbuf.

when you do that, sendcount and sendtype are ignored. the input data of each process is assumed to already be sitting in the area where that process would receive its own contribution to the receive buffer. cute, convenient, periodt.


πŸ’€ NOTES πŸ’€

all arguments on all processes matter. all of them. every single one. significant. and the comm argument especially has to describe the same communicator on every process β€” if it doesn't, that's a whole situation, and not the fun kind 😭

there are two MPI library functions that are more general than MPI_Alltoall:

  • MPI_Alltoallv lets you do all-to-all communication to and from buffers that don't need to be contiguous, and different processes can send and receive different amounts of data.
  • MPI_Alltoallw expands MPI_Alltoallv's functionality to let you exchange data with different datatypes.

πŸ™ˆ ERRORS πŸ™ˆ

almost all MPI routines return an error value; C routines hand it back as the return result of the function, and Fortran routines put it in the last argument.

before that error value comes back to you, the current MPI error handler associated with the communication object (e.g., communicator, window, file) gets called. if there's no communication object associated with the MPI call, then the call is considered attached to MPI_COMM_SELF and will call the associated MPI error handler. when MPI_COMM_SELF is not initialized β€” that's i.e., before MPI_Init/MPI_Init_thread, after MPI_Finalize, or when using the Sessions Model exclusively β€” the error raises the initial error handler. the initial error handler can be changed by calling MPI_Comm_set_errhandler on MPI_COMM_SELF when using the World model, or with the mpi_initial_errhandler CLI argument to mpiexec, or the info key to MPI_Comm_spawn/MPI_Comm_spawn_multiple. if no other appropriate error handler has been set, then the MPI_ERRORS_RETURN error handler is called for MPI I/O functions, and the MPI_ERRORS_ABORT error handler is called for all other MPI functions.

Open MPI ships three predefined error handlers you can use, bestie:

  • MPI_ERRORS_ARE_FATAL β€” causes the program to abort all connected MPI processes.
  • MPI_ERRORS_ABORT β€” an error handler that can be invoked on a communicator, window, file, or session. when called on a communicator, it acts as if MPI_Abort was called on that communicator. if called on a window or file, it acts as if MPI_Abort was called on a communicator containing the group of processes in the corresponding window or file. if called on a session, it aborts only the local process.
  • MPI_ERRORS_RETURN β€” returns an error code to the application.

MPI applications can also implement their own error handlers by calling:

  • MPI_Comm_create_errhandler then MPI_Comm_set_errhandler
  • MPI_File_create_errhandler then MPI_File_set_errhandler
  • MPI_Session_create_errhandler then MPI_Session_set_errhandler or at MPI_Session_init
  • MPI_Win_create_errhandler then MPI_Win_set_errhandler
note that MPI does not guarantee that an MPI program can continue past an error. so like... don't count on it 😬

see the MPI man page for a full list of MPI error codes.

see the Error Handling section of the MPI-3.1 standard for more information.

see also:

  • MPI_Alltoallv
  • MPI_Alltoallw

2003-2026, The Open MPI Community


and that's the whole page bestie, you ate that πŸ“πŸ’– this lil Open MPI gem was brought to you from the MPI_ALLTOALL_INIT(3) page, dated Sep 10, 2026 β€” go forth and all-to-all, you've got this, mwah πŸ’…βœ¨

πŸ“¦ where this page comes from