MPI:阻塞与非阻塞 [英] MPI: blocking vs non-blocking

查看:43
本文介绍了MPI:阻塞与非阻塞的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法理解 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_Send()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_Isend()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.

请注意,集体通信(例如,all-reduce)仅在 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 发送模式的快速概览.

这篇关于MPI:阻塞与非阻塞的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