Repository navigation
ParHIP: use the main KaHIP library instead of parallel/modified_kahip - #178
Merged
Merged
Conversation
…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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 inparallel/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_kahipis 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 installedlibparhip_interface_static.acould not be linked: it referencedkaffpaEfrom the copy, which was never installed.New entry point and library
interface/kaHIP_interface_mpi.h(MPI only) declareskaffpaE_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_asyncgets a matching setter.parallel_mh_asyncusedMPI_Barrier(MPI_COMM_WORLD)ininitialize; it now uses its own communicator. Without this fix, the call hangs on a sub-communicator.kahip_parallel_static(the KaHIP objects pluskaffpaE_comm< 8000 /code>). It is installed with its header.libparhip_interface_static.anow links with-lparhip_interface_static -lkahip_parallel_static(see README).libparhip_interface.socontains everything, as before.parallel/modified_kahip, ParHIP's copies of argtable3 andkaHIP_interface.h, andparallel/build.shplus 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,Edgeandsource_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-linestd::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'ssize_constraint_label_propagation::build_permuted_graphcalled ParHIP's 16-byte copy. Either way a vector is resized with the wrong element size, which is memory corruption. The same applies tovector<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.nmshows 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
ULTRAin KaHIP today, and it is no longer used.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/parhipalso matchedparhip_interface.pc. The copy of two files onto a non-directory failed, sodeploy/parhipwas never created, and the script still exited 0. The parallel executables andlibparhip.aare now copied by name. The script usesset -e, so a failing configure, build or copy step now gives a non-zero exit code. A straymakein the source directory (no Makefile there, it always failed) is removed;cmake --builddoes the build.deploy/parallel/libkahip.ais nowlibkahip_parallel_static.a, which is whatdeploy/libparhip.aneeds.cmake --installwith BUILDPYTHONMODULE wrote to/kahipbecauseCMAKE_INSTALL_PYTHONDIRwas never set. It is now a cache variable defaulting tolib/pythonX.Y/site-packagesunder 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.
kaffpa,libkahip.so,libkahip_static.aand the Python module are byte-identical to master in the MPI, NOMPI and DETERMINISTIC_PARHIP builds. All objects are identical exceptkaffpaE.cpp.oandparallel_mh_async.cpp.o(class layout and the new mode). ThekaffpaEprogram gives identical partitions to master for 1, 2 and 4 processes with fsocial, ssocial and eco.compile_withcmake.shpasses 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/, includingparhipfor the MPI variants, and the Python test passes. The Windows workflow calls CMake directly with NOMPI and does not touch the changed parts.cmake --installinto a temporary prefix works. A small program callingParHIPPartitionKWayon 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 tokaffpaE.misc/example_parhip_callbuilds and runs. A plaincmake --installwith 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.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.