8000 ParHIP: use the main KaHIP library instead of parallel/modified_kahip by schulzchristian · Pull Request #178 · KaHIP/KaHIP · GitHub
[go: up one dir, main page]

Skip to content

ParHIP: use the main KaHIP library instead of parallel/modified_kahip - #178

Merged
schulzchristian merged 6 commits into
masterfrom
parhip-use-main-kahip
Nov 17, 2026
Merged

schulzchristian merged 6 commits into
masterfrom
parhip-use-main-kahip

Conversation

@schulzchristian
Copy link
Copy Markdown
Member

Summary

ParHIP's initial partitioning now calls the main KaHIP library through a new MPI entry point, kaffpaE_comm. This removes the modified KaHIP copy in parallel/modified_kahip (about 35,000 lines). The PR also fixes a memory-corruption bug that came from ParHIP and KaHIP types sharing names, and two problems in the build and install scripts.

Motivation

parallel/modified_kahip is a 2017 copy of KaHIP that ParHIP used for initial partitioning (KaFFPaE on the coarsest graph). Improvements to KaHIP since then never reached ParHIP. Two partitioners with the same class names were linked into one binary, and the copy had to be maintained separately. The installed libparhip_interface_static.a could not be linked: it referenced kaffpaE from the copy, which was never installed.

New entry point and library

  • interface/kaHIP_interface_mpi.h (MPI only) declares
    kaffpaE_comm(n, vwgt, xadj, adjcwgt, adjncy, nparts, imbalance, suppress_output, graph_partitioned, time_limit, seed, mode, single_individual, communicator, edgecut, balance, part).
    It runs KaFFPaE on the processes of communicator, set up as in the kaffpaE program (balance_configuration). It works on a duplicate of the communicator, so its messages never mix with those of the caller.
  • single_individual: each process computes one partition with the given mode and the best one is returned, with no evolution and no exchange. parallel_mh_async gets a matching setter.
  • parallel_mh_async used MPI_Barrier(MPI_COMM_WORLD) in initialize; it now uses its own communicator. Without this fix, the call hangs on a sub-communicator.
  • New static library kahip_parallel_static (the KaHIP objects plus kaffpaE_comm< 8000 /code>). It is installed with its header. libparhip_interface_static.a now links with -lparhip_interface_static -lkahip_parallel_static (see README). libparhip_interface.so contains everything, as before.
  • Removed: parallel/modified_kahip, ParHIP's copies of argtable3 and kaHIP_interface.h, and parallel/build.sh plus the ParHIP SCons files. These referred to the removed copy and to argtable versions that no longer exist.

Namespace change and the Edge/Node bug

ParHIP and KaHIP both define random_functions, node_ordering, mpi_tools, stop_rule, configuration, timer, Node, Edge and source_target_pair, mostly with different definitions. When both are linked into one binary, the linker merges their weak symbols.

The worst case was Edge, which is 16 bytes in ParHIP and 8 bytes in KaHIP. Both sides emit an out-of-line std::vector<Edge>::_M_default_append, and only one copy survives. On master, ParHIP's graph readers (e.g. parallel_graph_io::readGraphBinary) call the copy compiled for the 8-byte type from modified_kahip. With the main library linked instead, KaHIP's size_constraint_label_propagation::build_permuted_graph called ParHIP's 16-byte copy. Either way a vector is resized with the wrong element size, which is memory corruption. The same applies to vector<Node>. Master also shared the random number generator state (random_functions::m_mt) between the two sides.

The ParHIP versions of these types now live in namespace parhip, with using-declarations so that the ParHIP code is unchanged. nm shows 28 symbols defined on both sides on master. On this branch only 6 remain, all standard-library instantiations on identical types (vector<int>, mt19937, ...).

Preset mapping

Every ParHIP initial partitioning algorithm is mapped explicitly onto a KaHIP mode. The old copy's mode 6 was "ultrafast social", but 6 is ULTRA in KaHIP today, and it is no longer used.

