Skip to content

Commit 5d24cc9

Browse files
committed
Merge pull request #136 from JuliaParallel/ksh/testwaiting
Add tests for isend and some wait/test methods
2 parents e373f90 + 3bf6aec commit 5d24cc9

File tree

5 files changed

+97
-8
lines changed

5 files changed

+97
-8
lines changed

src/mpi-base.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -265,8 +265,8 @@ function Recv!{T}(buf::Array{T}, src::Integer, tag::Integer,
265265
end
266266

267267
function Recv{T}(::Type{T}, src::Integer, tag::Integer, comm::Comm)
268-
buf = Ref{T}
269-
stat = Recv!(buf, src, tag, comm)
268+
buf = Ref{T}()
269+
stat = Recv!(buf, 1, src, tag, comm)
270270
(buf[], stat)
271271
end
272272

@@ -389,10 +389,10 @@ function Testany!(reqs::Array{Request,1})
389389
ccall(MPI_TESTANY, Void,
390390
(Ptr{Cint}, Ptr{Cint}, Ptr{Cint}, Ptr{Cint}, Ptr{Cint}, Ptr{Cint}),
391391
&count, reqvals, ind, flag, stat.val, &0)
392-
if flag[] == 0
392+
index = Int(ind[])
393+
if flag[] == 0 || index == MPI_UNDEFINED
393394
return (false, 0, nothing)
394395
end
395-
index = Int(ind[])
396396
reqs[index].val = reqvals[index]
397397
reqs[index].buffer = nothing
398398
(true, index, stat)

src/win_mpiconstants.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ const MPI_IPROBE = (:MPI_IPROBE, "msmpi.dll")
7676
const MPI_PROBE = (:MPI_PROBE, "msmpi.dll")
7777
const MPI_COMM_FREE = (:MPI_COMM_FREE, "msmpi.dll")
7878
const MPI_GET_COUNT = (:MPI_GET_COUNT, "msmpi.dll")
79+
const MPI_TEST = (:MPI_TEST, "msmpi.dll")
7980
const MPI_TESTSOME = (:MPI_TESTSOME, "msmpi.dll")
8081
const MPI_TESTANY = (:MPI_TESTANY, "msmpi.dll")
8182
const MPI_TESTALL = (:MPI_TESTALL, "msmpi.dll")

test/test_bcast.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ comm = MPI.COMM_WORLD
3434

3535
g = x -> x^2 + 2x - 1
3636
if MPI.Comm_rank(comm) == root
37-
f = copy(g)
37+
f = g
3838
else
3939
f = nothing
4040
end

test/test_sendrecv.jl

Lines changed: 59 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,27 @@ sreq = MPI.Isend(send_mesg, dst, rank+32, comm)
2525
stats = MPI.Waitall!([sreq, rreq])
2626
@test isequal(typeof(rreq), typeof(MPI.REQUEST_NULL))
2727
@test isequal(typeof(sreq), typeof(MPI.REQUEST_NULL))
28-
2928
@test MPI.Get_source(stats[2]) == src
3029
@test MPI.Get_tag(stats[2]) == src+32
3130
@test isapprox(norm(recv_mesg-recv_mesg_expected), 0.0)
3231

33-
(done,stats) = MPI.Testall!([sreq, rreq])
32+
(done, stats) = MPI.Testall!([sreq, rreq])
3433
@test done
34+
rreq = nothing
35+
sreq = nothing
36+
gc()
3537

38+
if rank == 0
39+
MPI.send(send_mesg, dst, rank+32, comm)
40+
recv_mesg = recv_mesg_expected
41+
elseif rank == size-1
42+
(recv_mesg, _) = MPI.recv(src, src+32, comm)
43+
else
44+
(recv_mesg, _) = MPI.recv(src, src+32, comm)
45+
MPI.send(send_mesg, dst, rank+32, comm)
46+
end
47+
48+
@test isapprox(norm(recv_mesg-recv_mesg_expected), 0.0)
3649

3750
rreq = nothing
3851
sreq = nothing
@@ -48,6 +61,49 @@ else
4861
MPI.send(send_mesg, dst, rank+32, comm)
4962
end
5063

51-
@test isapprox(norm(recv_mesg-recv_mesg_expected), 0.0)
64+
send_mesg = Float64(rank)
65+
recv_mesg = Array(Float64, N)
66+
recv_mesg_expected = Array(Float64, N)
67+
68+
fill!(recv_mesg_expected, Float64(src))
69+
70+
rreq = nothing
71+
sreq = nothing
72+
gc()
73+
74+
send_mesg = Float64(rank)
75+
recv_mesg = Array(Float64, N)
76+
recv_mesg_expected = Array(Float64, N)
77+
78+
fill!(recv_mesg_expected, Float64(src))
79+
80+
if rank == 0
81+
MPI.Send(send_mesg, dst, rank+32, comm)
82+
recv_mesg = recv_mesg_expected
83+
elseif rank == size-1
84+
(recv_mesg, _) = MPI.Recv(Float64,src, src+32, comm)
85+
else
86+
(recv_mesg, _) = MPI.Recv(Float64,src, src+32, comm)
87+
MPI.Send(send_mesg, dst, rank+32, comm)
88+
end
89+
90+
rreq = nothing
91+
sreq = nothing
92+
gc()
93+
94+
recv_mesg = Array(Float64, N)
95+
rreq = MPI.Irecv!(recv_mesg, src, src+32, comm)
96+
sreq = MPI.Isend(send_mesg, dst, rank+32, comm)
97+
98+
(inds, stats) = MPI.Waitsome!([sreq, rreq])
99+
req_arr = [sreq,rreq]
100+
for i in inds
101+
(done, status) = MPI.Test!( req_arr[i] )
102+
@test done
103+
end
104+
105+
rreq = nothing
106+
sreq = nothing
107+
gc()
52108

53109
MPI.Finalize()

test/test_test.jl

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
using Base.Test
2+
using MPI
3+
4+
MPI.Init()
5+
6+
comm = MPI.COMM_WORLD
7+
size = MPI.Comm_size(comm)
8+
rank = MPI.Comm_rank(comm)
9+
10+
dst = mod(rank+1, size)
11+
src = mod(rank-1, size)
12+
13+
N = 32
14+
15+
send_mesg = Array(Float64, N)
16+
recv_mesg = Array(Float64, N)
17+
recv_mesg_expected = Array(Float64, N)
18+
fill!(send_mesg, Float64(rank))
19+
fill!(recv_mesg_expected, Float64(src))
20+
21+
rreq = MPI.Irecv!(recv_mesg, src, src+32, comm)
22+
sreq = MPI.Isend(send_mesg, dst, rank+32, comm)
23+
24+
(ind,stats) = MPI.Waitsome!([sreq, rreq])
25+
(done, ind, stats) = MPI.Testany!([sreq, rreq])
26+
arr = [sreq,rreq]
27+
if done
28+
(onedone,stats) = MPI.Test!(arr[ind])
29+
@test onedone
30+
end
31+
32+
MPI.Finalize()

0 commit comments

Comments
 (0)