MPI 集体操作和进程生命周期 (C/C++)
MPI collective operations and process lifetime (C/C++)
对于我想讨论的问题,我们以MPI_Barrier
为例。 MPI3 标准规定
If comm is an intracommunicator, MPI_BARRIER blocks the caller until
all group members have called it. The call returns at any process only
after all group members have entered the call.
所以我想知道 - 这基本上适用于一般的所有集体操作 - 在通信上下文的某些进程在执行 MPI_Barrier
之前刚刚退出(成功)的情况下,如何解释这个断言: 例如,假设我们有两个进程 A 和 B,并使用 MPI_COMM_WORLD
作为通信器,并使用 comm
到 MPI_Barrier
的参数。 A和B调用MPI_Init
后,如果B立即调用MPI_Finalize
退出,如果只有A在调用MPI_Finalize
之前调用MPI_Barrier
,A是不是永远阻塞了?还是"all group members"的集合定义为所有还没有退出的原群成员的集合?我很确定 A 永远被阻止了,但也许 MPI 标准对此有更多说明?
备注:这不是关于 MPI_Barrier
的同步属性的问题,对 MPI_Barrier
的引用仅是一个具体示例。如果执行集体操作,这是一个关于MPI程序正确性的问题。看评论。
If B exits right at program start and only A calls MPI_Barrier, is A blocked for eternity?
基本上是的。但实际上,你是不允许这样做的。
简单来说就是在退出前必须对所有进程调用MPI_Finalize
。而 MPI_Finalize
就像一个集体(在 MPI_COMM_WORLD
上),所以它通常不会在每个进程调用 MPI_Finalize
之前完成。所以在你的例子中,进程 B 没有退出(至少没有正确退出)。
但我想 8.7 的 MPI 3.1 标准解释得更清楚:
MPI_Finalize
[...] This routine cleans up all MPI state. If an MPI
program terminates normally (i.e., not due to a call to MPI_ABORT
or
an unrecoverable error) then each process must call MPI_FINALIZE
before it exits. Before an MPI process invokes MPI_FINALIZE
, the
process must perform all MPI calls needed to complete its involvement
in MPI communications: It must locally complete all MPI operations
that it initiated and must execute matching calls needed to complete
MPI communications initiated by other processes.
请注意最后一句话还要求您完成问题中的障碍。
标准说,你的程序不正确。在实践中,它很可能 deadlock/hang.
对于我想讨论的问题,我们以MPI_Barrier
为例。 MPI3 标准规定
If comm is an intracommunicator, MPI_BARRIER blocks the caller until all group members have called it. The call returns at any process only after all group members have entered the call.
所以我想知道 - 这基本上适用于一般的所有集体操作 - 在通信上下文的某些进程在执行 MPI_Barrier
之前刚刚退出(成功)的情况下,如何解释这个断言: 例如,假设我们有两个进程 A 和 B,并使用 MPI_COMM_WORLD
作为通信器,并使用 comm
到 MPI_Barrier
的参数。 A和B调用MPI_Init
后,如果B立即调用MPI_Finalize
退出,如果只有A在调用MPI_Finalize
之前调用MPI_Barrier
,A是不是永远阻塞了?还是"all group members"的集合定义为所有还没有退出的原群成员的集合?我很确定 A 永远被阻止了,但也许 MPI 标准对此有更多说明?
备注:这不是关于 MPI_Barrier
的同步属性的问题,对 MPI_Barrier
的引用仅是一个具体示例。如果执行集体操作,这是一个关于MPI程序正确性的问题。看评论。
If B exits right at program start and only A calls MPI_Barrier, is A blocked for eternity?
基本上是的。但实际上,你是不允许这样做的。
简单来说就是在退出前必须对所有进程调用MPI_Finalize
。而 MPI_Finalize
就像一个集体(在 MPI_COMM_WORLD
上),所以它通常不会在每个进程调用 MPI_Finalize
之前完成。所以在你的例子中,进程 B 没有退出(至少没有正确退出)。
但我想 8.7 的 MPI 3.1 标准解释得更清楚:
MPI_Finalize
[...] This routine cleans up all MPI state. If an MPI program terminates normally (i.e., not due to a call toMPI_ABORT
or an unrecoverable error) then each process must callMPI_FINALIZE
before it exits. Before an MPI process invokesMPI_FINALIZE
, the process must perform all MPI calls needed to complete its involvement in MPI communications: It must locally complete all MPI operations that it initiated and must execute matching calls needed to complete MPI communications initiated by other processes.
请注意最后一句话还要求您完成问题中的障碍。
标准说,你的程序不正确。在实践中,它很可能 deadlock/hang.