This page was translated by an AI (LLM) with a cursory human check and is awaiting full review.
Intel Compiler Options (Fortran, C/C++)
We will only detail some of the options offered by the Intel compilers here. We invite you to consult the ifort and icc manuals available on Jean Zay (commands man ifort and man icc) for detailed information on all available options.
Optimisation Options
The -O option (uppercase letter O) is used to manage code optimisation. You can specify the desired optimisation level by adding an integer value (0, 1, 2 or 3). The -O0 option (uppercase letter O followed by zero) disables all compiler optimisations. The -O option (uppercase letter O alone) is equivalent to -O2; it is also the default optimisation level.
From level 3 onwards, the program semantics may be altered. For example: (2.*3.1)*4.2 may be interpreted as 2.*(3.1*4.2). Therefore, be very careful with the results of your computations: from -O3 onwards, it is necessary to validate the results of your model by comparing them with an execution performed with moderate or no optimisation.
| Optimisation Options | Comments |
|---|---|
-O0 | No optimisation performed. |
-O1 | Some optimisations moderately speed up computations. |
-O2 or -O (default) | Optimisation level including vectorisation, inlining, loop unrolling, inter-procedural optimisation within each source file, etc. |
-O3 | More aggressive optimisations than in -O2 with prefetching, loop transformations, code duplication, ... |
-O3 -xHost | Enables AVX2 and partial AVX512 vectorisation. It triggers a more exhaustive analysis of data dependencies and may increase compilation time. |
-O3 -xHost -qopt-zmm-usage=high | Fully enables AVX512 vectorisation. It triggers a more exhaustive analysis of data dependencies and may increase compilation time. |
It is possible that your code does not give the same results in -O3 as in -O2. You can then obtain an intermediate optimisation level by adding the -fp-model option followed by a keyword (for example -O3 -fp-model precise).
| Optimisation Options | Comments |
|---|---|
-O3 -fp-model strict | The optimisations performed ensure the precision of floating-point calculations (strictest level). Additionally, exception handling is enabled. |
-O3 -fp-model strict -fp-model no-except | As above, but without exception handling. |
-O3 -fp-model precise | Ensures the precision of floating-point calculations. There is no exception handling. |
-O3 -fp-model precise -fp-model except | As above, but with exception handling. |
-O3 -fp-model fast=1 or -O3 -fp-model fast | Allows more aggressive optimisations that may alter the precision of floating-point calculations. May provide better performance, but cannot be combined with exception handling (-fp-model except). |
-O3 -fp-model fast=2 | The code may be even faster and less precise than with -fp-model fast=1. Cannot be combined with exception handling (-fp-model except). |
Currently, the -fast option is equivalent to the options: -ipo -O3 -no-prec-div -xHost -static. To obtain an executable, it is necessary to remove the -static option. As we advise against specifying the -fast option in isolation, use: -ipo -O3 -no-prec-div -xHost.
Memory Options
| Memory Options | Comments |
|---|---|
-auto | Local variables declared within a program unit without the SAVE attribute and not initialised will be allocated in the execution stack (stack) upon entry to this unit. This option reduces the size of the executable (DATA and BSS static areas). Local variables must be explicitly valued; otherwise, they have an undefined value (the -ftrapuv option allows detection of uninitialised variables). By default, -auto-scalar is enabled (only scalar local variables are allocated in the stack). The opposite option is -save, where all local variables inherit the SAVE attribute and are statically allocated in the BSS area and initialised to a null value. |
-mcmodel=small | The memory space reserved for code (TXT area) and data (DATA and BSS areas) is limited to 2 GB. This value is sufficient in most cases and guarantees the best performance. |
-mcmodel=medium -shared-intel | Only the memory space reserved for code (TXT area) is limited to 2 GB, with no restriction for data. Performance may be slightly degraded. This option is necessary if you use static and global data (such as static arrays) whose size exceeds 2 GB. Note that the -shared-intel option must also be specified. |
-mcmodel=large -shared-intel | There is no restriction on the memory space reserved for code or data. Performance may be slightly degraded. Note that the -shared-intel option must also be specified. |
The -mcmodel=medium -shared-intel options must be added to both the compilation and the link editing; otherwise, you will receive messages like:
relocation truncated to fit: R_X86_64_PC32 against symbol ...
These messages may appear when using large static arrays, for example.
Diagnostic Options
During compilation, some options allow you to retrieve certain diagnostic messages on the standard output or in a file:
| Listing Option | Comments |
|---|---|
-qopt-report=[n] | Generates, on the standard output, a report of the transformations related to optimisation (inlining, vectorisation, loop unrolling, etc.). n is optional and can be 0, 1, 2 or 3 (default 2). The higher the n, the more detailed the report. |
-opt-report-file=filename | Generates a report in the file specified by filename. In this case, it is no longer necessary to specify the -qopt-report option. |
-qopt-report-phase=phase -qopt-report | Combination of two options to generate a report of the optimisations performed by the phase element of the optimiser. phase can be:ipo : Interprocedural Optimizer phase;hlo : High Level Optimizer phase;hpo : High Performance Optimizer phase;ilo : Intermediate Language Scalar Optimizer phase;pgo : Profile Guided Optimization phase;openmp : OpenMP;par : Auto-parallelisation;vec : Vectorisation;all : All optimizer 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 for 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 invite you to consult the compiler help on Jean Zay (commands man ifort and man icc) for more information.
| Debugging Option | Comments |
|---|---|
-g | Generates the symbol table (line numbers, variables, ...). This table can be exploited by a debugger. This option preserves the explicitly requested optimisation level (-O1, -O2 or -O3). Without explicitly specified optimisation, all optimisation is disabled (-g is equivalent to -g -O0). |
-debugor -debug fullor -debug all | Generates complete debugging information. Recommended with -g and 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 local variables in the stack with aberrant values (very large integer, invalid address). Allows detection of uninitialised variables by causing an error during execution. Also sets the -g option. |
-check uninit (Fortran)-check=uninit (C) | Detects at execution if scalar variables of intrinsic type (integer, real, complex, logical) and without the SAVE attribute are not initialised. |
-fp-stack-check | Allows an exception to be generated as soon as a function call returns an incorrect value. |
-no-ftz | The -ftz option is enabled by default with the optimisations -O1, -O2, and -O3. It sets very small denormalised numbers to zero during execution, which can produce incorrect results. The -no-ftz option allows this functionality to be disabled and these underflows to be detected. |
Debugging Options for the Fortran Compiler
With the Fortran compiler, you can also use the following options:
| Debugging Option | Comments |
|---|---|
-debug-parameters all | Generates debugging information for variables of type PARAMETER. This is necessary to see the values of PARAMETER with a debugger. |
-heap-arrays | Places all temporary or automatic arrays in the heap instead of the stack if the latter is too small. |
-init=arrays,snan | Forces all uninitialised intrinsic type variables and arrays to NaN. This option implies -fpe0. To avoid exceptions that are not related to uninitialised variables, it is recommended to reduce the optimisation level to -O1 or -O0. Alternatively, you can use -fp-speculation=safe for the detection of uninitialised variables. |
-fpe-all=0 -no-ftz -traceback | This combination of options stops execution as soon as an exception (overflow, underflow, division by zero, invalid operation, etc.) occurs. It indicates at which level of the code it occurred. The control is performed in each subroutine, unlike the -fpe0 option which only acts on the main program. |
-check bounds | Detects at compilation and execution if an array is addressed outside its bounds (bound checking). |
-check pointers | Detects at execution if a pointer is initialised or not, if an allocatable array is allocated or not when using pointers. |
-check all | Enables the two options listed above simultaneously. |
-warn declarations | Generates messages signalling all undeclared variables (as if the source code contained a IMPLICIT NONE). |
-warn interfaces | Generates messages signalling inconsistencies between the calls and the definitions of each subroutine and each function of the code. Note that the compiler generates an interface block for each of them (implicit -gen-interfaces option). |
-warn truncated_source | For fixed-format files, the compiler will issue a message if a line of the source exceeds the maximum allowed length (default: 72 characters). Note that this length can be increased to a maximum of 132 characters with the -extend_source option. |
-warn all or -warn | Generates various warning messages simultaneously (including those mentioned above). |
-stand f08 | Warnings are generated if the Fortran 2008 standard is not respected. |
Debugging Options for the C/C++ Compiler
With the C/C++ compiler, you can also use the following option:
| Debugging Option | Comments |
|---|---|
-check-pointers=rw | Allows detection at execution of invalid memory accesses when using pointers. This includes the use of arrays, whether they have been 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 Enabled Options for the Fortran Compiler
The list of options enabled by default by the Intel compiler may change over time and depending on the context in which the compiler is called. Therefore, it is possible that with different versions, a compilation that you launch on the same code with the same options will generate an executable that does not produce exactly the same results. It is therefore useful to generate a listing of the compilation of a source file using the -list option:
ifort -list prog.f90
This command creates the prog.lst file in the same directory as the source file. By default, it contains:
- the content of the files included via the INCLUDE instruction,
- the list of symbols for each subroutine,
- the list of compilation options.
The -show mot-clef option allows you to restrict the action of the -list option:
-show noincluderemoves the content of the files included via the INCLUDE instruction,-show nomapremoves the list of symbols for each subroutine,-show nooptionsremoves the list of compilation options.
Size of Different Fortran Base Types
Variables declared using the default types INTEGER, REAL or COMPLEX are allocated memory based on 4-byte words. The optional KIND=n parameter indicated after the type in the source code allows you to influence this size; this is the most explicit and safest way to do so.
There are also compilation options that allow you to globally modify the length of variables, but we strongly advise against using them for portability reasons:
- the equivalent options do not work the same way on different platforms,
- it is very easy to forget these options when compiling your code or sharing it with someone else; in this case, the execution results are incorrect!
To allow for some punctual tests, these options are as follows:
-integer-size 16/32/64forces the memory allocation of integers and logicals declared with the typeINTEGERorLOGICAL(without specification of theKIND=nparameter) on 2/4/8 byte words (4 by default);-real-size 32/64/128: entities declared with the typeREALorCOMPLEX(without specification of theKIND=nparameter) are promoted respectively to 4, 8 and 16 bytes.
Reading or Writing an IEEE Big-Endian Binary File in Fortran
Jean Zay is a Linux machine: by default, it generates little-endian Fortran binary files. To write or read an IEEE big-endian binary file in Fortran, you must use the F_UFMTENDIAN environment variable. To read a binary file written in big-endian (for example, from our old IBM Power6 Vargas) on unit 12:
ifort -o prog_big_endian prog_big_endian.f90
export F_UFMTENDIAN=big:12
./prog_big_endian
If you do not specify a logical unit number, then the variable operates on all units. Consequently, all files are considered to have the same format (big-endian 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; here, units 12, 15 and all those from 20 to 30:
export F_UFMTENDIAN="big:12,15,20-30"
./prog_big_endian
In the case of a direct access file, the record size, indicated during the OPEN of the file in the source code using the RECL keyword, is interpreted in 4-byte words. To specify this record size directly in bytes during the OPEN, you must 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