Skip to content

Commit a61ca21

Browse files
committed
Wrapped Iscatter{v}
1 parent cc4f368 commit a61ca21

File tree

5 files changed

+60
-1
lines changed

5 files changed

+60
-1
lines changed

deps/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ FortranCInterface_HEADER(jlmpi_f2c.h MACRO_NAMESPACE "JLMPI_" SYMBOLS
6161
MPI_INITIALIZED
6262
MPI_IPROBE
6363
MPI_IRECV
64+
MPI_ISCATTER
65+
MPI_ISCATTERV
6466
MPI_ISEND
6567
MPI_OP_CREATE
6668
MPI_OP_FREE

deps/gen_functions.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ int main(int argc, char *argv[]) {
4949
printf(" :MPI_INITIALIZED => \"%s\",\n", STRING(MPI_INITIALIZED));
5050
printf(" :MPI_IPROBE => \"%s\",\n", STRING(MPI_IPROBE));
5151
printf(" :MPI_IRECV => \"%s\",\n", STRING(MPI_IRECV));
52+
printf(" :MPI_ISCATTER => \"%s\",\n", STRING(MPI_ISCATTER));
53+
printf(" :MPI_ISCATTERV => \"%s\",\n", STRING(MPI_ISCATTERV));
5254
printf(" :MPI_ISEND => \"%s\",\n", STRING(MPI_ISEND));
5355
printf(" :MPI_OP_CREATE => \"%s\",\n", STRING(MPI_OP_CREATE));
5456
printf(" :MPI_OP_FREE => \"%s\",\n", STRING(MPI_OP_FREE));

src/mpi-base.jl

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -556,6 +556,16 @@ function Scatter{T}(sendbuf::MPIBuffertype{T},
556556
recvbuf
557557
end
558558

559+
function Iscatter{T}(sendbuf::MPIBuffertype{T},
560+
count::Integer, root::Integer, comm::Comm)
561+
rval = Ref{Cint}()
562+
recvbuf = Array(T, count)
563+
ccall(MPI_ISCATTER, Void,
564+
(Ptr{T}, Ptr{Cint}, Ptr{Cint}, Ptr{T}, Ptr{Cint}, Ptr{Cint}, Ptr{Cint}, Ptr{Cint}, Ptr{Cint}, Ptr{Cint}),
565+
sendbuf, &count, &mpitype(T), recvbuf, &count, &mpitype(T), &root, &comm.val, rval, &0)
566+
Request(rval[], sendbuf), recvbuf
567+
end
568+
559569
function Scatterv{T}(sendbuf::MPIBuffertype{T},
560570
counts::Vector{Cint}, root::Integer,
561571
comm::Comm)
@@ -568,6 +578,19 @@ function Scatterv{T}(sendbuf::MPIBuffertype{T},
568578
recvbuf
569579
end
570580

581+
function Iscatterv{T}(sendbuf::MPIBuffertype{T},
582+
counts::Vector{Cint}, root::Integer,
583+
comm::Comm)
584+
rval = Ref{Cint}()
585+
recvbuf = Array(T, counts[Comm_rank(comm) + 1])
586+
recvcnt = counts[Comm_rank(comm) + 1]
587+
disps = cumsum(counts) - counts
588+
ccall(MPI_ISCATTERV, Void,
589+
(Ptr{T}, Ptr{Cint}, Ptr{Cint}, Ptr{Cint}, Ptr{T}, Ptr{Cint}, Ptr{Cint}, Ptr{Cint}, Ptr{Cint}, Ptr{Cint}, Ptr{Cint}),
590+
sendbuf, counts, disps, &mpitype(T), recvbuf, &recvcnt, &mpitype(T), &root, &comm.val, rval, &0)
591+
Request(rval[], sendbuf), recvbuf
592+
end
593+
571594
function Gather{T}(sendbuf::MPIBuffertype{T}, count::Integer,
572595
root::Integer, comm::Comm)
573596
isroot = Comm_rank(comm) == root

test/test_scatter.jl

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,19 @@ function scatter_array(A, root)
1414
C = MPI.Scatter(B, 1, root, comm)
1515
end
1616

17+
function iscatter_array(A, root)
18+
comm = MPI.COMM_WORLD
19+
T = eltype(A)
20+
if MPI.Comm_rank(comm) == root
21+
B = copy(A)
22+
else
23+
B = Array(T,1)
24+
end
25+
req, C = MPI.Iscatter(B, 1, root, comm)
26+
MPI.Wait!(req)
27+
C
28+
end
29+
1730
comm = MPI.COMM_WORLD
1831
root = 0
1932

@@ -24,6 +37,9 @@ for typ in MPI.MPIDatatype.types
2437
A = convert(Vector{typ},collect(1:MPI.Comm_size(comm)))
2538
B = scatter_array(A, root)
2639
@test B[1] == convert(typ,MPI.Comm_rank(comm) + 1)
40+
A = convert(Vector{typ},collect(1:MPI.Comm_size(comm)))
41+
B = iscatter_array(A, root)
42+
@test B[1] == convert(typ,MPI.Comm_rank(comm) + 1)
2743
end
2844

2945
MPI.Finalize()

test/test_scatterv.jl

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,19 @@ function scatterv_array(A, counts::Vector{Cint}, root)
1414
C = MPI.Scatterv(B, counts, root, comm)
1515
end
1616

17+
function iscatterv_array(A, counts::Vector{Cint}, root)
18+
comm = MPI.COMM_WORLD
19+
T = eltype(A)
20+
if MPI.Comm_rank(comm) == root
21+
B = copy(A)
22+
else
23+
B = Array(T,1)
24+
end
25+
req, C = MPI.Iscatterv(B, counts, root, comm)
26+
MPI.Wait!(req)
27+
C
28+
end
29+
1730
comm = MPI.COMM_WORLD
1831
size = MPI.Comm_size(comm)
1932
rank = MPI.Comm_rank(comm)
@@ -23,11 +36,14 @@ root = 0
2336
Base.one(::Type{Char}) = '\01'
2437

2538
for typ in MPI.MPIDatatype.types
26-
2739
A = ones(typ, 3 * div(size,2) + mod(size,2))
2840
counts = Cint[ mod(i,2) + 1 for i in 0:(size-1)]
2941
B = scatterv_array(A, counts, root)
3042
@test B == ones(typ, mod(rank,2) + 1)
43+
A = ones(typ, 3 * div(size,2) + mod(size,2))
44+
counts = Cint[ mod(i,2) + 1 for i in 0:(size-1)]
45+
B = iscatterv_array(A, counts, root)
46+
@test B == ones(typ, mod(rank,2) + 1)
3147
end
3248

3349
MPI.Finalize()

0 commit comments

Comments
 (0)