From 4f601734d83ba9fd437d3bb673a748ad9fc402ef Mon Sep 17 00:00:00 2001 From: Jared Crean Date: Fri, 15 Apr 2016 16:55:06 -0400 Subject: [PATCH 01/11] add allreduce, tests --- src/mpi-base.jl | 33 +++++++++++++++++++++++++++++++++ test/test_allreduce.jl | 24 ++++++++++++++++++++++++ 2 files changed, 57 insertions(+) create mode 100644 test/test_allreduce.jl diff --git a/src/mpi-base.jl b/src/mpi-base.jl index 93b4afeb3..089a8d808 100644 --- a/src/mpi-base.jl +++ b/src/mpi-base.jl @@ -525,6 +525,39 @@ function Reduce{T}(object::T, op::Op, root::Integer, comm::Comm) isroot ? recvbuf[1] : nothing end +function Allreduce{T}(sendbuf::MPIBuffertype{T}, recvbuf::MPIBuffertype{T}, + count::Integer, op::Op, comm::Comm) + + flag = zero(Cint) + ccall(MPI_ALLREDUCE, Void, (Ptr{T}, Ptr{T}, Ptr{Cint}, Ptr{Cint}, Ptr{Cint}, + Ptr{Cint}, Ptr{Cint}), sendbuf, recvbuf, &Int32(count), &mpitype(T), &op.val, &comm.val, &flag) + + if flag != 0 + println(STDERR, "Warning: MPI_Allreduce exited with status ", flag) + end + + recvbuf +end + +function Allreduce{T}(sendbuf::MPIBuffertype{T}, recvbuf::MPIBuffertype{T}, + op::Op, comm::Comm) + + Allreduce(sendbuf, recvbuf, length(sendbuf), op, comm) +end + + +function Allreduce{T}(obj::T, op::Op, comm::Comm) + + objref = Ref(obj) + outref = Ref{T}() + Allreduce(objref, outref, 1, op, comm) + + return outref[] +end + +# how to handle allocating the recvbuf, in-place operation? + + function Scatter{T}(sendbuf::MPIBuffertype{T}, count::Integer, root::Integer, comm::Comm) recvbuf = Array(T, count) diff --git a/test/test_allreduce.jl b/test/test_allreduce.jl new file mode 100644 index 000000000..f53901877 --- /dev/null +++ b/test/test_allreduce.jl @@ -0,0 +1,24 @@ +using Base.Test +using MPI + +MPI.Init() + +#MPI.mpitype_dict[Boundary] = MPI.mpitype_dict[Int] +comm_size = MPI.Comm_size(MPI.COMM_WORLD) +comm_rank = MPI.Comm_rank(MPI.COMM_WORLD) + 1 + +send_arr = Int[1, 2, 3] +recv_arr = zeros(Int, 3) + +MPI.Allreduce(send_arr, recv_arr, MPI.SUM, MPI.COMM_WORLD) + +for i=1:3 + @test recv_arr[i] == comm_size*send_arr[i] +end + + +val = MPI.Allreduce(2, MPI.SUM, MPI.COMM_WORLD) +@test val == comm_size*2 + +MPI.Barrier( MPI.COMM_WORLD ) +MPI.Finalize() From 2179a268175c2bddb3c6c2444b3dc36526ffdfd9 Mon Sep 17 00:00:00 2001 From: Jared Crean Date: Fri, 15 Apr 2016 16:59:59 -0400 Subject: [PATCH 02/11] update whitespace, formatting --- src/mpi-base.jl | 27 ++++++++++++--------------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/src/mpi-base.jl b/src/mpi-base.jl index 089a8d808..0b23a0b02 100644 --- a/src/mpi-base.jl +++ b/src/mpi-base.jl @@ -527,37 +527,34 @@ end function Allreduce{T}(sendbuf::MPIBuffertype{T}, recvbuf::MPIBuffertype{T}, count::Integer, op::Op, comm::Comm) + flag = zero(Cint) + ccall(MPI_ALLREDUCE, Void, (Ptr{T}, Ptr{T}, Ptr{Cint}, Ptr{Cint}, Ptr{Cint}, + Ptr{Cint}, Ptr{Cint}), sendbuf, recvbuf, &Int32(count), &mpitype(T), + &op.val, &comm.val, &flag) - flag = zero(Cint) - ccall(MPI_ALLREDUCE, Void, (Ptr{T}, Ptr{T}, Ptr{Cint}, Ptr{Cint}, Ptr{Cint}, - Ptr{Cint}, Ptr{Cint}), sendbuf, recvbuf, &Int32(count), &mpitype(T), &op.val, &comm.val, &flag) - - if flag != 0 - println(STDERR, "Warning: MPI_Allreduce exited with status ", flag) - end + if flag != 0 + println(STDERR, "Warning: MPI_Allreduce exited with status ", flag) + end - recvbuf + recvbuf end function Allreduce{T}(sendbuf::MPIBuffertype{T}, recvbuf::MPIBuffertype{T}, op::Op, comm::Comm) - Allreduce(sendbuf, recvbuf, length(sendbuf), op, comm) end function Allreduce{T}(obj::T, op::Op, comm::Comm) + objref = Ref(obj) + outref = Ref{T}() + Allreduce(objref, outref, 1, op, comm) - objref = Ref(obj) - outref = Ref{T}() - Allreduce(objref, outref, 1, op, comm) - - return outref[] + outref[] end # how to handle allocating the recvbuf, in-place operation? - function Scatter{T}(sendbuf::MPIBuffertype{T}, count::Integer, root::Integer, comm::Comm) recvbuf = Array(T, count) From 944dd1fa21aecfd6b129f48943e896c14388ac8e Mon Sep 17 00:00:00 2001 From: Jared Crean Date: Sat, 16 Apr 2016 13:24:10 -0400 Subject: [PATCH 03/11] add new method --- deps/gen_constants.f90 | 1 + src/mpi-base.jl | 32 +++++++++++++++++++++++++++++--- test/test_allreduce.jl | 18 ++++++++++++++++++ 3 files changed, 48 insertions(+), 3 deletions(-) diff --git a/deps/gen_constants.f90 b/deps/gen_constants.f90 index b90e9f071..abdb23df6 100644 --- a/deps/gen_constants.f90 +++ b/deps/gen_constants.f90 @@ -54,6 +54,7 @@ program gen_constants call output("MPI_ANY_TAG ", MPI_ANY_TAG) call output("MPI_TAG_UB ", MPI_TAG_UB) call output("MPI_UNDEFINED ", MPI_UNDEFINED) + call output("MPI_IN_PLACE ", MPI_IN_PLACE) contains diff --git a/src/mpi-base.jl b/src/mpi-base.jl index 0b23a0b02..4f44a503c 100644 --- a/src/mpi-base.jl +++ b/src/mpi-base.jl @@ -525,7 +525,8 @@ function Reduce{T}(object::T, op::Op, root::Integer, comm::Comm) isroot ? recvbuf[1] : nothing end -function Allreduce{T}(sendbuf::MPIBuffertype{T}, recvbuf::MPIBuffertype{T}, +# T and T2 are different for MPI_IN_PLACE as the sendbuf +function Allreduce{T}(sendbuf::MPIBuffertype{T}, recvbuf::MPIBuffertype{T}, count::Integer, op::Op, comm::Comm) flag = zero(Cint) ccall(MPI_ALLREDUCE, Void, (Ptr{T}, Ptr{T}, Ptr{Cint}, Ptr{Cint}, Ptr{Cint}, @@ -541,10 +542,9 @@ end function Allreduce{T}(sendbuf::MPIBuffertype{T}, recvbuf::MPIBuffertype{T}, op::Op, comm::Comm) - Allreduce(sendbuf, recvbuf, length(sendbuf), op, comm) + Allreduce(sendbuf, recvbuf, length(recvbuf), op, comm) end - function Allreduce{T}(obj::T, op::Op, comm::Comm) objref = Ref(obj) outref = Ref{T}() @@ -553,6 +553,32 @@ function Allreduce{T}(obj::T, op::Op, comm::Comm) outref[] end +#= +# in-place version +function Allreduce{T}(recvbuf::MPIBuffertype{T}, op::Op, comm::Comm) + +# Allreduce(sendbuf, recvbuf, length(recvbuf), op, comm) + flag = zero(Cint) + ccall(MPI_ALLREDUCE, Void, (Ptr{Cint}, Ptr{Void}, Ptr{Cint}, Ptr{Cint}, + Ptr{Cint}, Ptr{Cint}, Ptr{Cint}), &MPI_IN_PLACE, recvbuf, + &Int32(length(recvbuf)), &mpitype(T), &op.val, &comm.val, &flag) + + if flag != 0 + println(STDERR, "Warning: MPI_Allreduce exited with status ", flag) + end + + recvbuf +end +=# + +# allocate receive buffer automatically +function allreduce{T}(sendbuf::MPIBuffertype{T}, op::Op, comm::Comm) + + len = length(sendbuf) + recvbuf = Array(T, len) + Allreduce(sendbuf, recvbuf, len, op, comm) +end + # how to handle allocating the recvbuf, in-place operation? function Scatter{T}(sendbuf::MPIBuffertype{T}, diff --git a/test/test_allreduce.jl b/test/test_allreduce.jl index f53901877..bde027113 100644 --- a/test/test_allreduce.jl +++ b/test/test_allreduce.jl @@ -20,5 +20,23 @@ end val = MPI.Allreduce(2, MPI.SUM, MPI.COMM_WORLD) @test val == comm_size*2 +vals = MPI.allreduce(send_arr, MPI.SUM, MPI.COMM_WORLD) +for i=1:3 + @test vals[i] == comm_size*send_arr[i] +end + +#= +# test in-place operation +send_arr2 = Int32[1,2,3] +send_arr3 = copy(send_arr2) +MPI.Allreduce(send_arr3, MPI.SUM, MPI.COMM_WORLD) +println("send_arr2 = ", send_arr2) +println("send_arr3 = ", send_arr3) +for i=1:3 + @test send_arr3[i] == comm_size*send_arr2[i] +end +=# + + MPI.Barrier( MPI.COMM_WORLD ) MPI.Finalize() From a38a191afa1d041ceabdf72af65780b9784fb8bf Mon Sep 17 00:00:00 2001 From: Jared Crean Date: Mon, 18 Apr 2016 14:09:43 -0400 Subject: [PATCH 04/11] misc updates --- src/mpi-base.jl | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/mpi-base.jl b/src/mpi-base.jl index 4f44a503c..753c73550 100644 --- a/src/mpi-base.jl +++ b/src/mpi-base.jl @@ -528,13 +528,13 @@ end # T and T2 are different for MPI_IN_PLACE as the sendbuf function Allreduce{T}(sendbuf::MPIBuffertype{T}, recvbuf::MPIBuffertype{T}, count::Integer, op::Op, comm::Comm) - flag = zero(Cint) + flag = Ref{Cint}() ccall(MPI_ALLREDUCE, Void, (Ptr{T}, Ptr{T}, Ptr{Cint}, Ptr{Cint}, Ptr{Cint}, Ptr{Cint}, Ptr{Cint}), sendbuf, recvbuf, &Int32(count), &mpitype(T), - &op.val, &comm.val, &flag) + &op.val, &comm.val, flag) - if flag != 0 - println(STDERR, "Warning: MPI_Allreduce exited with status ", flag) + if flag[] != 0 + throw(ErrorException("Allreduce returned non-zero exit status")) end recvbuf @@ -555,7 +555,7 @@ end #= # in-place version -function Allreduce{T}(recvbuf::MPIBuffertype{T}, op::Op, comm::Comm) +function Allreduce!{T}(recvbuf::MPIBuffertype{T}, op::Op, comm::Comm) # Allreduce(sendbuf, recvbuf, length(recvbuf), op, comm) flag = zero(Cint) From d84d4c5bf4fcd52a86fbba5dc9f52a236a66954d Mon Sep 17 00:00:00 2001 From: Jared Crean Date: Sun, 1 May 2016 16:59:37 -0400 Subject: [PATCH 05/11] attempt at in-place allreduce --- deps/gen_constants.f90 | 9 ++++++++- src/mpi-base.jl | 8 +++----- test/test_allreduce.jl | 3 +-- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/deps/gen_constants.f90 b/deps/gen_constants.f90 index abdb23df6..4c13d7099 100644 --- a/deps/gen_constants.f90 +++ b/deps/gen_constants.f90 @@ -54,7 +54,7 @@ program gen_constants call output("MPI_ANY_TAG ", MPI_ANY_TAG) call output("MPI_TAG_UB ", MPI_TAG_UB) call output("MPI_UNDEFINED ", MPI_UNDEFINED) - call output("MPI_IN_PLACE ", MPI_IN_PLACE) + call outputl("MPI_IN_PLACE ", loc(MPI_IN_PLACE)) contains @@ -64,4 +64,11 @@ subroutine output(name, value) print '("const ",a," = Cint(",i0,")")', name, value end subroutine output + subroutine outputl(name, value) + character*(*) name + INTEGER(8) value + print '("const ",a," = Int64(",i0,")")', name, value + end subroutine outputl + + end program gen_constants diff --git a/src/mpi-base.jl b/src/mpi-base.jl index f28347dac..148290e74 100644 --- a/src/mpi-base.jl +++ b/src/mpi-base.jl @@ -530,7 +530,7 @@ function Allreduce{T}(sendbuf::MPIBuffertype{T}, recvbuf::MPIBuffertype{T}, count::Integer, op::Op, comm::Comm) flag = zero(Cint) ccall(MPI_ALLREDUCE, Void, (Ptr{T}, Ptr{T}, Ptr{Cint}, Ptr{Cint}, Ptr{Cint}, - Ptr{Cint}, Ptr{Cint}), sendbuf, recvbuf, &Int32(count), &mpitype(T), + Ptr{Cint}, Ptr{Cint}), sendbuf, recvbuf, &count, &mpitype(T), &op.val, &comm.val, &flag) if flag != 0 @@ -553,14 +553,13 @@ function Allreduce{T}(obj::T, op::Op, comm::Comm) outref[] end -#= # in-place version function Allreduce{T}(recvbuf::MPIBuffertype{T}, op::Op, comm::Comm) # Allreduce(sendbuf, recvbuf, length(recvbuf), op, comm) flag = zero(Cint) - ccall(MPI_ALLREDUCE, Void, (Ptr{Cint}, Ptr{Void}, Ptr{Cint}, Ptr{Cint}, - Ptr{Cint}, Ptr{Cint}, Ptr{Cint}), &MPI_IN_PLACE, recvbuf, + ccall(MPI_ALLREDUCE, Void, (Ptr{Void}, Ptr{T}, Ptr{Cint}, Ptr{Cint}, + Ptr{Cint}, Ptr{Cint}, Ptr{Cint}), MPI_IN_PLACE, recvbuf, &Int32(length(recvbuf)), &mpitype(T), &op.val, &comm.val, &flag) if flag != 0 @@ -569,7 +568,6 @@ function Allreduce{T}(recvbuf::MPIBuffertype{T}, op::Op, comm::Comm) recvbuf end -=# # allocate receive buffer automatically function allreduce{T}(sendbuf::MPIBuffertype{T}, op::Op, comm::Comm) diff --git a/test/test_allreduce.jl b/test/test_allreduce.jl index bde027113..0d67f344f 100644 --- a/test/test_allreduce.jl +++ b/test/test_allreduce.jl @@ -25,7 +25,6 @@ for i=1:3 @test vals[i] == comm_size*send_arr[i] end -#= # test in-place operation send_arr2 = Int32[1,2,3] send_arr3 = copy(send_arr2) @@ -35,7 +34,7 @@ println("send_arr3 = ", send_arr3) for i=1:3 @test send_arr3[i] == comm_size*send_arr2[i] end -=# + MPI.Barrier( MPI.COMM_WORLD ) From f720117c03759ae9ad5113ff1830f068d8f50917 Mon Sep 17 00:00:00 2001 From: Jared Crean Date: Sun, 1 May 2016 17:11:53 -0400 Subject: [PATCH 06/11] address another comment --- src/mpi-base.jl | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/mpi-base.jl b/src/mpi-base.jl index f4930562c..aed1c0447 100644 --- a/src/mpi-base.jl +++ b/src/mpi-base.jl @@ -525,7 +525,6 @@ function Reduce{T}(object::T, op::Op, root::Integer, comm::Comm) isroot ? recvbuf[1] : nothing end -# T and T2 are different for MPI_IN_PLACE as the sendbuf function Allreduce{T}(sendbuf::MPIBuffertype{T}, recvbuf::MPIBuffertype{T}, count::Integer, op::Op, comm::Comm) flag = Ref{Cint}() @@ -572,8 +571,7 @@ end # allocate receive buffer automatically function allreduce{T}(sendbuf::MPIBuffertype{T}, op::Op, comm::Comm) - len = length(sendbuf) - recvbuf = Array(T, len) + recvbuf = similar(sendbuf) Allreduce(sendbuf, recvbuf, len, op, comm) end From b87153b3a9b3377ada7612e8953dd1501a597fa8 Mon Sep 17 00:00:00 2001 From: Jared Crean Date: Sun, 1 May 2016 17:22:15 -0400 Subject: [PATCH 07/11] another in-place attempt --- src/mpi-base.jl | 7 +++---- test/test_allreduce.jl | 4 +++- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/mpi-base.jl b/src/mpi-base.jl index aed1c0447..96e918fc6 100644 --- a/src/mpi-base.jl +++ b/src/mpi-base.jl @@ -557,8 +557,8 @@ function Allreduce!{T}(recvbuf::MPIBuffertype{T}, op::Op, comm::Comm) # Allreduce(sendbuf, recvbuf, length(recvbuf), op, comm) flag = zero(Cint) - ccall(MPI_ALLREDUCE, Void, (Ptr{Void}, Ptr{T}, Ptr{Cint}, Ptr{Cint}, - Ptr{Cint}, Ptr{Cint}, Ptr{Cint}), MPI_IN_PLACE, recvbuf, + ccall(MPI_ALLREDUCE, Void, (Ptr{Ptr{Void}}, Ptr{T}, Ptr{Cint}, Ptr{Cint}, + Ptr{Cint}, Ptr{Cint}, Ptr{Cint}), &MPI_IN_PLACE, recvbuf, &Int32(length(recvbuf)), &mpitype(T), &op.val, &comm.val, &flag) if flag != 0 @@ -572,10 +572,9 @@ end function allreduce{T}(sendbuf::MPIBuffertype{T}, op::Op, comm::Comm) recvbuf = similar(sendbuf) - Allreduce(sendbuf, recvbuf, len, op, comm) + Allreduce(sendbuf, recvbuf, length(recvbuf), op, comm) end -# how to handle allocating the recvbuf, in-place operation? function Scatter{T}(sendbuf::MPIBuffertype{T},count::Integer, root::Integer, comm::Comm) diff --git a/test/test_allreduce.jl b/test/test_allreduce.jl index bde027113..dbc0fc61a 100644 --- a/test/test_allreduce.jl +++ b/test/test_allreduce.jl @@ -29,7 +29,9 @@ end # test in-place operation send_arr2 = Int32[1,2,3] send_arr3 = copy(send_arr2) -MPI.Allreduce(send_arr3, MPI.SUM, MPI.COMM_WORLD) +MPI.Allreduce!(send_arr3, MPI.SUM,MPI.COMM_WORLD) +sleep(5*comm_rank) +println("process ", comm_rank, "proceeding") println("send_arr2 = ", send_arr2) println("send_arr3 = ", send_arr3) for i=1:3 From 52af66f65bca4abe8ae750c70bb4471c43737183 Mon Sep 17 00:00:00 2001 From: Jared Crean Date: Wed, 1 Jun 2016 18:40:06 -0400 Subject: [PATCH 08/11] remove MPI_IN_PLACE --- deps/gen_constants.f90 | 8 -------- src/mpi-base.jl | 16 ---------------- test/test_allreduce.jl | 15 --------------- 3 files changed, 39 deletions(-) diff --git a/deps/gen_constants.f90 b/deps/gen_constants.f90 index 4c13d7099..b90e9f071 100644 --- a/deps/gen_constants.f90 +++ b/deps/gen_constants.f90 @@ -54,7 +54,6 @@ program gen_constants call output("MPI_ANY_TAG ", MPI_ANY_TAG) call output("MPI_TAG_UB ", MPI_TAG_UB) call output("MPI_UNDEFINED ", MPI_UNDEFINED) - call outputl("MPI_IN_PLACE ", loc(MPI_IN_PLACE)) contains @@ -64,11 +63,4 @@ subroutine output(name, value) print '("const ",a," = Cint(",i0,")")', name, value end subroutine output - subroutine outputl(name, value) - character*(*) name - INTEGER(8) value - print '("const ",a," = Int64(",i0,")")', name, value - end subroutine outputl - - end program gen_constants diff --git a/src/mpi-base.jl b/src/mpi-base.jl index d987a3f8d..de9ce762f 100644 --- a/src/mpi-base.jl +++ b/src/mpi-base.jl @@ -556,22 +556,6 @@ function Allreduce{T}(obj::T, op::Op, comm::Comm) outref[] end -# in-place version -function Allreduce!{T}(recvbuf::MPIBuffertype{T}, op::Op, comm::Comm) - -# Allreduce(sendbuf, recvbuf, length(recvbuf), op, comm) - flag = zero(Cint) - ccall(MPI_ALLREDUCE, Void, (Ptr{Ptr{Void}}, Ptr{T}, Ptr{Cint}, Ptr{Cint}, - Ptr{Cint}, Ptr{Cint}, Ptr{Cint}), &MPI_IN_PLACE, recvbuf, - &Int32(length(recvbuf)), &mpitype(T), &op.val, &comm.val, &flag) - - if flag != 0 - println(STDERR, "Warning: MPI_Allreduce exited with status ", flag) - end - - recvbuf -end - # allocate receive buffer automatically function allreduce{T}(sendbuf::MPIBuffertype{T}, op::Op, comm::Comm) diff --git a/test/test_allreduce.jl b/test/test_allreduce.jl index dbc0fc61a..d2a7d9bad 100644 --- a/test/test_allreduce.jl +++ b/test/test_allreduce.jl @@ -25,20 +25,5 @@ for i=1:3 @test vals[i] == comm_size*send_arr[i] end -#= -# test in-place operation -send_arr2 = Int32[1,2,3] -send_arr3 = copy(send_arr2) -MPI.Allreduce!(send_arr3, MPI.SUM,MPI.COMM_WORLD) -sleep(5*comm_rank) -println("process ", comm_rank, "proceeding") -println("send_arr2 = ", send_arr2) -println("send_arr3 = ", send_arr3) -for i=1:3 - @test send_arr3[i] == comm_size*send_arr2[i] -end -=# - - MPI.Barrier( MPI.COMM_WORLD ) MPI.Finalize() From 0435deb19c5465a30c3a6ac88426281c0c5af6ae Mon Sep 17 00:00:00 2001 From: Jared Crean Date: Wed, 1 Jun 2016 19:16:21 -0400 Subject: [PATCH 09/11] address comments --- src/mpi-base.jl | 14 +++++--------- test/test_allreduce.jl | 6 +++--- 2 files changed, 8 insertions(+), 12 deletions(-) diff --git a/src/mpi-base.jl b/src/mpi-base.jl index de9ce762f..659494127 100644 --- a/src/mpi-base.jl +++ b/src/mpi-base.jl @@ -529,29 +529,25 @@ function Reduce{T}(object::T, op::Op, root::Integer, comm::Comm) isroot ? recvbuf[1] : nothing end -function Allreduce{T}(sendbuf::MPIBuffertype{T}, recvbuf::MPIBuffertype{T}, +function Allreduce!{T}(sendbuf::MPIBuffertype{T}, recvbuf::MPIBuffertype{T}, count::Integer, op::Op, comm::Comm) flag = Ref{Cint}() 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, flag) - if flag[] != 0 - throw(ErrorException("Allreduce returned non-zero exit status")) - end - recvbuf end -function Allreduce{T}(sendbuf::MPIBuffertype{T}, recvbuf::MPIBuffertype{T}, +function Allreduce!{T}(sendbuf::MPIBuffertype{T}, recvbuf::MPIBuffertype{T}, op::Op, comm::Comm) - Allreduce(sendbuf, recvbuf, length(recvbuf), op, comm) + Allreduce!(sendbuf, recvbuf, length(recvbuf), op, comm) end function Allreduce{T}(obj::T, op::Op, comm::Comm) objref = Ref(obj) outref = Ref{T}() - Allreduce(objref, outref, 1, op, comm) + Allreduce!(objref, outref, 1, op, comm) outref[] end @@ -560,7 +556,7 @@ end function allreduce{T}(sendbuf::MPIBuffertype{T}, op::Op, comm::Comm) recvbuf = similar(sendbuf) - Allreduce(sendbuf, recvbuf, length(recvbuf), op, comm) + Allreduce!(sendbuf, recvbuf, length(recvbuf), op, comm) end diff --git a/test/test_allreduce.jl b/test/test_allreduce.jl index d2a7d9bad..675efb4c4 100644 --- a/test/test_allreduce.jl +++ b/test/test_allreduce.jl @@ -3,14 +3,12 @@ using MPI MPI.Init() -#MPI.mpitype_dict[Boundary] = MPI.mpitype_dict[Int] comm_size = MPI.Comm_size(MPI.COMM_WORLD) -comm_rank = MPI.Comm_rank(MPI.COMM_WORLD) + 1 send_arr = Int[1, 2, 3] recv_arr = zeros(Int, 3) -MPI.Allreduce(send_arr, recv_arr, MPI.SUM, MPI.COMM_WORLD) +MPI.Allreduce!(send_arr, recv_arr, MPI.SUM, MPI.COMM_WORLD) for i=1:3 @test recv_arr[i] == comm_size*send_arr[i] @@ -23,6 +21,8 @@ val = MPI.Allreduce(2, MPI.SUM, MPI.COMM_WORLD) vals = MPI.allreduce(send_arr, MPI.SUM, MPI.COMM_WORLD) for i=1:3 @test vals[i] == comm_size*send_arr[i] + @test length(vals) == 3 + @test eltype(vals) == Int64 end MPI.Barrier( MPI.COMM_WORLD ) From aec957745fd655a2b76e75acb38594bd2f7eb46b Mon Sep 17 00:00:00 2001 From: Jared Crean Date: Thu, 2 Jun 2016 20:09:00 -0400 Subject: [PATCH 10/11] add ALLREDUCE constant to windows --- src/win_mpiconstants.jl | 1 + 1 file changed, 1 insertion(+) diff --git a/src/win_mpiconstants.jl b/src/win_mpiconstants.jl index 9daecd3bd..f5023c7f3 100644 --- a/src/win_mpiconstants.jl +++ b/src/win_mpiconstants.jl @@ -86,5 +86,6 @@ const MPI_WAIT = (:MPI_WAIT, "msmpi.dll") const MPI_WAITSOME = (:MPI_WAITSOME, "msmpi.dll") const MPI_WAITANY = (:MPI_WAITANY, "msmpi.dll") const MPI_CANCEL = (:MPI_CANCEL, "msmpi.dll") +const MPI_ALLREDUCE = (:MPI_ALLREDUCE, "msmpi.dll") bitstype 32 CComm From e238578e7b6dd59d1ecf858c73c890be4bc089ff Mon Sep 17 00:00:00 2001 From: Jared Crean Date: Fri, 3 Jun 2016 10:28:19 -0400 Subject: [PATCH 11/11] Int64 -> Int --- test/test_allreduce.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/test_allreduce.jl b/test/test_allreduce.jl index 675efb4c4..442568d4f 100644 --- a/test/test_allreduce.jl +++ b/test/test_allreduce.jl @@ -22,7 +22,7 @@ vals = MPI.allreduce(send_arr, MPI.SUM, MPI.COMM_WORLD) for i=1:3 @test vals[i] == comm_size*send_arr[i] @test length(vals) == 3 - @test eltype(vals) == Int64 + @test eltype(vals) == Int end MPI.Barrier( MPI.COMM_WORLD )