Skip to content

Commit

Permalink
Wrapped and tested {i}allreduce
Browse files Browse the repository at this point in the history
  • Loading branch information
kshyatt committed Apr 30, 2016
1 parent cdcc782 commit e29e0ee
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 0 deletions.
1 change: 1 addition & 0 deletions deps/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ FortranCInterface_HEADER(jlmpi_f2c.h MACRO_NAMESPACE "JLMPI_" SYMBOLS
MPI_GET_PROCESSOR_NAME
MPI_IALLGATHER
MPI_IALLGATHERV
MPI_IALLREDUCE
MPI_IALLTOALL
MPI_IALLTOALLV
MPI_IBARRIER
Expand Down
1 change: 1 addition & 0 deletions deps/gen_functions.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ int main(int argc, char *argv[]) {
STRING(MPI_GET_PROCESSOR_NAME));
printf(" :MPI_IALLGATHER => \"%s\",\n", STRING(MPI_IALLGATHER));
printf(" :MPI_IALLGATHERV => \"%s\",\n", STRING(MPI_IALLGATHERV));
printf(" :MPI_IALLREDUCE => \"%s\",\n", STRING(MPI_IALLREDUCE));
printf(" :MPI_IALLTOALL => \"%s\",\n", STRING(MPI_IALLTOALL));
printf(" :MPI_IALLTOALLV => \"%s\",\n", STRING(MPI_IALLTOALLV));
printf(" :MPI_IBARRIER => \"%s\",\n", STRING(MPI_IBARRIER));
Expand Down
39 changes: 39 additions & 0 deletions src/mpi-base.jl
Original file line number Diff line number Diff line change
Expand Up @@ -571,6 +571,45 @@ function Ireduce{T}(object::T, op::Op, root::Integer, comm::Comm)
req, isroot ? recvbuf[1] : nothing
end

function Allreduce{T}(sendbuf::MPIBuffertype{T}, count::Integer, op::Op, comm::Comm)
recvbuf = Array(T, count)
ccall(MPI_ALLREDUCE, Void,
(Ptr{T}, Ptr{T}, Ptr{Cint}, Ptr{Cint}, Ptr{Cint}, Ptr{Cint}, Ptr{Cint}),
sendbuf, recvbuf, &count, &mpitype(T), &op.val, &comm.val, &0)
recvbuf
end

function Allreduce{T}(sendbuf::Array{T}, op::Op, comm::Comm)
Allreduce(sendbuf, length(sendbuf), op, comm)
end

function Allreduce{T}(object::T, op::Op, comm::Comm)
sendbuf = T[object]
recvbuf = Allreduce(sendbuf, op, comm)
recvbuf[1]
end

function Iallreduce{T}(sendbuf::MPIBuffertype{T}, count::Integer, op::Op, comm::Comm)
rval = Ref{Cint}()
recvbuf = Array(T, count)
ccall(MPI_IALLREDUCE, Void,
(Ptr{T}, Ptr{T}, Ptr{Cint}, Ptr{Cint}, Ptr{Cint}, Ptr{Cint},
Ptr{Cint}, Ptr{Cint}),
sendbuf, recvbuf, &count, &mpitype(T), &op.val, &comm.val,
rval, &0)
Request(rval[], sendbuf), recvbuf
end

function Iallreduce{T}(sendbuf::Array{T}, op::Op, comm::Comm)
Iallreduce(sendbuf, length(sendbuf), op, comm)
end

function Iallreduce{T}(object::T, op::Op, comm::Comm)
sendbuf = T[object]
req, recvbuf = Iallreduce(sendbuf, op, comm)
req, recvbuf[1]
end

function Scatter{T}(sendbuf::MPIBuffertype{T},
count::Integer, root::Integer, comm::Comm)
recvbuf = Array(T, count)
Expand Down
2 changes: 2 additions & 0 deletions src/win_mpiconstants.jl
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ const MPI_ALLGATHER = (:MPI_ALLGATHER, "msmpi.dll")
const MPI_ALLGATHERV = (:MPI_ALLGATHERV, "msmpi.dll")
const MPI_IALLGATHER = (:MPI_ALLGATHER, "msmpi.dll")
const MPI_IALLGATHERV = (:MPI_ALLGATHERV, "msmpi.dll")
const MPI_ALLREDUCE = (:MPI_ALLREDUCE, "msmpi.dll")
const MPI_IALLREDUCE = (:MPI_IALLREDUCE, "msmpi.dll")
const MPI_ALLTOALL = (:MPI_ALLTOALL, "msmpi.dll")
const MPI_ALLTOALLV = (:MPI_ALLTOALLV, "msmpi.dll")
const MPI_IALLTOALL = (:MPI_IALLTOALL, "msmpi.dll")
Expand Down
30 changes: 30 additions & 0 deletions test/test_allreduce.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using Base.Test

using MPI

MPI.Init()

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

val = sum(0:size-1)
@test MPI.Allreduce(rank, MPI.SUM, comm) == val

val = size-1
@test MPI.Allreduce(rank, MPI.MAX, comm) == val

val = 0
@test MPI.Allreduce(rank, MPI.MIN, comm) == val

mesg = collect(1.0:5.0)
sum_mesg = MPI.Allreduce(mesg, MPI.SUM, comm)
@test isapprox(norm(sum_mesg-size*mesg), 0.0)

mesg = collect(1.0:5.0)
req, sum_mesg = MPI.Iallreduce(mesg, MPI.SUM, comm)
MPI.Wait!(req)
sum_mesg = sum_mesg
@test isapprox(norm(sum_mesg-size*mesg), 0.0)

MPI.Finalize()

0 comments on commit e29e0ee

Please sign in to comment.