Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
640 views
in Technique[技术] by (71.8m points)

parallel processing - 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?

question from:https://stackoverflow.com/questions/66052004/advantage-of-using-mpi-pack

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...