### Install Mt-KaHyPar C Library Source: https://github.com/kahypar/mt-kahypar/blob/master/README.md Installs the Mt-KaHyPar C library system-wide. Use sudo or administrator privileges for system-wide installation. ```sh make install-mtkahypar # use sudo (Linux & MacOS) or run shell as an administrator (Windows) to install system-wide ``` -------------------------------- ### Include Shared Library Installation Setup Source: https://github.com/kahypar/mt-kahypar/blob/master/CMakeLists.txt Includes a CMake script to set up the installation for shared libraries. This is conditionally executed only on non-Windows systems when shared libraries are enabled. ```cmake if(NOT WIN32 AND BUILD_SHARED_LIBS) # library installation target include(SetupInstallation) endif() ``` -------------------------------- ### Install Dependencies on Linux Source: https://github.com/kahypar/mt-kahypar/blob/master/README.md Install required libraries on Ubuntu systems using apt-get. ```bash sudo apt-get install libtbb-dev libhwloc-dev ``` -------------------------------- ### Partition a Hypergraph with the C Library Source: https://github.com/kahypar/mt-kahypar/blob/master/README.md Demonstrates the full lifecycle of partitioning a hypergraph using the C interface, including initialization, context setup, loading, partitioning, and resource cleanup. ```cpp #include #include #include #include #include #include int main(int argc, char* argv[]) { mt_kahypar_error_t error{}; // Initialize mt_kahypar_initialize( std::thread::hardware_concurrency() /* use all available cores */, true /* activate interleaved NUMA allocation policy */ ); // Setup partitioning context mt_kahypar_context_t* context = mt_kahypar_context_from_preset(DEFAULT); // In the following, we partition a hypergraph into two blocks // with an allowed imbalance of 3% and optimize the connective metric (KM1) mt_kahypar_set_partitioning_parameters(context, 2 /* number of blocks */, 0.03 /* imbalance parameter */, KM1 /* objective function */); mt_kahypar_set_seed(42 /* seed */); // Enable logging mt_kahypar_status_t status = mt_kahypar_set_context_parameter(context, VERBOSE, "1", &error); assert(status == SUCCESS); // Load Hypergraph for DEFAULT preset mt_kahypar_hypergraph_t hypergraph = mt_kahypar_read_hypergraph_from_file("path/to/hypergraph/file", context, HMETIS /* file format */, &error); if (hypergraph.hypergraph == nullptr) { std::cout << error.msg << std::endl; std::exit(1); } // Partition Hypergraph mt_kahypar_partitioned_hypergraph_t partitioned_hg = mt_kahypar_partition(hypergraph, context, &error); if (partitioned_hg.partitioned_hg == nullptr) { std::cout << error.msg << std::endl; std::exit(1); } // Extract Partition auto partition = std::make_unique( mt_kahypar_num_hypernodes(hypergraph)); mt_kahypar_get_partition(partitioned_hg, partition.get()); // Extract Block Weights auto block_weights = std::make_unique(2); mt_kahypar_get_block_weights(partitioned_hg, block_weights.get()); // Compute Metrics const double imbalance = mt_kahypar_imbalance(partitioned_hg, context); const int km1 = mt_kahypar_km1(partitioned_hg); // Output Results std::cout << "Partitioning Results:" << std::endl; std::cout << "Imbalance = " << imbalance << std::endl; std::cout << "Km1 = " << km1 << std::endl; std::cout << "Weight of Block 0 = " << block_weights[0] << std::endl; std::cout << "Weight of Block 1 = " << block_weights[1] << std::endl; mt_kahypar_free_context(context); mt_kahypar_free_hypergraph(hypergraph); mt_kahypar_free_partitioned_hypergraph(partitioned_hg); } ``` -------------------------------- ### Install Dependencies on Windows Source: https://github.com/kahypar/mt-kahypar/blob/master/README.md Update the MSYS2 package database and install required build tools. ```bash pacman -Syu ``` ```bash pacman -S make mingw-w64-x86_64-cmake mingw-w64-x86_64-gcc mingw-w64-x86_64-python3 mingw-w64-x86_64-tbb ``` -------------------------------- ### Install MtKaHyPar CLI Source: https://github.com/kahypar/mt-kahypar/blob/master/CMakeLists.txt Configures the installation of the Mt-KaHyPar Command Line Interface (CLI) target. It renames the executable to 'mtkahypar' and specifies its runtime destination and component for installation. ```cmake if(KAHYPAR_INSTALL_CLI) # CLI installation target include(GNUInstallDirs) set_target_properties(MtKaHyPar-CLI PROPERTIES OUTPUT_NAME mtkahypar) install(TARGETS MtKaHyPar-CLI RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} RENAME mtkahypar COMPONENT MtKaHyPar_CLI) add_custom_target(install-mtkahypar-cli ${CMAKE_COMMAND} -DBUILD_TYPE=${CMAKE_BUILD_TYPE} -DCMAKE_INSTALL_COMPONENT=MtKaHyPar_CLI -P ${CMAKE_BINARY_DIR}/cmake_install.cmake DEPENDS MtKaHyPar-CLI) endif() ``` -------------------------------- ### Install Dependencies on MacOS Source: https://github.com/kahypar/mt-kahypar/blob/master/README.md Install required libraries on MacOS using Homebrew. ```bash brew install tbb hwloc ``` -------------------------------- ### Install Mt-KaHyPar Python Package Source: https://github.com/kahypar/mt-kahypar/blob/master/README.md Use pip to install the Mt-KaHyPar package on Linux or MacOS. ```bash pip install mtkahypar ``` -------------------------------- ### Set Default Installation Prefix for Unix Source: https://github.com/kahypar/mt-kahypar/blob/master/CMakeLists.txt Sets the default installation prefix to '/usr/' if the project is the top-level CMake project and running on a Unix-like system with the default installation prefix not yet defined by the user. This ensures a consistent installation location. ```cmake if(${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_CURRENT_SOURCE_DIR}) if(UNIX AND CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT) # set default installation prefix if not user-defined set(CMAKE_INSTALL_PREFIX "/usr/" CACHE STRING "" FORCE) endif() endif() ``` -------------------------------- ### Include CPack Setup for Debian Packaging Source: https://github.com/kahypar/mt-kahypar/blob/master/CMakeLists.txt Includes a CMake script to set up CPack for building Debian packages. This is conditionally executed if the KAHYPAR_BUILD_DEBIAN_PACKAGE option is enabled. ```cmake if(KAHYPAR_BUILD_DEBIAN_PACKAGE) # packaging via CPack include(SetupCPack) endif() ``` -------------------------------- ### Build Python Wheel and Install TBB Source: https://github.com/kahypar/mt-kahypar/blob/master/CMakeLists.txt Enables the build of a Python wheel and installs necessary targets, including the 'mtkahypar_python' library and TBB components, to a specified directory. It includes a fatal error check if TBB is not built or its directory is not specified. ```cmake if(KAHYPAR_PYTHON AND DEFINED SKBUILD_PROJECT_NAME) # build python wheel if(NOT KAHYPAR_DOWNLOAD_TBB OR NOT DEFINED KAHYPAR_TBB_DIR) message(FATAL_ERROR "TBB must be built from source for python wheel and KAHYPAR_TBB_DIR must be specified.") endif() message(STATUS "Python wheel build enabled, installing TBB to ${KAHYPAR_TBB_DIR}") install(TARGETS mtkahypar_python DESTINATION . COMPONENT MtKaHyPar_Python) install(TARGETS tbb tbbmalloc DESTINATION ${KAHYPAR_TBB_DIR} COMPONENT MtKaHyPar_Python) endif() ``` -------------------------------- ### Integrate Mt-KaHyPar via CMake (find_package) Source: https://github.com/kahypar/mt-kahypar/blob/master/README.md Integrates the Mt-KaHyPar library into a CMake project using find_package, assuming the library is installed on the system. ```cmake find_package(MtKaHyPar) if(MtKaHyPar_FOUND) add_executable(example example.cc) target_link_libraries(example MtKaHyPar::mtkahypar) endif() ``` -------------------------------- ### Initialize and Partition a Hypergraph Source: https://github.com/kahypar/mt-kahypar/blob/master/README.md Initializes the library, sets partitioning parameters, and performs a hypergraph partition. ```python import mtkahypar # Initialize mtk = mtkahypar.initialize(multiprocessing.cpu_count()) # use all available cores # Setup partitioning context context = mtk.context_from_preset(mtkahypar.PresetType.DEFAULT) # In the following, we partition a hypergraph into two blocks # with an allowed imbalance of 3% and optimize the connectivity metric context.set_partitioning_parameters( 2, # number of blocks 0.03, # imbalance parameter mtkahypar.Objective.KM1) # objective function mtkahypar.set_seed(42) # seed context.logging = True # Load hypergraph from file (assumes hMetis file format per default) hypergraph = mtk.hypergraph_from_file("path/to/hypergraph/file", context) # Partition hypergraph partitioned_hg = hypergraph.partition(context) # Output metrics print("Partition Stats:") print("Imbalance = " + str(partitioned_hg.imbalance(context))) print("km1 = " + str(partitioned_hg.km1())) print("Block Weights:") for i in partitioned_hg.blocks(): print(f"Weight of Block {i} = {partitioned_hg.block_weight(i)}") ``` -------------------------------- ### Build Mt-KaHyPar from Source Source: https://github.com/kahypar/mt-kahypar/blob/master/README.md Commands to clone the repository, configure the build with CMake, and compile the application. ```bash git clone https://github.com/kahypar/mt-kahypar.git ``` ```bash mkdir build && cd build ``` ```bash export CMAKE_GENERATOR="MSYS Makefiles" ``` ```bash cmake .. --preset= ``` ```bash make MtKaHyPar -j ``` -------------------------------- ### Run Mt-KaHyPar Partitioning Source: https://github.com/kahypar/mt-kahypar/blob/master/README.md Execute the MtKaHyPar binary to partition a hypergraph with specific parameters. ```bash ./mt-kahypar/application/MtKaHyPar -h --preset-type=default -t <# threads> -k <# blocks> -e -o km1 ``` -------------------------------- ### Create Objective Function Folder Source: https://github.com/kahypar/mt-kahypar/blob/master/mt-kahypar/partition/refinement/gains/README.md Create a dedicated folder for your objective function within `partition/refinement/gains` to house all relevant gain computation techniques. ```c++ Create a folder for your objective function in ```partition/refinement/gains```. We will later add here all relevant gain computation techniques. ``` -------------------------------- ### Configure pybind11 and Build Python Module Source: https://github.com/kahypar/mt-kahypar/blob/master/python/CMakeLists.txt Uses FetchContent to download pybind11 and defines the mtkahypar_python module target with specific link and visibility properties. ```cmake FetchContent_Declare( pybind11 SYSTEM EXCLUDE_FROM_ALL GIT_REPOSITORY https://github.com/pybind/pybind11.git GIT_TAG ${KAHYPAR_PYBIND11_VERSION} ) FetchContent_MakeAvailable(pybind11) pybind11_add_module(mtkahypar_python module.cpp) target_link_libraries(mtkahypar_python PRIVATE MtKaHyPar-LibraryBuildSources) set_target_properties(mtkahypar_python PROPERTIES COMPILE_FLAGS "-fvisibility=hidden") # rename mtkahypar_python target output to mtkahypar set_target_properties(mtkahypar_python PROPERTIES OUTPUT_NAME mtkahypar) ``` -------------------------------- ### Flow-Based Refinement: Drop Hyperedge Function Source: https://github.com/kahypar/mt-kahypar/blob/master/mt-kahypar/partition/refinement/gains/README.md Implement this function to remove irrelevant hyperedges from the flow network. For example, for the cut metric, hyperedges not containing nodes from block_0 or block_1 can be removed. ```cpp template static bool dropHyperedge(const PartitionedHypergraph& phg, const HyperedgeID he, const PartitionID block_0, const PartitionID block_1); ``` -------------------------------- ### Fetch and Configure googletest for Testing (Conditional) Source: https://github.com/kahypar/mt-kahypar/blob/master/CMakeLists.txt Conditionally fetches the googletest framework if KAHYPAR_ENABLE_TESTING is enabled. It sets up testing infrastructure and links necessary libraries. ```cmake if (KAHYPAR_ENABLE_TESTING) FetchContent_Declare( googletest EXCLUDE_FROM_ALL SYSTEM GIT_REPOSITORY https://github.com/google/googletest.git GIT_TAG ${KAHYPAR_GOOGLETEST_VERSION} ) FetchContent_MakeAvailable(googletest) include(gmock) enable_testing() add_library(MtKaHyPar-Test INTERFACE) target_link_libraries(MtKaHyPar-Test INTERFACE gmock gtest gtest_main) endif() ``` -------------------------------- ### Integrate Mt-KaHyPar via CMake (FetchContent) Source: https://github.com/kahypar/mt-kahypar/blob/master/README.md Integrates the Mt-KaHyPar library into a CMake project using FetchContent, downloading it directly from GitHub. ```cmake FetchContent_Declare( MtKaHyPar EXCLUDE_FROM_ALL GIT_REPOSITORY https://github.com/kahypar/mt-kahypar GIT_TAG v1.5 ) FetchContent_MakeAvailable(MtKaHyPar) add_executable(example example.cc) target_link_libraries(example MtKaHyPar::mtkahypar) ``` -------------------------------- ### Copy Test Files with CMake Source: https://github.com/kahypar/mt-kahypar/blob/master/tests/interface/CMakeLists.txt Copies test instances and configuration files to the build directory. Ensure these files are available for testing. ```cmake file(COPY test_instances DESTINATION ${CMAKE_CURRENT_BINARY_DIR}) file(COPY test_preset.ini DESTINATION ${CMAKE_CURRENT_BINARY_DIR}) ``` -------------------------------- ### Run Mt-KaHyPar with Custom Objective Source: https://github.com/kahypar/mt-kahypar/blob/master/mt-kahypar/partition/refinement/gains/README.md Execute Mt-KaHyPar using the command-line parameter `-o `. Verify the objective function's value in the partitioning result section. Debug mode assertions may fail initially. ```bash At this point, you can run Mt-KaHyPar with your new objective function by adding the command line parameter ```-o ```. At the end of the partitioning process, you should see the value of your new objective function (directly under the *Partitioning Result* section). However, running Mt-KaHyPar in debug mode will fail due to failing assertions. ``` -------------------------------- ### Download or Find TBB Library Source: https://github.com/kahypar/mt-kahypar/blob/master/CMakeLists.txt Handles the Intel Threading Building Blocks (TBB) library. It can either download TBB from GitHub if KAHYPAR_DOWNLOAD_TBB is enabled, or find a system-installed version. It also supports static linking of TBB. ```cmake if(KAHYPAR_DOWNLOAD_TBB) # Download TBB library FetchContent_Declare( TBB EXCLUDE_FROM_ALL SYSTEM GIT_REPOSITORY https://github.com/oneapi-src/oneTBB.git GIT_TAG ${KAHYPAR_TBB_VERSION} GIT_SHALLOW FALSE # TBB seems to assume that a git repo is present ) block() if(KAHYPAR_STATIC_LINK_TBB) set(BUILD_SHARED_LIBS OFF) else() set(BUILD_SHARED_LIBS ON) endif() FetchContent_MakeAvailable(TBB) endblock() else() if(KAHYPAR_STATIC_LINK_TBB) message(WARNING "Static linking of TBB requires -DKAHYPAR_DOWNLOAD_TBB=On. Proceeding with dynamic linking.") endif() # Find system TBB library find_package(TBB 2021.5 COMPONENTS tbb tbbmalloc) if(NOT TBB_FOUND) message(FATAL_ERROR " TBB library not found or current TBB version is too old. Install TBB on your system or add -DKAHYPAR_DOWNLOAD_TBB=On to the cmake build command.") endif() get_target_property(KAHYPAR_TBB_INCLUDE_DIRS TBB::tbb INTERFACE_INCLUDE_DIRECTORIES) message(STATUS "TBB Version: ${TBB_VERSION_MAJOR}.${TBB_VERSION_MINOR}, TBB Include: ${KAHYPAR_TBB_INCLUDE_DIRS}") endif() target_link_libraries(MtKaHyPar-Include INTERFACE TBB::tbb TBB::tbbmalloc) ``` -------------------------------- ### Import Python Module Source: https://github.com/kahypar/mt-kahypar/blob/master/README.md Initial import statement for the Python interface. ```py import multiprocessing ``` -------------------------------- ### Check Configuration Compatibility Source: https://github.com/kahypar/mt-kahypar/blob/master/README.md Verifies if a hypergraph is compatible with a specific preset before attempting to partition. ```python context = mtk.context_from_preset(mtkahypar.PresetType.QUALITY) # Check if the hypergraph is compatible with the QUALITY preset if hypergraph.is_compatible(context.preset): partitioned_hg = hypergraph.partition(context) ``` -------------------------------- ### Fetch and Include CLI11 Dependency Source: https://github.com/kahypar/mt-kahypar/blob/master/CMakeLists.txt Fetches the CLI11 library from GitHub and makes it available for linking. This is used for command-line argument parsing. ```cmake FetchContent_Declare( cli11 QUIET EXLUDE_FROM_ALL GIT_REPOSITORY https://github.com/CLIUtils/CLI11.git GIT_TAG ${KAHYPAR_CLI11_VERSION} ) FetchContent_MakeAvailable(cli11) target_link_libraries(MtKaHyPar-Include INTERFACE CLI11::CLI11) ``` -------------------------------- ### Configure Bipartitioning Policy Source: https://github.com/kahypar/mt-kahypar/blob/master/mt-kahypar/partition/refinement/gains/README.md In `partition/refinement/gains/bipartitioning_policy.h`, add your objective function's `GainPolicy` type to switch statements in `useCutNetSplitting(...)` and `nonCutEdgeMultiplier(...)`. ```c++ ```partition/refinement/gains/bipartitioning_policy.h```: Add the ```GainPolicy``` type of your new objective function to the switch statements in ```useCutNetSplitting(...)``` and ```nonCutEdgeMultiplier(...)```. You can copy one of the existing parameters of an other objective function for now. An explanation how to configure these functions properly follows later. ``` -------------------------------- ### Build Python Library Source: https://github.com/kahypar/mt-kahypar/blob/master/README.md Builds the Python shared library from source. ```sh make mtkahypar_python ``` -------------------------------- ### Build mt-kahypar Library (Shared or Static) Source: https://github.com/kahypar/mt-kahypar/blob/master/lib/CMakeLists.txt Configures the build for the mt-kahypar library, choosing between SHARED or STATIC based on the BUILD_SHARED_LIBS variable. Links against MtKaHyPar-LibraryBuildSources and sets interface include directories. ```cmake if(BUILD_SHARED_LIBS) add_library(mtkahypar SHARED mtkahypar.cpp) else() add_library(mtkahypar STATIC mtkahypar.cpp) endif() target_link_libraries(mtkahypar PRIVATE MtKaHyPar-LibraryBuildSources) target_include_directories(mtkahypar INTERFACE $) ``` -------------------------------- ### Configure pyproject.toml for Python Wheel Source: https://github.com/kahypar/mt-kahypar/blob/master/CMakeLists.txt Configures the 'pyproject.toml' file from a template for Python wheel builds. This step is performed if Python support is enabled and the TBB directory is defined. ```cmake if(KAHYPAR_SETUP_PYTHON AND DEFINED KAHYPAR_TBB_DIR) # preparation for python wheel configure_file(${CMAKE_CURRENT_SOURCE_DIR}/pyproject.toml.in ${CMAKE_CURRENT_SOURCE_DIR}/pyproject.toml @ONLY) endif() ``` -------------------------------- ### Configure Compile and Link Options by Build Type Source: https://github.com/kahypar/mt-kahypar/blob/master/CMakeLists.txt Sets compiler and linker flags based on the build configuration (Release, RelWithDebInfo, Debug). Includes optimization levels and debugging symbols. ```cmake target_compile_options(MtKaHyPar-BuildFlags INTERFACE $<$:-O3> $<$:-g3 -UNDEBUG> # keep assertions activated $<$:-g3 -fno-omit-frame-pointer>) target_link_options(MtKaHyPar-BuildFlags INTERFACE $<$:-fno-omit-frame-pointer>) ``` -------------------------------- ### Map String Description to Enum Source: https://github.com/kahypar/mt-kahypar/blob/master/mt-kahypar/partition/refinement/gains/README.md In `partition/context_enum_classes.cpp`, create mappings between string descriptions and your new enum types for `Objective` and `GainPolicy`. ```c++ ```partition/context_enum_classes.cpp```: Create a mapping between a string description and your new enum type in ```operator<< (std::ostream& os, const Objective& objective)```, ```operator<< (std::ostream& os, const GainPolicy& type)``` and ```objectiveFromString(const std::string& obj)``` ``` -------------------------------- ### Fetch WHFC Dependency Source: https://github.com/kahypar/mt-kahypar/blob/master/CMakeLists.txt Fetches the WHFC library from GitHub. This dependency is placed in a specific source directory. ```cmake FetchContent_Populate( WHFC QUIET EXLUDE_FROM_ALL GIT_REPOSITORY https://github.com/larsgottesbueren/WHFC.git GIT_TAG ${KAHYPAR_WHFC_TAG} SOURCE_DIR external_tools/WHFC ) ``` -------------------------------- ### Configure Include Directories for External Tools Source: https://github.com/kahypar/mt-kahypar/blob/master/CMakeLists.txt Adds include directories for external tools, specifically kahypar-shared-resources and the general external tools directory. ```cmake target_include_directories(MtKaHyPar-Include INTERFACE ${CMAKE_CURRENT_BINARY_DIR}/external_tools/kahypar-shared-resources ${CMAKE_CURRENT_BINARY_DIR}/external_tools) ``` -------------------------------- ### Define Executable and Link Libraries Source: https://github.com/kahypar/mt-kahypar/blob/master/tests/CMakeLists.txt Defines the 'mtkahypar_tests' executable and links it against necessary libraries. This is typically used for test executables. ```cmake add_executable(mtkahypar_tests run_tests.cpp) target_link_libraries(mtkahypar_tests MtKaHyPar-BuildSources MtKaHyPar-Test) ``` -------------------------------- ### Configure Project Subdirectories Source: https://github.com/kahypar/mt-kahypar/blob/master/mt-kahypar/partition/CMakeLists.txt Adds project subdirectories to the build process. ```cmake add_subdirectory(preprocessing) add_subdirectory(coarsening) add_subdirectory(refinement) add_subdirectory(initial_partitioning) add_subdirectory(mapping) add_subdirectory(registries) ``` -------------------------------- ### Add Google Mock Test with CMake Source: https://github.com/kahypar/mt-kahypar/blob/master/tests/interface/CMakeLists.txt Defines a Google Mock test executable and links it with the required libraries. This is used for unit testing the mt-kahypar interface. ```cmake add_gmock_test(mtkahypar_interface_test interface_test.cc) target_link_libraries(mtkahypar_interface_test MtKaHyPar-LibraryBuildSources MtKaHyPar-Test mtkahypar) ``` -------------------------------- ### Add Subdirectories for Build Targets Source: https://github.com/kahypar/mt-kahypar/blob/master/CMakeLists.txt Includes build configurations from subdirectories for Python bindings, tests, and core components like application, tools, lib, and mt-kahypar. ```cmake if(KAHYPAR_PYTHON) if (NOT BUILD_SHARED_LIBS) message(SEND_ERROR "Python interface must be built as shared library. To do so, add -DBUILD_SHARED_LIBS=On to your cmake command.") endif() add_subdirectory(python) endif() if (KAHYPAR_ENABLE_TESTING) add_subdirectory(tests) endif() add_subdirectory(mt-kahypar/application) add_subdirectory(tools) add_subdirectory(lib) add_subdirectory(mt-kahypar) ``` -------------------------------- ### Add MtKaHyPar-CLI Executable Source: https://github.com/kahypar/mt-kahypar/blob/master/mt-kahypar/application/CMakeLists.txt Creates an additional executable for a command-line interface (CLI) variant of MtKaHyPar. This is useful for scenarios where installation-time renaming is not feasible. It links against the same MtKaHyPar-BuildSources library. ```cmake add_executable(MtKaHyPar-CLI mt_kahypar.cc) target_link_libraries(MtKaHyPar-CLI MtKaHyPar-BuildSources) ``` -------------------------------- ### Fetch and Configure parlay Dependency (Conditional) Source: https://github.com/kahypar/mt-kahypar/blob/master/CMakeLists.txt Conditionally fetches the parlaylib library if KAHYPAR_DISABLE_PARLAY is not set. It adds parlay's include directory and a compile option. ```cmake if(NOT KAHYPAR_DISABLE_PARLAY) FetchContent_Populate( parlay QUIET EXLUDE_FROM_ALL GIT_REPOSITORY https://github.com/cmuparlay/parlaylib.git GIT_TAG ${KAHYPAR_PARLAY_TAG} SOURCE_DIR external_tools/parlay ) target_include_directories(MtKaHyPar-Include INTERFACE ${CMAKE_CURRENT_BINARY_DIR}/external_tools/parlay/include) target_compile_options(MtKaHyPar-BuildFlags INTERFACE -DPARLAY_TBB) endif() ``` -------------------------------- ### Compile C Program with g++ Source: https://github.com/kahypar/mt-kahypar/blob/master/README.md Command to compile a C++ program linking against the Mt-KaHyPar library. ```sh g++ -std=c++17 -DNDEBUG -O3 your_program.cc -o your_program -lmtkahypar ``` -------------------------------- ### Define and Assign Utility Sources in CMake Source: https://github.com/kahypar/mt-kahypar/blob/master/mt-kahypar/utils/CMakeLists.txt Groups utility source files into a variable and assigns them to multiple interface targets. ```cmake set(UtilSources timer.cpp delete.cpp memory_tree.cpp ) target_sources(MtKaHyPar-Sources INTERFACE ${UtilSources}) target_sources(MtKaHyPar-ToolsSources INTERFACE ${UtilSources}) ``` -------------------------------- ### Check Hypergraph Compatibility Source: https://github.com/kahypar/mt-kahypar/blob/master/README.md Verifies if a loaded hypergraph is compatible with a specific preset before attempting to partition. ```cpp mt_kahypar_context_t* context = mt_kahypar_context_from_preset(QUALITY); // Check if the hypergraph is compatible with the QUALITY preset if ( mt_kahypar_check_compatibility(hypergraph, QUALITY) ) { mt_kahypar_partitioned_hypergraph_t partitioned_hg = mt_kahypar_partition(hypergraph, context, &error); } ``` -------------------------------- ### Determine GrowT Usage Source: https://github.com/kahypar/mt-kahypar/blob/master/CMakeLists.txt Sets a flag to indicate whether GrowT should be used. GrowT requires specific SSE instructions and is enabled based on several configuration options. ```cmake if (NOT KAHYPAR_DISABLE_GROWT AND KAHYPAR_ENABLE_STEINER_TREE_METRIC AND KAHYPAR_X86 AND KAHYPAR_ENABLE_EXTENDED_INSTRUCTIONS AND BUILTIN_POPCNT) # growt requires SSE instructions set(KAHYPAR_USE_GROWT TRUE) else() set(KAHYPAR_USE_GROWT FALSE) endif() ``` -------------------------------- ### Enable Native Architecture Optimizations Source: https://github.com/kahypar/mt-kahypar/blob/master/CMakeLists.txt Enables architecture-specific optimizations for native compilation in Release and RelWithDebInfo builds. This can improve performance on the build machine's architecture. ```cmake if(KAHYPAR_ENABLE_ARCH_COMPILE_OPTIMIZATIONS) target_compile_options(MtKaHyPar-BuildFlags INTERFACE $<$:-mtune=native -march=native> $<$:-mtune=native -march=native>) endif() ``` -------------------------------- ### Enable LLVM Linker (lld) Source: https://github.com/kahypar/mt-kahypar/blob/master/CMakeLists.txt Checks if the LLVM linker (lld) is available and enables it for faster linking if found. This is conditional on KAHYPAR_X86 being defined. ```cmake find_program(LLD_BIN lld) if (LLD_BIN AND KAHYPAR_X86) message(STATUS "Found and will use LLVM linker " ${LLD_BIN}) target_link_options(MtKaHyPar-BuildFlags INTERFACE -fuse-ld=lld) endif() ``` -------------------------------- ### Mt-Kahypar C Interface: Objective Mapping Source: https://github.com/kahypar/mt-kahypar/blob/master/mt-kahypar/partition/refinement/gains/README.md Create a mapping between your new objective function's enum type and the 'Objective' class in 'lib/mtkahypar.cpp' within the 'mt_kahypar_set_context_parameter(...)' and 'mt_kahypar_set_partitioning_parameters(...)' functions. ```cpp #include ``` -------------------------------- ### Define Steiner Tree Gain Cache Sources Source: https://github.com/kahypar/mt-kahypar/blob/master/mt-kahypar/partition/refinement/CMakeLists.txt Lists the C++ source files for Steiner Tree gain calculation. Includes general and graph-specific implementations. ```cmake set(SteinerTreeSources gains/steiner_tree/steiner_tree_gain_cache.cpp gains/steiner_tree/steiner_tree_flow_network_construction.cpp) ``` ```cmake set(SteinerTreeGraphSources gains/steiner_tree_for_graphs/steiner_tree_gain_cache_for_graphs.cpp gains/steiner_tree_for_graphs/steiner_tree_flow_network_construction_for_graphs.cpp) ``` -------------------------------- ### Define Refinement Sources Source: https://github.com/kahypar/mt-kahypar/blob/master/mt-kahypar/partition/refinement/CMakeLists.txt Lists the C++ source files for the core refinement algorithms. These are typically included by default. ```cmake set(RefinementSources fm/fm_commons.cpp fm/multitry_kway_fm.cpp fm/localized_kway_fm_core.cpp fm/global_rollback.cpp fm/sequential_twoway_fm_refiner.cpp label_propagation/label_propagation_refiner.cpp rebalancing/advanced_rebalancer.cpp rebalancing/deterministic_rebalancer.cpp rebalancing/repair_empty_blocks.cpp deterministic/deterministic_label_propagation.cpp deterministic/deterministic_jet_refiner.cpp flows/problem_construction.cpp flows/flow_refinement_scheduler.cpp flows/active_block_scheduler.cpp flows/quotient_graph.cpp flows/flow_refiner.cpp flows/sequential_construction.cpp flows/parallel_construction.cpp flows/flow_hypergraph_builder.cpp flows/deterministic/deterministic_flow_refinement_scheduler.cpp flows/deterministic/participation_scheduler.cpp ) ``` -------------------------------- ### Define Partitioning Source Targets Source: https://github.com/kahypar/mt-kahypar/blob/master/mt-kahypar/partition/CMakeLists.txt Groups source files into interface targets for the partitioning library and tools. ```cmake set(PartitionSources deep_multilevel.cpp partitioner.cpp partitioner_facade.cpp multilevel.cpp context.cpp context_enum_classes.cpp conversion.cpp metrics.cpp recursive_bipartitioning.cpp ) target_sources(MtKaHyPar-Sources INTERFACE ${PartitionSources}) set(PartitionToolsSources context.cpp context_enum_classes.cpp conversion.cpp metrics.cpp ) target_sources(MtKaHyPar-ToolsSources INTERFACE ${PartitionToolsSources}) ``` -------------------------------- ### Mt-Kahypar C Interface: Compute Objective Function Source: https://github.com/kahypar/mt-kahypar/blob/master/mt-kahypar/partition/refinement/gains/README.md Add a function in 'include/mtkahypar.h' that takes a 'mt_kahypar_partitioned_hypergraph_t' and computes your custom objective function, similar to 'mt_kahypar_cut(...)' and 'mt_kahypar_km1(...)' ```c mt_kahypar_partitioned_hypergraph_t; ``` -------------------------------- ### Add MtKaHyPar Executable Source: https://github.com/kahypar/mt-kahypar/blob/master/mt-kahypar/application/CMakeLists.txt Defines the main MtKaHyPar executable and links it with the MtKaHyPar-BuildSources library. This is the primary build target for the application. ```cmake add_executable(MtKaHyPar mt_kahypar.cc) target_link_libraries(MtKaHyPar MtKaHyPar-BuildSources) ``` -------------------------------- ### Partition a Graph Source: https://github.com/kahypar/mt-kahypar/blob/master/README.md Loads and partitions a standard graph using the optimized graph data structure. ```python # Load graph from file (assumes Metis file format per default) graph = mtkahypar.graph_from_file("path/to/graph/file", context) # Partition graph partitioned_graph = graph.partition(context) ``` -------------------------------- ### Fetch and Configure growt Dependency (Conditional) Source: https://github.com/kahypar/mt-kahypar/blob/master/CMakeLists.txt Conditionally fetches the growt library from a specific GitHub fork if KAHYPAR_USE_GROWT is enabled. It also defines a compile flag for growt. ```cmake if(KAHYPAR_USE_GROWT) # Note: we use our own fork of growt since growt is no longer maintained and we need to fix some errors FetchContent_Populate( growt QUIET EXLUDE_FROM_ALL GIT_REPOSITORY https://github.com/N-Maas/growt.git GIT_TAG ${KAHYPAR_GROWT_TAG} SOURCE_DIR external_tools/growt ) target_compile_definitions(MtKaHyPar-BuildFlags INTERFACE KAHYPAR_USE_GROWT) endif() ``` -------------------------------- ### Define Km1 Gain Cache Source Source: https://github.com/kahypar/mt-kahypar/blob/master/mt-kahypar/partition/refinement/CMakeLists.txt Lists the C++ source file for the Km1 gain cache. This is a specific gain calculation strategy. ```cmake set(Km1Sources gains/km1/km1_gain_cache.cpp) ``` -------------------------------- ### Define Cut Gain Cache Source Source: https://github.com/kahypar/mt-kahypar/blob/master/mt-kahypar/partition/refinement/CMakeLists.txt Lists the C++ source file for the Cut gain cache. This is a specific gain calculation strategy. ```cmake set(CutSources gains/cut/cut_gain_cache.cpp) ``` -------------------------------- ### Configure Mapping Sources in CMake Source: https://github.com/kahypar/mt-kahypar/blob/master/mt-kahypar/partition/mapping/CMakeLists.txt Defines a list of source files and assigns them to library or tool targets based on build configuration flags. ```cmake set(MappingSources target_graph.cpp all_pair_shortest_path.cpp steiner_tree.cpp greedy_mapping.cpp initial_mapping.cpp kerninghan_lin.cpp ) if ( KAHYPAR_ENABLE_STEINER_TREE_METRIC ) target_sources(MtKaHyPar-Sources INTERFACE ${MappingSources}) else () target_sources(MtKaHyPar-LibraryBuildSources PRIVATE ${MappingSources}) endif() target_sources(MtKaHyPar-ToolsSources INTERFACE ${MappingSources}) ``` -------------------------------- ### Configure Preprocessing Sources in CMake Source: https://github.com/kahypar/mt-kahypar/blob/master/mt-kahypar/partition/preprocessing/CMakeLists.txt Defines a list of preprocessing source files and associates them with the MtKaHyPar-Sources interface target. ```cmake set(PreprocessingSources community_detection/parallel_louvain.cpp community_detection/local_moving_modularity.cpp) target_sources(MtKaHyPar-Sources INTERFACE ${PreprocessingSources}) ``` -------------------------------- ### Set Dependency Versions and Tags Source: https://github.com/kahypar/mt-kahypar/blob/master/CMakeLists.txt Defines specific Git tags or versions for project dependencies like shared resources, WHFC, Growt, Parlay, CLI11, TBB, Googletest, and Pybind11. ```cmake include(FetchContent) set(KAHYPAR_SHARED_RESOURCES_TAG 6d5c8e2444e4310667ec1925e995f26179d7ee88) set(KAHYPAR_WHFC_TAG 51b27ff2c27a4794bfbaa4e8189d38159d249312) set(KAHYPAR_GROWT_TAG 04b2a1afe4c5844c960a5a8289bb608fe2c6c68c) set(KAHYPAR_PARLAY_TAG e1f1dc0ccf930492a2723f7fbef8510d35bf57f5) set(KAHYPAR_CLI11_VERSION v2.6.1) set(KAHYPAR_TBB_VERSION v2022.0.0) set(KAHYPAR_GOOGLETEST_VERSION v1.15.2) set(KAHYPAR_PYBIND11_VERSION v2.13.6) message(STATUS "Fetching dependencies...") ``` -------------------------------- ### Fetch kahypar-shared-resources Dependency Source: https://github.com/kahypar/mt-kahypar/blob/master/CMakeLists.txt Fetches the kahypar-shared-resources library from GitHub. This dependency is placed in a specific source directory. ```cmake FetchContent_Populate( kahypar-shared-resources QUIET EXLUDE_FROM_ALL GIT_REPOSITORY https://github.com/kahypar/kahypar-shared-resources.git GIT_TAG ${KAHYPAR_SHARED_RESOURCES_TAG} SOURCE_DIR external_tools/kahypar-shared-resources ) ``` -------------------------------- ### Include Subdirectories Source: https://github.com/kahypar/mt-kahypar/blob/master/tests/CMakeLists.txt Includes subdirectories for different modules within the project. This allows for modular build configurations. ```cmake add_subdirectory(datastructures) add_subdirectory(interface) add_subdirectory(io) add_subdirectory(parallel) add_subdirectory(partition) ``` -------------------------------- ### Heavy Initial Partitioning Assertions Compile Flag Source: https://github.com/kahypar/mt-kahypar/blob/master/CMakeLists.txt Defines KAHYPAR_ENABLE_HEAVY_INITIAL_PARTITIONING_ASSERTIONS for the MtKaHyPar-BuildFlags target when the CMake variable is set. ```cmake if(KAHYPAR_ENABLE_HEAVY_INITIAL_PARTITIONING_ASSERTIONS) target_compile_definitions(MtKaHyPar-BuildFlags INTERFACE KAHYPAR_ENABLE_HEAVY_INITIAL_PARTITIONING_ASSERTIONS) endif(KAHYPAR_ENABLE_HEAVY_INITIAL_PARTITIONING_ASSERTIONS) ``` -------------------------------- ### Enable Coverage Analysis Source: https://github.com/kahypar/mt-kahypar/blob/master/CMakeLists.txt Adds compile and link flags for GCOV coverage analysis when KAHYPAR_USE_GCOV is enabled. ```cmake if(KAHYPAR_USE_GCOV) # add coverage anaylsis compile and link flags target_compile_options(MtKaHyPar-BuildFlags INTERFACE -fprofile-arcs -ftest-coverage -fprofile-update=atomic) target_link_options(MtKaHyPar-BuildFlags INTERFACE -lgcov --coverage) endif(KAHYPAR_USE_GCOV) ``` -------------------------------- ### Deterministic Partitioning Citation Source: https://github.com/kahypar/mt-kahypar/blob/master/README.md BibTeX entry for citing the Deterministic Partitioning paper. ```bibtex // Deterministic Partitioning @inproceedings{MT-KAHYPAR-SDET, author = {Lars Gottesb{"u}}ren and Michael Hamann}, title = {Deterministic Parallel Hypergraph Partitioning}, booktitle = {European Conference on Parallel Processing (Euro-Par)}, volume = {13440}, pages = {301--316}, publisher = {Springer}, year = {2022}, doi = {10.1007/978-3-031-12597-3_19}, } ``` -------------------------------- ### Target Sources for MtKaHyPar-Sources Source: https://github.com/kahypar/mt-kahypar/blob/master/mt-kahypar/partition/refinement/CMakeLists.txt Adds core refinement, Km1, and Cut sources to the MtKaHyPar-Sources target. These are fundamental components. ```cmake target_sources(MtKaHyPar-Sources INTERFACE ${RefinementSources}) target_sources(MtKaHyPar-Sources INTERFACE ${Km1Sources}) target_sources(MtKaHyPar-Sources INTERFACE ${CutSources}) ``` -------------------------------- ### Uninstall Mt-KaHyPar C Library Source: https://github.com/kahypar/mt-kahypar/blob/master/README.md Removes the Mt-KaHyPar C library from the system. ```sh make uninstall-mtkahypar ``` -------------------------------- ### Enable Compiler Warnings Source: https://github.com/kahypar/mt-kahypar/blob/master/CMakeLists.txt Adds standard compiler warnings to the MtKaHyPar-BuildFlags target for enhanced code quality. ```cmake target_compile_options(MtKaHyPar-BuildFlags INTERFACE -W -Wall -Wextra -Wunused -Wuninitialized -Wfatal-errors -Wcast-qual -Woverloaded-virtual -Wredundant-decls -Wno-unused-function -Winit-self -pedantic -DPARANOID -Wno-unused-function) ``` -------------------------------- ### Enable Address Sanitizer for Debug Builds Source: https://github.com/kahypar/mt-kahypar/blob/master/CMakeLists.txt Enables the address sanitizer for debug builds, provided KAHYPAR_USE_ADDRESS_SANITIZER is true and it's not a CI build. This helps detect memory access errors. ```cmake if(KAHYPAR_USE_ADDRESS_SANITIZER AND (NOT KAHYPAR_CI_BUILD)) target_compile_options(MtKaHyPar-BuildFlags INTERFACE $<$:-fsanitize=address>) target_link_options(MtKaHyPar-BuildFlags INTERFACE $<$:-fsanitize=address>) endif() ``` -------------------------------- ### Map Objective to Gain Policy Source: https://github.com/kahypar/mt-kahypar/blob/master/mt-kahypar/partition/refinement/gains/README.md In `partition/context.cpp`, establish a mapping between the `Objective` enum type and `GainPolicy` within the `sanityCheck(...)` function. ```c++ ```partition/context.cpp```: Create a mapping between the enum type ```Objective``` and ```GainPolicy``` in the ```sanityCheck(...)``` function. ``` -------------------------------- ### Enable Flow-Based Refinement Logging Source: https://github.com/kahypar/mt-kahypar/blob/master/mt-kahypar/partition/refinement/gains/README.md Set the 'debug' flag to true in the FlowRefinementScheduler class to enable logging for the flow-based refinement algorithm. This is useful for testing custom objective function implementations. ```cpp debug = true; ``` -------------------------------- ### Define Cut Graph Gain Cache Source Source: https://github.com/kahypar/mt-kahypar/blob/master/mt-kahypar/partition/refinement/CMakeLists.txt Lists the C++ source file for the Cut gain cache when partitioning graphs. This is a specialized gain calculation strategy. ```cmake set(CutGraphSources gains/cut_for_graphs/cut_gain_cache_for_graphs.cpp) ``` -------------------------------- ### Update Gain Cache Pointer Source: https://github.com/kahypar/mt-kahypar/blob/master/mt-kahypar/partition/refinement/gains/README.md In `partition/refinement/gains/gain_cache_ptr.h`, add your objective function's `GainPolicy` type to switch statements in `GainCachePtr` and `bipartition_each_block(...)` in `partition/deep_multilevel.cpp`. ```c++ ```partition/refinement/gains/gain_cache_ptr.h```: Add the ```GainPolicy``` type of your new objective function to all switch statements in the ```GainCachePtr``` class. Use the gain cache implementation of your gain type struct defined in ```gain_definitions.h```. We will later replace it by the concrete gain cache implementation for your new objective function. Moreover, add the ```GainPolicy``` type of your new objective function to the switch statement of the ```bipartition_each_block(...)``` function in ```partition/deep_multilevel.cpp``` ``` -------------------------------- ### Verify Bipartitioning Invariant Source: https://github.com/kahypar/mt-kahypar/blob/master/mt-kahypar/partition/refinement/gains/README.md Ensure the invariant that the sum of cut values of all bipartitions equals the objective value of the initial k-way partition holds. Run unit tests using `make mtkahypar_tests` and `./tests/mtkahypar_tests --gtest_filter=*ABipartitioningPolicy*`. ```bash The main invariant of our recursive bipartitioning algorithm is that the cut of all bipartitions sum up to the objective value of the initial k-way partition. There are unit tests that asserts this invariant in ```tests/partition/refinement/bipartitioning_gain_policy_test.cc``` (build test suite via ```make mtkahypar_tests``` and then run ```./tests/mtkahypar_tests --gtest_filter=*ABipartitioningPolicy*```). ``` -------------------------------- ### Flow-Based Refinement: Capacity Function Source: https://github.com/kahypar/mt-kahypar/blob/master/mt-kahypar/partition/refinement/gains/README.md Implement this function to assign capacity to a hyperedge in the flow network. The capacity should be set such that the initial objective value minus the maximum flow value equals the objective function reduction when applying the minimum cut. ```cpp template static HyperedgeWeight capacity(const PartitionedHypergraph& phg, const HyperedgeID he, const PartitionID block_0, const PartitionID block_1); ``` -------------------------------- ### Define Soed Gain Cache Source Source: https://github.com/kahypar/mt-kahypar/blob/master/mt-kahypar/partition/refinement/CMakeLists.txt Lists the C++ source file for the Soed gain cache. This is a specific gain calculation strategy. ```cmake set(SoedSources gains/soed/soed_gain_cache.cpp) ``` -------------------------------- ### Check for CPU Instruction Set Extensions Source: https://github.com/kahypar/mt-kahypar/blob/master/CMakeLists.txt Checks for specific CPU instruction set extensions like MCX16 and CRC32, and enables them if available and requested. This is part of optimizing for x86 architectures. ```cmake include(CheckCXXCompilerFlag) include(CheckSSE4_2) block() set(CMAKE_REQUIRED_QUIET TRUE) check_cxx_compiler_flag(-mcx16 KAHYPAR_HAS_MCX16) endblock() block() set(CMAKE_REQUIRED_QUIET TRUE) check_cxx_compiler_flag(-mcrc32 KAHYPAR_HAS_CRC32) endblock() if(KAHYPAR_HAS_MCX16) target_compile_options(MtKaHyPar-BuildFlags INTERFACE -mcx16) endif() if(KAHYPAR_HAS_CRC32) target_compile_options(MtKaHyPar-BuildFlags INTERFACE -mcrc32) endif() if(BUILTIN_POPCNT) target_compile_options(MtKaHyPar-BuildFlags INTERFACE -msse4.2) endif() ``` -------------------------------- ### Export MtKaHyPar Target Source: https://github.com/kahypar/mt-kahypar/blob/master/CMakeLists.txt Exports the main mtkahypar library as an alias target 'MtKaHyPar::mtkahypar' for easier referencing in other CMake projects. ```cmake # export target for C interface add_library(MtKaHyPar::mtkahypar ALIAS mtkahypar) ``` -------------------------------- ### Large K Partitioning Features Compile Flag Source: https://github.com/kahypar/mt-kahypar/blob/master/CMakeLists.txt Defines KAHYPAR_ENABLE_LARGE_K_PARTITIONING_FEATURES for the MtKaHyPar-BuildFlags target when the CMake variable is set. ```cmake if(KAHYPAR_ENABLE_LARGE_K_PARTITIONING_FEATURES) target_compile_definitions(MtKaHyPar-BuildFlags INTERFACE KAHYPAR_ENABLE_LARGE_K_PARTITIONING_FEATURES) endif(KAHYPAR_ENABLE_LARGE_K_PARTITIONING_FEATURES) ``` -------------------------------- ### 64-bit IDs Compile Flag Source: https://github.com/kahypar/mt-kahypar/blob/master/CMakeLists.txt Defines KAHYPAR_USE_64_BIT_IDS for the MtKaHyPar-BuildFlags target when the CMake variable is set. ```cmake if(KAHYPAR_USE_64_BIT_IDS) target_compile_definitions(MtKaHyPar-BuildFlags INTERFACE KAHYPAR_USE_64_BIT_IDS) endif(KAHYPAR_USE_64_BIT_IDS) ``` -------------------------------- ### Define Parallel Sources for Mt-kahypar Source: https://github.com/kahypar/mt-kahypar/blob/master/mt-kahypar/parallel/CMakeLists.txt Defines a list of source files to be used in parallel processing. These sources are then added to the main library and tools targets. ```cmake set(ParallelSources thread_management.cpp) target_sources(MtKaHyPar-Sources INTERFACE ${ParallelSources}) target_sources(MtKaHyPar-ToolsSources INTERFACE ${ParallelSources}) ``` -------------------------------- ### Enable Undefined Behavior Sanitizer for Debug Builds on Unix Source: https://github.com/kahypar/mt-kahypar/blob/master/CMakeLists.txt Enables the undefined behavior sanitizer for debug builds on Unix-like systems. This helps detect runtime errors related to undefined behavior. ```cmake if(UNIX AND NOT WIN32) target_compile_options(MtKaHyPar-BuildFlags INTERFACE $<$:-fsanitize=undefined>) target_link_options(MtKaHyPar-BuildFlags INTERFACE $<$:-fsanitize=undefined>) endif() ``` -------------------------------- ### Experimental Features Compile Flag Source: https://github.com/kahypar/mt-kahypar/blob/master/CMakeLists.txt Defines KAHYPAR_ENABLE_EXPERIMENTAL_FEATURES for the MtKaHyPar-BuildFlags target when the CMake variable is set. ```cmake if(KAHYPAR_ENABLE_EXPERIMENTAL_FEATURES) target_compile_definitions(MtKaHyPar-BuildFlags INTERFACE KAHYPAR_ENABLE_EXPERIMENTAL_FEATURES) endif(KAHYPAR_ENABLE_EXPERIMENTAL_FEATURES) ``` -------------------------------- ### Graph Partitioning Features Compile Flag Source: https://github.com/kahypar/mt-kahypar/blob/master/CMakeLists.txt Defines KAHYPAR_ENABLE_GRAPH_PARTITIONING_FEATURES for the MtKaHyPar-BuildFlags target when the CMake variable is set. ```cmake if(KAHYPAR_ENABLE_GRAPH_PARTITIONING_FEATURES) target_compile_definitions(MtKaHyPar-BuildFlags INTERFACE KAHYPAR_ENABLE_GRAPH_PARTITIONING_FEATURES) endif(KAHYPAR_ENABLE_GRAPH_PARTITIONING_FEATURES) ``` -------------------------------- ### Add Objective Function Enum Source: https://github.com/kahypar/mt-kahypar/blob/master/mt-kahypar/partition/refinement/gains/README.md Extend the `Objective` and `GainPolicy` enum classes in `partition/context_enum_classes.h` to include your new objective function. ```c++ ```partition/context_enum_classes.h```: Add a new enum type to the enum classes ```Objective``` and ```GainPolicy``` representing your new objective function. ``` -------------------------------- ### Conditional Graph Partitioning Features Source: https://github.com/kahypar/mt-kahypar/blob/master/mt-kahypar/partition/refinement/CMakeLists.txt Conditionally adds graph partitioning related sources. Includes CutGraph and SteinerTreeGraph sources based on feature flags. ```cmake if ( KAHYPAR_ENABLE_GRAPH_PARTITIONING_FEATURES ) target_sources(MtKaHyPar-Sources INTERFACE ${CutGraphSources}) if ( KAHYPAR_ENABLE_STEINER_TREE_METRIC ) target_sources(MtKaHyPar-Sources INTERFACE ${SteinerTreeGraphSources}) else () target_sources(MtKaHyPar-LibraryBuildSources PRIVATE ${SteinerTreeGraphSources}) endif() else () target_sources(MtKaHyPar-LibraryBuildSources PRIVATE ${CutGraphSources}) target_sources(MtKaHyPar-LibraryBuildSources PRIVATE ${SteinerTreeGraphSources}) endif() ```