Skip to content

binding/fortran: make libmpifort standalone - #7803

Open
hzhou wants to merge 39 commits into
pmodels:mainfrom
hzhou:2512_fort_abi
Open

binding/fortran: make libmpifort standalone#7803
hzhou wants to merge 39 commits into
pmodels:mainfrom
hzhou:2512_fort_abi

Conversation

@hzhou

@hzhou hzhou commented May 7, 2026

Copy link
Copy Markdown
Collaborator

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-alone
   ./configure --with-mpi=/path/to/mpi --prefix=/path/to/install
   make install

It will install mpifort and libmpifort.so

  • mpicc by default only links to libmpi.so, which will not contain any Fortran, including MPI_INTEGER, MPI_Comm_f2c, etc.

  • mpicc -fortran will attempt to link in libmpifort.so so C programs that needs Fortran inter-op will work

TODO

  • Build MPICH ABI

  • Build MPI ABI

  • Remove the mpich handle assumption that uses direct cast for handle conversions

    • mpif_h
    • use_mpi_f08
  • Check MPIX_ dependency and create fallbacks

[warnings:normal]

Author Checklist

  • Provide Description
    Particularly focus on why, not what. Reference background, issues, test failures, xfail entries, etc.
  • Commits Follow Good Practice
    Commits are self-contained and do not do two things at once.
    Commit message is of the form: module: short description
    Commit message explains what's in the commit.
  • Passes All Tests
    Whitespace checker. Warnings test. Additional tests via comments.
  • Contribution Agreement
    For non-Argonne authors, check contribution agreement.
    If necessary, request an explicit comment from your companies PR approval manager.

@hzhou
hzhou force-pushed the 2512_fort_abi branch 14 times, most recently from 81858db to 4020a0b Compare May 14, 2026 15:47
@hzhou
hzhou force-pushed the 2512_fort_abi branch 12 times, most recently from a6e543a to 6b5c99b Compare May 24, 2026 15:01
@hzhou
hzhou force-pushed the 2512_fort_abi branch 4 times, most recently from 22a7176 to 004d580 Compare May 26, 2026 17:28
hzhou added 26 commits August 17, 2026 16:35
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.
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