On Jul 22, 2005, at 6:16 AM, L WK wrote:
> I would like to learn more about communcation mode and wonder if
> there are any codes for demonstrating the differences between each
> mode.
> Thinking about the following case, a all-to-all communication performed
> in a loop
>
> for (t=0; t<NC; t++) // NC computers in the parallel network
> {
> if (t!=myrank) // don't send the message to myself
> {
> if (t<myrank) // avoid deadlock
> {
> // N stands for the size of buffer to be sent or received,
> N>100
> MPI_Send(send_buf, N, MPI_INT, to, stag, MPI_COMM_WORLD);
> MPI_Recv(recv_buf, N, MPI_INT, from, rtag, MPI_COMM_WORLD,
> MPI_STATUS_IGNORE);
> }
> else
> {
> MPI_Recv(recv_buf, N, MPI_INT, from, rtag, MPI_COMM_WORLD,
> MPI_STATUS_IGNORE);
> MPI_Send(send_buf, N, MPI_INT, to, stag, MPI_COMM_WORLD);
> }
> }
> }
>
> In the above code, blocking send/receive in stand mode have been used.
> I have few questions about the send/recive process.
>
> 1) Because the send/recive procedure are run in a loop, for blocking
> methods, will the loop pause until the current send/receive procedure
> are finished?
Yes and no. Depending on the value of N, MPI_SEND may or may not block
(usually, for small N, it won't block; for large N, it'll block until
at least the data has been fully sent and your send_buf can be safely
re-used). But MPI_RECV will always block -- it wouldn't make sense
otherwise.
> 2) If nonblocking send/recv are imposed, will the loop go on without
> waiting the send/recv's finish?
Correct.
> If so, how can I make sure the
> each node receive the correct data (i.e. each send-receive procedure go
> without any problem)?
You must use one of the different flavors of MPI_TEST or MPI_WAIT to
complete each started non-blocking operation. When MPI_TEST returns
with flag==1, or when MPI_WAIT returns, then you know that a given
communication has completed (e.g., a send or a receive).
There's some examples of this kind of thing in various MPI internet
tutorials, in the MPI standard itself, and in popular MPI books.
> 3) Will the answer of 1) 2) change in other communcation mode?
It depends on which mode you're referring to -- I assume you mean
"mode" in the MPI sense of the word, which means:
- standard (discussed above)
- buffered: these are evil; don't use them (they just force an extra
memory copy)
- synchronous: these are used to impose synchronization between sender
and receiver
- ready: a potential for optimization when the sender can be guaranteed
that the receiver has already posted a matching receive (but LAM treats
it identical to standard mode)
--
{+} Jeff Squyres
{+} jsquyres_at_[hidden]
{+} http://www.lam-mpi.org/
|