Skip to content

Commit cc4f368

Browse files
committed
Wrapped i{all}gather{v}
1 parent 1bc31df commit cc4f368

File tree

8 files changed

+131
-0
lines changed

8 files changed

+131
-0
lines changed

deps/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,14 @@ FortranCInterface_HEADER(jlmpi_f2c.h MACRO_NAMESPACE "JLMPI_" SYMBOLS
4949
MPI_GATHERV
5050
MPI_GET_COUNT
5151
MPI_GET_PROCESSOR_NAME
52+
MPI_IALLGATHER
53+
MPI_IALLGATHERV
5254
MPI_IALLTOALL
5355
MPI_IALLTOALLV
5456
MPI_IBARRIER
5557
MPI_IBCAST
58+
MPI_IGATHER
59+
MPI_IGATHERV
5660
MPI_INIT
5761
MPI_INITIALIZED
5862
MPI_IPROBE

deps/gen_functions.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,14 @@ int main(int argc, char *argv[]) {
3737
printf(" :MPI_GET_COUNT => \"%s\",\n", STRING(MPI_GET_COUNT));
3838
printf(" :MPI_GET_PROCESSOR_NAME => \"%s\",\n",
3939
STRING(MPI_GET_PROCESSOR_NAME));
40+
printf(" :MPI_IALLGATHER => \"%s\",\n", STRING(MPI_IALLGATHER));
41+
printf(" :MPI_IALLGATHERV => \"%s\",\n", STRING(MPI_IALLGATHERV));
4042
printf(" :MPI_IALLTOALL => \"%s\",\n", STRING(MPI_IALLTOALL));
4143
printf(" :MPI_IALLTOALLV => \"%s\",\n", STRING(MPI_IALLTOALLV));
4244
printf(" :MPI_IBARRIER => \"%s\",\n", STRING(MPI_IBARRIER));
4345
printf(" :MPI_IBCAST => \"%s\",\n", STRING(MPI_IBCAST));
46+
printf(" :MPI_IGATHER => \"%s\",\n", STRING(MPI_IGATHER));
47+
printf(" :MPI_IGATHERV => \"%s\",\n", STRING(MPI_IGATHERV));
4448
printf(" :MPI_INIT => \"%s\",\n", STRING(MPI_INIT));
4549
printf(" :MPI_INITIALIZED => \"%s\",\n", STRING(MPI_INITIALIZED));
4650
printf(" :MPI_IPROBE => \"%s\",\n", STRING(MPI_IPROBE));

src/mpi-base.jl

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -589,6 +589,27 @@ function Gather{T}(object::T, root::Integer, comm::Comm)
589589
isroot ? recvbuf : nothing
590590
end
591591

592+
function Igather{T}(sendbuf::MPIBuffertype{T}, count::Integer,
593+
root::Integer, comm::Comm)
594+
isroot = Comm_rank(comm) == root
595+
recvbuf = Array(T, isroot ? Comm_size(comm) * count : 0)
596+
rval = Ref{Cint}()
597+
ccall(MPI_IGATHER, Void,
598+
(Ptr{T}, Ptr{Cint}, Ptr{Cint}, Ptr{T}, Ptr{Cint}, Ptr{Cint}, Ptr{Cint}, Ptr{Cint}, Ptr{Cint}, Ptr{Cint}),
599+
sendbuf, &count, &mpitype(T), recvbuf, &count, &mpitype(T), &root, &comm.val, rval, &0)
600+
Request(rval[], sendbuf), isroot ? recvbuf : nothing
601+
end
602+
603+
function Igather{T}(sendbuf::Array{T}, root::Integer, comm::Comm)
604+
Igather(sendbuf, length(sendbuf), root, comm)
605+
end
606+
607+
function Igather{T}(object::T, root::Integer, comm::Comm)
608+
isroot = Comm_rank(comm) == root
609+
sendbuf = T[object]
610+
Igather(sendbuf, root, comm)
611+
end
612+
592613
function Allgather{T}(sendbuf::MPIBuffertype{T}, count::Integer,
593614
comm::Comm)
594615
recvbuf = Array(T, Comm_size(comm) * count)
@@ -608,6 +629,25 @@ function Allgather{T}(object::T, comm::Comm)
608629
recvbuf
609630
end
610631

632+
function Iallgather{T}(sendbuf::MPIBuffertype{T}, count::Integer,
633+
comm::Comm)
634+
rval = Ref{Cint}()
635+
recvbuf = Array(T, Comm_size(comm) * count)
636+
ccall(MPI_IALLGATHER, Void,
637+
(Ptr{T}, Ptr{Cint}, Ptr{Cint}, Ptr{T}, Ptr{Cint}, Ptr{Cint}, Ptr{Cint}, Ptr{Cint}, Ptr{Cint}),
638+
sendbuf, &count, &mpitype(T), recvbuf, &count, &mpitype(T), &comm.val, rval, &0)
639+
Request(rval[], sendbuf), recvbuf
640+
end
641+
642+
function Iallgather{T}(sendbuf::Array{T}, comm::Comm)
643+
Iallgather(sendbuf, length(sendbuf), comm)
644+
end
645+
646+
function Iallgather{T}(object::T, comm::Comm)
647+
sendbuf = T[object]
648+
Iallgather(sendbuf, comm)
649+
end
650+
611651
function Gatherv{T}(sendbuf::MPIBuffertype{T}, counts::Vector{Cint},
612652
root::Integer, comm::Comm)
613653
isroot = Comm_rank(comm) == root
@@ -620,6 +660,19 @@ function Gatherv{T}(sendbuf::MPIBuffertype{T}, counts::Vector{Cint},
620660
isroot ? recvbuf : nothing
621661
end
622662

663+
function Igatherv{T}(sendbuf::MPIBuffertype{T}, counts::Vector{Cint},
664+
root::Integer, comm::Comm)
665+
isroot = Comm_rank(comm) == root
666+
rval = Ref{Cint}()
667+
displs = cumsum(counts) - counts
668+
sendcnt = counts[Comm_rank(comm) + 1]
669+
recvbuf = Array(T, isroot ? sum(counts) : 0)
670+
ccall(MPI_IGATHERV, Void,
671+
(Ptr{T}, Ptr{Cint}, Ptr{Cint}, Ptr{T}, Ptr{Cint}, Ptr{Cint}, Ptr{Cint}, Ptr{Cint}, Ptr{Cint}, Ptr{Cint}, Ptr{Cint}),
672+
sendbuf, &sendcnt, &mpitype(T), recvbuf, counts, displs, &mpitype(T), &root, &comm.val, rval, &0)
673+
Request(rval[], sendbuf), isroot ? recvbuf : nothing
674+
end
675+
623676
function Allgatherv{T}(sendbuf::MPIBuffertype{T}, counts::Vector{Cint},
624677
comm::Comm)
625678
displs = cumsum(counts) - counts
@@ -631,6 +684,18 @@ function Allgatherv{T}(sendbuf::MPIBuffertype{T}, counts::Vector{Cint},
631684
recvbuf
632685
end
633686

687+
function Iallgatherv{T}(sendbuf::MPIBuffertype{T}, counts::Vector{Cint},
688+
comm::Comm)
689+
rval = Ref{Cint}()
690+
displs = cumsum(counts) - counts
691+
sendcnt = counts[Comm_rank(comm) + 1]
692+
recvbuf = Array(T, sum(counts))
693+
ccall(MPI_IALLGATHERV, Void,
694+
(Ptr{T}, Ptr{Cint}, Ptr{Cint}, Ptr{T}, Ptr{Cint}, Ptr{Cint}, Ptr{Cint}, Ptr{Cint}, Ptr{Cint}, Ptr{Cint}),
695+
sendbuf, &sendcnt, &mpitype(T), recvbuf, counts, displs, &mpitype(T), &comm.val, rval, &0)
696+
Request(rval[], sendbuf), recvbuf
697+
end
698+
634699
function Alltoall{T}(sendbuf::MPIBuffertype{T}, count::Integer,
635700
comm::Comm)
636701
recvbuf = Array(T, Comm_size(comm)*count)

src/win_mpiconstants.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ const MPI_ISEND = (:MPI_ISEND, "msmpi.dll")
6262
const MPI_WAITALL = (:MPI_WAITALL, "msmpi.dll")
6363
const MPI_ALLGATHER = (:MPI_ALLGATHER, "msmpi.dll")
6464
const MPI_ALLGATHERV = (:MPI_ALLGATHERV, "msmpi.dll")
65+
const MPI_IALLGATHER = (:MPI_ALLGATHER, "msmpi.dll")
66+
const MPI_IALLGATHERV = (:MPI_ALLGATHERV, "msmpi.dll")
6567
const MPI_ALLTOALL = (:MPI_ALLTOALL, "msmpi.dll")
6668
const MPI_ALLTOALLV = (:MPI_ALLTOALLV, "msmpi.dll")
6769
const MPI_IALLTOALL = (:MPI_IALLTOALL, "msmpi.dll")
@@ -75,6 +77,8 @@ const MPI_SCAN = (:MPI_SCAN, "msmpi.dll")
7577
const MPI_EXSCAN = (:MPI_EXSCAN, "msmpi.dll")
7678
const MPI_GATHER = (:MPI_GATHER, "msmpi.dll")
7779
const MPI_GATHERV = (:MPI_GATHERV, "msmpi.dll")
80+
const MPI_IGATHER = (:MPI_GATHER, "msmpi.dll")
81+
const MPI_IGATHERV = (:MPI_GATHERV, "msmpi.dll")
7882
const MPI_COMM_DUP = (:MPI_COMM_DUP, "msmpi.dll")
7983
const MPI_IPROBE = (:MPI_IPROBE, "msmpi.dll")
8084
const MPI_PROBE = (:MPI_PROBE, "msmpi.dll")

test/test_allgather.jl

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,13 @@ function allgather(A)
88
C = MPI.Allgather(A, comm)
99
end
1010

11+
function iallgather(A)
12+
comm = MPI.COMM_WORLD
13+
req, C = MPI.Iallgather(A, comm)
14+
MPI.Wait!(req)
15+
C
16+
end
17+
1118
comm = MPI.COMM_WORLD
1219

1320
for typ in MPI.MPIDatatype.types
@@ -17,6 +24,12 @@ for typ in MPI.MPIDatatype.types
1724
A = convert(typ,MPI.Comm_rank(comm) + 1)
1825
C = allgather(A)
1926
@test C == collect(1:MPI.Comm_size(comm))
27+
A = typ[MPI.Comm_rank(comm) + 1]
28+
C = iallgather(A)
29+
@test C == collect(1:MPI.Comm_size(comm))
30+
A = convert(typ,MPI.Comm_rank(comm) + 1)
31+
C = iallgather(A)
32+
@test C == collect(1:MPI.Comm_size(comm))
2033
end
2134

2235
MPI.Finalize()

test/test_allgatherv.jl

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,13 @@ function allgatherv_array(A, counts::Vector{Cint})
88
B = MPI.Allgatherv(A, counts, comm)
99
end
1010

11+
function iallgatherv_array(A, counts::Vector{Cint})
12+
comm = MPI.COMM_WORLD
13+
req, B = MPI.Iallgatherv(A, counts, comm)
14+
MPI.Wait!(req)
15+
B
16+
end
17+
1118
comm = MPI.COMM_WORLD
1219
size = MPI.Comm_size(comm)
1320
rank = MPI.Comm_rank(comm)
@@ -21,6 +28,10 @@ for typ in MPI.MPIDatatype.types
2128
counts = Cint[ mod(i,2) + 1 for i in 0:(size-1)]
2229
B = allgatherv_array(A, counts)
2330
@test B == ones(typ, 3 * div(size,2) + mod(size,2))
31+
A = ones(typ, mod(rank,2) + 1)
32+
counts = Cint[ mod(i,2) + 1 for i in 0:(size-1)]
33+
B = iallgatherv_array(A, counts)
34+
@test B == ones(typ, 3 * div(size,2) + mod(size,2))
2435
end
2536

2637
MPI.Finalize()

test/test_gather.jl

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,13 @@ function gather(A, root)
88
C = MPI.Gather(A, root, comm)
99
end
1010

11+
function igather(A, root)
12+
comm = MPI.COMM_WORLD
13+
req, C = MPI.Igather(A, root, comm)
14+
MPI.Wait!(req)
15+
C
16+
end
17+
1118
comm = MPI.COMM_WORLD
1219
root = 0
1320

@@ -22,6 +29,16 @@ for typ in MPI.MPIDatatype.types
2229
if MPI.Comm_rank(comm) == root
2330
@test C == collect(1:MPI.Comm_size(comm))
2431
end
32+
A = typ[MPI.Comm_rank(comm) + 1]
33+
C = igather(A, root)
34+
if MPI.Comm_rank(comm) == root
35+
@test C == collect(1:MPI.Comm_size(comm))
36+
end
37+
A = convert(typ,MPI.Comm_rank(comm) + 1)
38+
C = igather(A, root)
39+
if MPI.Comm_rank(comm) == root
40+
@test C == collect(1:MPI.Comm_size(comm))
41+
end
2542
end
2643

2744
MPI.Finalize()

test/test_gatherv.jl

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,13 @@ function gatherv_array(A, counts::Vector{Cint}, root)
88
B = MPI.Gatherv(A, counts, root, comm)
99
end
1010

11+
function igatherv_array(A, counts::Vector{Cint}, root)
12+
comm = MPI.COMM_WORLD
13+
req, B = MPI.Igatherv(A, counts, root, comm)
14+
MPI.Wait!(req)
15+
B
16+
end
17+
1118
comm = MPI.COMM_WORLD
1219
size = MPI.Comm_size(comm)
1320
rank = MPI.Comm_rank(comm)
@@ -24,6 +31,12 @@ for typ in MPI.MPIDatatype.types
2431
if rank == root
2532
@test B == ones(typ, 3 * div(size,2) + mod(size,2))
2633
end
34+
A = ones(typ, mod(rank,2) + 1)
35+
counts = Cint[ mod(i,2) + 1 for i in 0:(size-1)]
36+
B = igatherv_array(A, counts, root)
37+
if rank == root
38+
@test B == ones(typ, 3 * div(size,2) + mod(size,2))
39+
end
2740
end
2841

2942
MPI.Finalize()

0 commit comments

Comments
 (0)