This guide walks you through writing a minimal C program that distributes a graph across MPI processes and callsDocumentation 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.
ParMETIS_V3_PartKway to partition it. By the end you will have a working program you can compile and run, and an understanding of the key data structures ParMETIS expects.
Complete the installation guide before starting. You need
mpicc, libparmetis, and libmetis installed and on your compiler’s search path.The example graph
The example uses a simple 8-vertex ring graph (each vertex connected to its two neighbors), distributed evenly across 4 MPI processes—2 vertices per process. ParMETIS will assign each vertex to one of 4 partitions.Steps
Understand the key data structures
ParMETIS represents the distributed graph using three arrays that every process must populate before calling any partitioning function.
vtxdist — a global array of length nprocs + 1 that describes how vertices are distributed. Process p owns vertices vtxdist[p] through vtxdist[p+1] - 1. Every process holds an identical copy.xadj — the local CSR row-pointer array. For a process owning n vertices, xadj has length n + 1. xadj[i] is the index into adjncy where the neighbors of local vertex i begin.adjncy — the local adjacency list. Each entry is the global index of a neighboring vertex.All vertex indices in
vtxdist and adjncy use 0-based (C) numbering by default. Set numflag = 1 to use 1-based (Fortran) numbering.Compile the program
Use
mpicc to compile and link against ParMETIS and METIS. If you installed the libraries to ~/local, pass the header and library paths explicitly.Run the program
Launch the program with 4 MPI processes:You should see output similar to the following (process ordering may vary):For an 8-vertex ring with 4 partitions, the minimum edge cut is 4 (two edges per partition boundary). ParMETIS may produce different but equally valid partition assignments across runs.
Parameter reference
The full signature ofParMETIS_V3_PartKway is:
Global vertex distribution array of length
nprocs + 1. Every process must hold the same copy. Process p owns vertices vtxdist[p] to vtxdist[p+1] - 1.Local CSR row-pointer array of length
(local vertex count) + 1. xadj[i] is the start index in adjncy for local vertex i.Local adjacency list. Each entry is the global index of a neighboring vertex.
Vertex weight array of length
(local vertex count) * ncon. Pass NULL to assign uniform weight 1 to all vertices.Edge weight array of length equal to the local number of edges. Pass
NULL to assign uniform weight 1 to all edges.Controls which weights are used:
0 = no weights, 1 = edge weights only, 2 = vertex weights only, 3 = both vertex and edge weights.Indexing convention:
0 for C-style 0-based, 1 for Fortran-style 1-based.Number of balance constraints. Use
1 for a standard single-constraint partitioning.Number of partitions to create.
Array of length
nparts * ncon specifying the desired fractional weight for each partition and constraint. Values must sum to 1.0 per constraint. Pass equal fractions (1.0 / nparts) for a balanced partition.Array of length
ncon specifying the allowed load imbalance per constraint. A value of 1.05 allows up to 5% imbalance.Options array of length 3. Set
options[0] = 0 to use all defaults, or options[0] = 1 to enable options[1] (debug level) and options[2] (random seed).Output. Set by ParMETIS to the total number of edges that cross partition boundaries.
Output array of length equal to the local vertex count. After the call,
part[i] is the partition assigned to local vertex i.Pointer to the MPI communicator that includes all processes participating in the partitioning. All processes in the communicator must call
ParMETIS_V3_PartKway collectively.Next steps
API reference
Full reference documentation for
ParMETIS_V3_PartKway and all other API functions.Graph partitioning guide
Learn about geometry-assisted partitioning and multi-constraint partitioning for more complex scenarios.