MPI_Alltoallv(3)

๐Ÿ“ฆ
version 5.0.1 ยท 5 versions
, in nixos 26.05, ubuntu stonking

๐Ÿ’– MPI_Alltoallv โ€” like, the โœจeverybody swap meetโœจ of MPI ๐Ÿ’–

okay bestie, pull up a chair, this is MPI_Alltoallv(3) from the MPI manual and it is ICONIC. she's the chaotic big sister of all-to-all: everybody in the communicator sends data to everybody else, but each process gets to send a different amount to each rank, and you get to say exactly where in your buffers stuff comes from and goes. no cap, this is the flexible one.


๐ŸŒธ NAME ๐ŸŒธ

MPI_Alltoallv โ€” Sends data from all to all processes; each process may send a different amount of data and provide displacements for the input and the output data. it's giving "everyone swaps with everyone, but make it custom-sized". ๐Ÿ’…


โœจ SYNOPSIS โœจ

the C glow-up, both flavours:

int MPI_Alltoallv(const void *sendbuf, const int sendcounts[],
const int sdispls[], MPI_Datatype sendtype, void *recvbuf,
const int recvcounts[], const int rdispls[],
MPI_Datatype recvtype, MPI_Comm comm)

int MPI_Alltoallv_c(const void *sendbuf, const MPI_Count sendcounts[],
const MPI_Aint sdispls[], MPI_Datatype sendtype,
void *recvbuf, const MPI_Count recvcounts[],
const MPI_Aint rdispls[], MPI_Datatype recvtype,
MPI_Comm comm)

๐Ÿ“ฅ INPUT PARAMETERS ๐Ÿ“ฅ

the receipts you gotta hand over, one by one:

  • sendbuf โ€” starting address of send buffer (choice). like, where your outgoing stuff lives ๐Ÿซถ
  • sendcounts โ€” non-negative integer array (of length group size) specifying the number of elements to send to each rank (non-negative integer). yes, per rank, it's a whole little list ๐Ÿ’–
  • sdispls โ€” integer array (of length group size). Entry j specifies the displacement (relative to sendbuf) from which to take the outgoing data destined for process j (integer). so entry j = "the stuff for rank j starts over there โœจ"
  • sendtype โ€” data type of send buffer elements (handle)
  • recvcounts โ€” non-negative integer array (of length group size) specifying the number of elements that can be received from each rank (non-negative integer). note the can be, she's permissive ๐ŸŒธ
  • rdispls โ€” integer array (of length group size). Entry i specifies the displacement (relative to recvbuf) at which to place the incoming data from process i (integer). entry i = "park rank i's gift right here ๐Ÿ’"
  • recvtype โ€” data type of receive buffer elements (handle)
  • comm โ€” communicator (handle)

๐Ÿ“ค OUTPUT PARAMETERS ๐Ÿ“ค

  • recvbuf โ€” address of receive buffer (choice). this is where everybody's stuff lands, no cap ๐Ÿ‘‘

๐Ÿงต THREAD AND INTERRUPT SAFETY ๐Ÿงต

okay so the good news first: this routine is thread-safe. that means it can be safely used by multiple threads without you needing to hand-write any thread locks. you're welcome, bestie, she handles it. ๐Ÿ’…

the less good news, and I need you to hear me on this one: the routine is not interrupt safe. typically this is because of memory allocation routines like malloc or other non-MPICH runtime routines that are themselves not interrupt-safe. so likeโ€ฆ respect the boundary, okay? ๐Ÿšซ


๐Ÿ”ฎ NOTES FOR FORTRAN ๐Ÿ”ฎ

  • All MPI routines in Fortran (except for MPI_WTIME and MPI_WTICK) have an additional argument ierr at the end of the argument list. ierr is an integer and has the same meaning as the return value of the routine in C. in Fortran, MPI routines are subroutines, and they're invoked with the call statement. periodt. ๐Ÿ“ž
  • All MPI objects (e.g., MPI_Datatype, MPI_Comm) are of type INTEGER in Fortran. they're just ints over there, so cute ๐ŸŒˆ

๐Ÿ’€ ERRORS ๐Ÿ’€

All MPI routines (except MPI_Wtime and MPI_Wtick) return an error value โ€” C routines as the value of the function, and Fortran routines in the last argument. Before the value is returned, the current MPI error handler is called. By default, this error handler aborts the MPI job (yes, dramatic, I know ๐Ÿ˜ญ). The error handler may be changed with MPI_Comm_set_errhandler (for communicators), MPI_File_set_errhandler (for files), and MPI_Win_set_errhandler (for RMA windows). The MPI-1 routine MPI_Errhandler_set may be used but its use is deprecated โ€” like, retire her already. The predefined error handler MPI_ERRORS_RETURN may be used to cause error values to be returned. Note that MPI does not guarantee that an MPI program can continue past an error; however, MPI implementations will attempt to continue whenever possible. ๐Ÿซถ

here's the whole error roster, alphabetical-ish, all of them, none skipped:

  • MPI_SUCCESS โ€” No error; MPI routine completed successfully. ๐ŸŽ‰ the vibe check passed
  • MPI_ERR_BUFFER โ€” Invalid buffer pointer. Usually a null buffer where one is not valid. ๐Ÿ’€
  • MPI_ERR_COMM โ€” Invalid communicator. A common error is to use a null communicator in a call (not even allowed in MPI_Comm_rank). ๐Ÿ™ˆ
  • MPI_ERR_COUNT โ€” Invalid count argument. Count arguments must be non-negative; a count of zero is often valid. so no negative counts, bestie, zero is fine though
  • MPI_ERR_TYPE โ€” Invalid datatype argument. Additionally, this error can occur if an uncommitted MPI_Datatype (see MPI_Type_commit) is used in a communication call. commit your types, I'm begging ๐Ÿฅบ
  • MPI_ERR_OTHER โ€” Other error; use MPI_Error_string to get more information about this error code. the catch-all, go read the label ๐Ÿ“–
fr fr: if you're seeing errors and you've checked everything twice, go hit up MPI_Error_string โ€” she'll tell you what's actually wrong. iykyk ๐Ÿ”ฅ

so yeah. that's MPI_Alltoallv. everybody send to everybody, counts and displacements on deck for both sides, thread-safe but not interrupt-safe, and the manual name is MPI_Alltoallv(3) if you ever need to cite her ๐Ÿ’–

signing off from the MPI manual, version stamped 4/10/2026, page MPI_Alltoallv(3) โ€” stay slay, keep your displacements straight, and may your buffers never be null ๐ŸŽ€โœจ๐Ÿฆ‹

๐Ÿ“ฆ where this page comes from