Skip to content

Commit

Permalink
Merge pull request #136 from JuliaParallel/ksh/testwaiting
Browse files Browse the repository at this point in the history
Add tests for isend and some wait/test methods
  • Loading branch information
kshyatt committed Apr 27, 2016
2 parents e373f90 + 3bf6aec commit 5d24cc9
Show file tree
Hide file tree
Showing 5 changed files with 97 additions and 8 deletions.
8 changes: 4 additions & 4 deletions src/mpi-base.jl
Original file line number Diff line number Diff line change
Expand Up @@ -265,8 +265,8 @@ function Recv!{T}(buf::Array{T}, src::Integer, tag::Integer,
end

function Recv{T}(::Type{T}, src::Integer, tag::Integer, comm::Comm)
buf = Ref{T}
stat = Recv!(buf, src, tag, comm)
buf = Ref{T}()
stat = Recv!(buf, 1, src, tag, comm)
(buf[], stat)
end

Expand Down Expand Up @@ -389,10 +389,10 @@ function Testany!(reqs::Array{Request,1})
ccall(MPI_TESTANY, Void,
(Ptr{Cint}, Ptr{Cint}, Ptr{Cint}, Ptr{Cint}, Ptr{Cint}, Ptr{Cint}),
&count, reqvals, ind, flag, stat.val, &0)
if flag[] == 0
index = Int(ind[])
if flag[] == 0 || index == MPI_UNDEFINED
return (false, 0, nothing)
end
index = Int(ind[])
reqs[index].val = reqvals[index]
reqs[index].buffer = nothing
(true, index, stat)
Expand Down
1 change: 1 addition & 0 deletions src/win_mpiconstants.jl
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ const MPI_IPROBE = (:MPI_IPROBE, "msmpi.dll")
const MPI_PROBE = (:MPI_PROBE, "msmpi.dll")
const MPI_COMM_FREE = (:MPI_COMM_FREE, "msmpi.dll")
const MPI_GET_COUNT = (:MPI_GET_COUNT, "msmpi.dll")
const MPI_TEST = (:MPI_TEST, "msmpi.dll")
const MPI_TESTSOME = (:MPI_TESTSOME, "msmpi.dll")
const MPI_TESTANY = (:MPI_TESTANY, "msmpi.dll")
const MPI_TESTALL = (:MPI_TESTALL, "msmpi.dll")
Expand Down
2 changes: 1 addition & 1 deletion test/test_bcast.jl
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ comm = MPI.COMM_WORLD

g = x -> x^2 + 2x - 1
if MPI.Comm_rank(comm) == root
f = copy(g)
f = g
else
f = nothing
end
Expand Down
62 changes: 59 additions & 3 deletions test/test_sendrecv.jl
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,27 @@ sreq = MPI.Isend(send_mesg, dst, rank+32, comm)
stats = MPI.Waitall!([sreq, rreq])
@test isequal(typeof(rreq), typeof(MPI.REQUEST_NULL))
@test isequal(typeof(sreq), typeof(MPI.REQUEST_NULL))

@test MPI.Get_source(stats[2]) == src
@test MPI.Get_tag(stats[2]) == src+32
@test isapprox(norm(recv_mesg-recv_mesg_expected), 0.0)

(done,stats) = MPI.Testall!([sreq, rreq])
(done, stats) = MPI.Testall!([sreq, rreq])
@test done
rreq = nothing
sreq = nothing
gc()

if rank == 0
MPI.send(send_mesg, dst, rank+32, comm)
recv_mesg = recv_mesg_expected
elseif rank == size-1
(recv_mesg, _) = MPI.recv(src, src+32, comm)
else
(recv_mesg, _) = MPI.recv(src, src+32, comm)
MPI.send(send_mesg, dst, rank+32, comm)
end

@test isapprox(norm(recv_mesg-recv_mesg_expected), 0.0)

rreq = nothing
sreq = nothing
Expand All @@ -48,6 +61,49 @@ else
MPI.send(send_mesg, dst, rank+32, comm)
end

@test isapprox(norm(recv_mesg-recv_mesg_expected), 0.0)
send_mesg = Float64(rank)
recv_mesg = Array(Float64, N)
recv_mesg_expected = Array(Float64, N)

fill!(recv_mesg_expected, Float64(src))

rreq = nothing
sreq = nothing
gc()

send_mesg = Float64(rank)
recv_mesg = Array(Float64, N)
recv_mesg_expected = Array(Float64, N)

fill!(recv_mesg_expected, Float64(src))

if rank == 0
MPI.Send(send_mesg, dst, rank+32, comm)
recv_mesg = recv_mesg_expected
elseif rank == size-1
(recv_mesg, _) = MPI.Recv(Float64,src, src+32, comm)
else
(recv_mesg, _) = MPI.Recv(Float64,src, src+32, comm)
MPI.Send(send_mesg, dst, rank+32, comm)
end

rreq = nothing
sreq = nothing
gc()

recv_mesg = Array(Float64, N)
rreq = MPI.Irecv!(recv_mesg, src, src+32, comm)
sreq = MPI.Isend(send_mesg, dst, rank+32, comm)

(inds, stats) = MPI.Waitsome!([sreq, rreq])
req_arr = [sreq,rreq]
for i in inds
(done, status) = MPI.Test!( req_arr[i] )
@test done
end

rreq = nothing
sreq = nothing
gc()

MPI.Finalize()
32 changes: 32 additions & 0 deletions test/test_test.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using Base.Test
using MPI

MPI.Init()

comm = MPI.COMM_WORLD
size = MPI.Comm_size(comm)
rank = MPI.Comm_rank(comm)

dst = mod(rank+1, size)
src = mod(rank-1, size)

N = 32

send_mesg = Array(Float64, N)
recv_mesg = Array(Float64, N)
recv_mesg_expected = Array(Float64, N)
fill!(send_mesg, Float64(rank))
fill!(recv_mesg_expected, Float64(src))

rreq = MPI.Irecv!(recv_mesg, src, src+32, comm)
sreq = MPI.Isend(send_mesg, dst, rank+32, comm)

(ind,stats) = MPI.Waitsome!([sreq, rreq])
(done, ind, stats) = MPI.Testany!([sreq, rreq])
arr = [sreq,rreq]
if done
(onedone,stats) = MPI.Test!(arr[ind])
@test onedone
end

MPI.Finalize()

0 comments on commit 5d24cc9

Please sign in to comment.