Skip to content

Commit e29e0ee

Browse files
committed
Wrapped and tested {i}allreduce
1 parent cdcc782 commit e29e0ee

File tree

5 files changed

+73
-0
lines changed

5 files changed

+73
-0
lines changed

deps/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ FortranCInterface_HEADER(jlmpi_f2c.h MACRO_NAMESPACE "JLMPI_" SYMBOLS
5151
MPI_GET_PROCESSOR_NAME
5252
MPI_IALLGATHER
5353
MPI_IALLGATHERV
54+
MPI_IALLREDUCE
5455
MPI_IALLTOALL
5556
MPI_IALLTOALLV
5657
MPI_IBARRIER

deps/gen_functions.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ int main(int argc, char *argv[]) {
3939
STRING(MPI_GET_PROCESSOR_NAME));
4040
printf(" :MPI_IALLGATHER => \"%s\",\n", STRING(MPI_IALLGATHER));
4141
printf(" :MPI_IALLGATHERV => \"%s\",\n", STRING(MPI_IALLGATHERV));
42+
printf(" :MPI_IALLREDUCE => \"%s\",\n", STRING(MPI_IALLREDUCE));
4243
printf(" :MPI_IALLTOALL => \"%s\",\n", STRING(MPI_IALLTOALL));
4344
printf(" :MPI_IALLTOALLV => \"%s\",\n", STRING(MPI_IALLTOALLV));
4445
printf(" :MPI_IBARRIER => \"%s\",\n", STRING(MPI_IBARRIER));

src/mpi-base.jl

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -571,6 +571,45 @@ function Ireduce{T}(object::T, op::Op, root::Integer, comm::Comm)
571571
req, isroot ? recvbuf[1] : nothing
572572
end
573573

574+
function Allreduce{T}(sendbuf::MPIBuffertype{T}, count::Integer, op::Op, comm::Comm)
575+
recvbuf = Array(T, count)
576+
ccall(MPI_ALLREDUCE, Void,
577+
(Ptr{T}, Ptr{T}, Ptr{Cint}, Ptr{Cint}, Ptr{Cint}, Ptr{Cint}, Ptr{Cint}),
578+
sendbuf, recvbuf, &count, &mpitype(T), &op.val, &comm.val, &0)
579+
recvbuf
580+
end
581+
582+
function Allreduce{T}(sendbuf::Array{T}, op::Op, comm::Comm)
583+
Allreduce(sendbuf, length(sendbuf), op, comm)
584+
end
585+
586+
function Allreduce{T}(object::T, op::Op, comm::Comm)
587+
sendbuf = T[object]
588+
recvbuf = Allreduce(sendbuf, op, comm)
589+
recvbuf[1]
590+
end
591+
592+
function Iallreduce{T}(sendbuf::MPIBuffertype{T}, count::Integer, op::Op, comm::Comm)
593+
rval = Ref{Cint}()
594+
recvbuf = Array(T, count)
595+
ccall(MPI_IALLREDUCE, Void,
596+
(Ptr{T}, Ptr{T}, Ptr{Cint}, Ptr{Cint}, Ptr{Cint}, Ptr{Cint},
597+
Ptr{Cint}, Ptr{Cint}),
598+
sendbuf, recvbuf, &count, &mpitype(T), &op.val, &comm.val,
599+
rval, &0)
600+
Request(rval[], sendbuf), recvbuf
601+
end
602+
603+
function Iallreduce{T}(sendbuf::Array{T}, op::Op, comm::Comm)
604+
Iallreduce(sendbuf, length(sendbuf), op, comm)
605+
end
606+
607+
function Iallreduce{T}(object::T, op::Op, comm::Comm)
608+
sendbuf = T[object]
609+
req, recvbuf = Iallreduce(sendbuf, op, comm)
610+
req, recvbuf[1]
611+
end
612+
574613
function Scatter{T}(sendbuf::MPIBuffertype{T},
575614
count::Integer, root::Integer, comm::Comm)
576615
recvbuf = Array(T, count)

src/win_mpiconstants.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ const MPI_ALLGATHER = (:MPI_ALLGATHER, "msmpi.dll")
6565
const MPI_ALLGATHERV = (:MPI_ALLGATHERV, "msmpi.dll")
6666
const MPI_IALLGATHER = (:MPI_ALLGATHER, "msmpi.dll")
6767
const MPI_IALLGATHERV = (:MPI_ALLGATHERV, "msmpi.dll")
68+
const MPI_ALLREDUCE = (:MPI_ALLREDUCE, "msmpi.dll")
69+
const MPI_IALLREDUCE = (:MPI_IALLREDUCE, "msmpi.dll")
6870
const MPI_ALLTOALL = (:MPI_ALLTOALL, "msmpi.dll")
6971
const MPI_ALLTOALLV = (:MPI_ALLTOALLV, "msmpi.dll")
7072
const MPI_IALLTOALL = (:MPI_IALLTOALL, "msmpi.dll")

test/test_allreduce.jl

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
using Base.Test
2+
3+
using MPI
4+
5+
MPI.Init()
6+
7+
comm = MPI.COMM_WORLD
8+
size = MPI.Comm_size(comm)
9+
rank = MPI.Comm_rank(comm)
10+
11+
val = sum(0:size-1)
12+
@test MPI.Allreduce(rank, MPI.SUM, comm) == val
13+
14+
val = size-1
15+
@test MPI.Allreduce(rank, MPI.MAX, comm) == val
16+
17+
val = 0
18+
@test MPI.Allreduce(rank, MPI.MIN, comm) == val
19+
20+
mesg = collect(1.0:5.0)
21+
sum_mesg = MPI.Allreduce(mesg, MPI.SUM, comm)
22+
@test isapprox(norm(sum_mesg-size*mesg), 0.0)
23+
24+
mesg = collect(1.0:5.0)
25+
req, sum_mesg = MPI.Iallreduce(mesg, MPI.SUM, comm)
26+
MPI.Wait!(req)
27+
sum_mesg = sum_mesg
28+
@test isapprox(norm(sum_mesg-size*mesg), 0.0)
29+
30+
MPI.Finalize()

0 commit comments

Comments
 (0)