MPI_SCATTERV_INIT(3)
π« MPI_SCATTERV_INIT β the Open MPI glow-up π«
okay bestie, sit DOWN, because we're talking about MPI_Scatterv, MPI_Iscatterv, and MPI_Scatterv_init β the Open MPI girlies who take one big buffer and scatter it in parts to every task in the group. it's giving β¨distributionβ¨, it's giving main character energy. this page lives in section 3 of the Open MPI manual, iykyk. π¦
πΈ NAME πΈ
MPI_Scatterv, MPI_Iscatterv, MPI_Scatterv_init β scatters a buffer in parts to all tasks in a group. no cap, that's literally the whole job. π
β¨ SYNTAX β¨
π C Syntax
#include <mpi.h>
int MPI_Scatterv(const void *sendbuf, const int sendcounts[], const int displs[],
MPI_Datatype sendtype, void *recvbuf, int recvcount,
MPI_Datatype recvtype, int root, MPI_Comm comm)
int MPI_Iscatterv(const void *sendbuf, const int sendcounts[], const int displs[],
MPI_Datatype sendtype, void *recvbuf, int recvcount,
MPI_Datatype recvtype, int root, MPI_Comm comm, MPI_Request *request)
int MPI_Scatterv_init(const void *sendbuf, const int sendcounts[], const int displs[],
MPI_Datatype sendtype, void *recvbuf, int recvcount,
MPI_Datatype recvtype, int root, MPI_Comm comm, MPI_Info info, MPI_Request *request)
π Fortran Syntax
USE MPI
! or the older form: INCLUDE 'mpif.h'
MPI_SCATTERV(SENDBUF, SENDCOUNTS, DISPLS, SENDTYPE, RECVBUF,
RECVCOUNT, RECVTYPE, ROOT, COMM, IERROR)
<type> SENDBUF(*), RECVBUF(*)
INTEGER SENDCOUNTS(*), DISPLS(*), SENDTYPE
INTEGER RECVCOUNT, RECVTYPE, ROOT, COMM, IERROR
MPI_ISCATTERV(SENDBUF, SENDCOUNTS, DISPLS, SENDTYPE, RECVBUF,
RECVCOUNT, RECVTYPE, ROOT, COMM, REQUEST, IERROR)
<type> SENDBUF(*), RECVBUF(*)
INTEGER SENDCOUNTS(*), DISPLS(*), SENDTYPE
INTEGER RECVCOUNT, RECVTYPE, ROOT, COMM, REQUEST, IERROR
MPI_SCATTERV_INIT(SENDBUF, SENDCOUNTS, DISPLS, SENDTYPE, RECVBUF,
RECVCOUNT, RECVTYPE, ROOT, COMM, INFO, REQUEST, IERROR)
<type> SENDBUF(*), RECVBUF(*)
INTEGER SENDCOUNTS(*), DISPLS(*), SENDTYPE
INTEGER RECVCOUNT, RECVTYPE, ROOT, COMM, INFO, REQUEST, IERROR
π§ Fortran 2008 Syntax
USE mpi_f08
MPI_Scatterv(sendbuf, sendcounts, displs, sendtype, recvbuf, recvcount,
recvtype, root, comm, ierror)
TYPE(*), DIMENSION(..), INTENT(IN) :: sendbuf
TYPE(*), DIMENSION(..) :: recvbuf
INTEGER, INTENT(IN) :: sendcounts(*), displs(*), recvcount, root
TYPE(MPI_Datatype), INTENT(IN) :: sendtype, recvtype
TYPE(MPI_Comm), INTENT(IN) :: comm
INTEGER, OPTIONAL, INTENT(OUT) :: ierror
MPI_Iscatterv(sendbuf, sendcounts, displs, sendtype, recvbuf, recvcount,
recvtype, root, comm, request, ierror)
TYPE(*), DIMENSION(..), INTENT(IN), ASYNCHRONOUS :: sendbuf
TYPE(*), DIMENSION(..), ASYNCHRONOUS :: recvbuf
INTEGER, INTENT(IN), ASYNCHRONOUS :: sendcounts(*), displs(*)
INTEGER, INTENT(IN) :: recvcount, root
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_scatterv_init(sendbuf, sendcounts, displs, sendtype, recvbuf, recvcount,
recvtype, root, comm, info, request, ierror)
TYPE(*), DIMENSION(..), INTENT(IN), ASYNCHRONOUS :: sendbuf
TYPE(*), DIMENSION(..), ASYNCHRONOUS :: recvbuf
INTEGER, INTENT(IN), ASYNCHRONOUS :: sendcounts(*), displs(*)
INTEGER, INTENT(IN) :: recvcount, root
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 π«Ά
okay here's the tea on every single argument, no skipping, bestie's honor:
sendbufβ address of send buffer (choice, significant only at root). like, the root is the one holding the bag, everyone else is just receiving. πsendcountsβ integer array (of length group size) that specifies how many elements to send to each processor. one count per bestie, we love personalized service. πdisplsβ integer array (of length group size). entryisays the displacement (relative tosendbuf) from which to take the outgoing data headed to processi. it's the lil GPS for your data. πΊοΈsendtypeβ datatype of send buffer elements (handle).recvcountβ number of elements in receive buffer (integer).recvtypeβ datatype of receive buffer elements (handle).rootβ rank of sending process (integer). the source of all the good stuff. πcommβ communicator (handle).infoβ info (handle, persistent only). so if you're on plainMPI_Scatterv/MPI_Iscattervthis one literally isn't invited. π
π OUTPUT PARAMETERS π
recvbufβ address of receive buffer (choice).requestβ request (handle, non-blocking only). so this one's for the async girlies only, fr fr.ierrorβ Fortran only: error status (integer).
π DESCRIPTION π
MPI_Scatterv is the inverse operation to MPI_Gatherv. so likeβ¦ gather v's inverse. the mirror. the reflection. the "we're so back" to gather's "it's over". πͺ
MPI_Scatterv extends the functionality of MPI_Scatter by allowing a varying count of data to be sent to each process, since sendcounts is now an array. it also allows more flexibility as to where the data is taken from on the root, by providing the new argument, displs. like MPI_Scatter but with β¨optionsβ¨. she ate and left no crumbs.
the outcome is as if the root executed n send operations,
MPI_Send(sendbuf + displs[i] * extent(sendtype),
sendcounts[i], sendtype, i, ...);
// and each process executed a receive,
MPI_Recv(recvbuf, recvcount, recvtype, root, ...)
the send buffer is ignored for all nonroot processes. sorry non-roots, sendbuf is not your business. π
the type signature implied by sendcount[i], sendtype at the root must be equal to the type signature implied by recvcount, recvtype at process i (however, the type maps may be different). this implies that the amount of data sent must be equal to the amount of data received, pairwise between each process and the root. distinct type maps between sender and receiver are still allowed. so like, same energy, different outfit. matching counts, unmatched vibes. π
all arguments to the function are significant on process root, while on other processes, only arguments recvbuf, recvcount, recvtype, root, comm are significant. the arguments root and comm must have identical values on all processes. consistency check, bestie. β
the specification of counts, types, and displacements should not cause any location on the root to be read more than once. β οΈ don't double-dip into your own buffer, it's not cute and it's not correct.
Example 1: the reverse of Example 5 in the MPI_Gatherv manpage. we have a varying stride between blocks at the sending (root) side, and at the receiving side we receive 100 - i elements into the ith column of a 100 x 150 C array at process i. iconic layout, honestly.
MPI_Comm comm;
int gsize,recvarray[100][150],*rptr;
int root, *sendbuf, myrank, bufsize, *stride;
MPI_Datatype rtype;
int i, *displs, *scounts, offset;
...
MPI_Comm_size( comm, &gsize);
MPI_Comm_rank( comm, &myrank );
stride = (int *)malloc(gsize*sizeof(int));
...
/* stride[i] for i = 0 to gsize-1 is set somehow
* sendbuf comes from elsewhere
*/
...
displs = (int *)malloc(gsize*sizeof(int));
scounts = (int *)malloc(gsize*sizeof(int));
offset = 0;
for (i=0; i<gsize; ++i) {
displs[i] = offset;
offset += stride[i];
scounts[i] = 100 - i;
}
/* Create datatype for the column we are receiving
*/
MPI_Type_vector( 100-myrank, 1, 150, MPI_INT, &rtype);
MPI_Type_commit( &rtype );
rptr = &recvarray[0][myrank];
MPI_Scatterv(sendbuf, scounts, displs, MPI_INT,
rptr, 1, rtype, root, comm);
Example 2: the reverse of Example 1 in the MPI_Gather manpage. the root process scatters sets of 100 ints to the other processes, but the sets of 100 are stride ints apart in the sending buffer. requires use of MPI_Scatterv, where stride >= 100. not a vibe, just a requirement. π₯
MPI_Comm comm;
int gsize,*sendbuf;
int root, rbuf[100], i, *displs, *scounts;
...
MPI_Comm_size(comm, &gsize);
sendbuf = (int *)malloc(gsize*stride*sizeof(int));
...
displs = (int *)malloc(gsize*sizeof(int));
scounts = (int *)malloc(gsize*sizeof(int));
for (i=0; i<gsize; ++i) {
displs[i] = i*stride;
scounts[i] = 100;
}
MPI_Scatterv(sendbuf, scounts, displs, MPI_INT,
rbuf, 100, MPI_INT, root, comm);
π¦ USE OF IN-PLACE OPTION π¦
when the communicator is an intracommunicator, you can perform a scatter operation in-place (the output buffer is used as the input buffer). use the variable MPI_IN_PLACE as the value of the root process recvbuf. in this case, recvcount and recvtype are ignored, and the root process sends no data to itself. self-care, literally. π
note that MPI_IN_PLACE is a special kind of value; it has the same restrictions on its use as MPI_BOTTOM. so treat it with the same respect, bestie, it's not a normal value. π
because the in-place option converts the receive buffer into a send-and-receive buffer, a Fortran binding that includes INTENT must mark these as INOUT, not OUT. the Fortran girlies had to write that one down. π
π WHEN COMMUNICATOR IS AN INTER-COMMUNICATOR π
when the communicator is an inter-communicator, the root process in the first group sends data to all processes in the second group.
- the first group defines the root process.
- that process uses
MPI_ROOTas the value of itsrootargument. - the remaining processes use
MPI_PROC_NULLas the value of theirrootargument. - all processes in the second group use the rank of that root process in the first group as the value of their
rootargument. - the receive buffer argument of the root process in the first group must be consistent with the receive buffer argument of the processes in the second group.
two groups, one root, zero confusion (once you've read it three times, ngl). π
ERRORS π
okay so real talk: literally almost every MPI routine hands back an error value. In C it's the return value of the function itself, and in Fortran it rides in the last argument. classic.
But before that error value ever gets to you, the current MPI error handler that's attached to the communication object (think: communicator, window, file, whatever) gets called first. If there's no communication object linked to the MPI call at all? Then the call counts as attached to MPI_COMM_SELF, and that handler gets called. And if MPI_COMM_SELF isn't even initialized yet β like before MPI_Init / MPI_Init_thread, after MPI_Finalize, or when you're using the Sessions Model exclusively β then the error goes straight up to the initial error handler.
Wanna swap the initial error handler? You can, by calling MPI_Comm_set_errhandler on MPI_COMM_SELF when you're using the World model π«Ά, or by using the mpi_initial_errhandler CLI argument to mpiexec, or the info key to MPI_Comm_spawn / MPI_Comm_spawn_multiple.
And if nobody set any other appropriate error handler? Then MPI_ERRORS_RETURN gets called for MPI I/O functions, and MPI_ERRORS_ABORT gets called for literally every other MPI function. yeah. π
Open MPI ships with three predefined error handlers you can use:
MPI_ERRORS_ARE_FATALβ causes the program to abort all connected MPI processes. everyone. gone. πMPI_ERRORS_ABORTβ an error handler you can invoke on a communicator, window, file, or session. Call it on a communicator and it acts exactly as ifMPI_Abortwas called on that communicator. Call it on a window or file and it acts as ifMPI_Abortwas called on a communicator containing the group of processes in the corresponding window or file. Call it on a session and it aborts only the local process.MPI_ERRORS_RETURNβ returns an error code back to the application. the chill one β¨
Your MPI app can also roll its own error handlers by calling:
MPI_Comm_create_errhandlerand thenMPI_Comm_set_errhandlerMPI_File_create_errhandlerand thenMPI_File_set_errhandlerMPI_Session_create_errhandlerand thenMPI_Session_set_errhandlerβ or atMPI_Session_initMPI_Win_create_errhandlerand thenMPI_Win_set_errhandler
β οΈ important bestie: MPI does not guarantee that an MPI program can keep going past an error. like, at all.
Want the full list of MPI error codes? Check the MPI man page. Want the deep lore? The Error Handling section of the MPI-3.1 standard has you covered.
See also:
MPI_GatherMPI_GathervMPI_Scatter
Copyright π
2003-2026, The Open MPI Community
and that's a wrap on MPI_SCATTERV_INIT(3), bestie ππ
you made it to the end, iconic behavior fr fr. huge shoutout to the Open MPI girlies, this page is stamped Sep 10, 2026 and the whole thing lives in the Open MPI MPI_SCATTERV_INIT(3) source/version, so if you're holding a printed copy from 2019 it's giving vintage and you should probably update πβ¨
π¦ where this page comes from
- ubuntu stonking: openmpi-doc 5.0.10-6 Β· other
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms