What exactly does MPI_IN_PLACE
do when given as an argument to MPI_Scatter
and how should it be used? I can\'t make sense of man MPI_Scatter<
The sendbuf of MPI_scatter is only relevant on the root according to mpich,
sendbuf -- address of send buffer (choice, significant only at root)
From this discussion,
For scatter/scatterv, MPI_IN_PLACE should be passed as the recvbuf. For gather and most other collectives, MPI_IN_PLACE should passed as the sendbuf.
You therefore need to use MPI_IN_PLACE in the recv buffer location on the root process, e.g.
if (rank == iroot)
MPI_Scatter(buf, sendcount, MPI_Datatype, MPI_IN_PLACE, sendcount,
MPI_Datatype, iroot, MPI_COMM_WORLD);
else
MPI_Scatter(dummy, sendcount, MPI_Datatype, buf, sendcount, MPI_Datatype,
iroot, MPI_COMM_WORLD);
You could then use buf
in the send on root and the same buf
in the recv position on each other process. The dummy
buffer on the receiving processors could probably also be replaced by MPI_IN_PLACE
.