我想使用MPI函数MPI_GATHERV
,其中每个MPI级别都有一个不同大小的缓冲区,需要在根进程中收集这些缓冲区。我的根进程将只收集缓冲区,但与往常一样,它本身没有发送缓冲区。
例如。
RANK1
buf_sz =3
buf(1) = 1
buf(2) = 2
buf(3) = 3
等级2
buf_sz =3
buf(1) = 4
buf(2) = 5
buf(3) = 6
在MPI_GATHERV之后,我的根应该
buf(1) = 1
buf(2) = 2
buf(3) = 3
buf(4) = 4
buf(5) = 5
buf(6) = 6
就目前而言,这将意味着我必须在根上应用sendbuf,该sendbuf分配有零元素和零计数。我不知道这大致上有多明确,有多安全?
样本代码
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)
发布于 2019-10-27 08:04:32
(把我的评论变成回答)
是的,这是合法的分配到零大小和传递。这正是我所做的
https://stackoverflow.com/questions/58577544
复制