@@ -2,6 +2,7 @@ typealias MPIDatatype Union{Char,
22 Int8, UInt8, Int16, UInt16, Int32, UInt32, Int64,
33 UInt64,
44 Float32, Float64, Complex64, Complex128}
5+ typealias MPIBuffertype{T} Union{Ptr{T}, Array{T}, Ref{T}}
56
67# Define a function mpitype(T) that returns the MPI datatype code for
78# a given type T. The dictonary is defined in __init__ so the module
@@ -196,7 +197,7 @@ function Get_count{T}(stat::Status, ::Type{T})
196197 Int (count[])
197198end
198199
199- function Send {T} (buf:: Union{Ptr{T},Array{T} } , count:: Integer ,
200+ function Send {T} (buf:: MPIBuffertype{T } , count:: Integer ,
200201 dest:: Integer , tag:: Integer , comm:: Comm )
201202 ccall (MPI_SEND, Void,
202203 (Ptr{T}, Ptr{Cint}, Ptr{Cint}, Ptr{Cint}, Ptr{Cint}, Ptr{Cint},
@@ -219,7 +220,7 @@ function send(obj, dest::Integer, tag::Integer, comm::Comm)
219220 Send (buf, dest, tag, comm)
220221end
221222
222- function Isend {T} (buf:: Union{Ptr{T},Array{T} } , count:: Integer ,
223+ function Isend {T} (buf:: MPIBuffertype{T } , count:: Integer ,
223224 dest:: Integer , tag:: Integer , comm:: Comm )
224225 rval = Ref {Cint} ()
225226 ccall (MPI_ISEND, Void,
@@ -244,7 +245,7 @@ function isend(obj, dest::Integer, tag::Integer, comm::Comm)
244245 Isend (buf, dest, tag, comm)
245246end
246247
247- function Recv! {T} (buf:: Union{Ptr{T},Array{T} } , count:: Integer ,
248+ function Recv! {T} (buf:: MPIBuffertype{T } , count:: Integer ,
248249 src:: Integer , tag:: Integer , comm:: Comm )
249250 stat = Status ()
250251 ccall (MPI_RECV, Void,
@@ -273,7 +274,7 @@ function recv(src::Integer, tag::Integer, comm::Comm)
273274 (MPI. deserialize (buf), stat)
274275end
275276
276- function Irecv! {T} (buf:: Union{Ptr{T},Array{T} } , count:: Integer ,
277+ function Irecv! {T} (buf:: MPIBuffertype{T } , count:: Integer ,
277278 src:: Integer , tag:: Integer , comm:: Comm )
278279 val = Ref {Cint} ()
279280 ccall (MPI_IRECV, Void,
@@ -463,7 +464,7 @@ function Barrier(comm::Comm)
463464 ccall (MPI_BARRIER, Void, (Ptr{Cint},Ptr{Cint}), & comm. val, & 0 )
464465end
465466
466- function Bcast! {T} (buffer:: Union{Ptr{T},Array{T} } , count:: Integer ,
467+ function Bcast! {T} (buffer:: MPIBuffertype{T } , count:: Integer ,
467468 root:: Integer , comm:: Comm )
468469 ccall (MPI_BCAST, Void,
469470 (Ptr{T}, Ptr{Cint}, Ptr{Cint}, Ptr{Cint}, Ptr{Cint}, Ptr{Cint}),
@@ -501,7 +502,7 @@ function bcast(obj, root::Integer, comm::Comm)
501502 obj
502503end
503504
504- function Reduce {T} (sendbuf:: Union{Ptr{T},Array{T} } , count:: Integer ,
505+ function Reduce {T} (sendbuf:: MPIBuffertype{T } , count:: Integer ,
505506 op:: Op , root:: Integer , comm:: Comm )
506507 isroot = Comm_rank (comm) == root
507508 recvbuf = Array (T, isroot ? count : 0 )
@@ -524,7 +525,7 @@ function Reduce{T}(object::T, op::Op, root::Integer, comm::Comm)
524525 isroot ? recvbuf[1 ] : nothing
525526end
526527
527- function Scatter {T} (sendbuf:: Union{Ptr{T},Array{T} } ,
528+ function Scatter {T} (sendbuf:: MPIBuffertype{T } ,
528529 count:: Integer , root:: Integer , comm:: Comm )
529530 recvbuf = Array (T, count)
530531 ccall (MPI_SCATTER, Void,
@@ -533,7 +534,7 @@ function Scatter{T}(sendbuf::Union{Ptr{T},Array{T}},
533534 recvbuf
534535end
535536
536- function Scatterv {T} (sendbuf:: Union{Ptr{T},Array{T} } ,
537+ function Scatterv {T} (sendbuf:: MPIBuffertype{T } ,
537538 counts:: Vector{Cint} , root:: Integer ,
538539 comm:: Comm )
539540 recvbuf = Array (T, counts[Comm_rank (comm) + 1 ])
@@ -545,7 +546,7 @@ function Scatterv{T}(sendbuf::Union{Ptr{T},Array{T}},
545546 recvbuf
546547end
547548
548- function Gather {T} (sendbuf:: Union{Ptr{T},Array{T} } , count:: Integer ,
549+ function Gather {T} (sendbuf:: MPIBuffertype{T } , count:: Integer ,
549550 root:: Integer , comm:: Comm )
550551 isroot = Comm_rank (comm) == root
551552 recvbuf = Array (T, isroot ? Comm_size (comm) * count : 0 )
@@ -566,7 +567,7 @@ function Gather{T}(object::T, root::Integer, comm::Comm)
566567 isroot ? recvbuf : nothing
567568end
568569
569- function Allgather {T} (sendbuf:: Union{Ptr{T},Array{T} } , count:: Integer ,
570+ function Allgather {T} (sendbuf:: MPIBuffertype{T } , count:: Integer ,
570571 comm:: Comm )
571572 recvbuf = Array (T, Comm_size (comm) * count)
572573 ccall (MPI_ALLGATHER, Void,
@@ -585,7 +586,7 @@ function Allgather{T}(object::T, comm::Comm)
585586 recvbuf
586587end
587588
588- function Gatherv {T} (sendbuf:: Union{Ptr{T},Array{T} } , counts:: Vector{Cint} ,
589+ function Gatherv {T} (sendbuf:: MPIBuffertype{T } , counts:: Vector{Cint} ,
589590 root:: Integer , comm:: Comm )
590591 isroot = Comm_rank (comm) == root
591592 displs = cumsum (counts) - counts
@@ -597,7 +598,7 @@ function Gatherv{T}(sendbuf::Union{Ptr{T},Array{T}}, counts::Vector{Cint},
597598 isroot ? recvbuf : nothing
598599end
599600
600- function Allgatherv {T} (sendbuf:: Union{Ptr{T},Array{T} } , counts:: Vector{Cint} ,
601+ function Allgatherv {T} (sendbuf:: MPIBuffertype{T } , counts:: Vector{Cint} ,
601602 comm:: Comm )
602603 displs = cumsum (counts) - counts
603604 sendcnt = counts[Comm_rank (comm) + 1 ]
@@ -608,7 +609,7 @@ function Allgatherv{T}(sendbuf::Union{Ptr{T},Array{T}}, counts::Vector{Cint},
608609 recvbuf
609610end
610611
611- function Alltoall {T} (sendbuf:: Union{Ptr{T},Array{T} } , count:: Integer ,
612+ function Alltoall {T} (sendbuf:: MPIBuffertype{T } , count:: Integer ,
612613 comm:: Comm )
613614 recvbuf = Array (T, Comm_size (comm)* count)
614615 ccall (MPI_ALLTOALL, Void,
@@ -617,7 +618,7 @@ function Alltoall{T}(sendbuf::Union{Ptr{T},Array{T}}, count::Integer,
617618 recvbuf
618619end
619620
620- function Alltoallv {T} (sendbuf:: Union{Ptr{T},Array{T} } , scounts:: Vector{Cint} ,
621+ function Alltoallv {T} (sendbuf:: MPIBuffertype{T } , scounts:: Vector{Cint} ,
621622 rcounts:: Vector{Cint} , comm:: Comm )
622623 recvbuf = Array (T, sum (rcounts))
623624 sdispls = cumsum (scounts) - scounts
@@ -628,7 +629,7 @@ function Alltoallv{T}(sendbuf::Union{Ptr{T},Array{T}}, scounts::Vector{Cint},
628629 recvbuf
629630end
630631
631- function Scan {T} (sendbuf:: Union{Ptr{T},Array{T} } , count:: Integer ,
632+ function Scan {T} (sendbuf:: MPIBuffertype{T } , count:: Integer ,
632633 op:: Op , comm:: Comm )
633634 recvbuf = Array (T, count)
634635 ccall (MPI_SCAN, Void,
@@ -642,7 +643,7 @@ function Scan{T}(object::T, op::Op, comm::Comm)
642643 Scan (sendbuf,1 ,op,comm)
643644end
644645
645- function ExScan {T} (sendbuf:: Union{Ptr{T},Array{T} } , count:: Integer ,
646+ function ExScan {T} (sendbuf:: MPIBuffertype{T } , count:: Integer ,
646647 op:: Op , comm:: Comm )
647648 recvbuf = Array (T, count)
648649 ccall (MPI_EXSCAN, Void,
0 commit comments