Skip to content

Commit 6fdc271

Browse files
authored
Add methods for keyword integer arguments (#510)
Fixes #423.
1 parent f97d2f1 commit 6fdc271

19 files changed

+373
-283
lines changed

docs/src/onesided.md

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,11 @@
44
MPI.Win_create
55
MPI.Win_create_dynamic
66
MPI.Win_allocate_shared
7-
MPI.Get
8-
MPI.Put
9-
MPI.Accumulate
10-
MPI.Get_accumulate
7+
MPI.Win_flush
8+
MPI.Win_lock
9+
MPI.Win_unlock
10+
MPI.Get!
11+
MPI.Put!
12+
MPI.Accumulate!
13+
MPI.Get_accumulate!
1114
```

src/collective.jl

Lines changed: 52 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ end
3737

3838

3939
"""
40-
Bcast!(buf, root::Integer, comm::Comm)
40+
Bcast!(buf, comm::Comm; root::Integer=0)
4141
4242
Broadcast the buffer `buf` from `root` to all processes in `comm`.
4343
@@ -47,6 +47,9 @@ Broadcast the buffer `buf` from `root` to all processes in `comm`.
4747
# External links
4848
$(_doc_external("MPI_Bcast"))
4949
"""
50+
Bcast!(buf, comm::Comm; root::Integer=Cint(0)) =
51+
Bcast!(buf, root, comm)
52+
5053
function Bcast!(buf::Buffer, root::Integer, comm::Comm)
5154
# int MPI_Bcast(void* buffer, int count, MPI_Datatype datatype, int root,
5255
# MPI_Comm comm)
@@ -60,14 +63,17 @@ function Bcast!(data, root::Integer, comm::Comm)
6063
end
6164

6265
"""
63-
bcast(obj, root::Integer, comm::Comm)
66+
bcast(obj, comm::Comm; root::Integer=0)
6467
65-
Broadcast the object `obj` from rank `root` to all processes on `comm`. This is able to handle arbitrary data.
68+
Broadcast the object `obj` from rank `root` to all processes on `comm`. This is
69+
able to handle arbitrary data.
6670
6771
# See also
6872
6973
- [`Bcast!`](@ref)
7074
"""
75+
bcast(obj, comm::Comm; root::Integer=Cint(0)) =
76+
bcast(obj, root, comm)
7177
function bcast(obj, root::Integer, comm::Comm)
7278
isroot = Comm_rank(comm) == root
7379
count = Ref{Cint}()
@@ -87,7 +93,8 @@ function bcast(obj, root::Integer, comm::Comm)
8793
end
8894

8995
"""
90-
Scatter!(sendbuf::Union{UBuffer,Nothing}, recvbuf, root::Integer, comm::Comm)
96+
Scatter!(sendbuf::Union{UBuffer,Nothing}, recvbuf, comm::Comm;
97+
root::Integer=0)
9198
9299
Splits the buffer `sendbuf` in the `root` process into `Comm_size(comm)` chunks,
93100
sending the `j`-th chunk to the process of rank `j-1` into the `recvbuf` buffer.
@@ -101,9 +108,9 @@ defined. On the root process, it can also be [`MPI.IN_PLACE`](@ref), in which ca
101108
unmodified. For example:
102109
```
103110
if root == MPI.Comm_rank(comm)
104-
MPI.Scatter!(UBuffer(buf, count), MPI.IN_PLACE, root, comm)
111+
MPI.Scatter!(UBuffer(buf, count), MPI.IN_PLACE, comm; root=root)
105112
else
106-
MPI.Scatter!(nothing, buf, root, comm)
113+
MPI.Scatter!(nothing, buf, comm; root=root)
107114
end
108115
```
109116
@@ -113,6 +120,8 @@ end
113120
# External links
114121
$(_doc_external("MPI_Scatter"))
115122
"""
123+
Scatter!(sendbuf, recvbuf, comm::Comm; root::Integer=Cint(0)) =
124+
Scatter!(sendbuf, recvbuf, root, comm)
116125
function Scatter!(sendbuf::UBuffer, recvbuf::Buffer, root::Integer, comm::Comm)
117126
if sendbuf.nchunks !== nothing && Comm_rank(comm) == root
118127
@assert sendbuf.nchunks >= Comm_size(comm)
@@ -134,24 +143,24 @@ Scatter!(sendbuf::Nothing, recvbuf, root::Integer, comm::Comm) =
134143

135144
# determine UBuffer count from recvbuf
136145
Scatter!(sendbuf::AbstractArray{T}, recvbuf::Union{Ref{T},AbstractArray{T}}, root::Integer, comm::Comm) where {T} =
137-
Scatter!(UBuffer(sendbuf,length(recvbuf)), recvbuf, root, comm)
146+
Scatter!(UBuffer(sendbuf,length(recvbuf)), recvbuf, root, comm)
138147

139148
"""
140-
Scatter(sendbuf, T, root::Integer, comm::Comm)
149+
Scatter(sendbuf, T, comm::Comm; root::Integer=0)
141150
142151
Splits the buffer `sendbuf` in the `root` process into `Comm_size(comm)` chunks,
143152
sending the `j`-th chunk to the process of rank `j-1` as an object of type `T`.
144153
145154
# See also
146155
- [`Scatter!`](@ref)
147156
"""
148-
function Scatter(sendbuf, ::Type{T}, root::Integer, comm::Comm) where {T}
157+
Scatter(sendbuf, T, comm; root::Integer=Cint(0)) =
158+
Scatter(sendbuf, T, root, comm)
159+
Scatter(sendbuf, ::Type{T}, root::Integer, comm::Comm) where {T} =
149160
Scatter!(sendbuf, Ref{T}(), root, comm)[]
150-
end
151-
152161

153162
"""
154-
Scatterv!(sendbuf, recvbuf, root, comm)
163+
Scatterv!(sendbuf, recvbuf, comm::Comm; root::Integer=0)
155164
156165
Splits the buffer `sendbuf` in the `root` process into `Comm_size(comm)` chunks and sends
157166
the `j`th chunk to the process of rank `j-1` into the `recvbuf` buffer.
@@ -164,9 +173,9 @@ defined. On the root process, it can also be [`MPI.IN_PLACE`](@ref), in which ca
164173
unmodified. For example:
165174
```
166175
if root == MPI.Comm_rank(comm)
167-
MPI.Scatterv!(VBuffer(buf, counts), MPI.IN_PLACE, root, comm)
176+
MPI.Scatterv!(VBuffer(buf, counts), MPI.IN_PLACE, comm; root=root)
168177
else
169-
MPI.Scatterv!(nothing, buf, root, comm)
178+
MPI.Scatterv!(nothing, buf, comm; root=root)
170179
end
171180
```
172181
@@ -176,6 +185,8 @@ end
176185
# External links
177186
$(_doc_external("MPI_Scatterv"))
178187
"""
188+
Scatterv!(sendbuf, recvbuf, comm::Comm; root::Integer=Cint(0)) =
189+
Scatterv!(sendbuf, recvbuf, root, comm)
179190
function Scatterv!(sendbuf::VBuffer, recvbuf::Buffer, root::Integer, comm::Comm)
180191
if Comm_rank(comm) == root
181192
@assert length(sendbuf.counts) >= Comm_size(comm)
@@ -198,7 +209,7 @@ Scatterv!(sendbuf::Nothing, recvbuf, root::Integer, comm::Comm) =
198209

199210

200211
"""
201-
Gather!(sendbuf, recvbuf::Union{UBuffer,Nothing}, root::Integer, comm::Comm)
212+
Gather!(sendbuf, recvbuf, comm::Comm; root::Integer=0)
202213
203214
Each process sends the contents of the buffer `sendbuf` to the `root` process. The `root`
204215
process stores elements in rank order in the buffer buffer `recvbuf`.
@@ -212,9 +223,9 @@ case the corresponding entries in `recvbuf` are assumed to be already in place (
212223
corresponds the behaviour of `MPI_IN_PLACE` in `MPI_Gather`). For example:
213224
```
214225
if root == MPI.Comm_rank(comm)
215-
MPI.Gather!(MPI.IN_PLACE, UBuffer(buf, count), root, comm)
226+
MPI.Gather!(MPI.IN_PLACE, UBuffer(buf, count), comm; root=root)
216227
else
217-
MPI.Gather!(buf, nothing, root, comm)
228+
MPI.Gather!(buf, nothing, comm; root=root)
218229
end
219230
```
220231
@@ -230,6 +241,8 @@ can be `nothing`.
230241
# External links
231242
$(_doc_external("MPI_Gather"))
232243
"""
244+
Gather!(sendbuf, recvbuf, comm::Comm; root::Integer=Cint(0)) =
245+
Gather!(sendbuf, recvbuf, root, comm)
233246
function Gather!(sendbuf::Buffer, recvbuf::UBuffer, root::Integer, comm::Comm)
234247
if recvbuf.nchunks !== nothing && Comm_rank(comm) == root
235248
@assert recvbuf.nchunks >= Comm_size(comm)
@@ -255,7 +268,7 @@ Gather!(sendbuf::Nothing, recvbuf, root::Integer, comm::Comm) =
255268

256269

257270
"""
258-
Gather(sendbuf, root, comm::Comm)
271+
Gather(sendbuf, comm::Comm; root=0)
259272
260273
Each process sends the contents of the buffer `sendbuf` to the `root` process. The `root`
261274
allocates the output buffer and stores elements in rank order.
@@ -271,13 +284,15 @@ processes.
271284
# External links
272285
$(_doc_external("MPI_Gather"))
273286
"""
287+
Gather(sendbuf, comm::Comm; root::Integer=Cint(0)) =
288+
Gather(sendbuf, root, comm)
274289
Gather(sendbuf::AbstractArray, root::Integer, comm::Comm) =
275290
Gather!(sendbuf, Comm_rank(comm) == root ? similar(sendbuf, Comm_size(comm) * length(sendbuf)) : nothing, root, comm)
276291
Gather(object::T, root::Integer, comm::Comm) where {T} =
277292
Gather!(Ref(object), Comm_rank(comm) == root ? Array{T}(undef, Comm_size(comm)) : nothing, root, comm)
278293

279294
"""
280-
Gatherv!(sendbuf, recvbuf::Union{VBuffer,Nothing}, root, comm)
295+
Gatherv!(sendbuf, recvbuf, comm::Comm; root::Integer=0)
281296
282297
Each process sends the contents of the buffer `sendbuf` to the `root` process. The `root`
283298
stores elements in rank order in the buffer `recvbuf`.
@@ -289,9 +304,9 @@ On the root process, `sendbuf` can be [`MPI.IN_PLACE`](@ref), in which case the
289304
corresponding entries in `recvbuf` are assumed to be already in place. For example
290305
```
291306
if root == MPI.Comm_rank(comm)
292-
Gatherv!(MPI.IN_PLACE, VBuffer(buf, counts), root, comm)
307+
Gatherv!(MPI.IN_PLACE, VBuffer(buf, counts), comm; root=root)
293308
else
294-
Gatherv!(buf, nothing, root, comm)
309+
Gatherv!(buf, nothing, comm; root=root)
295310
end
296311
```
297312
@@ -307,6 +322,8 @@ can be `nothing`.
307322
# External links
308323
$(_doc_external("MPI_Gatherv"))
309324
"""
325+
Gatherv!(sendbuf, recvbuf, comm::Comm; root::Integer=Cint(0)) =
326+
Gatherv!(sendbuf, recvbuf, root, comm)
310327
function Gatherv!(sendbuf::Buffer, recvbuf::VBuffer, root::Integer, comm::Comm)
311328
if Comm_rank(comm) == root
312329
@assert length(recvbuf.counts) >= Comm_size(comm)
@@ -518,7 +535,7 @@ Alltoall(sendbuf::UBuffer, comm::Comm) =
518535
"""
519536
Alltoallv!(sendbuf::VBuffer, recvbuf::VBuffer, comm::Comm)
520537
521-
Similar to [`Alltoall!`](@ref), except with different size chunks per process.
538+
Similar to [`Alltoall!`](@ref), except with different size chunks per process.
522539
523540
# See also
524541
- [`VBuffer`](@ref)
@@ -542,7 +559,7 @@ function Alltoallv!(sendbuf::VBuffer, recvbuf::VBuffer, comm::Comm)
542559
sendbuf.data, sendbuf.counts, sendbuf.displs, sendbuf.datatype,
543560
recvbuf.data, recvbuf.counts, recvbuf.displs, recvbuf.datatype,
544561
comm)
545-
562+
546563
return recvbuf.data
547564
end
548565

@@ -553,13 +570,13 @@ end
553570

554571
# mutating
555572
"""
556-
Reduce!(sendbuf, recvbuf, op, root::Integer, comm::Comm)
557-
Reduce!(sendrecvbuf, op, root::Integer, comm::Comm)
573+
Reduce!(sendbuf, recvbuf, op, comm::Comm; root::Integer=0)
574+
Reduce!(sendrecvbuf, op, comm::Comm; root::Integer=0)
558575
559576
Performs elementwise reduction using the operator `op` on the buffer `sendbuf` and stores
560577
the result in `recvbuf` on the process of rank `root`.
561578
562-
On non-root processes `recvbuf` is ignored, and can be `nothing`.
579+
On non-root processes `recvbuf` is ignored, and can be `nothing`.
563580
564581
To perform the reduction in place, provide a single buffer `sendrecvbuf`.
565582
@@ -571,6 +588,11 @@ To perform the reduction in place, provide a single buffer `sendrecvbuf`.
571588
# External links
572589
$(_doc_external("MPI_Reduce"))
573590
"""
591+
Reduce!(sendrecvbuf, op, comm::Comm; root::Integer=Cint(0)) =
592+
Reduce!(sendrecvbuf, op, root, comm)
593+
Reduce!(sendbuf, recvbuf, op, comm::Comm; root::Integer=Cint(0)) =
594+
Reduce!(sendbuf, recvbuf, op, root, comm)
595+
574596
function Reduce!(rbuf::RBuffer, op::Union{Op,MPI_Op}, root::Integer, comm::Comm)
575597
# int MPI_Reduce(const void* sendbuf, void* recvbuf, int count,
576598
# MPI_Datatype datatype, MPI_Op op, int root, MPI_Comm comm)
@@ -597,7 +619,7 @@ end
597619

598620
# allocating
599621
"""
600-
recvbuf = Reduce(sendbuf, op, root::Integer, comm::Comm)
622+
recvbuf = Reduce(sendbuf, op, comm::Comm; root::Integer=0)
601623
602624
Performs elementwise reduction using the operator `op` on the buffer `sendbuf`, returning
603625
the result `recvbuf` on the process of rank `root`, and `nothing` on non-root processes.
@@ -612,8 +634,10 @@ the result `recvbuf` on the process of rank `root`, and `nothing` on non-root pr
612634
# External links
613635
$(_doc_external("MPI_Reduce"))
614636
"""
637+
Reduce(sendbuf, op, comm::Comm; root::Integer=Cint(0)) =
638+
Reduce(sendbuf, op, root, comm)
615639
function Reduce(sendbuf::AbstractArray, op, root::Integer, comm::Comm)
616-
if Comm_rank(comm) == root
640+
if Comm_rank(comm) == root
617641
Reduce!(sendbuf, similar(sendbuf), op, root, comm)
618642
else
619643
Reduce!(sendbuf, nothing, op, root, comm)

src/deprecated.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -219,8 +219,8 @@ import Base: @deprecate
219219
@deprecate(Waitsome!(reqs::Vector{Request}), ((inds, statuses) = MPI.Waitsome(reqs, MPI.Status); (something(inds, Int[]), statuses)), false)
220220
@deprecate(Testsome!(reqs::Vector{Request}), ((inds, statuses) = MPI.Testsome(reqs, MPI.Status); (something(inds, Int[]), statuses)), false)
221221

222-
@deprecate(Recv!(recvbuf, src::Integer, tag::Integer, comm::Comm), Recv!(recvbuf, src, tag, comm, MPI.Status)[2], false)
223-
@deprecate(Recv(T, src::Integer, tag::Integer, comm::Comm), Recv(T, src, tag, comm, MPI.Status), false)
224-
@deprecate(recv(src::Integer, tag::Integer, comm::Comm), recv(src, tag, comm, MPI.Status), false)
222+
@deprecate(Recv!(recvbuf, source::Integer, tag::Integer, comm::Comm), Recv!(recvbuf, comm, MPI.Status; source=source, tag=tag)[2], false)
223+
@deprecate(Recv(T, source::Integer, tag::Integer, comm::Comm), Recv(T, comm, MPI.Status; source=source, tag=tag), false)
224+
@deprecate(recv(source::Integer, tag::Integer, comm::Comm), recv(comm, MPI.Status; source=source, tag=tag), false)
225225
@deprecate(Sendrecv!(sendbuf, dest::Integer, sendtag::Integer, recvbuf, source::Integer, recvtag::Integer, comm::Comm),
226-
Sendrecv!(sendbuf, dest, sendtag, recvbuf, source, recvtag, comm, MPI.Status)[2], false)
226+
Sendrecv!(sendbuf, recvbuf, comm, MPI.Status; dest=dest, sendtag=sendtag, source=source, recvtag=recvtag)[2], false)

0 commit comments

Comments
 (0)