METIS provides two graph partitioning functions that implement the multilevel paradigm: coarsen the graph, compute an initial partition on the coarsened graph, then refine and uncoarsen back to the original.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/KarypisLab/METIS/llms.txt
Use this file to discover all available pages before exploring further.
METIS_PartGraphKway computes a direct k-way partition in a single multilevel pass, while METIS_PartGraphRecursive builds the partition by repeatedly bisecting subgraphs. Both accept the same parameter list, support multi-constraint balancing, and return a partition assignment for every vertex.
CSR Graph Format
Both functions expect the graph in Compressed Sparse Row (CSR) format:xadj— array of sizenvtxs + 1. Vertexi’s neighbors are stored inadjncy[xadj[i] .. xadj[i+1]-1].adjncy— flat array of all adjacency lists concatenated. Total length equals the sum of all degrees, i.e., twice the number of undirected edges.
METIS_PartGraphKway
Partitions a graph intonparts parts using multilevel k-way partitioning. Produces high-quality partitions for larger values of k and supports both edge-cut and communication-volume objectives.
Number of vertices in the graph. Passed by pointer.
Number of balancing constraints. For a standard single-weight problem, pass
1. For multi-constraint problems, vertex weights have ncon components each.CSR row-pointer array of size
nvtxs + 1. xadj[i] gives the starting index in adjncy for vertex i.CSR column-index array. Stores all adjacency lists back-to-back. Length equals
xadj[nvtxs].Vertex weights array of size
nvtxs * ncon. For multi-constraint problems, the ncon weights for vertex i are stored at vwgt[i*ncon .. i*ncon+ncon-1]. Pass NULL for unit weights (all vertices weight 1 per constraint).Vertex sizes used when minimizing the total communication volume (
METIS_OBJTYPE_VOL). Array of size nvtxs. Pass NULL to use unit sizes or when minimizing edge cut.Edge weights array of the same length as
adjncy. adjwgt[j] is the weight of the edge stored at adjncy[j]. Pass NULL for unit edge weights.Number of desired partitions. Passed by pointer.
Target partition weights. Array of size
nparts * ncon. Entry tpwgts[i*ncon+j] specifies the desired fraction of the total weight of constraint j to be assigned to partition i. The values for each constraint must sum to 1.0. Pass NULL for equal-weight partitioning (each part receives 1.0 / nparts of the total weight).Load imbalance tolerance. Array of size
ncon. ubvec[j] is the maximum allowed ratio of actual to target weight for constraint j. Must be greater than 1.0. Pass NULL to use the UFACTOR-based default: 1.030 for k-way (UFACTOR=30), 1.001 for recursive bisection with a single constraint (UFACTOR=1), or 1.010 for recursive bisection with multiple constraints (UFACTOR=10).Options array of size
METIS_NOPTIONS (40). Initialize with METIS_SetDefaultOptions before setting individual entries. See the Options Reference.Output: the edge cut (or communication volume when
METIS_OPTION_OBJTYPE = METIS_OBJTYPE_VOL) of the computed partition.Output: partition assignment array of size
nvtxs. part[i] is the partition number (0-based) assigned to vertex i. Must be pre-allocated by the caller.METIS_PartGraphRecursive
Partitions a graph intonparts parts using multilevel recursive bisection. At each level the graph is bisected; the two halves are recursively bisected until nparts parts are reached. Typically produces better results than k-way for small nparts (up to about 8).
METIS_PartGraphKway. The differences are algorithmic:
- Uses FM 2-way refinement rather than greedy k-way refinement.
- The initial coarsened partition is obtained via a grow-bisection strategy (single constraint) or random bisection (multi-constraint).
METIS_OPTION_OBJTYPEmust beMETIS_OBJTYPE_CUT; volume minimization is not supported.
When to Use Each Function
- Use METIS_PartGraphKway when
- Use METIS_PartGraphRecursive when
- Partitioning into a large number of parts (roughly 8 or more)
- Minimizing communication volume (
METIS_OBJTYPE_VOL) as well as edge cut - Requiring contiguous partitions (
METIS_OPTION_CONTIG = 1) - Requiring minimization of subdomain connectivity (
METIS_OPTION_MINCONN = 1) - Performance is important and quality for large
kis sufficient
Complete Example: Partitioning a 5-Vertex Graph
Multi-Constraint Partitioning
When vertices carry multiple weights (e.g., memory and compute load), setncon > 1 and provide a flat vwgt array:
Additional Graph Functions
METIS_ComputeVertexSeparator
Computes a vertex separator of a graph — a set of vertices whose removal makes the graph disconnected into two roughly equal halves. Primarily used internally by ParMETIS.Number of vertices.
CSR row-pointer array of size
nvtxs + 1.CSR column-index array.
Vertex weights of size
nvtxs. Pass NULL for unit weights.Options array initialized with
METIS_SetDefaultOptions.Output: the weight of the computed separator.
Output: three-way assignment array of size
nvtxs. Values are 0 (left partition), 1 (right partition), or 2 (separator).METIS_CacheFriendlyReordering
Computes a cache-friendly reordering of vertices within each partition to improve memory access patterns during subsequent computation. Primarily used by the DGL graph learning framework.Number of vertices. Passed by value (not a pointer).
CSR row-pointer array.
CSR column-index array.
Partition assignment from a prior call to
METIS_PartGraphKway or METIS_PartGraphRecursive.Output: mapping from old vertex IDs to new IDs after reordering. Must be pre-allocated to size
nvtxs.