175
175
struct Unweighted
176
176
end
177
177
Base. cconvert (:: Type{Ptr{Cint}} , :: Unweighted ) = API. MPI_UNWEIGHTED[]
178
+ """
179
+ MPI.UNWEIGHTED :: MPI.Unweighted
180
+
181
+ This is used to indicate that a graph topology is unweighted. It can be supplied
182
+ as an argument to [`Dist_graph_create_adjacent`](@ref),
183
+ [`Dist_graph_create`](@ref), and [`Dist_graph_neighbors!`](@ref); or obtained as
184
+ the return value from [`Dist_graph_neighbors`](@ref).
185
+ """
178
186
const UNWEIGHTED = Unweighted ()
179
187
180
188
struct WeightsEmpty
@@ -183,16 +191,19 @@ Base.cconvert(::Type{Ptr{Cint}}, ::WeightsEmpty) = API.MPI_WEIGHTS_EMPTY[]
183
191
const WEIGHTS_EMPTY = WeightsEmpty ()
184
192
185
193
"""
186
- graph_comm = Dist_graph_create_adjacent(comm::Comm, sources::Vector{Cint}, destinations::Vector{Cint}; source_weights::Union{Vector{Cint}, Unweighted, WeightsEmpty}=UNWEIGHTED, destination_weights::Union{Vector{Cint}, Unweighted, WeightsEmpty}=UNWEIGHTED, reorder=false, infokws...)
194
+ graph_comm = Dist_graph_create_adjacent(comm::Comm,
195
+ sources::Vector{Cint}, destinations::Vector{Cint};
196
+ source_weights::Union{Vector{Cint}, Unweighted, WeightsEmpty}=UNWEIGHTED, destination_weights::Union{Vector{Cint}, Unweighted, WeightsEmpty}=UNWEIGHTED,
197
+ reorder=false, infokws...)
187
198
188
199
Create a new communicator from a given directed graph topology, described by local incoming and outgoing edges on an existing communicator.
189
200
190
201
# Arguments
191
202
- `comm::Comm`: The communicator on which the distributed graph topology should be induced.
192
203
- `sources::Vector{Cint}`: The local, incoming edges on the rank of the calling process.
193
204
- `destinations::Vector{Cint}`: The local, outgoing edges on the rank of the calling process.
194
- - `source_weights::Union{Vector{Cint}, Unweighted, WeightsEmpty}=MPI.UNWEIGHTED `: The edge weights of the local, incoming edges.
195
- - `destinations_weights::Union{Vector{Cint}, Unweighted, WeightsEmpty}=MPI.UNWEIGHTED `: The edge weights of the local, outgoing edges.
205
+ - `source_weights::Union{Vector{Cint}, Unweighted, WeightsEmpty}`: The edge weights of the local, incoming edges. The default is [`MPI.UNWEIGHTED`](@ref) .
206
+ - `destinations_weights::Union{Vector{Cint}, Unweighted, WeightsEmpty}`: The edge weights of the local, outgoing edges. The default is [`MPI.UNWEIGHTED`](@ref) .
196
207
- `reorder::Bool=false`: If set true, then the MPI implementation can reorder the source and destination indices.
197
208
198
209
# Example
@@ -232,7 +243,7 @@ Create a new communicator from a given directed graph topology, described by inc
232
243
- `degrees::Vector{Cint}`: An array with the number of outgoing edges for each entry in the sources array.
233
244
- `destinations::Vector{Cint}`: An array containing with lenght of the sum of the entries in the degrees array
234
245
describing the ranks towards the edges point.
235
- - `weights::Union{Vector{Cint}, Unweighted, WeightsEmpty}=MPI.UNWEIGHTED `: The edge weights of the specified edges.
246
+ - `weights::Union{Vector{Cint}, Unweighted, WeightsEmpty}`: The edge weights of the specified edges. The default is [`MPI.UNWEIGHTED`](@ref) .
236
247
- `reorder::Bool=false`: If set true, then the MPI implementation can reorder the source and destination indices.
237
248
238
249
# Example
@@ -291,32 +302,49 @@ function Dist_graph_neighbors_count(graph_comm::Comm)
291
302
end
292
303
293
304
"""
294
- Dist_graph_neighbors!(graph_comm::Comm, sources::Vector{Cint}, source_weights::Vector{Cint}, destinations::Vector{Cint}, destination_weights::Vector{Cint})
305
+ Dist_graph_neighbors!(graph_comm::MPI.Comm,
306
+ sources::Vector{Cint}, source_weights::Union{Vector{Cint}, Unweighted},
307
+ destinations::Vector{Cint}, destination_weights::Union{Vector{Cint}, Unweighted},
308
+ )
309
+ Dist_graph_neighbors!(graph_comm::Comm, sources::Vector{Cint}, destinations::Vector{Cint})
295
310
296
- Return the neighbors and edge weights of the calling process in a distributed graph topology.
311
+ Query the neighbors and edge weights (optional) of the calling process in a
312
+ distributed graph topology.
297
313
298
314
# Arguments
299
315
- `graph_comm::Comm`: The communicator of the distributed graph topology.
300
- - `sources::Vector{Cint}`: A preallocated vector, which will be filled with the ranks
301
- of the processes whose edges pointing towards the calling process. The
302
- length is exactly the indegree returned by [`MPI.Dist_graph_neighbors_count`](@ref).
303
- - `source_weights::Vector{Cint}`: A preallocated vector, which will be filled with the weights
304
- associated to the edges pointing towards the calling process. The
305
- length is exactly the indegree returned by [`MPI.Dist_graph_neighbors_count`](@ref).
306
- - `destinations::Vector{Cint}`: A preallocated vector, which will be filled with the ranks
307
- of the processes towards which the edges of the calling process point. The
308
- length is exactly the outdegree returned by [`MPI.Dist_graph_neighbors_count`](@ref).
309
- - `destination_weights::Vector{Cint}`: A preallocated vector, which will be filled with the weights
310
- associated to the edges of the outgoing edges of the calling process point. The
311
- length is exactly the outdegree returned by [`MPI.Dist_graph_neighbors_count`](@ref).
316
+ - `sources`: A preallocated `Vector{Cint}`, which will be filled with the ranks
317
+ of the processes whose edges pointing towards the calling process.
318
+ The length is exactly the indegree returned by
319
+ [`MPI.Dist_graph_neighbors_count`](@ref).
320
+ - `source_weights`: A preallocated `Vector{Cint}`, which will be filled with the
321
+ weights associated to the edges pointing towards the calling
322
+ process. The length is exactly the indegree returned by
323
+ [`MPI.Dist_graph_neighbors_count`](@ref). Alternatively,
324
+ [`MPI.UNWEIGHTED`](@ref) can be used if weight information is not required.
325
+ - `destinations`: A preallocated `Vector{Cint}``, which will be filled with the
326
+ ranks of the processes towards which the edges of the calling
327
+ process point. The length is exactly the outdegree returned by
328
+ [`MPI.Dist_graph_neighbors_count`](@ref).
329
+ - `destination_weights`: A preallocated `Vector{Cint}`, which will be filled
330
+ with the weights associated to the edges of the outgoing edges of
331
+ the calling process point. The length is exactly the outdegree
332
+ returned by [`MPI.Dist_graph_neighbors_count`](@ref). Alternatively,
333
+ [`MPI.UNWEIGHTED`](@ref) can be used if weight information is not required.
312
334
313
335
# Example
314
- Let us assume the following graph `0 <-3-> 1 -4-> 2`, then the process with rank 1 will require to
315
- preallocate a sources vector of length 1 and a destination vector of length 2. The call will fill
316
- the vectors as follows:
336
+ Let us assume the following graph:
337
+ ```
338
+ rank 0 <-----> rank 1 ------> rank 2
339
+ weights: 3 4
340
+ ```
341
+ then then the process with rank 1 will need to preallocate `sources` and
342
+ `source_weights` as vectors of length 1, and a `destinations` and `destination_weights` as vectors of length 2.
343
+
344
+ The call will fill the vectors as follows:
317
345
318
346
```julia-repl
319
- julia> Dist_graph_neighbors!(graph_comm, sources, source_weights, destinations, destination_weights);
347
+ julia> MPI. Dist_graph_neighbors!(graph_comm, sources, source_weights, destinations, destination_weights);
320
348
julia> sources
321
349
[0]
322
350
julia> source_weights
@@ -327,63 +355,41 @@ julia> destination_weights
327
355
[3,4]
328
356
```
329
357
330
- Note that the edge between ranks 0 and 1 can have a different weight depending on wether it is the
331
- incoming edge "`(0,1)"` or the outgoing one "`(1,0)"`.
358
+ Note that the edge between ranks 0 and 1 can have a different weight depending
359
+ on whether it is the incoming edge `0 --> 1` or the outgoing one `0 <-- 1`.
360
+
361
+ # See also
362
+ - [`Dist_graph_neighbors`](@ref)
332
363
333
364
# External links
334
365
$(_doc_external (" MPI_Dist_graph_neighbors" ))
335
366
"""
336
- function Dist_graph_neighbors! (graph_comm:: Comm , sources:: Vector{Cint} , source_weights:: Vector{Cint} , destinations:: Vector{Cint} , destination_weights:: Vector{Cint} )
367
+ function Dist_graph_neighbors! (graph_comm:: Comm ,
368
+ sources:: Vector{Cint} , source_weights:: Union{Vector{Cint}, Unweighted} ,
369
+ destinations:: Vector{Cint} , destination_weights:: Union{Vector{Cint}, Unweighted} ,
370
+ )
371
+ @assert source_weights isa Unweighted || length (sources) == length (source_weights)
372
+ @assert destination_weights isa Unweighted || length (destinations) == length (destination_weights)
373
+
337
374
# int MPI_Dist_graph_neighbors(MPI_Comm comm,
338
375
# int maxindegree, int sources[], int sourceweights[],
339
376
# int maxoutdegree, int destinations[], int destweights[])
340
377
API. MPI_Dist_graph_neighbors (graph_comm,
341
378
length (sources), sources, source_weights,
342
- length (destinations), destinations, destination_weights)
379
+ length (destinations), destinations, destination_weights,
380
+ )
381
+ return sources, source_weights, destinations, destination_weights
343
382
end
383
+ Dist_graph_neighbors! (graph_comm:: Comm , sources:: Vector{Cint} , destinations:: Vector{Cint} ) =
384
+ Dist_graph_neighbors! (graph_comm, sources:: Vector{Cint} , UNWEIGHTED, destinations:: Vector{Cint} , UNWEIGHTED)
344
385
345
- """
346
- Dist_graph_neighbors!(graph_comm::Comm, sources::Vector{Cint}, destinations::Vector{Cint})
347
-
348
- Return the neighbors of the calling process in a distributed graph topology without edge weights.
349
-
350
- # Arguments
351
- - `graph_comm::Comm`: The communicator of the distributed graph topology.
352
- - `sources::Vector{Cint}`: A preallocated vector, which will be filled with the ranks of the
353
- processes whose edges pointing towards the calling process. The
354
- length is exactly the indegree returned by [`MPI.Dist_graph_neighbors_count`](@ref).
355
- - `destinations::Vector{Cint}`: A preallocated vector, which will be filled with the ranks
356
- of the processes towards which the edges of the calling process point. The
357
- length is exactly the outdegree returned by [`MPI.Dist_graph_neighbors_count`](@ref).
358
-
359
- # Example
360
- Let us assume the following graph `0 <--> 1 --> 2`, then the process with rank 1 will require to
361
- preallocate a sources vector of length 1 and a destination vector of length 2. The call will fill
362
- the vectors as follows:
363
-
364
- ```julia-repl
365
- julia> Dist_graph_neighbors!(graph_comm, sources, destinations);
366
- julia> sources
367
- [0]
368
- julia> destinations
369
- [0,2]
370
- ```
371
-
372
- # External links
373
- $(_doc_external (" MPI_Dist_graph_neighbors" ))
374
- """
375
- function Dist_graph_neighbors! (graph_comm:: Comm , sources:: Vector{Cint} , destinations:: Vector{Cint} )
376
- source_weights = Array {Cint} (undef,0 )
377
- destination_weights = Array {Cint} (undef,0 )
378
- Dist_graph_neighbors! (graph_comm, sources:: Vector{Cint} , source_weights, destinations:: Vector{Cint} , destination_weights)
379
- end
380
386
381
387
"""
382
- Dist_graph_neighbors(graph_comm::Comm)
388
+ sources, source_weights, destinations, destination_weights = Dist_graph_neighbors(graph_comm::MPI. Comm)
383
389
384
390
Return `(sources, source_weights, destinations, destination_weights)` of the graph
385
391
communicator `graph_comm`. For unweighted graphs `source_weights` and `destination_weights`
386
- are `nothing` .
392
+ are returned as [`MPI.UNWEIGHTED`](@ref) .
387
393
388
394
This function is a wrapper around [`MPI.Dist_graph_neighbors_count`](@ref) and
389
395
[`MPI.Dist_graph_neighbors!`](@ref) that automatically handles the allocation of the result
@@ -396,10 +402,9 @@ function Dist_graph_neighbors(graph_comm::Comm)
396
402
if weighted
397
403
source_weights = Vector {Cint} (undef, indegree)
398
404
destination_weights = Vector {Cint} (undef, outdegree)
399
- Dist_graph_neighbors! (graph_comm, sources, source_weights, destinations, destination_weights)
400
- return sources, source_weights, destinations, destination_weights
401
405
else
402
- Dist_graph_neighbors! (graph_comm, sources, destinations)
403
- return sources, nothing , destinations, nothing
406
+ source_weights = UNWEIGHTED
407
+ destination_weights = UNWEIGHTED
404
408
end
409
+ return Dist_graph_neighbors! (graph_comm, sources, source_weights, destinations, destination_weights)
405
410
end
0 commit comments