Usage of different Fortran and C compilers with MPICH
From EGEE-see WIki
The page is part of SEE-GRID Gridification Guide
This topic is contributed by Center for Scientific Research of SASA and University of Kragujevac,Serbia
Introduction
Usually, MPICH is built using one set of compilers and then libraries are linked with the code compiled with other compilers. However, this depends on the fact if compilers produce compatible object files. According to the documentation, the compilers must fulfill the following requirements:
- The sizes of basic data types must be the same. For example, the C compilers should use the same byte size for long double.
- Map the names of functions and subroutines from the source code to the object file in the same manner. This can be a big issue if one plans to mix Fortran and C/C++ code (though majority of Fortran compilers own directives intended to force naming conventions). More specifically, bu default, most Fortran compilers map names from the source code into all-lower case with one or two underscores in postfix.
- Perform the same layout for C structures because C language specification does not specify how structure reserves memory. MPICH overcomes this issue by implementation of MPI_Type_struct or MPI_Type_create_struct functions. Thus, this requirement can be ignored in most cases.
- Require the same additional runtime libraries. Not all compilers implement the same version of Unix and some routines that MPICH uses may be present in only some libraries associated with specific compilers.
Although these requirements seem strong, in everyday usage many compilers meet these needs. First, in our grid based on gLite case, the application environment is very uniform; we deal only with SL3/SL4 distributions with Intel 32 and 64 bit architecture and that is all. If one is sure the compilers are completely compatible the compilation can be done without reconfiguring and remaking MPICH itself in the following way:
mpicc -cc=icc -c example.c
or with the environment variables MPICH_CC etc:
export MPICH_CC=icc (or setenv MPICH_CC icc in case of csh) mpicc -c example.c
PBFS case
However, if one wants to reach consistency (specifically when linking a lot of pieces of Fortran and C code, which was the case in the development of Parallel Blood Flow Simulation - PBFS), the better approach is to compile every piece of code using the same compiler/linker chain. Another reason can be the significant performance gain observed when using new compilers with new features. For example, the mpich-1.2.6 configure script invocation intended to be used with Intel compiler/linker chain (Fortran/C++) looks like this:
./configure -cc=icc -c++=icpc -clinker=icc -c++linker=icpc -fc=ifort -f90=ifort -flinker=ifort -f90=ifort –enable-f90modules
The main reason for separated compilation of MPICH for PBFS was the fact that default mpich-1.2.6 from RPM package has been compiled without support for F90 modules. Of course, this step requires correctly configured Intel compilers and their environment variables (according to the installation manual).
