在 "root" 没有发送缓冲区的情况下使用 MPI_GATHERV

Use of MPI_GATHERV where the "root" has no send buffer

我想使用 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之后,我的Root应该有

 buf(1) = 1 
 buf(2) = 2 
 buf(3) = 3
 buf(4) = 4 
 buf(5) = 5 
 buf(6) = 6

至于现在,这意味着我必须在根目录应用一个分配有零元素和零计数的 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)

(将我的评论变成答案)

是的,分配到零大小并传递它是合法的。这正是我所做的