Skip to content

Commit 4070fbc

Browse files
authored
Merge pull request #199 from tbole/add_subarrays
Add support for SubArrays
2 parents 6c47fba + 6ec701a commit 4070fbc

File tree

1 file changed

+45
-1
lines changed

1 file changed

+45
-1
lines changed

src/mpi-base.jl

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ const MPIDatatype = Union{Char,
22
Int8, UInt8, Int16, UInt16, Int32, UInt32, Int64,
33
UInt64,
44
Float32, Float64, Complex64, Complex128}
5-
MPIBuffertype{T} = Union{Ptr{T}, Array{T}, Ref{T}}
5+
MPIBuffertype{T} = Union{Ptr{T}, Array{T}, SubArray{T}, Ref{T}}
66

77
fieldoffsets(::Type{T}) where {T} = Int[fieldoffset(T, i) for i in 1:nfields(T)]
88

@@ -354,6 +354,12 @@ function Send(buf::Array{T}, dest::Integer, tag::Integer,
354354
Send(buf, length(buf), dest, tag, comm)
355355
end
356356

357+
function Send(buf::SubArray{T}, dest::Integer, tag::Integer,
358+
comm::Comm) where T
359+
@assert Base.iscontiguous(buf)
360+
Send(buf, length(buf), dest, tag, comm)
361+
end
362+
357363
function Send(obj::T, dest::Integer, tag::Integer, comm::Comm) where T
358364
buf = [obj]
359365
Send(buf, dest, tag, comm)
@@ -379,6 +385,12 @@ function Isend(buf::Array{T}, dest::Integer, tag::Integer,
379385
Isend(buf, length(buf), dest, tag, comm)
380386
end
381387

388+
function Isend(buf::SubArray{T}, dest::Integer, tag::Integer,
389+
comm::Comm) where T
390+
@assert Base.iscontiguous(buf)
391+
Isend(buf, length(buf), dest, tag, comm)
392+
end
393+
382394
function Isend(obj::T, dest::Integer, tag::Integer, comm::Comm) where T
383395
buf = [obj]
384396
Isend(buf, dest, tag, comm)
@@ -404,6 +416,12 @@ function Recv!(buf::Array{T}, src::Integer, tag::Integer,
404416
Recv!(buf, length(buf), src, tag, comm)
405417
end
406418

419+
function Recv!(buf::SubArray{T}, src::Integer, tag::Integer,
420+
comm::Comm) where T
421+
@assert Base.iscontiguous(buf)
422+
Recv!(buf, length(buf), src, tag, comm)
423+
end
424+
407425
function Recv(::Type{T}, src::Integer, tag::Integer, comm::Comm) where T
408426
buf = Ref{T}()
409427
stat = Recv!(buf, 1, src, tag, comm)
@@ -433,6 +451,12 @@ function Irecv!(buf::Array{T}, src::Integer, tag::Integer,
433451
Irecv!(buf, length(buf), src, tag, comm)
434452
end
435453

454+
function Irecv!(buf::SubArray{T}, src::Integer, tag::Integer,
455+
comm::Comm) where T
456+
@assert Base.iscontiguous(buf)
457+
Irecv!(buf, length(buf), src, tag, comm)
458+
end
459+
436460
function irecv(src::Integer, tag::Integer, comm::Comm)
437461
(flag, stat) = Iprobe(src, tag, comm)
438462
if !flag
@@ -620,6 +644,11 @@ function Bcast!(buffer::Array{T}, root::Integer, comm::Comm) where T
620644
Bcast!(buffer, length(buffer), root, comm)
621645
end
622646

647+
function Bcast!(buffer::SubArray{T}, root::Integer, comm::Comm) where T
648+
@assert Base.iscontiguous(buffer)
649+
Bcast!(buffer, length(buffer), root, comm)
650+
end
651+
623652
#=
624653
function Bcast{T}(obj::T, root::Integer, comm::Comm)
625654
buf = [T]
@@ -662,6 +691,11 @@ function Reduce(sendbuf::Array{T}, op::Union{Op,Function}, root::Integer, comm::
662691
Reduce(sendbuf, length(sendbuf), op, root, comm)
663692
end
664693

694+
function Reduce(sendbuf::SubArray{T}, op::Union{Op,Function}, root::Integer, comm::Comm) where T
695+
@assert Base.iscontiguous(sendbuf)
696+
Reduce(sendbuf, length(sendbuf), op, root, comm)
697+
end
698+
665699
function Reduce(object::T, op::Union{Op,Function}, root::Integer, comm::Comm) where T
666700
isroot = Comm_rank(comm) == root
667701
sendbuf = T[object]
@@ -736,6 +770,11 @@ function Gather(sendbuf::Array{T}, root::Integer, comm::Comm) where T
736770
Gather(sendbuf, length(sendbuf), root, comm)
737771
end
738772

773+
function Gather(sendbuf::SubArray{T}, root::Integer, comm::Comm) where T
774+
@assert Base.iscontiguous(sendbuf)
775+
Gather(sendbuf, length(sendbuf), root, comm)
776+
end
777+
739778
function Gather(object::T, root::Integer, comm::Comm) where T
740779
isroot = Comm_rank(comm) == root
741780
sendbuf = T[object]
@@ -756,6 +795,11 @@ function Allgather(sendbuf::Array{T}, comm::Comm) where T
756795
Allgather(sendbuf, length(sendbuf), comm)
757796
end
758797

798+
function Allgather(sendbuf::SubArray{T}, comm::Comm) where T
799+
@assert Base.iscontiguous(sendbuf)
800+
Allgather(sendbuf, length(sendbuf), comm)
801+
end
802+
759803
function Allgather(object::T, comm::Comm) where T
760804
sendbuf = T[object]
761805
recvbuf = Allgather(sendbuf, comm)

0 commit comments

Comments
 (0)