We next discuss the precise MPI syntax of a couple of "v" calls. It will be useful to know the entire calling sequence when completing the exercise at the end of this topic.

MPI_Scatterv syntax

The MPI_Scatterv calling sequence is really pretty straightforward—perhaps (dare we say) self-explanatory?

int sendcounts[NPROC], displs[NPROC];
  ...
  MPI_Scatterv(
    sendbuf, sendcounts, displs, sendtype,
    recvbuf, recvcount, recvtype,
    root, comm);
INTEGER SENDCOUNTS(0:NPROC-1), DISPLS(0:NPROC-1)
...
CALL MPI_SCATTERV( &
       SENDBUF, SENDCOUNTS, DISPLS, SENDTYPE, &
       RECVBUF, RECVCOUNT, RECVTYPE, &
       ROOT, COMM, IERROR )

Compared to just plain scatter there are two differences: the SENDCOUNTS argument has become an array, and a new argument — DISPLS — has been added to the list.

SENDCOUNTS(I)
is an array of the number of items of type SENDTYPE to send from process ROOT to process I. Thus its value is significant only on ROOT.
DISPLS(I)
is an array of the displacement from SENDBUF to the beginning of the I-th message, in units of SENDTYPE. Thus its value is significant only on ROOT.

And that's pretty much it! The other arguments in the list simply mirror the usual MPI_Scatter calling sequence:

Scatterv parameters
sendbuf
is the starting address of the send buffer
sendcounts
is an integer array specifying the number of elements to be received from each process
displs
is an array specifying the displacement relative to sbuf from which to take the data going out to the corresponding process
sendtype
is the data type of send buffer elements
recvbuf
is the address of the receive buffer
recvcount
is the number of elements in the receive buffer
recvtype
is the data type of the receive buffer elements
root
is the rank of the receiving process
comm
is the group communicator
MPI_Gatherv syntax

Let's turn now to gather and gatherv, which are the exact inverses of scatter and scatterv. In fact, we don't even need new diagrams! Simply think about reversing the directions of the arrows in the diagrams on the previous page. We will therefore turn our attention directly to the syntax of the gatherv call.

int recvcounts[NPROC], displs[NPROC];
  ...
  MPI_Scatterv(
    sendbuf, sendcount, sendtype,
    recvbuf, recvcounts, displs, recvtype,
    root, comm);
INTEGER RECVCOUNTS(0:NPROC-1), DISPLS(0:NPROC-1)
...
CALL MPI_GATHERV( &
       SENDBUF, SENDCOUNT, SENDTYPE, &
       RECVBUF, RECVCOUNTS, DISPLS, RECVTYPE, &
       ROOT, COMM, IERROR )

Here, RECVCOUNTS(I) plays the role that SENDCOUNTS(I) played in the call to MPI_Scatterv. Its location in the argument list has been shifted accordingly, to put it among the arguments relating to the receiver. DISPLS(I) in this case indicates where to place the data arriving from process I. It is given as an offset relative to address RECVBUF on the ROOT process, and it is in units of SENDTYPE. Therefore, compared to MPI_Gather, there is an additional array DISPLS, while RECVCOUNTS has been stretched into an array.

Gatherv parameters
sbuf
is the starting address of the send buffer
scount
is the number of elements in the send buffer
stype
is the data type of send buffer elements
rbuf
is the address of the receive buffer
rcounts
is an array containing the number of elements to be received from each process
displs
is an array specifying the displacement relative to rbuf at which to place the incoming data from the corresponding process
rtype
is the data type of the receive buffer elements
root
is the rank of the receiving process
comm
is the group communicator
 
©   Cornell University  |  Center for Advanced Computing  |  Copyright Statement  |  Inclusivity Statement