mt-kahypar — (Non-official) Static & Safe Rust bindings for Mt‑KaHyPar
mt-kahypar provides an idiomatic, ownership‑aware interface to the high‑performance C++ Mt‑KaHyPar (multi‑level hypergraph partitioner) library.
mt-kahypar compiles and links Mt-KaHyPar and all its dependencies (Boost and TBB) statically inside special namespaces.
Add the dependency
[]
= "0.2"
Quick start
use mt_kahypar::*;
// 1. Build a partitioning context.
let ctx = Context::builder()
.preset(Preset::Deterministic)
.k(4) // number of blocks
.epsilon(0.03) // 3 % imbalance
.objective(Objective::Km1)
.seed(42)
.verbose(false) // change to true to print detailed logs
.build()?;
// 2. Load (or construct) the hypergraph to be partitioned.
let hg = Hypergraph::from_file("netlist.hgr", &ctx, FileFormat::HMetis)?;
// 3. Partition it.
let part = hg.partition()?;
println!("cut = {} | imbalance = {}%", part.cut(), part.imbalance()*100.0);
# Ok::<(), mt_kahypar::Error>(())
Thread‑pool control
The very first Context creation implicitly calls [initialize_default],
spawning an Mt‑KaHyPar thread pool with as many threads as logical CPUs.
If you need finer control invoke [initialize] once before any other
call:
mt_kahypar::initialize(64, /* interleaved = */ true);
Design notes & safety
- All FFI handles (
Context,Hypergraph, …) own their native resources and free them viaDrop. - Each handle stores an immutable reference to the
Contextit was created with. Mixing objects built from different contexts triggers an assertion at the point of use.
For more details see the docs of individual types below or the upstream Mt‑KaHyPar README.