Search code examples
performanceparallel-processingmpihpcpacking

Advantage of using MPI_PACK()


I know that MPI_PACK() is used to bundle the non-contiguous data together and send them, but what is the use of it, rather then sending data using MPI_Send() one after the other?


Solution

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

    One of the advantages is precisely not having to

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

    You used to reduce the number of MPI calls across processes (which tend to be a parallelization bottleneck). Typically, the time that one saves by having fewer communication calls justifies the time taken on computing all the code related with the MPI_PACK() call.

    From Pack and unpack one can read some of the other benefits (e.g., compatibility, flexibility and abstraction), namely:

    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.

    This may not be the best analogy; very superficially you can think of it as for the same reason that one tries to pack as many items as possible in one box; to minimize the number of times that one has to carry that box, and consequently reducing the number of trips -- analogous to the communication.

    Outside of the scope of this question but still useful nonetheless:

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

    for a better understand have a look at Derived Datatypes vs Pack/Unpack