Skip to content

binding/fortran: make libmpifort standalone#7803

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

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

Conversation

@hzhou
Copy link
Copy Markdown
Contributor

@hzhou hzhou commented May 7, 2026

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

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

    • mpif_h
    • use_mpi_f08
  • Check MPIX_ dependency and create fallbacks

[skip warnings]

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 10 times, most recently from e116cee to 6e55129 Compare May 12, 2026 17:06
hzhou added 2 commits May 13, 2026 21:41
Since MPL_hash is effectively a memory storage device, add a memory
class to track it.

Use bool instead of int or char value of 0 and 1.

Fix MPL_hash_has, it need check whether the hash is empty.
We need set the last 8 bits of the internal type to the index of the
original builtin type, or we will lose the original names.
@hzhou hzhou force-pushed the 2512_fort_abi branch 3 times, most recently from 920311e to 81858db Compare May 14, 2026 15:24
hzhou added 15 commits May 14, 2026 10:45
There are some build issue due to typerep_pre.h lives in
src/mpi/datatype/typerep/src but it is used outside in mpir_misc.h.

Consolidate the declarations into mpir_typerep.h. Move the declarations
of MPIR_Localcopy family into mpir_typerep.h as well due to its
dependency on struct MPIR_Typerep_req. They don't fit in mpir_misc.h
anyway.

Declare MPIDI_POSIX_rma_req_t in posix_types.h and use void * in
posix_pre.h. This relieves the struggle of header dependency.
When configured with --disable-cxx, renaming MPICXXLIBNAME to MPILIBNAME
results in duplicate target rules for lib@MPILIBNAME@.la.
Autoconf complains that we can't call AC_USE_SYSTEM_EXTENSIONS after
PAC_CHECK_VISIBILITY.
Instead of build both mpich abi and mpi abi, only build a single library
with --enable-mpi-abi.

If configured with --enable-mpi-abi, we only install libmpi_abi.so and
mpi.h will be a link to mpi_abi.h. Compiler scripts such as mpicc no
longer supports -mpi-abi option. It will either link to libmpi.so or
libmpi_abi.so based on the configure option.
Gather the code and remove leftovers from simplemake.

Only define $ABIVERSIONFLAGS since now we only build one ABI.
Internally we will include mpi_mpich.h instead of mpi.h. On the other
hand, mpi.h will be a copy from mpi_abi.h or mpi_mpich.h based on
whether --enable-mpi-abi is configured.

This allows examples as well as utilities (e.g. mpichversion and
mpivars) to work when mpi-abi is enabled.
Since these links, including libmpl.so, libopa.so, libmpich.so, etc. are
not in use any more, let's remove them.
Both are no longer in use. Just use subsystems to simplify the configure
design.
This is only used in mpicxx.h. We don't need it now that we always
define standard MPI Fortran datatypes in mpi.h.
Add MPIX_Init_fortran to initialize fortran datatypes. This is called
from mpirinitc_ so Fortran applications will have the datatype
initialized upon entry.

TODO: add a mechanism for MPI_Init in libmpi.so to call
MPIX_Init_fortran for those *C* programs that require Fortran interop
such as MPI_Fint, xxx_f2c, etc.

TODO: Call MPIX_Init_fortran for mpi_f08 module.
To separate the fortran binding from the core libmpi, we need rely on
MPI_Abi_set_fortran_info to support
MPI_Type_create_f90_{integer,real,complex}.
Always use MPI_{Comm,Type,...}_{from,to}int to convert handles between
Fortran and C rather than assuming the C handle types are int.

I don't think we are concerned with overhead of handle conversions. But
if we ever do care, we may add a configure option and internally define
the conversion functions into direct C casts.
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.
hzhou added 7 commits May 14, 2026 10:46
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..
Let MPI_Init initialize Fortran datatypes and inter-op functions.
The mpi_f08 module also need call MPIX_Init_fortran to initialize the
datatypes.
@hzhou
Copy link
Copy Markdown
Contributor Author

hzhou commented May 14, 2026

test:mpich/ch3/tcp

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