Fortran guide - Linux

This section takes you through compiling and linking csWMPI applications with different Fortran compilers. 32 and 64 bit versions of Fortran 77, 90 and 95 compilers from major vendors are fully supported, and since all bindings are compiled directly into the csWMPI binaries, there is a good chance that other Fortran compilers are supported as well.


Fortran 77

This section contains the steps necessary for compiling and linking programs Fotran 77 programs using csWMPI:

  1. Include the files mpif.h and mpi_init.f
  2. Set the correct include path
  3. Link with the library csWMPI

Step 1: Include the files mpif.h and mpi_init.f
In order to use csWMPI in Fortran 77 programs you MUST include the file mpi_init.f before the program statement. Moreover, you should include the file mpif.h after program statement. See the example below:

      ...
      include "mpi_init.f"

      program main
      implicit none
      include 'mpif.h'
      ...
      

In case you do not include mpi_init.f you will experience link errors.

Step 2: Set the correct include path
When compiling Fortran programs you must add the path in which the files mpif.h and mpi_init.f are located to the include path. In case you installed csWMPI using the default directories suggested by the install script, the directory is:

/usr/local/include/csWMPI/fortran

However, if you are using g77 or ifc, then you should use the following directory:

/usr/local/include/csWMPI/fortran/gcc

For most compilers this can be adding the following switch when compiling/linking:

-I/usr/local/include/csWMPI/fortran

Or:

-I/usr/local/include/csWMPI/fortran/gcc

for g77 and ifc.

Step 3: Link with the library csWMPI
In order to link Fortran programs with the csWMPI library: csWMPI. The following switch should be supplied with linking (or compiling and linking):

-lcsWMPI

Example:

g77 -o myapp myapp.f -I/usr/include/csWMPI/fortran/gcc -lcsWMPI

Some additional options might be necessary for your compiler. Please see the appropriate section below.


Fortran 90

This section contains the steps necessary for compiling and linking programs Fotran 90 programs using csWMPI:

  1. Include the file mpif.f90
  2. Set the correct include path
  3. Link with the library csWMPI

Step 1: Include the file mpif.f90
In the beginning of your source code file, simply include the file outside any subroutine:


      ...
      include "mpif.f90"
      ...
      

And you will be able to use the MPI Fortran 90 module and all the MPI calls in your subroutines.

Step 2: Set the correct include path
When compiling Fortran programs you must add the path in which the file mpif.f90 is located to the include path. In case you installed csWMPI using the default directories suggested by the install script, the directory is:

/usr/local/include/csWMPI/fortran

For most compilers this can be adding the following switch when compiling/linking:

-I/usr/local/include/csWMPI/fortran

Step 3: Link with the library csWMPI
In order to link Fortran programs with the library csWMPI. The following switch should be supplied with linking (or compiling and linking):

-lcsWMPI

Example (Lahey Fortran):

lf95 -o myapp myapp.f90 -I/usr/include/csWMPI/fortran -lcsWMPI

Some additional options might be necessary for your compiler. Please see the appropriate section below.


Intel's Fortran Compiler

csWMPI supports Intel's Fortran compiler ifc for both Fortran 77 and Fortran 90 programs. csWMPI has been tested with version 7.1 of Intel's Fortran Compiler for Linux.

For Fortran 77 programs, the Intel compiler is rather pedantic and therefore it uses the same header files as gcc/g77. If you have installed csWMPI in the default installation directories the include files for Fortran 77 programs can be found in:

/usr/include/csWMPI/fortran/gcc

Moreover, you will have to link with Intel's portability library, which is done by adding the switch -Vaxlib when compiling.

Thus, if you want to compile the Fortran 77 Hello World example from command-line you have to execute the following command:

ifc -o hello_world hello_world.f -I/usr/include/csWMPI/fortran/gcc -Vaxlib -lcsWMPI2

Further more, you can add the -cm switch if you do not want the compiler to display comments.

For Fortran 90 programs you will have to supply the same set of switches as for Fortran 77 programs, however, the include directory has to be changed to:

/usr/include/csWMPI/fortran

Thus, if you want to compile the Fortran 90 Hello World example from command-line you have to execute the following command:

ifc -o hello_world hello_world.f90 -I/usr/include/csWMPI/fortran -Vaxlib -lcsWMPI2
Absoft Pro Fortran

csWMPI supports Absoft Fortran compiler f77/f90 for both Fortran 77 and Fortran 90 programs. csWMPI has been tested with version 9.0 of Absoft Fortran for Linux.

Compiling Fortran 77 and 90 programs follow the same pattern and the same switches have to be used. The include directory has to be set to:

/usr/include/csWMPI/fortran

Provided that you have installed csWMPI in the default directories. Moreover, a compiler specific library (U77) has to be linked into the executable. This is done by adding the switch -lU77 when compiling. Thus, if you want to compile the Fortran 90 Hello World example from command-line you have to execute the following command:

f90 -o hello_world hello_world.f90 -I/usr/include/csWMPI/fortran -lU77 -lcsWMPI2

And if you want to compile the Fortran 77 Hello World example from command-line you have to execute the following command:

f77 -o hello_world hello_world.f -I/usr/include/csWMPI/fortran -lU77 -lcsWMPI2

(Actually, the f90 can be used for both Fortran 77 and Fortran 90 programs.)


Lahey

csWMPI supports Lahey's Fortran compiler lf95 for both Fortran 77 and Fortran 90 programs. csWMPI has been tested with version 6.20 of Lahey Fortran for Linux.

In order to compile Fortran programs with lf95 you have to add the path of the csWMPI Fortran header files. If you have installed csWMPI in the default location the include files can be found in:

/usr/include/csWMPI/fortran

Thus, if you want to compile the Fortran 90 Hello World example from command-line you have to execute the following command:

lf95 -o hello_world hello_world.f90 -I/usr/include/csWMPI/fortran -lcsWMPI2

And if you want to compile the Fortran 77 Hello World example from command-line you have to execute the following command:

lf95 -o hello_world hello_world.f -I/usr/include/csWMPI/fortran -lcsWMPI2



© 2009 Critical Software SA. All trademarks and copyrights on this page are owned by their respective owners.
cscsWMPI II™, cscsWMPI™ and PatentMPI™ are trademarks of Critical Software SA. All Rights Reserved.