ParMETIS distributes a graph across MPI processes so that each process owns a contiguous range of vertices and only the adjacency data for those vertices. Before you call any ParMETIS function, you must build four core arrays —Documentation Index
Fetch the complete documentation index at: https://mintlify.com/KarypisLab/ParMETIS/llms.txt
Use this file to discover all available pages before exploring further.
vtxdist, xadj, adjncy, and optionally vwgt and adjwgt — and populate them on every process.
CSR format
ParMETIS stores the local adjacency structure in Compressed Sparse Row (CSR) format, the same format used throughout the sparse linear algebra community. Two arrays together describe the edges:xadj— row pointers of length(nvtxs + 1).xadj[i]is the index intoadjncywhere the neighbor list of local vertexibegins, andxadj[i+1] - xadj[i]is the degree of vertexi.xadj[0]is always 0 andxadj[nvtxs]equals the total number of local edges.adjncy— flat adjacency list of length equal to the number of local edges. Each entry is the global index of a neighboring vertex.
Example: 4-vertex undirected graph
Consider a 4-vertex graph with these edges: 0–1, 0–3, 1–2, 1–3, 2–3.- Vertex 0 uses
adjncy[xadj[0]..xadj[1]-1]=adjncy[0..1]={1, 3}. - Vertex 1 uses
adjncy[xadj[1]..xadj[2]-1]=adjncy[2..4]={0, 2, 3}. - Vertex 2 uses
adjncy[xadj[2]..xadj[3]-1]=adjncy[5..6]={1, 3}. - Vertex 3 uses
adjncy[xadj[3]..xadj[4]-1]=adjncy[7..9]={0, 1, 2}.
adjncy entries are global vertex indices, even for vertices owned by the same process. When numflag = 0 (the default), indices are 0-based.Distributed representation with vtxdist
In a parallel run, the full graph is split across nprocs processes. The vtxdist array tells every process the global vertex range owned by each process:
vtxdisthas lengthnprocs + 1.- Process
powns global verticesvtxdist[p]throughvtxdist[p+1] - 1. - Every process holds an identical copy of
vtxdist.
xadj and adjncy covering only its local vertices, but using global indices in adjncy.
Example: 4-vertex graph on 2 processes
xadj on each process always starts at 0 and counts edges relative to the local vertex list. The adjncy entries remain global vertex IDs.
Vertex and edge weights
ParMETIS supports optional integer weights on vertices and edges, plus a communication-size hint for vertices.- Vertex weights (vwgt)
- Edge weights (adjwgt)
- Vertex size (vsize)
The ParMETIS balances partitions so that the total vertex weight in each partition is within
vwgt array stores integer vertex weights. It has length nvtxs * ncon, where ncon is the number of balance constraints. For the common case of a single constraint (ncon = 1), vwgt[i] is the weight of local vertex i.ubvec of the target fraction specified by tpwgts.The wgtflag parameter
wgtflag is a bitmask that tells ParMETIS which weight arrays you are providing:
wgtflag | Vertex weights (vwgt) | Edge weights (adjwgt) |
|---|---|---|
0 | Not used | Not used |
1 | Not used | Used |
2 | Used | Not used |
3 | Used | Used |
The numflag parameter
numflag controls the indexing convention used throughout vtxdist, xadj, and adjncy:
numflag = 0— C-style 0-based indexing (default). Vertex indices run from0tognvtxs - 1.numflag = 1— Fortran-style 1-based indexing. Vertex indices run from1tognvtxs.vtxdist,xadj, and all entries inadjncymust be incremented by 1.
Multi-constraint vertex weights
When you setncon > 1, each vertex carries ncon weight values — one per balance constraint. The values are stored interleaved in vwgt: vertex i has weights at vwgt[i * ncon] through vwgt[i * ncon + ncon - 1].
c must satisfy the ubvec[c] tolerance relative to the target fractions in tpwgts[p * ncon + c].
Internal graph_t structure
Internal graph_t structure
The ParMETIS copies your input arrays into this structure at the start of each API call via
graph_t structure in libparmetis/struct.h stores the distributed graph internally. The key fields mirror the external API arrays:SetupGraph(). The free_xadj, free_adjncy, free_vwgt, and free_adjwgt flags track whether ParMETIS owns the allocations and should free them.Memory layout tips
Memory layout tips
- Allocate
vtxdistwithnprocs + 1elements and broadcast it so every process has the same values. - Allocate
xadjwithnvtxs + 1elements on each process.xadj[0]must be 0. - Allocate
adjncywithxadj[nvtxs]elements (the total local edge count). - If you provide
vwgt, allocatenvtxs * nconelements. If you provideadjwgt, allocatexadj[nvtxs]elements. - ParMETIS does not modify your input arrays except when
numflag = 1, in which case it converts to 0-based numbering on entry and back to 1-based on return.