The Fortran Agenda

#Fortran, #Debian, #pkg-config

So, I'm working on Fortran (mostly within Debian). The aim is to make it as feature-complete and optimal as possible; this mostly comes down to:
* Adding Flang and multiple Fortran support to Debian
* dh_fortran_mod: multiple fortrans mean multiple modules.
* submodule support to makedepf90
* Ensuring coarrays work everywhere (* with Flang, automatically to f2py)

Multiple module support is the challenge of the day. The difficulty is that different compilers produce incompatible module files, and different compiler versions, too. dh_fortran_mod is a debhelper module to, well, help. It puts the modules in $fmoddir, with fmoddir as /usr/lib/$arch-triplet/fortran/$compiler-version

Ok, the problem now becomes: when a package such as MPI produces multiple identically named modules, what to do?
eg. both mpich and openmpi (and other mpi implementations) provide mpi.mod.
Currently this is solved by putting the module in .eg. /usr/include/$mpi, and then putting -I /usr/include/$mpi on the compile path. So it appears that $fmoddir/$mpi is the right place, But that means making the include path compiler-sensitive. Can we include relative paths ?

Potential solutions may include:
* Use of --sysroot, but could conflict with other uses?
* use of alternatives within Debian ?

Prerequisites: it is possible to use both mpich and openmpi within the same build (e.g. for open-coarrays, adios).

Also, we need to be able to work with wrapper scripts (mpif90) and pkg-config ( f95 -c pkg-config --cflags mpi-fort )

In the current iteration (dh_fortran_mod 0.9) we have as $fmoddir, /usr/lib/$triplet/fortran containing

gfortran-mod-15/
<modules>
gfortran-8 -> gfortran-mod-15
flang-mod-33/
<modules>?
flang-7 -> flang-mod-33

with eg. fmoddir=/usr/lib/$triplet/fortran/flang-7 as the $fmoddir in the flang default path.
We could change these symlinks to the "canonical compiler name" (e.g resolving gfortran through its symlinks.

Note:

alastair@debian:~$ readlink -f /usr/bin/gfortran
/usr/bin/x86_64-linux-gnu-gfortran-8

but

alastair@debian:~$ readlink -f /usr/bin/mpif90
/usr/bin/opal_wrapper

So: it becomes important to avoid the wrapper and use the gfortran compiler name in build scripts.

So in e.g. open-coarrays, which needs to link against both versions of mpi.mod, we can create the appropriate include path, if we use the 'canonical' compiler name (e.g. add or change gfortran-8 to x86_64-linux-gnu-gfortran-8 within dh_fortran_mod).

pkg-config ?

But what about pkg-config ? what should it return as the path ? Consider hdf5. It ships serial, openmpi and mpich flavours. These are packaged so we have a 'root' directory /usr/lib/$triplet/hdf5/$flavour
and inside $flavour are ./include and ./lib directories. There are hdf5-mpich.pc and hdf5-serial.pc and hdf5-openmpi.c with hdf5.pc as a symlink to these. but :

alastair@debian:~$ pkg-config hdf5-mpich --cflags
-I/usr/include/hdf5/mpich -I/usr/include/x86_64-linux-gnu/mpich

This include dir is wrong: for multiple fortran compilers this needs to be different for each compiler.

Either:
* we can include relative includes for the compiler, eg. -I ./mpich looks in $fmoddir/mpich., or:
* pkg-config takes a compiler option for Fortran compiler, and constructs a $fmoddir to return.
* other solution ?

There are no comments yet.