使用 MPI_PACK() 的优势

Advantage of using MPI_PACK()

我知道MPI_PACK()是用来把不连续的数据捆绑在一起发送的,但是它有什么用,而不是用MPI_Send()一个接一个地发送数据呢?

I know that MPI_PACK() is used to bundle the non-contiguous data together and send them, but what is the use of it,

优点之一就是不必

then sending data using MPI_Send() one after the other?

您曾经减少跨进程的 MPI 调用次数(这往往是并行化瓶颈)。通常,通过减少通信调用而节省的时间证明计算与 MPI_PACK() 调用相关的所有代码所花费的时间是合理的。

Pack and unpack可以读到其他一些好处(例如,兼容性、灵活性和抽象性),即:

The pack/unpack routines are provided **for compatibility with previous libraries. ** Also, they provide some functionality that is not otherwise available in MPI. For instance, a message can be received in several parts, where the receive operation done on a later part may depend on the content of a former part. Another use is that outgoing messages may be explicitly buffered in user supplied space, thus overriding the system buffering policy. Finally, the availability of pack and unpack operations facilitates the development of additional communication libraries layered on top of MPI.

这可能不是最好的类比;从表面上看,您可以将其视为出于与尝试将尽可能多的物品装在一个盒子中相同的原因;尽量减少携带箱子的次数,从而减少旅行的次数——类似于通信。

超出了这个问题的范围,但仍然useful

Derived datatypes, which are described in Section Derived datatypes , allow one, in most cases, to avoid explicit packing and unpacking

为了更好地理解,请查看 Derived Datatypes vs Pack/Unpack