Skip to content

[KaHIPApplication] Introduction of KaHIPApplication for high-quality graph partitioning#14453

Open
loumalouomega wants to merge 55 commits into
KratosMultiphysics:masterfrom
loumalouomega:kahip/add-kahip-application
Open

[KaHIPApplication] Introduction of KaHIPApplication for high-quality graph partitioning#14453
loumalouomega wants to merge 55 commits into
KratosMultiphysics:masterfrom
loumalouomega:kahip/add-kahip-application

Conversation

@loumalouomega

@loumalouomega loumalouomega commented May 22, 2026

Copy link
Copy Markdown
Member

name: ✨ Feature
about: Introduction of KaHIPApplication for high-quality graph partitioning


📝 Description

Logo

This Pull Request introduces the KaHIPApplication, a new partitioning tool for Kratos Multiphysics based on the Karlsruhe High Quality Partitioning (KaHIP) framework. It is designed as a high-performance, drop-in alternative to the existing MetisApplication, offering superior edge-cut reduction for parallel computations.

Comparison

The resulñts, at least in these examples, are similar to the one obtained with Metis. Feel free to test with more complex meshes.

Cube

image

Quad

image

Why KaHIP?

While METIS is a standard in the industry, KaHIP provides several key advantages for our users:

  • Efficiency: The eco configuration is comparable in speed to METIS but typically produces 5–20% fewer edge cuts on FEM meshes.
  • Flexibility: The strong configuration allows for even lower edge cuts for users who prioritize communication efficiency over partitioning time.
  • Licensing: KaHIP is MIT licensed, providing a friendly legal framework for various project types.
  • In-Memory Workflow: Supports MPI Scatterv to distribute data directly in-memory, bypassing the need for intermediate .mdpa files on disk.

Basic usage example

Using the new high-level Modeler is straightforward:

import KratosMultiphysics as KM
import KratosMultiphysics.KaHIPApplication as KaHIP

model = KM.Model()
model_part = model.CreateModelPart("Main")
model_part.AddNodalSolutionStepVariable(KM.PARTITION_INDEX)

settings = KM.Parameters("""{
    "model_part_name": "Main",
    "input_filename":  "my_mesh",
    "partition_in_memory": true,
    "kahip_settings": {
        "preconfiguration": "eco",
        "imbalance": 0.03
    }
}""")

modeler = KaHIP.KaHIPPartitioningModeler(model, settings)
modeler.SetupModelPart()

Technical Details & Prerequisites

  • Dependencies: Requires KaHIP ≥ v3.25 (included in-tree by default) and OpenMP.

  • Build Configuration: Can be enabled via add_app in your configure script. Supports optional 64-bit edge indices for massive meshes:

    -DKAHIP_64BIT=ON

Key changes

  1. Drop-in Compatibility: Includes processes like KaHIPDivideHeterogeneousInputProcess that mirror the interface of their Metis counterparts.
  2. Advanced Modeler: Introduces KaHIPPartitioningModeler, a high-level API that handles the entire "partition-and-read" workflow in a single step.
  3. CSR Integration: Automatically converts mesh nodal connectivity to CSR format for processing.
  4. Boundary Synchronization: Optional synchronization to ensure conditions and constraints are co-located with their parent elements.
  5. Customizable: Full access to KaHIP's preconfigurations (fast, eco, strong, etc.) and imbalance controls via Kratos Parameters.

Validation

I have included comprehensive tests covering both serial and MPI workflows. You can run them using the following commands:

# Python tests
python -m pytest applications/KaHIPApplication/tests/

# MPI tests
mpirun -n 4 python applications/KaHIPApplication/tests/test_KaHIPApplication_mpi.py

# C++ Unit tests
ctest -R KaHIPApplication

🆕 Changelog

  • Core Application: Introduced KaHIPApplication, providing high-quality graph partitioning based on the Karlsruhe High Quality Partitioning (KaHIP) framework.
  • Partitioning Processes:
    • KaHIPDivideHeterogeneousInputProcess: A serial partitioner designed as a drop-in replacement for MetisDivideHeterogeneousInputProcess.
    • KaHIPDivideHeterogeneousInputInMemoryProcess: An MPI-aware process for in-memory partitioning and distribution via MPI_Scatterv, eliminating the need for intermediate files.
  • High-Level API: Added KaHIPPartitioningModeler, a streamlined modeler to automate the "partition-and-read" workflow in a single Python call.
  • KaHIP Integration:
    • Integrated KaHIP v3.25 (in-tree build support under external_libraries/KaHIP).
    • Support for all KaHIP preconfigurations: fast, eco, strong, fastsocial, ecosocial, and strongsocial.
    • Support for configurable node weight imbalance and random seeds.
  • Features:
    • Automatic conversion of Kratos mesh connectivity to CSR (Compressed Sparse Row) format.
    • Boundary Synchronization: Logic to ensure conditions, geometries, and master-slave constraints are co-located with their parent elements.
    • 64-bit Support: Added CMake option -DKAHIP_64BIT=ON for partitioning meshes with more than (2^{31}) edges.
  • Testing Suite:
    • Comprehensive Python tests for both Serial and MPI execution.
    • C++ unit tests for core partitioning logic.
    • Integration with kratos_run_tests.py.

loumalouomega and others added 30 commits May 22, 2026 08:47
auto-merge was automatically disabled May 23, 2026 16:06

Pull request was converted to draft

loumalouomega and others added 19 commits May 27, 2026 10:29
This commit introduces a new test case in the form of a .mdpa file, which includes nodes, elements, conditions, and conditional data for a 2D quadrilateral mesh. The test case is designed to validate the functionality of the KaHIPApplication with respect to handling 2D mesh structures.
…d pre-generated plots; add new quality comparison images for cube and quads meshes.
@loumalouomega loumalouomega marked this pull request as ready for review May 28, 2026 10:49
@loumalouomega loumalouomega requested a review from a team as a code owner May 28, 2026 10:49
@loumalouomega loumalouomega enabled auto-merge May 28, 2026 10:50
@loumalouomega

Copy link
Copy Markdown
Member Author

Okay, this is ready, I tested and the fast mode is not significantly better than Metis, but is MPI ready...

@loumalouomega

Copy link
Copy Markdown
Member Author

Okay, this is ready for review

@roigcarlo

Copy link
Copy Markdown
Member

Looks good also from my side, not very into MPI nowadays, but if you need something added to the images I can add it

@loumalouomega

Copy link
Copy Markdown
Member Author

Looks good also from my side, not very into MPI nowadays, but if you need something added to the images I can add it

I added automatic download in case not defined the lib, That's why I could add it to CI, and looks like it works. The library is small so the penalty of compiling is not that high, but if you prefer we can add it to the images

@pooyan-dadvand

Copy link
Copy Markdown
Member

@KratosMultiphysics/technical-committee agrees with the addition of the library and assigns @roigcarlo to review it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Applications Feature Parallel-MPI Distributed memory parallelism for HPC / clusters

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants