From 01b4c16a55690fd747382784e4d3a2788d1b0c8f Mon Sep 17 00:00:00 2001 From: Simon Byrne Date: Tue, 19 Nov 2019 09:10:45 -0800 Subject: [PATCH] Change Sendrecv to Sendrecv! (#319) Since it is a mutating operation. --- docs/src/pointtopoint.md | 2 +- src/pointtopoint.jl | 22 ++++++++++++---------- test/test_sendrecv.jl | 12 ++++++------ 3 files changed, 19 insertions(+), 17 deletions(-) diff --git a/docs/src/pointtopoint.md b/docs/src/pointtopoint.md index 74a70fa20..46e2eb375 100644 --- a/docs/src/pointtopoint.md +++ b/docs/src/pointtopoint.md @@ -20,7 +20,7 @@ MPI.Get_count ```@docs MPI.Send MPI.Recv! -MPI.Sendrecv +MPI.Sendrecv! ``` ### Non-blocking diff --git a/src/pointtopoint.jl b/src/pointtopoint.jl index 93071b4ce..d83957014 100644 --- a/src/pointtopoint.jl +++ b/src/pointtopoint.jl @@ -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) @@ -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 @@ -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, @@ -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 diff --git a/test/test_sendrecv.jl b/test/test_sendrecv.jl index e55342792..e0febc188 100644 --- a/test/test_sendrecv.jl +++ b/test/test_sendrecv.jl @@ -114,8 +114,8 @@ 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] @@ -123,8 +123,8 @@ MPI.Sendrecv(a, 1, subarr_send, dest_rank, 0, # --------------------------- 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] @@ -132,8 +132,8 @@ MPI.Sendrecv(a, 2, dest_rank, 1, # --------------------------- 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]