Skip to content

Commit 756ee25

Browse files
authored
add tag_ub function (#551)
1 parent e9b7ab0 commit 756ee25

File tree

3 files changed

+32
-10
lines changed

3 files changed

+32
-10
lines changed

docs/src/comm.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,4 +48,5 @@ MPI.Intercomm_merge
4848

4949
```
5050
MPI.universe_size
51+
MPI.tag_ub
5152
```

src/comm.jl

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ The rank of the process in the particular communicator's group.
5050
5151
Returns an integer in the range `0:MPI.Comm_size()-1`.
5252
53-
# See also
53+
# See also
5454
- [`MPI.Comm_size`](@ref).
5555
5656
# External links
@@ -237,6 +237,20 @@ function Intercomm_merge(intercomm::Comm, flag::Bool)
237237
return newcomm
238238
end
239239

240+
241+
function unsafe_get_attr(comm::Comm, keyval::Integer)
242+
flag = Ref{Cint}()
243+
result = Ref(C_NULL)
244+
# int MPI_Comm_get_attr(MPI_Comm comm, int comm_keyval, void *attribute_val, int *flag)
245+
@mpichk ccall((:MPI_Comm_get_attr, libmpi), Cint,
246+
(MPI_Comm, Cint, Ptr{Cvoid}, Ptr{Cint}), comm, keyval, result, flag)
247+
if flag[] == 0
248+
return nothing
249+
end
250+
return result[]
251+
end
252+
253+
240254
"""
241255
universe_size()
242256
@@ -245,17 +259,22 @@ The total number of available slots, or `nothing` if it is not defined. This is
245259
This is typically dependent on the MPI implementation: for MPICH-based implementations, this is specified by the `-usize` argument. OpenMPI defines a default value based on the number of processes available.
246260
"""
247261
function universe_size()
248-
flag = Ref{Cint}()
249-
result = Ref(Ptr{Cint}(C_NULL))
250-
# int MPI_Comm_get_attr(MPI_Comm comm, int comm_keyval, void *attribute_val, int *flag)
251-
@mpichk ccall((:MPI_Comm_get_attr, libmpi), Cint,
252-
(MPI_Comm, Cint, Ptr{Cvoid}, Ptr{Cint}), MPI.COMM_WORLD, Consts.MPI_UNIVERSE_SIZE[], result, flag)
253-
if flag[] == 0
254-
return nothing
255-
end
256-
Int(unsafe_load(result[]))
262+
ptr = unsafe_get_attr(COMM_WORLD, Consts.MPI_UNIVERSE_SIZE[])
263+
isnothing(ptr) && return nothing
264+
return Int(unsafe_load(Ptr{Cint}(ptr)))
257265
end
258266

267+
"""
268+
tag_ub()
269+
270+
The maximum value tag value for point-to-point operations.
271+
"""
272+
function tag_ub()
273+
ptr = something(unsafe_get_attr(COMM_WORLD, Consts.MPI_TAG_UB[]))
274+
return Int(unsafe_load(Ptr{Cint}(ptr)))
275+
end
276+
277+
259278
"""
260279
Comm_compare(comm1::Comm, comm2::Comm)::MPI.Comparison
261280

test/test_universe_size.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,6 @@ MPI.Init()
66
usize = MPI.universe_size()
77
@test usize === nothing || usize >= 1
88

9+
@test MPI.tag_ub() >= 32767
10+
911
MPI.Finalize()

0 commit comments

Comments
 (0)