MPI_Alltoallv(3)
๐ 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). Entryjspecifies the displacement (relative tosendbuf) from which to take the outgoing data destined for processj(integer). so entryj= "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). Entryispecifies the displacement (relative torecvbuf) at which to place the incoming data from processi(integer). entryi= "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_WTIMEandMPI_WTICK) have an additional argumentierrat the end of the argument list.ierris 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 thecallstatement. periodt. ๐ - All MPI objects (e.g.,
MPI_Datatype,MPI_Comm) are of typeINTEGERin 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 passedMPI_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 inMPI_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 thoughMPI_ERR_TYPEโ Invalid datatype argument. Additionally, this error can occur if an uncommittedMPI_Datatype(seeMPI_Type_commit) is used in a communication call. commit your types, I'm begging ๐ฅบMPI_ERR_OTHERโ Other error; useMPI_Error_stringto 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
- nixos 26.05: mpich 5.0.1
- ubuntu stonking: mpich-doc 5.0.1-9 ยท other
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms