1
1
"""
2
- Dims_create! (nnodes::Integer, [ndims::Integer] , dims)
2
+ newdims = Dims_create(nnodes::Integer, dims)
3
3
4
- Create a division of `nnodes` processes in a Cartesian grid.
4
+ A convenience function for selecting a balanced Cartesian grid of a total of `nnodes`
5
+ nodes, for example to use with [`MPI.Cart_create`](@ref).
6
+
7
+ `dims` is an array or tuple of integers specifying the number of nodes in each dimension.
8
+ The function returns an array `newdims` of the same length, such that if `newdims[i] =
9
+ dims[i]` if `dims[i]` is non-zero, and `prod(newdims) == nnodes`, and values `newdims` are
10
+ as close to each other as possible.
11
+
12
+ `nnodes` should be divisible by the product of the non-zero entries of `dims`.
5
13
6
14
# External links
7
15
$(_doc_external (" MPI_Dims_create" ))
8
16
"""
9
- function Dims_create! (nnodes:: Integer , ndims :: Integer , dims:: MPIBuffertype{T} ) where {T <: Integer }
10
- # int MPI_Dims_create(int nnodes, int ndims, int dims[])
17
+ function Dims_create (nnodes:: Integer , dims)
18
+ dims = Cint[dim for dim in dims]
11
19
@mpichk ccall ((:MPI_Dims_create , libmpi), Cint,
12
- (Cint, Cint, Ptr{Cint}), nnodes, ndims, dims)
20
+ (Cint, Cint, Ptr{Cint}), nnodes, length (dims), dims)
21
+ return dims
13
22
end
14
23
15
- function Dims_create! (nnodes:: Integer , dims:: AbstractArray{T,N} ) where {T<: Integer , N}
16
- cdims = Cint .(dims[:])
17
- ndims = length (cdims)
18
- Dims_create! (nnodes, ndims, cdims)
19
- dims[:] .= cdims
20
- end
21
24
22
25
"""
23
- comm_cart = Cart_create(comm_old::Comm, [ndims::Integer], dims, periods, reorder)
26
+ comm_cart = Cart_create(comm::Comm, dims; periodic=map(_->false, dims), reorder=false)
27
+
28
+ Create new MPI communicator with Cartesian topology information attached.
24
29
25
- Create new MPI communicator with Cartesian structure from an existent communicator.
30
+ `dims` is an array or tuple of integers specifying the number of MPI processes in each
31
+ coordinate direction, and `periodic` is an array or tuple of `Bool`s indicating the
32
+ periodicity of each coordinate. `prod(dims)` must be less than or equal to the size of
33
+ `comm`; if it is smaller than some processes are returned a null communicator.
34
+
35
+ If `reorder == false` then the rank of each process in the new group is identical to its
36
+ rank in the old group, otherwise the function may reorder the processes.
37
+
38
+ See also [`MPI.Dims_create`](@ref).
26
39
27
40
# External links
28
41
$(_doc_external (" MPI_Cart_create" ))
29
42
"""
30
- function Cart_create (comm_old:: Comm , ndims:: Integer , dims:: MPIBuffertype{Cint} , periods:: MPIBuffertype{Cint} , reorder)
43
+ function Cart_create (comm:: Comm , dims; periodic = map (_-> false , dims), reorder= false )
44
+ if ! (dims isa Array{Cint})
45
+ dims = Cint[dim for dim in dims]
46
+ end
47
+ if ! (periodic isa Array{Cint})
48
+ periodic = Cint[flag for flag in periodic]
49
+ end
50
+ length (dims) == length (periodic) || error (" dims and periodic arguments are not the same length" )
31
51
comm_cart = Comm ()
32
52
# int MPI_Cart_create(MPI_Comm comm_old, int ndims, const int dims[],
33
53
# const int periods[], int reorder, MPI_Comm *comm_cart)
34
54
@mpichk ccall ((:MPI_Cart_create , libmpi), Cint,
35
55
(MPI_Comm, Cint, Ptr{Cint}, Ptr{Cint}, Cint, Ptr{MPI_Comm}),
36
- comm_old, ndims , dims, periods , reorder, comm_cart)
56
+ comm, length (dims) , dims, periodic , reorder, comm_cart)
37
57
if comm_cart != COMM_NULL
38
58
finalizer (free, comm_cart)
39
59
end
40
60
comm_cart
41
- end
42
-
43
- function Cart_create (comm_old:: Comm , dims:: AbstractArray{T,N} , periods:: Array{T,N} , reorder) where T <: Integer where N
44
- cdims = Cint .(dims[:])
45
- cperiods = Cint .(periods[:])
46
- ndims = length (cdims)
47
- Cart_create (comm_old, ndims, cdims, cperiods, reorder)
48
- end
61
+ end
49
62
50
63
"""
51
64
rank = Cart_rank(comm::Comm, coords)
52
65
53
- Determine process rank in communicator `comm` with Cartesian structure.
54
- The `coords` array specifies the Cartesian coordinates of the process.
66
+ Determine process rank in communicator `comm` with Cartesian structure. The `coords`
67
+ array specifies the 0-based Cartesian coordinates of the process. This is the inverse of [`MPI.Cart_coords`](@ref)
55
68
56
69
# External links
57
70
$(_doc_external (" MPI_Cart_rank" ))
58
71
"""
59
- function Cart_rank (comm:: Comm , coords:: MPIBuffertype{Cint} )
72
+ function Cart_rank (comm:: Comm , coords)
73
+ if ! (coords isa Vector{Cint})
74
+ coords = Cint[coord for coord in coords]
75
+ end
60
76
rank = Ref {Cint} ()
61
77
# int MPI_Cart_rank(MPI_Comm comm, const int coords[], int *rank)
62
78
@mpichk ccall ((:MPI_Cart_rank , libmpi), Cint,
@@ -65,10 +81,6 @@ function Cart_rank(comm::Comm, coords::MPIBuffertype{Cint})
65
81
Int (rank[])
66
82
end
67
83
68
- function Cart_rank (comm:: Comm , coords:: AbstractArray{T} ) where {T <: Integer }
69
- ccoords = Cint .(coords[:])
70
- Cart_rank (comm, ccoords)
71
- end
72
84
73
85
"""
74
86
dims, periods, coords = Cart_get(comm::Comm)
@@ -112,34 +124,24 @@ function Cartdim_get(comm::Comm)
112
124
end
113
125
114
126
"""
115
- Cart_coords! (comm::Comm, rank::Integer, coords )
127
+ coords = Cart_coords(comm::Comm, rank::Integer=Comm_rank(comm) )
116
128
117
- Determine coordinates of a given process in Cartesian communicator.
129
+ Determine coordinates of a process with rank `rank` in the Cartesian communicator
130
+ `comm`. If no `rank` is provided, it returns the coordinates of the current process.
131
+
132
+ Returns an integer array of the 0-based coordinates. The inverse of [`Cart_rank`](@ref).
118
133
119
134
# External links
120
135
$(_doc_external (" MPI_Cart_coords" ))
121
136
"""
122
- function Cart_coords! (comm:: Comm , rank:: Integer , coords :: MPIBuffertype{Cint} )
137
+ function Cart_coords (comm:: Comm , rank:: Integer = Comm_rank (comm) )
123
138
maxdims = Cartdim_get (comm)
139
+ coords = Vector {Cint} (undef, maxdims)
124
140
# int MPI_Cart_coords(MPI_Comm comm, int rank, int maxdims, int coords[])
125
141
@mpichk ccall ((:MPI_Cart_coords , libmpi), Cint,
126
142
(MPI_Comm, Cint, Cint, Ptr{Cint}),
127
143
comm, rank, maxdims, coords)
128
- end
129
-
130
- """
131
- Cart_coords(comm::Comm)
132
-
133
- Determine coordinates of local process in Cartesian communicator.
134
-
135
- See also [`Cart_coords!`](@ref).
136
- """
137
- function Cart_coords (comm:: Comm )
138
- maxdims = Cartdim_get (comm)
139
- ccoords = Vector {Cint} (undef, maxdims)
140
- rank = Comm_rank (comm)
141
- Cart_coords! (comm, rank, ccoords)
142
- Int .(ccoords)
144
+ return Int .(coords)
143
145
end
144
146
145
147
"""
@@ -174,7 +176,10 @@ be kept in the generated subgrid.
174
176
# External links
175
177
$(_doc_external (" MPI_Cart_sub" ))
176
178
"""
177
- function Cart_sub (comm:: Comm , remain_dims:: MPIBuffertype{Cint} )
179
+ function Cart_sub (comm:: Comm , remain_dims)
180
+ if ! (remain_dims isa Array{Cint})
181
+ remain_dims = Cint[dim for dim in remain_dims]
182
+ end
178
183
comm_sub = Comm ()
179
184
# int MPI_Cart_sub(MPI_Comm comm, const int remain_dims[], MPI_Comm *comm_new)
180
185
@mpichk ccall ((:MPI_Cart_sub , libmpi), Cint,
@@ -185,8 +190,3 @@ function Cart_sub(comm::Comm, remain_dims::MPIBuffertype{Cint})
185
190
end
186
191
comm_sub
187
192
end
188
-
189
- function Cart_sub (comm:: Comm , remain_dims)
190
- cremain_dims = [Cint (dim) for dim in remain_dims]
191
- Cart_sub (comm, cremain_dims)
192
- end
0 commit comments