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
.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…