ParHIP preset IP algorithm KaHIP call
ultrafastsocial, ultrafastmesh, fastsocial, fastmesh KAFFPAEULTRAFASTSNW FASTSOCIAL, single_individual
ecosocial, ecomesh KAFFPAEFASTSNW FASTSOCIAL (evolutionary, time limit as before)
(command line) KAFFPAESTRONG / ECO / FAST STRONG / ECO / FAST
(command line) KAFFPAEECOSNW / STRONGSNW ECOSOCIAL / STRONGSOCIAL

The eco presets keep their wall-clock limit for the evolutionary algorithm. The DETERMINISTIC_PARHIP build is unchanged and still passes time limit 0.

Script and install fixes

  • compile_withcmake.sh: cp parhip* ./deploy/parhip also matched parhip_interface.pc. The copy of two files onto a non-directory failed, so deploy/parhip was never created, and the script still exited 0. The parallel executables and libparhip.a are now copied by name. The script uses set -e, so a failing configure, build or copy step now gives a non-zero exit code. A stray make in the source directory (no Makefile there, it always failed) is removed; cmake --build does the build. deploy/parallel/libkahip.a is now libkahip_parallel_static.a, which is what deploy/libparhip.a needs.
  • Python module install: outside scikit-build, cmake --install with BUILDPYTHONMODULE wrote to /kahip because CMAKE_INSTALL_PYTHONDIR was never set. It is now a cache variable defaulting to lib/pythonX.Y/site-packages under the install prefix. The package is installed as in the wheel (kahip/ with the extension and __init__.py). The scikit-build rule used for the PyPI wheels is unchanged.

Checks

Run on Linux with gcc 13 and Open MPI 5.0.9; the CI variants also with clang 23.

  • Main KaHIP unchanged: kaffpa, libkahip.so, libkahip_static.a and the Python module are byte-identical to master in the MPI, NOMPI and DETERMINISTIC_PARHIP builds. All objects are identical except kaffpaE.cpp.o and parallel_mh_async.cpp.o (class layout and the new mode). The kaffpaE program gives identical partitions to master for 1, 2 and 4 processes with fsocial, ssocial and eco.
  • Builds: MPI with ParHIP, NOMPI, and DETERMINISTIC_PARHIP all build. The first two commits were also built on their own; the later ones change only ParHIP sources, scripts and docs and were built as part of the branch head. compile_withcmake.sh passes with gcc for "", BUILDPYTHONMODULE, DETERMINISTIC_PARHIP and NOMPI, and with clang for "", BUILDPYTHONMODULE and DETERMINISTIC_PARHIP. In each variant, all expected files are in deploy/, including parhip for the MPI variants, and the Python test passes. The Windows workflow calls CMake directly with NOMPI and does not touch the changed parts.
  • Install and link: cmake --install into a temporary prefix works. A small program calling ParHIPPartitionKWay on a 64x64 grid links and runs (1 and 4 processes) three ways: against the installed static libraries (-lparhip_interface_static -lkahip_parallel_static), against the shared library, and via pkg-config. All three give the same cut. On master, the static library alone fails with an undefined reference to kaffpaE. misc/example_parhip_call builds and runs. A plain cmake --install with BUILDPYTHONMODULE puts the package in <prefix>/lib/python3.9/site-packages/kahip, and it imports and partitions. A locally built wheel (pip wheel .) has the same file list as master's wheel, and its module imports and partitions.
  • ParHIP smoke test, old (master) vs new. Graphs: PGPgiantcompo, cnr-2000, coAuthorsDBLP, delaunay_n18, rgg_n_2_18 and web-Google, with 1, 4 and 16 processes, k = 8 and 32, seed 1. The ratios below are geometric means of new/old.
    • Normal build, presets ultrafastsocial, fastsocial, ultrafastmesh and fastmesh (144 runs): cut 0.995, time 0.881. Runs with balance above 1.03: 2 old, 3 new.
    • DETERMINISTIC_PARHIP build, all six presets including ecosocial and ecomesh (216 runs): cut 0.995, time 0.863. Eco presets alone: cut 0.993, time 0.786. Runs with balance above 1.03: 5 old, 4 new.
    • All imbalanced runs, old and new, are cnr-2000 with k = 32. The largest cut changes are also on cnr-2000 (ratios from 0.48 to 1.16); the other graphs are within a few percent.
  • Determinism: repeating the new runs gives identical cuts, balances and partitions in 144 of 144 runs (normal build, non-eco presets) and 216 of 216 runs (DETERMINISTIC_PARHIP, all presets).
  • Duplicate symbols: see above (28 shared symbols on master, 6 standard-library instantiations here).

