The METIS mesh file format describes a finite element mesh as a list of elements, where each element is defined by its constituent nodes. This format is consumed by theDocumentation 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.
mpmetis and m2gmetis command-line programs (via ReadMesh in programs/io.c) and corresponds directly to the eptr/eind arrays used in the C API functions METIS_PartMeshDual, METIS_PartMeshNodal, METIS_MeshToDual, and METIS_MeshToNodal. Unlike the graph file format, the mesh file does not encode connectivity between elements—METIS derives that connectivity internally.
Header line
The first non-comment line of the mesh file contains one or two integers:| Field | Meaning |
|---|---|
ne | Number of elements in the mesh |
ncon | Optional number of element-weight constraints (default 1) |
% are treated as comments and skipped. The number of nodes (nn) is not stored explicitly in the header; METIS infers it from the maximum node ID seen across all element lines.
The mesh file format does not include an explicit
etype (element type) field in the header, unlike what the manual describes for older versions. The current ReadMesh implementation in METIS 5 reads the header as ne [ncon] and derives element type from the node count per element line.Element lines
After the header, there is exactly one line per element, from element 1 to elementne. Each line contains:
- If
ncon > 0, each line starts withnconinteger element weights. - Following the weights (or at the start of the line if
ncon == 0) are the 1-based node IDs that form the element. - The number of nodes per line determines the element type implicitly.
| Element type | Nodes per element | etype constant |
|---|---|---|
| Triangle | 3 | 1 |
| Tetrahedron | 4 | 2 |
| Hexahedron | 8 | 3 |
| Quadrilateral | 4 | 4 |
ReadMesh converts by subtracting 1 from each node ID).
Example: metis.mesh
The filegraphs/metis.mesh is a triangulation of the word “METIS” (7,434 triangular elements). The first few lines are:
- Header: 7434 elements, no explicit
nconfield (defaults to 0, treated as 1 internally). - Each element line contains exactly 3 node IDs, making every element a triangle.
- Element 1 uses nodes 3708, 57, and 2094.
- Element 2 uses nodes 25, 308, and 2956.
In-memory eptr/eind arrays
The mesh file maps to two CSR arrays in the C API:| File concept | C API array | Size |
|---|---|---|
| Element start offsets | eptr | ne + 1 |
| All node IDs (0-based), concatenated | eind | total nodes across all elements |
eptr[i] is the index into eind where the node list of element i begins. The nodes of element i are eind[eptr[i]] through eind[eptr[i+1] - 1]. This is the same CSR pattern used for xadj/adjncy in graph representation.
For a pure triangular mesh with ne elements, eptr and eind look like:
ReadMesh function in programs/io.c fills these arrays directly. When calling the API without file I/O, you construct eptr and eind manually. The total length of eind equals eptr[ne], which is the total number of node references across all elements.
Dual graph vs nodal graph
METIS can derive two different graphs from the same mesh:- Dual graph
- Nodal graph
In the dual graph, each element becomes a vertex. Two element-vertices are connected by an edge if they share at least For triangular meshes,
ncommon nodes. The dual graph is used when you want to assign entire elements to processors (each element belongs to exactly one partition).ncommon = 2 means two triangles are adjacent if they share an edge (2 nodes). For tetrahedral meshes, use ncommon = 3 to connect tetrahedra that share a face.The ncommon parameter
ncommon controls how many nodes two elements must share to be considered adjacent in the dual graph. It is passed to METIS_MeshToDual and METIS_PartMeshDual.
Typical values by element type:
| Element type | Typical ncommon | Adjacency semantics |
|---|---|---|
| Triangle (3 nodes) | 2 | Adjacent if sharing an edge |
| Tetrahedron (4 nodes) | 3 | Adjacent if sharing a face |
| Hexahedron (8 nodes) | 4 | Adjacent if sharing a face |
| Quadrilateral (4 nodes) | 2 | Adjacent if sharing an edge |
ncommon = 1 makes two elements adjacent if they share any single node (corner adjacency). Setting ncommon equal to the full element size connects only identical elements, which is rarely useful.
Partitioning a mesh directly
METIS_PartMeshDual and METIS_PartMeshNodal partition a mesh without requiring you to construct the dual or nodal graph explicitly:
epart[i] holds the partition number (0-based) for element i, and npart[j] holds the partition number for node j.