Expand description
§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
[dependencies]
mt-kahypar = "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);§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.
Modules§
- sys
- The raw C bindings for Mt-KaHyPar.
Structs§
- Context
- A partitioning context bundles all algorithmic parameters.
- Context
Builder - Fluent builder for
Context. Construct viaContext::builder. - Error
- Library‑level error wrapper returned by most fallible API calls.
- Hypergraph
- A (Hyper)graph to be partitioned.
- Partitioned
Hypergraph - A partitioned hypergraph.
- Target
Graph - Target graph. See
sys::mt_kahypar_map.
Enums§
- File
Format - Supported on‑disk formats for
Hypergraph::from_file. - Objective
- Objective functions.
- Preset
- High‑level preset recipes shipped with Mt‑KaHyPar.
- Status
- Mirror of
mt_kahypar_status_t.
Functions§
- initialize
- Manual global initialization (optional) of thread pools.
- initialize_
default - Like
initializebut automatically picksnum_threadsequal to the number of logical CPUs.