Which Fortran compiler options to use?

To get TONTO to work on any platform, or to understand how to change it to produce certain version for debugging or profiling, you need to decide what compile options to use on the Fortran compiler that you have. In general these changes are compiler specific, but there are usually compler options which correspond to each other across platforms.

In all cases, you should alter the Makefile variables FC, FOPTNS, FFLAGS, FPROF, FDEBUG, FFAST, FSUFFIX, PROGSUFFIX, MODSUFFIX, OBJSUFFIX, LIBS, and DEFS. For example, here are the values for the COMPAQ f95 compiler on the OSF1 operating system. These options can be found in the COMPAQ-f95-on-OSF1 file in the site_config directory.

FC       = f95
FOPTNS   = $(FFAST)
FFLAGS  := -cpp -module ./new_modules  \
           -I. -I./f90files -I./interfaces -I./modules -I./objects
FPROF   := -p -g3 -gen_feedback
FDEBUG  := -g -ladebug -check bounds -check format -check overflow \
           -warn argument_checking -warn declarations -warn unused \
           -warn truncated_source -error_limit 10 -std
FFAST   := -g0 -O4 -arch host -align dcommons -assume noaccuracy_sensitive \
           -pipeline -unroll 8 -threads -speculate by_routine -transform_loops
FSUFFIX := f90
 
LIBS    := -lcxml
DEFS    := -DCOMPAQ -DUSE_ERROR_MANAGEMENT

The meaning of each of these variables is now discussed.

The FC variable

The variable FC is set to the command for the Fortran95 compiler on your machine,

FC       = f95
It consists of the FC variable, followed by the assignment operator =, and then command f95, which is the name of the Fortran95 compiler to use. If you don't know what this command is, try typing
man -k fortran

The FOPTNS variable

The FOPTNS variable is not set to have any specific compiler optionsr; instead, it is is set to be equal to one of three other variables, as shown by the three possibile the lines below:

FOPTNS   = $(FFAST)
FOPTNS   = $(FDEBUG)
FOPTNS   = $(FFAST) $(FPROF)
Which one you choose depends on the type of executable that you want to generate. If set to $(FFAST) then the options used will be those for producing the optimal executable for TONTO. If set to $(FDEBUG) the options used will be those appropriate for using TONTO in a debugger, and will usually involve no optimisation at all. If set to $(FFAST) $(FPROF) then the executable generated will be appropriate for profiling using a profiling tools, to see where the bottlenecks in exdecutaion speed will occur.

The complie options to set for the variables FFAST, FDEBUG and FPROF are described below.

The FFLAGS variable

The FFLAGS variable must be set to the basic option flags that are needed to compile TONTO which are common to all compilations.For example,

FFLAGS  := -cpp -module ./new_modules  \
           -I. -I./f90files -I./interfaces -I./modules -I./objects
This line consists of the FFLAGS variable, followed by an assignment operator, :=, followed by the list of standard options which the compiler is to use. The \ character at the end of the first two lines means that the line following the \ character should be joined onto the first, as if the \ character was not there, as if there were only one line in all. It is useful for splitting up long lines.

To get TONTO to compile and work, Fortran compiler options must be found for the tasks described below, and they must replace or substitute for all the options to the right of the FFLAGS variable assignment in the example above.

The FFAST variable

The FFAST variable must be set to the options flags that are needed to compile TONTO with as high a degree of optimisation as is reasonably possible. For example,

FFAST   := -g0 -O4 -arch host -align dcommons -assume noaccuracy_sensitive \
           -pipeline -unroll 8 -threads -speculate by_routine -transform_loops
In this case, the -g0 option indicates that no debugging information is to be used. The -O4 indicates that optimisation level 4 is to be used, which is the highest appropriate for intra-module optimisation on the COMPAQ compiler. SImilar options will be available on other compilers.

Other options which may not appear on other compilers are:

The FDEBUG variable

The FDEBUG variable must be set to the options flags that are needed to compile TONTO so that it works with a debugger and so that appropriate warnings are issued for unusual or non-conformant code. This is recommended for developers.

FDEBUG  := -g -ladebug -check bounds -check format -check overflow \
           -warn argument_checking -warn declarations -warn unused \
           -warn truncated_source -error_limit 10 -std
In this case, the -g option indicates that full debugging information is to be used. Sometimes, the -O0 option may also need to be specified to indicate that there is to be no optimisation used. (In this case, it is assumed as the default).

The options which may be compiler specific are:

The FPROF variable

The FPROF variable is set to the compiler options needed to perform profiling tests on TONTO programs. That is, tests which examine the speed of execution of various routines in TONTO. Profiling tests are often done in conjunction with the highest levels of optimisation (it doesn't make sense to check the speed of an unoptimised program).

For the COMPAQ compiler, the following options are required

FPROF   := -p -g3 -gen_feedback
The -p indicates profiling options should be turned on. The -g3 indicates a high level of debugging information is to be included with the executable. The -gen_feedback indicates that a statistics file is to be generated at the time of execuation, which can be later analysed by a profiling tool.

The FSUFFIX variable

This is set to the suffix used to indicate a Fortran90 or Fortran95 program to your compiler. Typically, it will be

FSUFFIX := f90
Although other common possibilities are .F90, .f95 or .F95. The default is .F90. Note that unix is case-sensitive for filenames.

It is important to note that on some systems, the type of suffix determines whether the C-preprocessor is executed.

The PROGSUFFIX variable

This is set to the suffix used to indicate an executable program to your compiler. The default is

PROGSUFFIX := exe
if none is specified. Note that unix is case-sensitive for filenames.

The MODSUFFIX variable

This is set to the suffix used for module information files by your compiler. It is by the makefile while building the program. The default is

MODSUFFIX := mod
if none is specified. Other possibilities include .d and .vo. Note that unix is case-sensitive for filenames.

The OBJSUFFIX variable

This is set to the suffix used for object files used by your compiler. The default is

OBJSUFFIX := o
if none is specified. A common possibility on the Windows platform is .obj. Note that unix is case-sensitive for filenames.

The LIBS variable

The LIBS variable is set so that the compiler can use the BLAS and LAPACK libraries. On the COMPAQ system these are bundled together in the libcxml library, which is included by the line

LIBS  := -lcxml
Other common possibilities may be
LIBS  := -llapack -lblas
or
LIBS  := -L /usr/lib/gcc-lib/i386-redhat-linux/2.96 -lg2c -llapack -lblas
The above lines are what you would use if you compile and install the freely available BLAS and LAPACK libraries with your own compiler. The procedure for doing this is described in a separate section.

The MODCASE variable

This is to tell the Makefile whether the module names get converted to uppercase or lowercase when outputting module information files. The default is

MODCASE := -lc
if none is specified. The other alternative is -uc to specify conversion to uppercase.

The DEFS variable

The DEFS variable is set to enable any machine specific commands in the fortran code, via the C-preprocessor. On the COMPAQ machine, we have

DEFS    := -DCOMPAQ -DUSE_ERROR_MANAGEMENT
Here, the -DCOMPAQ indicates that any C-processor directives which apply to the COMPAQ switch are to be activated. The -DUSE_ERROR_MANAGEMENT instructs the C-preprocessor to use code appropriate for generating an error-managed executable. You can also generate version which check for memory leaks, and test preconditions are postconditions to a routine. These possibilities are discussed in the chapter called Compiling customised versions of TONTO>.