Jean Zay: Principal options of the Intel Fortran and C/C++ compilers

We have detailed only some of the options proposed by the Intel compilers. We suggest that you consult the manual pages for the ifort and icc commands on Jean Zay (man ifort and man icc) to have more detailed information about 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: This is, moreover, the default optimisation level.

Important note: 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 model by comparing them with an execution implemented with a moderate optimisation or, intentionally, without any optimisation at all.

Optimisation options Commentaries
-O0 No optimisation is performed.
-O1 Some optimisations are performed which allow moderate acceleration of the calculations.
-O2 or -O (default) Level of optimisation which includes vectorisation, inlining, loop unrolling, inter-procedural optimisation within each source file, etc.
-O3 Optimisations are more aggressive than in -O2, with prefetching, loop transformations, code duplication, etc.
-O3 -xHost Allows activation of the AVX2 vectorisation, and partially of AVX512. It provokes a more exhaustive analysis of data dependency and, therefore, can increase the compilation time.
-O3 -xHost -qopt-zmm-usage=high Allows the total activation of AVX512 vectorisation. It provokes a more exhaustive analysis of data dependency and, therefore, can increase the compilation time.

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 (for example, -O3 -fp-model precise).

Optimisation options Commentaries
-O3 -fp-model strict Optimisations which ensure the precision of floating-point calculations (the strictest level). In addition, Exception Handling is activated.
-O3 -fp-model strict -fp-model no-except The same as the preceding option but without Exception Handling.
-O3 -fp-model precise Ensures the precision of calculations on floating-point data but without Exception Handling.
-O3 -fp-model precise -fp-model except The same as the preceding option but with Exception 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 Exception 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 Exception Handling (-fp-model except).

Comment: In its current state, the -fast option is equivalent to the -ipo -O3 -no-prec-div -xHost -static options. To obtain an executable file, it is necessary to remove the -static option. We also advise you to NOT specify the -fast option alone: use -ipo -O3 -no-prec-div -xHost.

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

Memory options Commentaries
-auto The local variables declared within a program unit without the SAVE attribute and uninitialised are allocated to the run-time stack at the beginning of the unit. This option, then, reduces the size of the executable file (DATA and BSS static zones). The local variables must be set manually; if not, they have an undefined value (the ''-ftrapuv'' option detects the uninitialised variables). The default option is -auto-scalar (only the local scalar variables are allocated in the stack). The inverse option is -save : all the local variables inherit the SAVE attribute; they are allocated statically in the BSS zone and automatically initialised to a null value.
-mcmodel=small The memory space reserved for the code (zone TXT) and for the data (DATA and BSS zones) 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 (zone TXT) 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 arrays, for example) which exceed 2GB. Note that you must also specify the -shared-intel option.
-mcmodel=large -shared-intel There is no restriction concerning the memory space reserved for the code and data. The code performance can be slightly degraded. Note that you must also specify the -shared-intel option.

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

relocation truncated to fit: R_X86_64_PC32 against symbol ...

These messages can appear when using the large static arrays, for example.

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

At compilation, the following options allow you to recuperate certain diagnostic messages on the standard output or in a file:

Listing options Commentaries
-qopt-report=[n] Generates, on the standard output, a report of the transformations related to the optimisation (inlining, vectorisation, loop unrolling, etc.). The n value is optional and can have the value of 0, 1, 2 or 3 (default is 2) . The higher the n value, the more detailed the report.
-opt-report-file=filename Generates a report in the specified file (filename). In this case, it is no longer necessary to specify the -qopt-report option.
-qopt-report-phase=phase -qopt-report Combination of 2 options in order to generate a report of the optimisations realised by the optimiser phase element. The values of phase can be:
ipo : Interprocedural Optimiser phase
hlo : High Level Optimiser phase
hpo : High Performance Optimiser phase
ilo : Intermediate Language Scalar Optimiser phase
pgo : Profile Guided Optimisation phase
openmp: OpenMP
par : Auto-parallelisation
vec : Vectorisation
all : All optimiser phases.

Examples :

$ ifort -O3 -qopt-report=3 prog.f90
$ ifort -O3 -qopt-report-file=my_report_file prog.f90
$ ifort -O3 -qopt-report=3 -qopt-report-phase=par -parallel prog.f90
$ icc -O3 -qopt-report=3 prog.c
$ icc -O3 -qopt-report-file=my_report_file prog.c
$ icc -O3 -qopt-report=3 -qopt-report-phase=par -parallel prog.c

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

During a debugging session, the following options can be used with both the Fortran compiler and the C/C++ compiler. We suggest that you consult the compiler information on Jean Zay (commands man ifort and man icc) to obtain more complete information.

Debugging options Commentaries
-g Generates the symbol table (line numbers, variables, …) which can then be exploited by a debugger. This option retains the optimisation level manually requested (-O1, -O2 or -O3). If the optimisation level is not manually specified, this option deactivates all optimisation (-g is equivalent to -g -O0).
-debug or -debug full or -debug all Generates complete debug information. Recommended when combining -g with a specific optimisation level (-O1, -O2 or -O3) : for example, -g -O2 -debug.
-traceback Provides more information when an error occurs during execution. This option is also set with -g.
-ftrapuv Initialises the local variables in the stack with aberrant values (very large integer, invalid address). This allows detecting the uninitialised variables by provoking an error during execution. Note that it also sets the -g option.
-check uninit (Fortran) -check=uninit (C) During execution, allows detection of scalar variables of intrinsic type (integer, real, complex or logical), without the SAVE attribute, which are not initialised.
-fp-stack-check Generates an Exception as soon as a function call returns an incorrect value.
-no-ftz The -ftz option is set by default with the -O1, -O2 and -O3 optimisations: This flushes the very small subnormal numbers to zero during the execution which can produce erroneous results. It is possible, therefore, to deactivate this function by adding the -no-ftz option in order to detect these underflows.

