Reputation: 119
In contrast to a normal Sendrecv operation, I understand that _replace uses the same memory location, count and data type.
After some readings, I found that it's supposed to prevent buffer overlapping, but can't Sendrecv also serve the same purpose?
Can anyone explain what is going on with the data after the operation?
Typical usage examples would be really helpful
Thank you
Upvotes: 1
Views: 351
Reputation: 74405
Think of MPI_SENDRECV_REPLACE
as of a convenience function. MPI_SENDRECV
requires that both buffers are disjoint - it cannot operate on overlapping buffers. This translates into the need for a separate receive buffer, even when what one really wants to achieve is to exchange the content of the send buffer with that of another rank. In order to implement such an exchange using MPI_SENDRECV
, one would do something like (in pseudocode):
populate data buffer "data"
allocate receive buffer "recv"
call MPI_SENDRECV(data, count, type, recv, count, type)
copy "recv" over "data"
deallocate "recv"
This might become tedious, especially if needed in multiple locations throughout the program and, more importantly, if the datatype is non-contiguous (i.e. a column of a matrix in C/C++). The solution is to use MPI_SENDRECV_REPLACE
, which performs an equivalent of the above pseudocode internally and handles properly non-contiguous types.
I'm hard pressed to think of a common use case of such an exchange. In most cases, e.g. for halo exchanges, the usual send-receive operation with disjoint buffers suffices.
Upvotes: 4