I want to employ the MPI function MPI_GATHERV
, where each MPI rank has a certain buffer with varying sizes that needs to be Gathered at the Root process.
My root process will only gather the buffers, but has no send buffer itself, as usual.
E.g.
RANK1
buf_sz =3
buf(1) = 1
buf(2) = 2
buf(3) = 3
Rank 2
buf_sz =3
buf(1) = 4
buf(2) = 5
buf(3) = 6
After MPI_GATHERV, my Root should have
buf(1) = 1
buf(2) = 2
buf(3) = 3
buf(4) = 4
buf(5) = 5
buf(6) = 6
As for now, this will mean that at the Root I will have to apply a sendbuf which is allocated with zero elements and zero count. I am not sure how well defined and safe this is generally?
Sample code
if(myrankid == root)then
allocate(displ(3))
allocate(counts(3))
displ(1) = 0
displ(2) = 0
displ(3) = 3
counts(1) = 0
counts(2) = 3
counts(3) = 3
allocate(buf_send(0))
sendcount = 0
allocate(recvbuf(6))
else
allocate(displ(1))
allocate(counts(1))
allocate(buf_send(3))
allocate(recvbuf(1))
sendcount = 3
endif
MPI_Gatherv(buf_send, sendcount, mpi_integer,&
recvbuf, counts, displs,&
mpi_integer, root, mpi_comm_world)