Skip to content

Commit 291f09e

Browse files
Wrap MPI_Comm_compare (#374)
Co-authored-by: Simon Byrne <[email protected]>
1 parent f5d395a commit 291f09e

File tree

7 files changed

+64
-2
lines changed

7 files changed

+64
-2
lines changed

deps/gen_consts.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,10 @@ MPI_Cints = [
115115
:MPI_MODE_UNIQUE_OPEN,
116116
:MPI_MODE_SEQUENTIAL,
117117
:MPI_MODE_APPEND,
118+
:MPI_IDENT,
119+
:MPI_CONGRUENT,
120+
:MPI_SIMILAR,
121+
:MPI_UNEQUAL,
118122
]
119123

120124
MPI_pointers = [

docs/src/comm.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,11 @@ each process a unique *rank* (see [`MPI.Comm_rank`](@ref)) taking an integer val
66
`0:n-1`, where `n` is the number of processes in the communicator (see
77
[`MPI.Comm_size`](@ref).
88

9-
## Types
9+
## Types and enums
1010

1111
```@docs
1212
MPI.Comm
13+
MPI.Comparison
1314
```
1415

1516
## Constants
@@ -21,11 +22,12 @@ MPI.COMM_SELF
2122

2223
## Functions
2324

24-
### Accessors
25+
### Operations
2526

2627
```@docs
2728
MPI.Comm_size
2829
MPI.Comm_rank
30+
MPI.Comm_compare
2931
```
3032

3133
### Constructors

src/comm.jl

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,3 +179,40 @@ function universe_size()
179179
end
180180
Int(unsafe_load(result[]))
181181
end
182+
183+
184+
"""
185+
Comparison
186+
187+
An enum denoting the result of [`Comm_compare`](@ref):
188+
189+
- `MPI.IDENT`: the objects are handles for the same object (identical groups and same contexts).
190+
191+
- `MPI.CONGRUENT`: the underlying groups are identical in constituents and rank order; these communicators differ only by context.
192+
193+
- `MPI.SIMILAR`: members of both objects are the same but the rank order differs.
194+
195+
- `MPI.UNEQUAL`: otherwise
196+
"""
197+
@enum Comparison begin
198+
IDENT = MPI_IDENT
199+
CONGRUENT = MPI_CONGRUENT
200+
SIMILAR = MPI_SIMILAR
201+
UNEQUAL = MPI_UNEQUAL
202+
end
203+
204+
205+
"""
206+
Comm_compare(comm1::Comm, comm2::Comm)::MPI.Comparison
207+
208+
Compare two communicators, returning an element of the [`Comparison`](@ref) enum.
209+
210+
# External links
211+
$(_doc_external("MPI_Comm_compare"))
212+
"""
213+
function Comm_compare(comm1::Comm, comm2::Comm)
214+
result = Ref{Comparison}()
215+
@mpichk ccall((:MPI_Comm_compare, libmpi), Cint,
216+
(MPI_Comm, MPI_Comm, Ptr{Comparison}), comm1, comm2, result)
217+
result[]
218+
end

src/consts/microsoftmpi.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,11 @@ const MPI_IN_PLACE = reinterpret(SentinelPtr, -1)
102102
const MPI_STATUS_IGNORE = reinterpret(SentinelPtr, 1)
103103
const MPI_STATUSES_IGNORE = reinterpret(SentinelPtr, 1)
104104

105+
const MPI_IDENT = Cint(0)
106+
const MPI_CONGRUENT = Cint(1)
107+
const MPI_SIMILAR = Cint(2)
108+
const MPI_UNEQUAL = Cint(3)
109+
105110
struct Status
106111
_pad1::Cint
107112
_pad2::Cint

src/consts/mpich.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,3 +105,8 @@ const MPI_BOTTOM = reinterpret(SentinelPtr, 0)
105105
const MPI_IN_PLACE = reinterpret(SentinelPtr, -1)
106106
const MPI_STATUS_IGNORE = reinterpret(SentinelPtr, 1)
107107
const MPI_STATUSES_IGNORE = reinterpret(SentinelPtr, 1)
108+
109+
const MPI_IDENT = Cint(0)
110+
const MPI_CONGRUENT = Cint(1)
111+
const MPI_SIMILAR = Cint(2)
112+
const MPI_UNEQUAL = Cint(3)

src/consts/openmpi.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,3 +111,8 @@ const MPI_BOTTOM = reinterpret(SentinelPtr, 0)
111111
const MPI_IN_PLACE = reinterpret(SentinelPtr, 1)
112112
const MPI_STATUS_IGNORE = reinterpret(SentinelPtr, 0)
113113
const MPI_STATUSES_IGNORE = reinterpret(SentinelPtr, 0)
114+
115+
const MPI_IDENT = Cint(0)
116+
const MPI_CONGRUENT = Cint(1)
117+
const MPI_SIMILAR = Cint(2)
118+
const MPI_UNEQUAL = Cint(3)

test/test_comm.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,14 @@ using MPI
44
MPI.Init()
55

66
comm = MPI.COMM_WORLD
7+
@test MPI.Comm_compare(comm, comm) === MPI.IDENT
8+
@test MPI.Comm_compare(comm, MPI.COMM_SELF) == (MPI.Comm_size(comm) == 1 ? MPI.CONGRUENT : MPI.UNEQUAL)
79
MPI.Barrier(comm)
810
comm2 = MPI.Comm_dup(comm)
11+
@test MPI.Comm_compare(comm, comm2) === MPI.CONGRUENT
912
MPI.Barrier(comm2)
1013
comm3 = MPI.Comm_dup(comm2)
14+
@test MPI.Comm_compare(comm, comm3) === MPI.CONGRUENT
1115
MPI.Barrier(comm3)
1216
MPI.free(comm2)
1317
MPI.Barrier(comm3)

0 commit comments

Comments
 (0)