Ada: Principal options of the Fortran and C/C++ compilers

We have detailed only some of the options proposed by the Intel compilers. We suggest that you consult the information online for the ifort and icc (man ifort and man icc) commands to have more ample information on all the available options.

Optimisation options of the Fortran and C/C++ compilers

Option -O (uppercase letter O) is used to manage a code optimisation. It is possible to indicate the desired level of optimisation by adding an integer value (0, 1, 2 or 3). Option -O0 (hyphen uppercase O plus zero) inhibits all optimisation done by the compiler. Writing -O (hyphen uppercase O) is equivalent to -O2.

Attention: Beginning at level 3, the program semantic can be modified. For example, (2.*3.1)*4.2 can be interpreted as 2.*(3.1*4.2). Be very vigilant, therefore, regarding the results of your calculations: Beginning with -O3, it is necessary to validate the results of your models.

Optimisation options Comments
-O0 No optimisation is done.
-O1 Some optimisations are done which allow you to accelerate the calculations.
-O2 or -O Optimisation level, including vectorisation, inlining, loop unrolling, inter-procedural optimisation within each source file, …
-O3 Optimisations which are more aggressive than in -O2, with prefetching, loop transformations, code duplication, …
-O3 -xAVX The -xAVX option allows you to activate vectorisation (specific instructions for Sandy Bridge type processors). It produces a more extensive analysis of data dependancy and can, therefore, increase the compilation time. Attention: The code compiled in this way cannot be executed on the pre/post-processing nodes because these are Westmere type processors.
-O3 -axAVX,SSE4.2 The -ax option allows you to generate a code called architecture dependent. The choice of instructions executed is made in function of the architecture which you are running on. This combination of options allows you to obtain a code optimised for Sandy Bridge (compute nodes) and for Westmere (pre/post-processing nodes).

It is possible that your code won't give you the same results in -O3 as in -O2. You can, however, obtain an intermediate optimisation level by adding the option -fp-model followed by a keyword such as -O3 -fp-model precise (for example).

Optimisation options Comments
-O3 -fp-model strict Optimisations which ensure the precision of floating-point calculations (the strictest level). In addition, exceptions handling is activated.
-O3 -fp-model strict -fp-model no-except The same as the preceding option but without exceptions handling.
-O3 -fp-model precise Ensures the precision of calculations on floating-point data but without exceptions handling.
-O3 -fp-model precise -fp-model except The same as the preceding option but with exceptions handling.
-O3 -fp-model fast=1 ou -O3 -fp-model fast Authorises more aggressive optimisations but can alter the accuracy of calculations on floating-point numbers. It can give improved performance but cannot be combined with exceptions handling (-fp-model except).
-O3 -fp-model fast=2 The code can be even faster but also less accurate than with -fp-model fast. It cannot be combined with exceptions handling (-fp-model except).

Remark: The Intel option -fast is equivalent to specifying the following options: -ipo -O3 -no-prec-div -xHost -static. On Ada, you must remove -static in order to obtain an executable file; alternatively, you can specify the options individually (and not include -static).

Memory options of the Fortran and C/C++ compilers

Memory options Comments
-auto The variables declared within a program unit without the attribute save, and uninitialized, will be appropriated to the run-time stack. The -auto option allows you to reduce the size of the executable file and to use the memory in a dynamic way. Nevertheless, you must be careful in reading such variables before they have been initialised because, by default, they have an unpredictable initial content. The -ftrapuv option allows you to detect uninitialised variables (see debugging options).
-assume realloc_lhs This option allows you to activate the Fortran 2003 mechanism of memory auto-allocation during the assignments; this concerns variables having the ALLOCATABLE attribute, most often the tables. Using this mechanism can result in additional cost. Be well aware that if the mechanism is used without also positioning this option, the results are unpredictable.
-mcmodel=small This is the default value. Therefore, the memory space reserved for the code and data is limited to 2GB. This value is sufficient in most cases and it gives the best code performance.
-mcmodel=medium -shared-intel In this case, only the memory space reserved for the code is limited to 2GB; there is no restriction for the data. The code performance can be slightly degraded. This option is necessary if you have static and global data (static tables) which exceed 2GB in size. Note that you must also specify the option -shared-intel.
-mcmodel=large -shared-intel With this option there is no restriction concerning the memory space reserved for the code and data. The code performance can be slightly degraded. This option is necessary if you have static and global data (static tables) which exceed 2GB in size. Note that you must also specify the option -shared-intel.

