Skip to content

binding/fortran: make libmpifort standalone - #7803

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

binding/fortran: make libmpifort standalone#7803
hzhou wants to merge 49 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]

Wiki Doc

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 7 commits August 26, 2026 15:35
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.
@hzhou

hzhou commented Aug 26, 2026

Copy link
Copy Markdown
Collaborator Author

test:mpich/ch3/tcp

test:mpich/custom
config: mpi-abi

hzhou added 17 commits August 26, 2026 18:24
Move all the fortran inter-op C API to libmpifort.so. There is no
Fortran depenence in libmpi.so, including MPI_Fint. Install Fortran
binding to provide MPI_Fint and f2c/c2f functions.

We can't use MPIR_Err_create_code now the fortran bindings are separate.
Return MPI_ERR_ARG instead.
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.
The f2c functions need be generated in Fortran binding as it depends on
MPI_Fint.
Should use `MPI_Fint *` rather than `void *`.
If the function is annotated in api file (e.g.
src/binding/c/abi_api.txt), check its skip Fortran annotation.
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.
We can run fortran tests with MPI ABI now.

The CXX testing won't work with MPI ABI.
Define mpi_c_interface_types based on parsing mpi.h.

mpi_c_interface_types defines C interoperable Fortran types such as
c_Comm and c_Status.
@hzhou
hzhou force-pushed the 2512_fort_abi branch 3 times, most recently from 1e2ea4b to 3a39242 Compare August 27, 2026 13:39
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