MPI:阻止与非阻止 [英] MPI: blocking vs non-blocking
问题描述
我很难理解MPI中阻塞通信和非阻塞通信的概念.两者之间有什么区别?优点和缺点是什么?
I am having trouble understanding the concept of blocking communication and non-blocking communication in MPI. What are the differences between the two? What are the advantages and disadvantages?
推荐答案
使用 MPI_Recv()
.在通信完成之前,这些函数不会返回(即,它们阻塞).稍微简化一下,这意味着传递给MPI_Send()
的缓冲区可以重复使用,这是因为MPI将其保存在某个位置,或者是因为它已被目标接收.同样,MPI_Recv()
将在接收缓冲区中已填充有效数据时返回.
Blocking communication is done using MPI_Send()
and MPI_Recv()
. These functions do not return (i.e., they block) until the communication is finished. Simplifying somewhat, this means that the buffer passed to MPI_Send()
can be reused, either because MPI saved it somewhere, or because it has been received by the destination. Similarly, MPI_Recv()
returns when the receive buffer has been filled with valid data.
相反,使用 MPI_Irecv()
.即使通信尚未完成,这些函数也会立即返回(即,它们不会阻塞).您必须致电 MPI_Wait()
或 MPI_Test()
以查看通信是否已完成.
In contrast, non-blocking communication is done using MPI_Isend()
and MPI_Irecv()
. These function return immediately (i.e., they do not block) even if the communication is not finished yet. You must call MPI_Wait()
or MPI_Test()
to see whether the communication has finished.
在足够的情况下使用阻塞通信,因为它比较容易使用.必要时使用无阻塞通信,例如,您可以调用MPI_Isend()
,进行一些计算,然后再进行MPI_Wait()
.这样可以使计算和通信重叠,从而通常可以提高性能.
Blocking communication is used when it is sufficient, since it is somewhat easier to use. Non-blocking communication is used when necessary, for example, you may call MPI_Isend()
, do some computations, then do MPI_Wait()
. This allows computations and communication to overlap, which generally leads to improved performance.
请注意,集体通信(例如全减少)仅在其阻塞版本(最多MPIv2)中可用. IIRC,MPIv3引入了非阻塞的集体通信.
Note that collective communication (e.g., all-reduce) is only available in its blocking version up to MPIv2. IIRC, MPIv3 introduces non-blocking collective communication.
此处.
这篇关于MPI:阻止与非阻止的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!