Skip to content

Commit c31b5ba

Browse files
gasagnasimonbyrne
authored andcommitted
WIP: add wrapper to Cart_get (#314)
* add Cart_get this includes docs and tests * add `Cartdim_get`
1 parent d4b9892 commit c31b5ba

File tree

2 files changed

+63
-0
lines changed

2 files changed

+63
-0
lines changed

src/topology.jl

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,40 @@ function Cart_create(comm_old::Comm, dims::AbstractArray{T,N}, periods::Array{T,
3232
Cart_create(comm_old, ndims, cdims, cperiods, reorder)
3333
end
3434

35+
"""
36+
Cart_get(comm::Comm, maxdims::Integer)
37+
38+
Obtain information on the Cartesian topology of dimension `maxdims` underlying the
39+
communicator `comm`. This is specified by two `Cint` arrays of `maxdims` elements
40+
for the number of processes and periodicity properties along each Cartesian dimension.
41+
A third `Cint` array is returned, containing the Cartesian coordinates of the calling process.
42+
"""
43+
function Cart_get(comm::Comm, maxdims::Integer)
44+
# preallocate with nontrivial values
45+
dims = Cint[-1 for i = 1:maxdims]
46+
periods = Cint[-1 for i = 1:maxdims]
47+
coords = Cint[-1 for i = 1:maxdims]
48+
# int MPI_Cart_get(MPI_Comm comm, int maxdims, int dims[], int periods[], int coords[])
49+
@mpichk ccall((:MPI_Cart_get, libmpi), Cint,
50+
(MPI_Comm, Cint, Ptr{Cint}, Ptr{Cint}, Ptr{Cint}),
51+
comm, maxdims, dims, periods, coords)
52+
return dims, periods, coords
53+
end
54+
55+
"""
56+
Cartdim_get(comm::Comm)
57+
58+
Return number of dimensions of the Cartesian topology associated with the communicator `comm`.
59+
"""
60+
function Cartdim_get(comm::Comm)
61+
dims = Cint[0]
62+
# int MPI_Cartdim_get(MPI_Comm comm, int *ndims)
63+
@mpichk ccall((:MPI_Cartdim_get, libmpi), Cint,
64+
(MPI_Comm, Ptr{Cint}),
65+
comm, dims)
66+
return Int(dims[1])
67+
end
68+
3569
function Cart_coords!(comm::Comm, rank::Integer, maxdims::Integer, coords::MPIBuffertype{Cint})
3670
# int MPI_Cart_coords(MPI_Comm comm, int rank, int maxdims, int coords[])
3771
@mpichk ccall((:MPI_Cart_coords, libmpi), Cint,

test/test_cart_get.jl

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
using Test
2+
using MPI
3+
4+
MPI.Init()
5+
6+
comm = MPI.COMM_WORLD
7+
nnodes = MPI.Comm_size(comm)
8+
9+
# setting
10+
maxdims = 3
11+
periods = Cint[0, 1, 0]
12+
dims = Cint[1, 1, nnodes]
13+
14+
# create
15+
comm_cart = MPI.Cart_create(comm, maxdims, dims, periods, false)
16+
17+
# check number of dimensions
18+
@test MPI.Cartdim_get(comm_cart) == maxdims
19+
20+
# get info
21+
_dims, _periods, _coords = MPI.Cart_get(comm_cart, maxdims)
22+
23+
# test
24+
@test _dims == dims
25+
@test _periods == periods
26+
@test _coords == MPI.Cart_coords(comm_cart, maxdims)
27+
28+
MPI.Finalize()
29+

0 commit comments

Comments
 (0)