Notes

ParHIP's results change: initial partitioning now runs the current kaffpa instead of the 2017 copy, and ParHIP no longer shares its random number generator with KaHIP. The checks above are smoke-level on small graphs. The full quality and scaling comparison against master on large graphs and many processes has not been run yet.

…municator

New MPI-only interface interface/kaHIP_interface_mpi.h with kaffpaE_comm,
built into the installed static library kahip_parallel_static.
parallel_mh_async gets a single-individual mode (each process computes one
partition, the best is returned) and its barrier now uses its own
communicator instead of MPI_COMM_WORLD.
The classes random_functions, node_ordering, mpi_tools, stop_rule,
configuration and timer and the structs Node, Edge and source_target_pair
exist in both ParHIP and KaHIP, mostly with different definitions (Edge is
16 bytes in ParHIP and 8 bytes in KaHIP). Linked into one binary, the weak
symbols of the two sides were merged, e.g. one out-of-line
std::vector<Edge>::_M_default_append served both Edge types. Moving the
ParHIP versions into namespace parhip (with using-declarations, so the
ParHIP code is unchanged) keeps the symbols apart when ParHIP links the
KaHIP library. In particular ParHIP no longer shares the random number
generator state of KaHIP.
…odified_kahip

Initial partitioning now calls kaffpaE_comm from kahip_parallel_static
instead of the modified KaHIP copy in parallel/modified_kahip, which is
removed together with ParHIP's copies of argtable3 and kaHIP_interface.h.

Every ParHIP initial partitioning algorithm is mapped explicitly onto a
KaHIP mode. The former ULTRAFASTSOCIAL mode of the modified copy (used by
the ultrafast and fast presets) becomes FASTSOCIAL with
single_individual, i.e. each process computes one partition and the best
one is taken; mode 6 is ULTRA in KaHIP and is not used.

parhip_interface_static now carries its dependency on kahip_parallel_static,
so the installed static library links with -lkahip_parallel_static.
…ld SCons ParHIP build

compile_withcmake.sh deploys libkahip_parallel_static.a as
deploy/parallel/libkahip.a (needed by deploy/libparhip.a) and
kaHIP_interface_mpi.h. parallel/build.sh and the SCons files of the ParHIP
interface referred to the removed modified KaHIP copy and to argtable
versions that no longer exist.
The pattern parhip* also matched parhip_interface.pc, so cp of two files
onto ./deploy/parhip failed and the parhip binary never reached deploy/.
The parallel executables and libparhip.a are now copied by name. The
script stops with a non-zero exit code when a step fails (set -e), so CI
notices broken builds or copies. The 'make' call in the source directory,
which had no Makefile and always failed, is removed; the build is done by
cmake --build.
Outside scikit-build, the install rule of the Python module used
CMAKE_INSTALL_PYTHONDIR, which was never set, so cmake --install wrote
to /kahip. CMAKE_INSTALL_PYTHONDIR is now a cache variable defaulting to
lib/pythonX.Y/site-packages relative to the install prefix, and the
package is installed as in the wheel (kahip/ with the extension and
__init__.py). The scikit-build (wheel) install rule is unchanged.
@schulzchristian
schulzchristian merged commit dea3c4e into master Nov 17, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

0