1

使用 MPI,您如何等待线程完成?

例如:

for (int i = localstart; i < localend; i++)
{
    // do stuff that is computationally intensive
}
// I need to wait for all other threads to finish here
if (rank == 0) do_something();
4

1 回答 1

4

如果线程是指进程/等级,那么答案是MPI_Barrier.

但也要看看其他集体操作:它们可能在您的应用程序中有意义,并且提供比手动编码通信更好的性能。例如,您可以使用MPI_Allgather将所有数据传达给所有等级,等等。

如果您的意思是线程(如 pthreads),那么您必须使用线程库提供的任何内容。

于 2012-04-24T19:33:17.040 回答