Using mpi4py for MPI parallel programming is relatively simple and convenient, but to use mpi4py well to write a practical and powerful MPI parallel computing program, we also need to have a deeper understanding of the various methods and their usage provided by mpi4py. We first introduce the most basic point-to-point communication.
Point-to-point communication requires that send and recv must be paired. For example, if multiple sending processes send two consecutive messages to the same target process, both of which match the same recv on the receiving end, the order of receipt must match the order of sending. If the receiver process also initiates two consecutive recvs, both of which match the same message, and the first recv is still waiting, the second recv cannot be charged before the first operation. news. The tag in message passing is decisive. If the process uses a single thread and does not use a wildcard (ie MPI.ANY_SOURCE) as a tag in the receive message operation, the order of sending strictly matches the order of receiving.
There are 12 pairs of point-to-point communication, corresponding to 1 group (4) of blocking communication modes and 2 groups of non-blocking communication modes (respectively non-repetitive non-blocking and repeatable non-blocking), some of which are also divided into lowercase Methods starting with a letter and methods starting with an uppercase letter, the former works with any Python object that can be pickled serialized, while the latter is more efficient for data communication of array types. The detailed classification is shown in the table below:
It can be seen that these sending functions follow a certain naming convention: ??[S/s]end, where B/b means buffer mode (Buffer), R/r means ready mode (Ready), and S/s means synchronization mode ( Synchonous), I/i means to send immediately, that is, to send in non-blocking mode (Imediately). Send/send without any prefix modification is called standard mode. I/i can be combined with B/b, R/r, S/s respectively to obtain various communication modes as shown in the table above.
The data transfer process of message communication is as follows:
- The sender calls the send function;
- The MPI environment extracts the data to be sent from the send buffer, and assembles the send message accordingly;
- Send the assembled message to the target;
- The receiver receives the matching message and parses it into the receive buffer.