问题
Consider the configuration to be
First:
Not buffered, blocking(synchronous)
As I understand MPI is an API, so when we do the mpi_send
blocking function call, does the sender function/program get blocked?
OR
Does the MPI API function mpi_send
get blocked, so that the program can continue its work till message is sent?
Second:
Similar confusion, does the mpi_recv
get blocked or the function from where it was called gets blocked?
Reason for such a stupid question:
It's parallel processing so why would some one make something that would block a process who wants some info?
Another reason:
It is possible that when mpi_send
is called by a process, no other process can use the mpi_send
function because it's working?!
回答1:
First: Yes, the calling program is "blocked" because the MPI_Send call will not return until the message is "sent."
Second: MPI_Recv is also a "blocking" call, and will not return until the message has been "received."
Some additional information:
MPI_Send is a "blocking" call because the call will not return control to the caller until the message has been sent. And the definition of "sent" is that the user buffer that holds the message can be safely reused. There is no guarantee that the message has been received, or even that the MPI_Recv call has been reached in the remote rank. (The exact behavior is implementation dependent. RDMA style interconnects cause the most issues with the exact "inside the black box" behavior.)
MPI_Isend is a "non blocking" call. Control will return to the calling program "instantly"...but the buffer can not be reused until the program calls MPI_Test or MPI_Wait to confirm that the message has been "sent."
The purpose of the "blocking" calls is to provide a positive confirmation to the calling program that the buffer holding the message can be reused (in the case of MPI_Send) or reliably read and altered (in the case of MPI_Recv). If a "non-blocking" (e.g. MPI_Isend, MPI_Irecv) call is used, the calling program can continue performing calculations, but can not reliably (or legally) alter the message buffer until MPI_Wait or MPI_Test is called to complete the message transaction.
回答2:
The answer to your last question is no: some processes can be blocked waiting for a Send or Receive to complete while other processes are executing. Blocking calls block only on the process that calls them.
来源:https://stackoverflow.com/questions/4070173/in-message-passing-mpi-mpi-send-and-recv-what-waits