Skip to content

Commit

Permalink
Change Sendrecv to Sendrecv! (#319)
Browse files Browse the repository at this point in the history
Since it is a mutating operation.
  • Loading branch information
simonbyrne committed Nov 20, 2019
1 parent ca95656 commit 01b4c16
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 17 deletions.
2 changes: 1 addition & 1 deletion docs/src/pointtopoint.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ MPI.Get_count
```@docs
MPI.Send
MPI.Recv!
MPI.Sendrecv
MPI.Sendrecv!
```

### Non-blocking
Expand Down
22 changes: 12 additions & 10 deletions src/pointtopoint.jl
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ number of entries received.
"""
Status

Base.:(==)(a::Status, b::Status) = a.source == b.source && a.tag == b.tag && a.error == b.error

Get_source(status::Status) = Int(status.source)
Get_tag(status::Status) = Int(status.tag)
Get_error(status::Status) = Int(status.error)
Expand Down Expand Up @@ -333,15 +335,15 @@ function irecv(src::Integer, tag::Integer, comm::Comm)
end

"""
Sendrecv(sendbuf, [sendcount::Integer, [sendtype::Union{Datatype, MPI_Datatype}]],
Sendrecv!(sendbuf, [sendcount::Integer, [sendtype::Union{Datatype, MPI_Datatype}]],
dest::Integer, sendtag::Integer,
recvbuf, [recvcount::Integer, [recvtype::Union{Datatype, MPI_Datatype}]],
recvbuf, [recvcount::Integer, [recvtype::Union{Datatype, MPI_Datatype}]],
source::Integer, recvtag::Integer,
comm::Comm)
Complete a blocking send-receive operation over the MPI communicator `comm`. Send
`sendcount` elements of type `sendtype` from `sendbuf` to the MPI rank `dest` using message
tag `tag`, and receive `recvcount` elements of type `recvtype` from MPI rank `source` into
Complete a blocking send-receive operation over the MPI communicator `comm`. Send
`sendcount` elements of type `sendtype` from `sendbuf` to the MPI rank `dest` using message
tag `tag`, and receive `recvcount` elements of type `recvtype` from MPI rank `source` into
the buffer `recvbuf` using message tag `tag`. Return a [`Status`](@ref) object.
If not provided, `sendtype`/`recvtype` and `sendcount`/`recvcount` are derived from the
Expand All @@ -350,7 +352,7 @@ element type and length of `sendbuf`/`recvbuf`, respectively.
# External links
$(_doc_external("MPI_Sendrecv"))
"""
function Sendrecv(sendbuf, sendcount::Integer, sendtype::Union{Datatype, MPI_Datatype}, dest::Integer, sendtag::Integer,
function Sendrecv!(sendbuf, sendcount::Integer, sendtype::Union{Datatype, MPI_Datatype}, dest::Integer, sendtag::Integer,
recvbuf, recvcount::Integer, recvtype::Union{Datatype, MPI_Datatype}, source::Integer, recvtag::Integer,
comm::Comm)
# int MPI_Sendrecv(const void *sendbuf, int sendcount, MPI_Datatype sendtype, int dest, int sendtag,
Expand All @@ -366,16 +368,16 @@ function Sendrecv(sendbuf, sendcount::Integer, sendtype::Union{Datatype, MPI_Dat
return stat_ref[]
end

function Sendrecv(sendbuf, sendcount::Integer, dest::Integer, sendtag::Integer,
function Sendrecv!(sendbuf, sendcount::Integer, dest::Integer, sendtag::Integer,
recvbuf, recvcount::Integer, source::Integer, recvtag::Integer,
comm::Comm)
return Sendrecv(sendbuf, sendcount, mpitype(eltype(sendbuf)), dest, sendtag,
return Sendrecv!(sendbuf, sendcount, mpitype(eltype(sendbuf)), dest, sendtag,
recvbuf, recvcount, mpitype(eltype(recvbuf)), source, recvtag, comm)
end
function Sendrecv(sendbuf::AbstractArray, dest::Integer, sendtag::Integer,
function Sendrecv!(sendbuf::AbstractArray, dest::Integer, sendtag::Integer,
recvbuf::AbstractArray, source::Integer, recvtag::Integer,
comm::Comm)
return Sendrecv(sendbuf, length(sendbuf), dest, sendtag,
return Sendrecv!(sendbuf, length(sendbuf), dest, sendtag,
recvbuf, length(recvbuf), source, recvtag, comm)
end

Expand Down
12 changes: 6 additions & 6 deletions test/test_sendrecv.jl
Original file line number Diff line number Diff line change
Expand Up @@ -114,26 +114,26 @@ comm_cart = MPI.Cart_create(comm, 1, Cint[comm_size], Cint[1], false)
src_rank, dest_rank = MPI.Cart_shift(comm_cart, 0, -1)

# execute left shift using subarrays
MPI.Sendrecv(a, 1, subarr_send, dest_rank, 0,
a, 1, subarr_recv, src_rank, 0, comm_cart)
MPI.Sendrecv!(a, 1, subarr_send, dest_rank, 0,
a, 1, subarr_recv, src_rank, 0, comm_cart)

@test a == [comm_rank, comm_rank, (comm_rank+1) % comm_size]

# send elements from a buffer
# ---------------------------
a = Float64[comm_rank, comm_rank, comm_rank]
b = Float64[ -1, -1, -1]
MPI.Sendrecv(a, 2, dest_rank, 1,
b, 2, src_rank, 1, comm_cart)
MPI.Sendrecv!(a, 2, dest_rank, 1,
b, 2, src_rank, 1, comm_cart)

@test b == [(comm_rank+1) % comm_size, (comm_rank+1) % comm_size, -1]

# send entire buffer
# ---------------------------
a = Float64[comm_rank, comm_rank, comm_rank]
b = Float64[ -1, -1, -1]
MPI.Sendrecv(a, dest_rank, 2,
b, src_rank, 2, comm_cart)
MPI.Sendrecv!(a, dest_rank, 2,
b, src_rank, 2, comm_cart)

@test b == [(comm_rank+1) % comm_size, (comm_rank+1) % comm_size, (comm_rank+1) % comm_size]

Expand Down

0 comments on commit 01b4c16

Please sign in to comment.