Skip to content

Commit 7c118cf

Browse files
authored
wrap MPI_Cart_sub (#311)
1 parent edab8ef commit 7c118cf

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

src/topology.jl

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,3 +56,17 @@ function Cart_shift(comm::Comm, direction::Integer, disp::Integer)
5656
comm, direction, disp, rank_source, rank_dest)
5757
Int(rank_source[]), Int(rank_dest[])
5858
end
59+
60+
function Cart_sub(comm::Comm, remain_dims)
61+
comm_sub = Comm()
62+
remain_dims = [Cint(dim) for dim in remain_dims]
63+
# int MPI_Cart_sub(MPI_Comm comm, const int remain_dims[], MPI_Comm *comm_new)
64+
@mpichk ccall((:MPI_Cart_sub, libmpi), Cint,
65+
(MPI_Comm, Ptr{Cint}, Ptr{MPI_Comm}),
66+
comm, remain_dims, comm_sub)
67+
if comm_sub.val != MPI_COMM_NULL
68+
refcount_inc()
69+
finalizer(free, comm_sub)
70+
end
71+
comm_sub
72+
end

test/test_cart_create.jl

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,15 @@ comm_cart = MPI.Cart_create(comm, ndims, cdims, cperiods, reorder)
1818
comm_cart2 = MPI.Cart_create(comm, dims, periods, reorder)
1919
@test MPI.Comm_size(comm_cart2) == nnodes
2020

21+
comm_sub1 = MPI.Cart_sub(comm_cart, (false, true, true))
22+
@test MPI.Comm_size(comm_sub1) == div(nnodes, dims[1])
23+
24+
comm_sub2 = MPI.Cart_sub(comm_cart, (true, false, true))
25+
@test MPI.Comm_size(comm_sub2) == div(nnodes, dims[2])
26+
27+
comm_sub3 = MPI.Cart_sub(comm_cart, (true, true, false))
28+
@test MPI.Comm_size(comm_sub2) == div(nnodes, dims[3])
29+
30+
2131
MPI.Finalize()
2232
#@test MPI.Finalized()

0 commit comments

Comments
 (0)