Debugging options of the Fortran compiler

With the Fortran compiler, you can also use the following options:

Debugging options Commentaries
-debug-parameters all Generates the debug information for the PARAMETER type variables. It is necessary to do this to see the PARAMETER values with a debugger.
-heap-arrays Places all the temporary or automatic arrays in the heap (rather than the stack) if there is not enough remaining space in the stack.
-init=arrays,snan Initialises all uninitialised intrinsic type variables and arrays to signaling NaNs. This option also sets -fpe0. To avoid recovering exceptions which are not related to uninitialised variables, we recommend reducing the optimisation level to -O1 or -O0, or to use -fp-speculation=safe when doing uninitialised variable detection.
-fpe-all=0 -no-ftz -traceback This combination stops the execution as soon as there is an Exception (overflow, underflow, divide-by-zero, invalid operation, …). It also shows at what code level the exception occurred. This option operates in each subroutine, contrary to the -fpe0 which only acts on the principal program.
-check bounds Detects if there is an out-of-bounds array access (bounds checking), at compilation and during execution.
-check pointers When using pointers, this option detects during execution if a pointer is initialised or not and if an allocatable array has been allocated or not.
-check all Allows the simultaneous effectuation of the 2 checks listed above.
-warn declarations Generates messages which indicate all the undeclared variables (the same as if the source code contained an IMPLICIT NONE).
-warn interfaces Generates messages which indicate the incoherences between the calls and the definitions of each code subroutine and each code function. Note that the compiler generates an interface block for each of these (option -gen-interfaces is implicit).
-warn truncated_source For files in fixed format, the compiler will transmit a message if a source line surpasses the maximum authorised length (default: 72 characters). Note that this length can be increased to 132 characters (maximum) with the option -extend_source.
-warn all or -warn Generates various warning messages simultaneously (particularly those cited above).
-stand f08 Warnings are generated if the Fortran 2008 standard is not respected.

Debugging options of the C/C++ compiler

With the C/C++ compiler, you can also use the following option:

Debugging options Commentaries
-check-pointers=rw When using pointers, detects the invalid memory accesses during execution (this includes the usage of arrays, whether dynamically allocated or not).

Examples :

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

List of options activated for the Fortran compiler

The list of default options activated by Intel can evolve over time, but also in function of the context of a compiler call. Thus, the same source code compiled with the same options can lead to a different executable file which does not give the same numerical results. Therefore, it is useful to generate a listing of the compilation of a source file by using the option -list :

ifort -list prog.f90

This command creates the prog.lst file in the same directory as the source file.
It contains, by default:

  • The content of the included files via the INCLUDE instruction.
  • The list of symbols for each subroutine.
  • The list of compilation options.

The -show keyword option allows restricting the action of the -list option :

  • -show noinclude deletes the content of the files included via the INCLUDE instruction.
  • -show nomap deletes the list of symbols printed for each subroutine.
  • -show nooptions deletes the list of the compilation options.

Sizes of the basic Fortran data types

The variables declared by using the default types INTEGER, REAL or COMPLEX are stored in memory based on 4-byte words. We can change this size in the source code with the optional parameter KIND=n which is indicated after the type: This is the most explicit and dependable way to do this.

There are compilation options which modify the length of variables overall, but we strongly advise you against their usage for the portability reasons:

  • Equivalent options do not function in the same way on different platforms.
  • It is very easy to forget these options when compiling your code or when sharing it with someone else: If this happens, the execution results are false!

For the purpose of occasional one-time tests, these options are:

  • -integer-size 16/32/64: Forces the reservation in memory of the integers and Booleans declared with the INTEGER or LOGICAL type (without specifying the parameter KIND=n) on words of 2/4/8 bytes (4 by default).
  • -real-size 32/64/128: The integers declared with the REAL or COMPLEX type (without specifying the parameter KIND=n) are promoted respectively on 4, 8 and 16 bytes.

Read or write a big-endian IEEE binary file with Fortran

Jean Zay is a Linux machine. By default, it generates the Fortran binary files in the little-endian format. To read or write a big-endian IEEE binary file with Fortran, it is necessary to use the environment variable F_UFMTENDIAN. For example, to read a binary file which was written in big-endian (from our former IBM Power6 Vargas) on logical unit 12:

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

Comment: If you do not specify the logical unit number, the variable will operate on all the units. In consequence, all the files will be considered as having the same format (the following example is for big-endian):

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

It is possible to specify several logical units. Here, the units 12, 15 and all those from 20 to 30:

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

Important note: In case of a file with direct access, the default record length, specified with the RECL keyword when doing the file OPEN in the source code, is in 4-byte words. To specify this record size in bytes directly when OPENing the file, it is necessary to compile with the -assume byterecl option.

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