MCPcopy
hub / github.com/dmlc/dgl / metis_partition_assignment

Function metis_partition_assignment

python/dgl/partition.py:278–397  ·  view source on GitHub ↗

This assigns nodes to different partitions with Metis partitioning algorithm. When performing Metis partitioning, we can put some constraint on the partitioning. Current, it supports two constrants to balance the partitioning. By default, Metis always tries to balance the number of node

(
    g, k, balance_ntypes=None, balance_edges=False, mode="k-way", objtype="cut"
)

Source from the content-addressed store, hash-verified

276
277
278def metis_partition_assignment(
279 g, k, balance_ntypes=None, balance_edges=False, mode="k-way", objtype="cut"
280):
281 """This assigns nodes to different partitions with Metis partitioning algorithm.
282
283 When performing Metis partitioning, we can put some constraint on the partitioning.
284 Current, it supports two constrants to balance the partitioning. By default, Metis
285 always tries to balance the number of nodes in each partition.
286
287 * `balance_ntypes` balances the number of nodes of different types in each partition.
288 * `balance_edges` balances the number of edges in each partition.
289
290 To balance the node types, a user needs to pass a vector of N elements to indicate
291 the type of each node. N is the number of nodes in the input graph.
292
293 After the partition assignment, we construct partitions.
294
295 Parameters
296 ----------
297 g : DGLGraph
298 The graph to be partitioned
299 k : int
300 The number of partitions.
301 balance_ntypes : tensor
302 Node type of each node
303 balance_edges : bool
304 Indicate whether to balance the edges.
305 mode : str, "k-way" or "recursive"
306 Whether use multilevel recursive bisection or multilevel k-way paritioning.
307 objtype : str, "cut" or "vol"
308 Set the objective as edge-cut minimization or communication volume minimization. This
309 argument is used by the Metis algorithm.
310
311 Returns
312 -------
313 a 1-D tensor
314 A vector with each element that indicates the partition ID of a vertex.
315 """
316 assert mode in (
317 "k-way",
318 "recursive",
319 ), "'mode' can only be 'k-way' or 'recursive'"
320 assert (
321 g.idtype == F.int64
322 ), "IdType of graph is required to be int64 for now."
323 # METIS works only on symmetric graphs.
324 # The METIS runs on the symmetric graph to generate the node assignment to partitions.
325 start = time.time()
326 sym_gidx = _CAPI_DGLMakeSymmetric_Hetero(g._graph)
327 sym_g = DGLGraph(gidx=sym_gidx)
328 print(
329 "Convert a graph into a bidirected graph: {:.3f} seconds, peak memory: {:.3f} GB".format(
330 time.time() - start, get_peak_mem()
331 )
332 )
333 vwgt = []
334 # To balance the node types in each partition, we can take advantage of the vertex weights
335 # in Metis. When vertex weights are provided, Metis will tries to generate partitions with

Callers 4

metis_partitionFunction · 0.85
__init__Method · 0.85
partition_graphFunction · 0.85
metis_permFunction · 0.85

Calls 11

DGLGraphClass · 0.85
get_peak_memFunction · 0.85
formatMethod · 0.80
appendMethod · 0.80
asnumpyMethod · 0.80
tousertensorMethod · 0.80
num_nodesMethod · 0.45
astypeMethod · 0.45
in_degreesMethod · 0.45
shapeMethod · 0.45
cpuMethod · 0.45

Tested by

no test coverage detected