Standard graph partitioning balances a single quantity—typically computational work—across partitions. In practice, parallel applications often involve multiple resources that must be balanced simultaneously: computation time, memory usage, communication bandwidth, or I/O load. METIS supports this through multi-constraint partitioning, where each vertex carries a vector of weights and the partitioner must balance every component of that weight vector across all partitions at the same time.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.
Enabling multi-constraint partitioning
Multi-constraint partitioning is enabled by settingncon > 1 in the METIS_PartGraphKway or METIS_PartGraphRecursive call. The vwgt array then stores ncon weights per vertex, laid out as a flat interleaved array:
nvtxs = 4 and ncon = 3:
BetterVBalance function in mcutil.c prefers matchings that improve multi-dimensional balance), initial partitioning (multi-constraint bisection uses McRandomBisection and McGrowBisection), and refinement (balance checks test all ncon constraints simultaneously).
The sample file
graphs/test.mgraph uses fmt=010 with ncon=2, giving each of its 766 vertices two weight values. This is a convenient file for testing multi-constraint behavior with gpmetis graphs/test.mgraph 4.Target partition weights: tpwgts
Thetpwgts array specifies the desired fraction of total weight that each partition should receive, independently per constraint. It is a flat array of size nparts * ncon:
j, the weights must sum to 1.0:
NULL for tpwgts is equivalent to setting every entry to 1.0 / nparts (equal partition weights for all constraints).
Example: 3 constraints, 4 partitions
Suppose you have 4 partitions and 3 constraints (compute, memory, I/O), and you want equal distribution across all:Imbalance tolerance: ubvec
Theubvec array specifies the maximum allowed load imbalance for each constraint independently. It has ncon elements:
ubvec[j] is the multiplicative imbalance tolerance for constraint j. A value of 1.05 means each partition is allowed to hold up to 5% more than its target weight tpwgts[i*ncon+j] of constraint j’s total weight. The values must all be greater than 1.0.
Passing NULL for ubvec sets the default tolerance: 1.001 when ncon == 1, and 1.01 when ncon > 1.
Looser tolerances (larger ubvec values) allow METIS more freedom to improve cut quality at the cost of balance. Tighter tolerances force near-perfect balance but may produce higher edge cuts.
Complete C example with ncon=2
The following example uses the two-constraint structure oftest.mgraph—each vertex has two weights—and partitions into 4 equal parts:
When to use multi-constraint partitioning
Multi-constraint partitioning is useful whenever a single weight per vertex cannot adequately model the true computational requirements. Common scenarios:Heterogeneous parallel machines
Heterogeneous parallel machines
Different processors have different compute speeds, memory capacities, or network bandwidths. Assign one constraint per resource type and set
tpwgts to reflect the relative capabilities of each processor. Partition 0 might receive a larger share of compute weight if it is faster, while all partitions receive equal memory weight.Multi-physics simulations
Multi-physics simulations
A mesh vertex may represent a point where multiple physical fields are computed (fluid, temperature, chemical species). Each field has different computational cost. Assigning one weight per field allows METIS to balance each field’s total work independently.
Memory and compute co-balance
Memory and compute co-balance
In GPU or accelerator programming, balancing computation alone may cause memory overflow on some devices. Adding a memory-usage constraint (e.g., bytes of working set per vertex) ensures that no partition exceeds device memory capacity.
Sparse matrix applications
Sparse matrix applications
A sparse matrix row may have different computational costs depending on whether it involves floating-point, integer, or boolean operations. Assigning one weight per operation type prevents load imbalance from mixed-type computations.
The UFACTOR option and balance interaction
METIS_OPTION_UFACTOR sets a global imbalance tolerance as an integer, used internally by METIS when ubvec is NULL. The relationship is:
UFACTOR is 1 for METIS_PTYPE_RB (giving ubvec = 1.001) and 30 for METIS_PTYPE_KWAY (giving ubvec = 1.03).
When you supply ubvec explicitly, UFACTOR is ignored for that call. For multi-constraint problems it is generally better to supply ubvec directly so you can control the tolerance per constraint, since different resource types may have very different sensitivity to imbalance.