Collective Communication I

2.3.3 Gatherv and Scatterv
Gatherv Purpose:
    Same as GATHER, except that varying amounts of data may be gathered from each process.
Fortran Binding:
MPI_GATHERV (sbuf, scount, stype, rbuf, rcount, displs, rtype, root, comm, ierr)
C Binding:
int MPI_Gatherv (void* sbuf, int scount, MPI_Datatype stype, void* rbuf, int* rcount, int* displs, MPI_Datatype rtype, int root, MPI_Comm comm)


Scatterv Purpose:

    Same as SCATTER, except that varying amounts of data may be scattered to each process; inverse of GATHERV.

Fortran Binding:
MPI_SCATTERV (sbuf, scount, displs, stype, rbuf, rcount, rtype, root, comm, ierr)
C Binding:
int MPI_Scatterv (void* sbuf, int* scount, int* displs, MPI_Datatype stype, void* rbuf, int rcount, MPI_Datatype rtype, int root, MPI_Comm comm)


MPI_GATHERV and MPI_SCATTERV are the variable-message-size versions of MPI_GATHER and MPI_SCATTER. MPI_GATHERV extends the functionality of MPI_GATHER by changing the receive count from an integer to an integer array and providing a new argument displs(array). MPI_GATHERV allows a varying count of data from each process and allows some flexibility for where the gathered data is placed in the root as well. As a counterpart of MPI_GATHERV, MPI_SCATTERV is an extension of MPI_SCATTER in the same relationship as MPI_GATHERV is to MPI_GATHER. There is more information on this topic in the module MPI Collective Communication II.

C
int MPI_Gatherv (void* sbuf, int scount, MPI_Datatype stype, void* rbuf int *rcount, int* displs, MPI_Datatype rtype, int root, MPI_Comm comm)
int MPI_Scatterv (void* sbuf, int* scount, int* displs, MPI_Datatype stype, void* rbuf, int rcount, MPI_Datatype rtype, int root, MPI_Comm comm)
FORTRAN
MPI_GATHERV (sbuf, scount, stype, rbuf, rcount, displs, rtype, root, comm, ierr)
MPI_SCATTERV (sbuf, scount, displs, stype, rbuf, rcount, rtype, root, comm, ierr)

The variables for Gatherv are:
sbuf starting address of send buffer,
scount number of elements in send buffer,
stype data type of send buffer elements,
rbuf starting address of receive buffer,
rcount array containing number of elements to be received from each process,
displs array specifying the displacement relative to rbuf at which to place the incoming data from corresponding process,
rtype data type of receive buffer,
root rank of receiving process,
comm group communicator.

    Note: rbuf, rcount, rtype are significant for the root process only.

The variables for Scatterv are:
sbuf address of send buffer,
scount integer array specifying the number of elements to send to each process,
displs array specifying the displacement relative to sbuf from which to take the data going out to the corresponding process,
stype data type of send buffer elements,
rbuf address of receive buffer,
rcount number of elements in receive buffer,
rtype data type of receive buffer elements,
root rank of sending process,
comm group communicator

    Note: sbuf, scount, and stype are significant for root process only

For the purpose of illustrating the usage of MPI_GATHERV and MPI_SCATTERV, we give two Fortran program fragments below:

MPI_GATHERV

Gather

real a(25), rbuf(MAX)
integer displs(NX), rcounts(NX), nsize
...
do i= 1, nsize
   displs(i) = (i-1)*stride
   rcounts(i) = 25
enddo
call mpi_gatherv(a,25,MPI_REAL,rbuf,rcounts,displs,
  & MPI_REAL,root,comm,ierr)
...
MPI_SCATTERV

scatterv

real a(25), sbuf(MAX)
integer displs(NX), scounts(NX), nsize
...
do i= 1, nsize
   displs(i) = (i-1)*stride
   scounts(i) = 25
enddo
call mpi_scatterv(sbuf,scounts,displs,MPI_REAL,a,25,
  & MPI_REAL,root,comm,ierr)
...