Skip to content

Commit

Permalink
Wrapped ireduce, iscan, iexscan
Browse files Browse the repository at this point in the history
  • Loading branch information
kshyatt committed May 3, 2016
1 parent 5e01ef5 commit 95cc4ca
Show file tree
Hide file tree
Showing 7 changed files with 78 additions and 0 deletions.
3 changes: 3 additions & 0 deletions deps/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,15 @@ FortranCInterface_HEADER(jlmpi_f2c.h MACRO_NAMESPACE "JLMPI_" SYMBOLS
MPI_IALLTOALLV
MPI_IBARRIER
MPI_IBCAST
MPI_IEXSCAN
MPI_IGATHER
MPI_IGATHERV
MPI_INIT
MPI_INITIALIZED
MPI_IPROBE
MPI_IRECV
MPI_IREDUCE
MPI_ISCAN
MPI_ISCATTER
MPI_ISCATTERV
MPI_ISEND
Expand Down
3 changes: 3 additions & 0 deletions deps/gen_functions.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,15 @@ int main(int argc, char *argv[]) {
printf(" :MPI_IALLTOALLV => \"%s\",\n", STRING(MPI_IALLTOALLV));
printf(" :MPI_IBARRIER => \"%s\",\n", STRING(MPI_IBARRIER));
printf(" :MPI_IBCAST => \"%s\",\n", STRING(MPI_IBCAST));
printf(" :MPI_IEXSCAN => \"%s\",\n", STRING(MPI_IEXSCAN));
printf(" :MPI_IGATHER => \"%s\",\n", STRING(MPI_IGATHER));
printf(" :MPI_IGATHERV => \"%s\",\n", STRING(MPI_IGATHERV));
printf(" :MPI_INIT => \"%s\",\n", STRING(MPI_INIT));
printf(" :MPI_INITIALIZED => \"%s\",\n", STRING(MPI_INITIALIZED));
printf(" :MPI_IPROBE => \"%s\",\n", STRING(MPI_IPROBE));
printf(" :MPI_IRECV => \"%s\",\n", STRING(MPI_IRECV));
printf(" :MPI_IREDUCE => \"%s\",\n", STRING(MPI_IREDUCE));
printf(" :MPI_ISCAN => \"%s\",\n", STRING(MPI_ISCAN));
printf(" :MPI_ISCATTER => \"%s\",\n", STRING(MPI_ISCATTER));
printf(" :MPI_ISCATTERV => \"%s\",\n", STRING(MPI_ISCATTERV));
printf(" :MPI_ISEND => \"%s\",\n", STRING(MPI_ISEND));
Expand Down
54 changes: 54 additions & 0 deletions src/mpi-base.jl
Original file line number Diff line number Diff line change
Expand Up @@ -547,6 +547,30 @@ function Reduce{T}(object::T, op::Op, root::Integer, comm::Comm)
isroot ? recvbuf[1] : nothing
end

function Ireduce{T}(sendbuf::MPIBuffertype{T}, count::Integer,
op::Op, root::Integer, comm::Comm)
rval = Ref{Cint}()
isroot = Comm_rank(comm) == root
recvbuf = Array(T, isroot ? count : 0)
ccall(MPI_IREDUCE, Void,
(Ptr{T}, Ptr{T}, Ptr{Cint}, Ptr{Cint}, Ptr{Cint}, Ptr{Cint},
Ptr{Cint}, Ptr{Cint}, Ptr{Cint}),
sendbuf, recvbuf, &count, &mpitype(T), &op.val, &root, &comm.val,
rval, &0)
Request(rval[], sendbuf), isroot ? recvbuf : nothing
end

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

function Ireduce{T}(object::T, op::Op, root::Integer, comm::Comm)
isroot = Comm_rank(comm) == root
sendbuf = T[object]
req, recvbuf = Ireduce(sendbuf, op, root, comm)
req, isroot ? recvbuf[1] : nothing
end

function Scatter{T}(sendbuf::MPIBuffertype{T},
count::Integer, root::Integer, comm::Comm)
recvbuf = Array(T, count)
Expand Down Expand Up @@ -775,6 +799,21 @@ function Scan{T}(object::T, op::Op, comm::Comm)
Scan(sendbuf,1,op,comm)
end

function Iscan{T}(sendbuf::MPIBuffertype{T}, count::Integer,
op::Op, comm::Comm)
recvbuf = Array(T, count)
rval = Ref{Cint}()
ccall(MPI_ISCAN, 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 Iscan{T}(object::T, op::Op, comm::Comm)
sendbuf = T[object]
Iscan(sendbuf,1,op,comm)
end

function ExScan{T}(sendbuf::MPIBuffertype{T}, count::Integer,
op::Op, comm::Comm)
recvbuf = Array(T, count)
Expand All @@ -789,6 +828,21 @@ function ExScan{T}(object::T, op::Op, comm::Comm)
ExScan(sendbuf,1,op,comm)
end

function IExScan{T}(sendbuf::MPIBuffertype{T}, count::Integer,
op::Op, comm::Comm)
recvbuf = Array(T, count)
rval = Ref{Cint}()
ccall(MPI_IEXSCAN, 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 IExScan{T}(object::T, op::Op, comm::Comm)
sendbuf = T[object]
IExScan(sendbuf,1,op,comm)
end

# Conversion between C and Fortran Comm handles:
if HAVE_MPI_COMM_C2F
# use MPI_Comm_f2c and MPI_Comm_c2f
Expand Down
3 changes: 3 additions & 0 deletions src/win_mpiconstants.jl
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ const MPI_FINALIZE = (:MPI_FINALIZE, "msmpi.dll")
const MPI_BCAST = (:MPI_BCAST, "msmpi.dll")
const MPI_IBCAST = (:MPI_IBCAST, "msmpi.dll")
const MPI_REDUCE = (:MPI_REDUCE, "msmpi.dll")
const MPI_IREDUCE = (:MPI_IREDUCE, "msmpi.dll")
const MPI_IRECV = (:MPI_IRECV, "msmpi.dll")
const MPI_RECV = (:MPI_RECV, "msmpi.dll")
const MPI_ISEND = (:MPI_ISEND, "msmpi.dll")
Expand All @@ -74,7 +75,9 @@ const MPI_SCATTER = (:MPI_SCATTER, "msmpi.dll")
const MPI_SCATTERV = (:MPI_SCATTERV, "msmpi.dll")
const MPI_SEND = (:MPI_SEND, "msmpi.dll")
const MPI_SCAN = (:MPI_SCAN, "msmpi.dll")
const MPI_ISCAN = (:MPI_ISCAN, "msmpi.dll")
const MPI_EXSCAN = (:MPI_EXSCAN, "msmpi.dll")
const MPI_IEXSCAN = (:MPI_IEXSCAN, "msmpi.dll")
const MPI_GATHER = (:MPI_GATHER, "msmpi.dll")
const MPI_GATHERV = (:MPI_GATHERV, "msmpi.dll")
const MPI_IGATHER = (:MPI_GATHER, "msmpi.dll")
Expand Down
5 changes: 5 additions & 0 deletions test/test_exscan.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ for typ in typs
if rank > 0
@test_approx_eq B[1] factorial(rank)
end
req, C = MPI.IExScan(val, MPI.PROD, comm)
MPI.Wait!(req)
if rank > 0
@test_approx_eq C[1] factorial(rank)
end
end

MPI.Finalize()
6 changes: 6 additions & 0 deletions test/test_reduce.jl
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,10 @@ sum_mesg = MPI.Reduce(mesg, MPI.SUM, root, comm)
sum_mesg = rank == root ? sum_mesg : size*mesg
@test isapprox(norm(sum_mesg-size*mesg), 0.0)

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

MPI.Finalize()
4 changes: 4 additions & 0 deletions test/test_scan.jl
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ for typ in typs
val = convert(typ,rank + 1)
B = MPI.Scan(val, MPI.PROD, comm)
@test_approx_eq B[1] factorial(val)
val = convert(typ,rank + 1)
req, B = MPI.Iscan(val, MPI.PROD, comm)
MPI.Wait!(req)
@test_approx_eq B[1] factorial(val)
end

MPI.Finalize()

0 comments on commit 95cc4ca

Please sign in to comment.