MPI_IBcast是否能保证在某些队伍不参与的情况下也能发送?

问题描述 投票:0回答:1

我正在创建一个MPI程序,在这个程序中,我试图在所有进程完成计算后立即向它们发送相同的数据。这些进程的计算时间可能有很大的差异,所以我不希望一个处理器等待另一个处理器。

保证根进程总是先发送。

我知道MPI_Bcast作为一个Barries,所以我用MPI_IBcast做了实验。

program main
   use mpi
   implicit none 


   integer rank, nprcos, ierror, a(10), req
   call MPI_INIT(ierror)
   call MPI_COMM_SIZE(MPI_COMM_WORLD, nprcos, ierror)
   call MPI_COMM_RANK(MPI_COMM_WORLD, rank, ierror)

   a = rank

   if(rank /= 2) then
      call MPI_IBCAST(a, size(a), MPI_INTEGER, 0, MPI_COMM_WORLD, req, ierror)
      call MPI_WAIT(req, MPI_STATUS_IGNORE, IERROR)
   endif

   write (*,*) 'Hello World from process: ', rank, 'of ', nprcos, "a = ", a(1)

   call MPI_FINALIZE(ierror)

end program main

从我的实验来看,不管哪个等级的处理器在 "抵制 "MPI_IBcast 它总是能在其他处理器上工作。

> $ mpifort test.f90 && mpiexec --mca btl tcp,self -np 4 ./a.out
 Hello World from process:            2 of            4 a =            2
 Hello World from process:            1 of            4 a =            0
 Hello World from process:            0 of            4 a =            0
 Hello World from process:            3 of            4 a =            0

这是一个有保证的行为还是我的OpenMPI实现所特有的?我还能如何实现这个功能?我只能想到在MPI_Isends上循环。

fortran mpi broadcast nonblocking
1个回答
2
投票

不,这是不保证的,通讯器中的所有行列都应该参与。在MPI内,这就是集体通信的定义。

© www.soinside.com 2019 - 2024. All rights reserved.