binding/fortran: make libmpifort standalone - #7803
Open
hzhou wants to merge 39 commits into
Open
Conversation
hzhou
force-pushed
the
2512_fort_abi
branch
14 times, most recently
from
May 14, 2026 15:47
81858db to
4020a0b
Compare
hzhou
force-pushed
the
2512_fort_abi
branch
12 times, most recently
from
May 24, 2026 15:01
a6e543a to
6b5c99b
Compare
hzhou
force-pushed
the
2512_fort_abi
branch
4 times, most recently
from
May 26, 2026 17:28
22a7176 to
004d580
Compare
Since now we only support the same Fortran compiler as FC and F77, we can directly use offset type as INTEGER(KIND=@OFFSET_KIND@).
We no longer support having romio define its own constants that are incompatible from MPICH or MPI ABI. Thus, we no longer need export ROMIO constants via mpiof.h. Remove all its support for mpiof.h.
With MPI 5.0, C programs should not need to use MPI_Fint directly. We hard code MPI_Fint as int in mpi.h, which is the common case, so legacy code should continue to work. If the Fortran compiler uses a different INTEGER size than C int, users can add `-DMPI_FINT_CTYPE=[ctype]` work around the issue. The proper solution is to avoid direct access of MPI_Fint altogether.
Move AC_ARG_WITH([wrapper-dl-type],...) into PAC_COMPILER_SHLIB_FLAGS since both need be set together.
Split the part of code from mpif_h/setbot.c that require autoconf substitutions so when we modify mpirinitc_ etc. we don't have to rerun autoconf. Split .gitignore as well since now the fortran binding is treated as separate.
The binding generation scripts can be run - 1. autogen from mpich main_top_srcdir. 2. src/binding/fortran/configure within the mpich source tree. 3. fortran binding tarball, i.e. src/binding/fortran without mpich source tree. This commit makes all 3 ways work. Option 2 and 3 of course depends on next commits. Set default option for "-mpi-h", which will be used for standalone libmpifort build. Remove the autogen check. In the coming commits, the python script will directly generate files without autoconf macros.
Configure and build the fortran binding separately from MPICH.
Configure and install mpifort and libmpifort.so from src/binding/fortran as a sub-package.. temp: fix up fortran binding as a separate package
Let MPI_Init initialize Fortran datatypes and inter-op functions. Both MPI_Abi_get_fortran_info and MPI_Abi_set_fortran_info will fail if MPI is not initialized. There are MPI functions can be called before MPI is initialized and there is no good way of testing it -- MPI_Initialized does not work with MPI_Session_init -- we simply return if MPI_Abi_get_fortran_info return an error assuming it is due to MPI uninitialized.
The mpi_f08 module also need call MPIX_Init_fortran to initialize the datatypes.
We handle ENABLE_ROMIO at the C binding layer.
Use mpi_f08 instead of mpif.h or it won't compile.
The C interface for MPI_Info_create_env has extra argc and argv parameter. This was uncaught due to previous test/f08/info/infocrenvf90 didn't use mpi_f08.
Separate all fortran inter-op related declarations to mpi_fortran.h.
MPI_F_{STATUS_SIZE,SOURCE,TAG,ERROR} are still defined in mpi_mpich.h.in
since they describes the C struct MPI_Status.
The C library no longer handle Fortran callbacks directly. The MPI Fortran binding should provide proxy to handle the callbacks.
Move all the fortran inter-op C API to libmpifort.so and only installed by the mpifort package.
Should use `MPI_Fint *` rather than `void *`.
We can't use MPIR_Err_create_code now the fortran bindings are separate.
Instead of assuming MPI_Status as defined by MPICH, assume struct MPI_Status is equivalent to an int array of size MPI_F_STATUS_SIZE.
If the function is annotated in api file (e.g. src/binding/c/abi_api.txt), check its skip Fortran annotation.
Define _f2c/c2f functions. These functions will be used internally in mpi_f08. TODO: export and properly set weak symbols.
We used to generate both branches: the case fint is the same as c_int and the case require explicit conversions. Previously we changed that switch to the python layer. Consequently, we can need generate one version and we no longer need keep track of both branches in python. Merge arg_list_1/arg_list_2 into single arg_list. Fold convert_list_1/ convert_list_2 into convert_list_pre/convert_list_post. All process_* functions return a single arg instead of a tuple. Replace runtime need_check_int_kind with generation-time need_int_conversions.
dump_fortran_line uses split_line_with_break which assumes a
function-like line and tries to indent after the first '(', and it
assumes the '(' (if found) comes before the line length. This may not be
true when the line isn't a function, such as:
USE :: mpi_f08_types, ONLY : MPI_Datatype, MPI_Type_f2c,
MPI_Message, MPI_Message_f2c, MPI_Message_c2f, MPI_Status, assignment(=)
Replace dump_fortran_line with dump_use_line that properly splits
long USE statements at symbol boundaries.
Do not assume we can pass MPI_VAL directly to C. Use _f2c conversions.
If configure detect there is not necessary MPIX functions defined in the exposed mpi.h, skip exposing fortran interface for MPIX functions, and use fallback for registering callbacks. That may mean the callback won't parse some argument correctly without c2f conversions.
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.
Pull Request Description
Configure and build the fortran binding separately from MPICH.
src/binding/fortran/will be separately packaged and be able to build stand-aloneIt will install
mpifortandlibmpifort.sompiccby default only links tolibmpi.so, which will not contain any Fortran, includingMPI_INTEGER,MPI_Comm_f2c, etc.mpicc -fortranwill attempt to link inlibmpifort.soso C programs that needs Fortran inter-op will workTODO
Build MPICH ABI
Build MPI ABI
Remove the mpich handle assumption that uses direct cast for handle conversions
mpif_huse_mpi_f08Check
MPIX_dependency and create fallbacks[warnings:normal]
Author Checklist
Particularly focus on why, not what. Reference background, issues, test failures, xfail entries, etc.
Commits are self-contained and do not do two things at once.
Commit message is of the form:
module: short descriptionCommit message explains what's in the commit.
Whitespace checker. Warnings test. Additional tests via comments.
For non-Argonne authors, check contribution agreement.
If necessary, request an explicit comment from your companies PR approval manager.