Skip to main content

Crate mt_kahypar

Crate mt_kahypar 

Source
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 via Drop.
  • Each handle stores an immutable reference to the Context it 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.
ContextBuilder
Fluent builder for Context. Construct via Context::builder.
Error
Library‑level error wrapper returned by most fallible API calls.
Hypergraph
A (Hyper)graph to be partitioned.
PartitionedHypergraph
A partitioned hypergraph.
TargetGraph
Target graph. See sys::mt_kahypar_map.

Enums§

FileFormat
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 initialize but automatically picks num_threads equal to the number of logical CPUs.

Type Aliases§

Result