Visible to Intel only — GUID: GUID-B518987A-F903-4113-ABA0-638C8F96D527
Visible to Intel only — GUID: GUID-B518987A-F903-4113-ABA0-638C8F96D527
Floating-Point Optimizations
Application performance is an important goal of the Intel® Fortran Compiler, even at default optimization levels. A number of optimizations involve transformations that might affect the floating-point behavior of the application, such as evaluation of constant expressions at compile time, hoisting invariant expressions out of loops, or changes in the order of evaluation of expressions. These optimizations usually help the compiler to produce the most efficient code possible. However, the optimizations might be contrary to the floating-point requirements of the application.
Some optimizations are not consistent with strict interpretation of the ANSI or ISO standards for Fortran. Such optimizations can cause differences in rounding and small variations in floating-point results that may be more or less accurate than the ANSI-conformant result.
The Intel® Fortran Compiler provides the -fp-model (Linux*) or /fp (Windows*) option, which allows you to control the optimizations performed when you build an application. The option allows you to specify the compiler rules for:
Value safety: Whether the compiler may perform transformations that could affect the result. For example, in the SAFE mode, the compiler won't transform x/x to 1.0 because the value of x at runtime might be a zero or a NaN . The UNSAFE mode is the default.
Floating-point contractions: Whether the compiler should generate fused multiply-add (FMA) instructions on processors that support them. When enabled, the compiler may generate FMA instructions for combining multiply and add operations; when disabled, the compiler must generate separate multiply and add instructions with intermediate rounding.
Floating-point environment access: Whether the compiler must account for the possibility that the program might access the floating-point environment, either by changing the default floating-point control settings or by reading the floating-point status flags. This is disabled by default. You can use the -fp-model:strict (Linux) /fp:strict (Windows) option to enable it.
Precise floating-point exceptions: Whether the compiler should account for the possibility that floating-point operations might produce an exception. This is disabled by default. You can use -fp-model:strict (Linux*) or /fp:strict (Windows). For ifort only, you can use -fp-model:except (Linux) or /fp:except (Windows) to enable it.
The following table lists possible keyword values for the -fp-model option:
Keyword |
Description |
---|---|
precise |
Enables value-safe optimizations on floating-point data and rounds intermediate results to source-defined precision. |
source (ifort only) |
Enables value-safe optimizations on floating-point data and rounds intermediate results to source-defined precision (same as precise keyword). |
strict |
Enables precise and except , disables contractions, and enables the property that allows modification of the floating-point environment. |
consistent |
Enables consistent, reproducible results for different optimization levels or between different processors of the same architecture. This setting is equivalent to the use of the following options: Linux: -fp-model precise -no-fma -fimf-arch-consistency=true Windows: /fp:precise /Qfma- /Qimf-arch-consistency:true |
fast |
Enables more aggressive optimizations on floating-point data. |
[no-]except (Linux) or except[-] (Windows) (ifort only) |
Determines whether strict floating-point exception semantics are used. |
The keyword that is specified for the -fp-model option may influence the choice of math routines that are invoked. Many routines in the libirc, libm, and libsvml libraries are more highly optimized for Intel microprocessors than for non-Intel microprocessors.
The following table describes the impact of different -fp-model keywords on compiler rules and optimizations:
Keyword |
Value Safety |
Floating-Point |
Floating-Point |
Precise Floating-Point |
---|---|---|---|---|
precise source (source is ifort only) |
Safe |
Sets fp-contract=on (ifx) or |
No |
No |
strict |
Safe |
No |
Yes |
Yes |
consistent |
Safe |
No |
No |
No |
fast (ifx only) |
Unsafe |
Sets fp-contract=fast |
No |
No |
fast=1 (default) (ifort only) |
Unsafe |
Sets fp-contract=fast |
No |
No |
fast=2 (ifort only) |
Very unsafe |
Sets fp-contract=fast |
No |
No |
except (ifort only) |
Unaffected |
Unaffected |
Unaffected |
Yes |
ifort only: It is illegal to specify the except keyword in an unsafe safety mode.
Based on the objectives of an application, you can choose to use different sets of compiler options and keywords to enable or disable certain optimizations, so that you can get the desired result.
For example, for applications that do not require support for subnormal numbers, the -fp-model or /fp option can be combined with the [Q]ftz option to flush subnormal results to zero. This flush can improve runtime performance on processors based on all Intel® architectures.