The task you want to solve can be easier solver by using MPI_Gather
.
Documentation: http://www.mcs.anl.gov/research/projects/mpi/mpi-standard/mpi-report-1.1/node69.htm#Node69
Each process (root process included) sends the contents of its send buffer to the root process. The root process receives the messages and stores them in rank order.
Documentation also shows equivalent MPI_Send/MPI_Recv usage, which is similar to your code, but note the "+i*recvcount*extent
" offset in MPI_Recv
:
The outcome is as if each of the n processes in the group (including the root process) had executed a call to
MPI_Send(sendbuf, sendcount, sendtype, root , ...),
and the root had executed n calls to
MPI_Recv(recvbuf+i · recvcount· extent(recvtype), recvcount, recvtype, i ,...),
Example: http://www.mcs.anl.gov/research/projects/mpi/mpi-standard/mpi-report-1.1/node70.htm