MPI 中的障碍:如何实施障碍以使进程相互等待

Barrier in MPI: How to implement barrier to make processes wait for one another

有什么方法可以在 MPI 代码中添加屏障。

我的意思是障碍,我希望所有不同的处理器首先完成一个点,然后从那里继续。那就是一个处理器必须等待其他处理器完成该区域的代码,然后才继续执行代码的其余部分。

例如,

int main()
{
.
.
.
  //I want all my processors to do till this and 
   wait for other processers to complete till this point, 
   and then resume the remaining part
.
.
.

}

有没有办法在 MPIch 中做到这一点?

That is a processor must wait for the other processors to finish the code till that region and then only proceed to the remaining part of the code.

是的,你要找的就是套路MPI_Barrier:

Blocks until all processes in the communicator have reached this routine.

Notes

Blocks the caller until all processes in the communicator have called it; that is, the call returns at any process only after all members of the communicator have entered the call.

要了解有关何时使用 MPI_Barrier 的更多信息,您可以阅读何时使用 I need to use MPI_Barrier()?