Skip to content

Commit 98746f0

Browse files
committed
Merge pull request #98 from JuliaParallel/ksh/fixgather
Fix all/gather bugs and add tests
2 parents d290464 + e7f9175 commit 98746f0

File tree

3 files changed

+16
-12
lines changed

3 files changed

+16
-12
lines changed

src/mpi-base.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -444,7 +444,7 @@ function Gather{T<:MPIDatatype}(object::T, root::Integer, comm::Comm)
444444
isroot = Comm_rank(comm) == root
445445
sendbuf = T[object]
446446
recvbuf = Gather(sendbuf, root, comm)
447-
isroot ? recvbuf[1] : nothing
447+
isroot ? recvbuf : nothing
448448
end
449449

450450
function Allgather{T<:MPIDatatype}(sendbuf::Union{Ptr{T},Array{T}}, count::Integer,
@@ -463,7 +463,7 @@ end
463463
function Allgather{T<:MPIDatatype}(object::T, comm::Comm)
464464
sendbuf = T[object]
465465
recvbuf = Allgather(sendbuf, comm)
466-
recvbuf[1]
466+
recvbuf
467467
end
468468

469469
function Gatherv{T<:MPIDatatype}(sendbuf::Union{Ptr{T},Array{T}}, counts::Vector{Cint},

test/test_allgather.jl

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,19 @@ using MPI
33

44
MPI.Init()
55

6-
function allgather_array(A)
6+
function allgather(A)
77
comm = MPI.COMM_WORLD
8-
9-
B = copy(A)
10-
C = MPI.Allgather(B, comm)
8+
C = MPI.Allgather(A, comm)
119
end
1210

1311
comm = MPI.COMM_WORLD
1412

1513
for typ in MPI.MPIDatatype.types
1614
A = typ[MPI.Comm_rank(comm) + 1]
17-
C = allgather_array(A)
15+
C = allgather(A)
16+
@test C == collect(1:MPI.Comm_size(comm))
17+
A = convert(typ,MPI.Comm_rank(comm) + 1)
18+
C = allgather(A)
1819
@test C == collect(1:MPI.Comm_size(comm))
1920
end
2021

test/test_gather.jl

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,22 @@ using MPI
33

44
MPI.Init()
55

6-
function gather_array(A, root)
6+
function gather(A, root)
77
comm = MPI.COMM_WORLD
8-
9-
B = copy(A)
10-
C = MPI.Gather(B, root, comm)
8+
C = MPI.Gather(A, root, comm)
119
end
1210

1311
comm = MPI.COMM_WORLD
1412
root = 0
1513

1614
for typ in MPI.MPIDatatype.types
1715
A = typ[MPI.Comm_rank(comm) + 1]
18-
C = gather_array(A, root)
16+
C = gather(A, root)
17+
if MPI.Comm_rank(comm) == root
18+
@test C == collect(1:MPI.Comm_size(comm))
19+
end
20+
A = convert(typ,MPI.Comm_rank(comm) + 1)
21+
C = gather(A, root)
1922
if MPI.Comm_rank(comm) == root
2023
@test C == collect(1:MPI.Comm_size(comm))
2124
end

0 commit comments

Comments
 (0)