MPI_SCATTERV_INIT(3)

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

πŸ’« 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). entry i says the displacement (relative to sendbuf) from which to take the outgoing data headed to process i. 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 plain MPI_Scatterv / MPI_Iscatterv this 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_ROOT as the value of its root argument.
  • the remaining processes use MPI_PROC_NULL as the value of their root argument.
  • all processes in the second group use the rank of that root process in the first group as the value of their root argument.
  • 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 if MPI_Abort was called on that communicator. Call it on a window or file and it acts as if MPI_Abort was 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_errhandler and then MPI_Comm_set_errhandler
  • MPI_File_create_errhandler and then MPI_File_set_errhandler
  • MPI_Session_create_errhandler and then MPI_Session_set_errhandler β€” or at MPI_Session_init
  • MPI_Win_create_errhandler and then MPI_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_Gather
  • MPI_Gatherv
  • MPI_Scatter

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