Remark: The -mcmodel=medium -shared-intel options must be added to the compilation and linking phases if you obtain linking messages such as the following:

relocation truncated to fit: R_X86_64_PC32 against symbol

These messages can appear when using the large static tables.

Diagnostic options of the Fortran et C/C++ compilers

Options which allow you to recuperate certain diagnostic messages on the standard output or in a file:

Listing options Comments
-openmp-report[=n] Allows you to generate a report (on the standard output) of the transformations done for an OpenMP code. <The n is optional (= 1 by default) and can have the value of 0, 1 or 2: The higher the n value is, the more detailed the report is. Of course, this option is only activated if it is accompanied by the option -openmp.
-opt-report [n] To generate a report (on the standard output) of the transformations related to the optimisation (inlining, vectorisation, loop unrolling, etc). The n is optional (= 2 by default) and can have the value of 0, 1, 2 or 3: The higher the n value is, the more detailed the report is.
-opt-report-file=filename To generate a report in the file specified by filename. In this case, it is not necessary to specify the option -opt-report.
-opt-report-phase=phase -opt-report Combination of 2 options allowing you to generate a report of the optimisations carried out with the phase element of the optimiser; phase can have the following values :
ipo : The Interprocedural Optimiser phase
hlo : The High Level Optimiser phase
hpo : The High Performance Optimiser phase
ilo : The Intermediate Language Scalar Optimiser phase
pgo : The Profile Guided Optimisation phase
all : All optimiser phases
-par-report[n] -parallel To generate a report concerning the auto-parallelisation of the code. When the loops are not parallelised, it indicates the reason why the parallelisation was not carried out (dependancy, …). In this case, you must also specify the option -parallel. The n is optional (= 1 by default) and can have the value of 0, 1, 2 or 3: The higher the n value is, the more detailed the report is.
-vec-report[n] To generate a report (on the standard output) concerning the vectorisation of the code. When the vectorisation cannot be done, it indicates the reason for this (dependancy, …). The n is optional (= 1 by default) and can have the value of 0, 1, 2, 3, 4, or 5: The higher the n value is, the more detailed the report is.

Examples :

    $ ifort -O3 -opt-report 3 prog.f90
    $ ifort -O3 -opt-report-file=my_report_file prog.f90
    $ ifort -O3 -par-report3 -parallel prog.f90
    $ icc -O3 -opt-report 3 prog.f90
    $ icc -O3 -opt-report-file=my_report_file prog.f90
    $ icc -O3 -par-report3 -parallel prog.f90

Debugging options of the Fortran and C/C++ compilers

In a debugging phase, the following options can be used with both the Fortran compiler and the C/C++ compiler. We suggest that you consult the information online for the ifort and icc (man ifort and man icc) commands to have more ample information on all the available options.

Debugging options Comments
-g Allows you to generate the table of symbols (line number, variables, …) which can be used afterwards by a debugger. This option retains the requested optimisation level (-O1, -O2, -O3). Otherwise, this option disactivates all optimisation by default (implies -O0).
-debug or -debug full or -debug all These options allow generating the complete information of debug. Recommended when combining -g with a requested optimisation level (-O1, -O2, -O3): by example -g -O2 -debug.
-traceback Allows obtaining more information when an error is produced at the execution. -traceback is positioned along with option -g but it is not positioned with -g0.
-ftrapuv Initialises the local variables with aberrant values in the stack (very large integer, invalid address). This allows the detection of uninitialized variables by provoking an error at the execution. Note that the **-ftrapuv** option also positions -g.
-check uninit Fortran -check-uninit C Allows detecting, during the execution, if the intrinsic type scalar variables (integer, real, complex or logical) without the attribute SAVE are uninitialized.
-fp-stack-check Allows the generation of an exception as soon as a function call returns an incorrect value.
-no-ftz The -ftz option is positioned by default with the -O1, -O2 and -O3 optimisations. As a result, the very small denormal numbers are flushed to zero during the execution and this can produce erroneous results. It is possible, therefore, to disactivate this function by adding -no-ftz which permits the detection of these underflows.

Debugging options of the Fortran compiler

The Fortran compiler also allows you to use the following options:

