diff --git a/src/mpi-base.jl b/src/mpi-base.jl index ce64c5131..64fefb88f 100644 --- a/src/mpi-base.jl +++ b/src/mpi-base.jl @@ -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 @@ -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) diff --git a/src/win_mpiconstants.jl b/src/win_mpiconstants.jl index e8b1146d5..165680945 100644 --- a/src/win_mpiconstants.jl +++ b/src/win_mpiconstants.jl @@ -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") diff --git a/test/test_bcast.jl b/test/test_bcast.jl index d8d474afc..7b5d4ed11 100644 --- a/test/test_bcast.jl +++ b/test/test_bcast.jl @@ -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 diff --git a/test/test_sendrecv.jl b/test/test_sendrecv.jl index 6738c511e..f84c822bd 100644 --- a/test/test_sendrecv.jl +++ b/test/test_sendrecv.jl @@ -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 @@ -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() diff --git a/test/test_test.jl b/test/test_test.jl new file mode 100644 index 000000000..b6bbd9cae --- /dev/null +++ b/test/test_test.jl @@ -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()