8000 Fortran interface: modules kahip and parhip by schulzchristian · Pull Request #186 · KaHIP/KaHIP · GitHub
[go: up one dir, main page]

Skip to content

Fortran interface: modules kahip and parhip - #186

Merged
schulzchristian merged 2 commits into
masterfrom
fortran-interface
Nov 21, 2026
Merged

schulzchristian merged 2 commits into
masterfrom
fortran-interface

Conversation

@schulzchristian
@schulzchristian schulzchristian commented Nov 21, 2026 •
Copy link
Copy Markdown
Member

Makes KaHIP and ParHIP usable from Fortran.

  • interface/fortran/kahip.F90: module kahip with bind(C) interfaces for every routine of kaHIP_interface.h (kaffpa, kaffpa_balance, kaffpa_connected_blocks, kaffpa_balance_NE, process_mapping, node_separator, reduced_nd, edge_partitioning, kahip_sizeof_idx). kahip_idx follows 64BITMODE; node and edge weights are optional arguments; constants are prefixed (KAHIP_ECO, ...).
  • parallel/parallel_src/interface/fortran/parhip.F90: module parhip with parhip_partition_kway; the Fortran communicator handle is converted with MPI_Comm_f2c.
  • Two small C++ helpers: node_separator copies the separator into a caller array (the library allocates it with new[], which Fortran cannot free), and the communicator conversion for ParHIP.
  • CMake option -DBUILDFORTRAN=On builds and installs libkahip_fortran.a, libparhip_fortran.a, kahip.mod, parhip.mod.
  • Examples in misc/example_library_call/fortran call every routine and check the results (partition validity, reported cut vs. recomputed cut, perfect balance, connected blocks, separator disconnects the graph, ordering is a permutation). They run as ctest tests.
  • README: new section Using KaHIP in Fortran.

Tested locally with gfortran 8.3 and OpenMPI 5.0.11: 32 and 64 bit, ctest (both tests), install, and linking by hand with gfortran/mpifort against the installed prefix exactly as in the README. The ParHIP example passes with 1 to 4 processes; it checks that the reported edge cut equals the recomputed one (unweighted and with edge weight 2) and that every block is used. A CI workflow for the Fortran interface follows once the push token has the workflow scope.

🤖 Generated with Claude Code

Christian Schulz and others added 2 commits November 21, 2026 13:08
Adds the Fortran modules kahip (all routines of kaHIP_interface.h) and
parhip (ParHIPPartitionKWay), built with -DBUILDFORTRAN=On. The modules
bind directly to the C interface via iso_c_binding; two small C helpers
copy the node separator into a caller array (the library allocates it
with new[]) and convert the Fortran MPI communicator handle. Node and
edge weights are optional arguments. kahip_idx follows 64BITMODE.

Examples in misc/example_library_call/fortran call every routine and
check the results; they run as ctest tests.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The example now gathers the whole partition, checks that the reported
edge cut matches the recomputed one and that every block is used, and
runs a second partition with edge weight 2 (cut must double).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@schulzchristian
schulzchristian merged commit ca394c2 into master Nov 21, 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