Debugging options Comments
-debug-parameters all Allows generating debug information for parameter type variables. This is necessary in order to see the parameter values with a debugger.
-heap-arrays Allows placing all the temporary or automatic tables in the heap (instead of the stack) in the case of the stack turning out to be too small.
-fpe-all=0 -no-ftz -traceback This combination allows stopping the execution as soon as an exception (overflow, underflow, division by zero, invalid operation,…) is produced; it also shows at what code level the exception was produced. This option operates in each subroutine, contrary to the-fpe0 option which only acts on the principal program.
-check bounds Allows detecting, during the compilation and/or the execution, if a table is addressed outside of its bounds (bounds checking).
-check pointers Allows detecting, during the execution, if a pointer is initialized or not, and if an allocatable table has been allocated or not, before using them.
-check all Allows carrying out different checks simultaneously (in particular, those listed above).
-warn declarations Allows obtaining messages signaling undeclared variables (the same as if the source contained an IMPLICIT NONE).
-warn interfaces Allows obtaining messages signaling incoherences between the calls and the definitions of each code subroutine and function. Note that the compiler generates an interface block for each subroutine and function (option -gen-interfaces).
-warn truncated_source For files in fixed format, the compiler will transmit a message if a source line surpasses the maximum authorised length. Note that this length can be extended to 132 characters maximum (default 72) with the option -extend_source.
-warn all ou -warn Allows the simultaneous generation of different warning messages (in particular, those listed above).

Examples :

$ ifort -g -debug -fpe-all=0 -no-ftz -traceback -fp-stack-check -check all -warn all my_prog.f90
$ icc -g -debug -no-ftz -traceback -fp-stack-check -check-uninit my_prog.c

See also the paragraph: Debugging tools.

List of options activated for the Fortran compiler

  • The list of activated options can evolve over time and can also change in function of the compiler call made. It is possible to generate a source file list by using -list : rlab432@ada > ifort -list prog.f90 This command creates the file prog.lst in the same directory as the source. By default, it contains:
    • The included file content via the instruction include
    • The list of symbols for each subroutine
    • The list of compilation options
  • The option -show mot-clef allows restraining the action of the option -list :
    • -show noinclude prevents writing the included file content in prog.lst (obtained via the instruction include)
    • -show nomap prevents writing the list of symbols for each subroutine in prog.lst.
    • -show nooptions prevents writing the list of compilation options in prog.lst.

Size of different Fortran base types

The variables declared by using the default types INTEGER, REAL, or COMPLEX are stored in memory based on words of 4 bytes. The optional parameter KIND=n, indicated after the type, allows us to influence this size in the most explicit and dependable way.In addition, there are compilation options which allow overall modification of memory size for storing variables:

  • -integer-size 16/32/64:

Sets the reservation in memory on words of 2/4/8 bytes (4 by default) for the integer and logical values declared with the INTEGER or LOGICAL types (without specifying the parameter KIND=n)

  • -real-size 32/64/128: The variables declared with REAL or COMPLEX types (without specifying the parameter KIND) are promoted respectively on 4, 8 and 16 bytes.

Read or write a Fortran IEEE big_endian binary file

Ada is a Linux machine. It generates, therefore, the Fortran binary files in the little-endian format by default. In order to read or write a Fortran IEEE big-endian binary file, it is necessary to use the environment variable F_UFMTENDIAN.Example, to read a Fortran binary file written in big-endian (originating from our Power6 Vargas, as example) on unit 12 :

$ ifort -o prog_big_endian prog_big_endian.f90
$ export F_UFMTENDIAN=''big:12''
$ ./prog_big_endian

Remark:

If you do not specify the logical unit number, the variable operates on all the units and, as a result, all the files are considered as having the same format (big-endian, as on Power6 in this example) :

$ ifort -o prog_big_endian prog_big_endian.f90
$ export F_UFMTENDIAN=''big''
$ ./prog_big_endian

It is possible to specify several logical units. The units 12, 15 and all those from 20 to 30 are shown in this example:

$ export F_UFMTENDIAN=''big:12,15,20-30''
$ ./prog_big_endian

Attention:

On Ada, in the case of a file with direct access, the default record length specified with RECL is in words (4 bytes). To specify this in octets it is necessary to compile with the option -assume byterecl.

$ ifort -assume byterecl -o prog_big_endian prog_big_endian.f90
$ export F_UFMTENDIAN=''big:12''
$ ./prog_big_endian