If you want to have a true asynchronous data exchange with no
synchronization, there really is no way to avoid using extra buffers,
and copying over the "real" buffers only when you are sure that the
real buffers have been sent.
More generally, you have a pair of buffers A and B, and you want to
exchange data between them. If either buffer can be sent at any time,
and then you have to send to A' and B', because A and B may still be
being used by their respective owners and not be ready for the new
data. When they're ready, they can send and then copy X' into X and
then keep going.
Alternatively, you can be a little clever about internal data
structures and avoid copying if you simply have a pointer that points
to the latest buffer that should be used (e.g., A or A') and simply
rotate that pointer around. If you distinguish between the receiving
buffer and the current-use-this-buffer buffer, it might make some
abstractions simpler in your code.
Hope that helps.
On Aug 6, 2005, at 7:23 PM, L WK wrote:
> Hi there,
> Suppose I have 2 nodes take part in the parallel computing.
> Initially, each node owns a full identical 2D array as follow
>
> _______________________
> | 0 | 1 | 2 | 3 | 4 | 5 |
> |---|---|----------------
> | 6 | 7 | 8 | 9 | 10| 11|
> ------------------------
>
> the array are divided into 12 parts
>
> Assume that rank 0 will exchange data with rank 1: * rank 0 send part
> 1,2 to rank 1; rank 1 recv data and copy to part 0, 6
> * rank 1 send part 0,6 to rank 0; rank 0 recv data and copy to part 1,
> 2
>
> In this case, if I don't know which node will send data first. Suppose
> rank 0 send data first, so rank 1 get data and copy them to the
> position of part 0, 6, then part 0,6 will get exactly the same data as
> part 1,2. So, in the mean time, rank 1 sends part 0,6 (extactly
> identical to part 1,2) to rank 0. We know that the data being sent is
> not what rank 1 really want. What I want to do is data exchange,
> someone suggest that I should setup an additional buffer and have my
> code like
>
> rank 0:copy part 1, 2 to A; send A to rank 1; recv data from rank 1
> and copy to part 1,2
> rank 1:copy part 0,6 to B; send B to rank 0; recv data from rank 0 and
> copy to part 0,6
>
> it do work. However, I need an extra storage and time to perform the
> copy operation( in this case, the cost maybe negligible, but in real
> case, the cost is much larger). Is there is any better approach for my
> issue ?
>
> Thanks in advance.
>
> _________________________________________________________________
> ~{SkA*;z5DEsSQ=xPP=;Aw#,GkJ9SC~} MSN Messenger: http://messenger.msn.com/cn
> _______________________________________________
> This list is archived at http://www.lam-mpi.org/MailArchives/lam/
--
{+} Jeff Squyres
{+} jsquyres_at_[hidden]
{+} http://www.lam-mpi.org/
|