[mpich-discuss] Compiling shared libraries with Fortran 77 compiler and unexpected option

Anthony Chan chan at mcs.anl.gov
Fri Sep 9 15:24:29 CDT 2011



----- Original Message -----

> > but obtaining the addresses can be emulated from C, cfortran.h[1]
> > has this.
> >
> > Regards, Thomas
> >
> > [1] http://www-zeus.desy.de/~burow/cfortran/
> > iii) Using C to manipulate FORTRAN COMMON BLOCKS

Here is my 2 cents on this issue: Getting Fortran common block address
solely in C would require knowledge of how Fortran common block is
implemented in C and also how Fortran compiler mangles common block name.
Some compiler, e.g. Absoft Fortran compiler, provides option to change the
common block name mangling scheme, so getting the address directly in C
would assume common block naming scheme unchanged.  We actually did something
similar to cfortran.h in our multiple Fortran compilers as enduser compilers
(e.g. MPICH2 is compiled with gcc + whatever Fortran compiler).  Our experience
is that it isn't ideal.  The problem is linker alignment warning about C struct
used in Fortran (or the other way around).  Since MPICH2 is a library, our users
do not like to see any warnings (even they are harmless) when linking even a
simple C MPI program.  An application developer would have tolerated the warnings
if he/she uses the approach like cfortran.h in their own codes as long as it is not
from MPICH2.  Since our multiple Fortran compiler support is optional (it is one of
those "nice to have feature"), we could tolerate hacking around to get rid of warning
message.  But overall, our experience indicates that the most portable way (or least
intrusive way) to end users to obtain these common block addresses is to getting them
directly from Fortran.

mpirinitf_() does not have to be called from C side.  Based on
https://trac.mcs.anl.gov/projects/mpich2/changeset/4796 and src/mpi/initthread.c,
mpirinitf_() is called in initthread.c to resolve a bug caused by portland compiler.
In any case, mpirinitf_() is called in initthread only if the test
PAC_F77_INIT_WORKS_WITH_C passes.  In your case of building shared library with
nagfor, the test should have been failed.  Is it the case ?

A.Chan

For the moment, if you don't want mpirinitf_() called from C and you don't need Fortran
support, you could disable Fortran support, i.e. add --disable-f77 --disable-fc
when configuring mpich2.

A.Chan


More information about the mpich-discuss mailing list