Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
29243 Discussions

Can the -O3 option create unexpected numerical instability?

woshiwuxin
Novice
614 Views
Hi, everyone!

I observed the default optimization option for ifort is -O2, and I tried -O3 and I found the performance of the compiled binary could be improved. Thus, I want to know why not to set -O3 as the default option? Is it possible for the -O3 option to produce some unexpected numerical instability?

Thank you in advance!
0 Kudos
1 Solution
TimP
Honored Contributor III
614 Views
Quoting - woshiwuxin
I observed the default optimization option for ifort is -O2, and I tried -O3 and I found the performance of the compiled binary could be improved. Thus, I want to know why not to set -O3 as the default option? Is it possible for the -O3 option to produce some unexpected numerical instability?

-O3 doesn't always improve performance, and may increase compile time. On a large application, it's likely to be necessary to find out which source files are best compiled at -O3.
I usually set -O3 -assume protect_parens,minus0 -prec-div -prec-sqrt so as to improve standards compliance and avoid risky optimizations which don't often improve performance on current CPUs.

View solution in original post

0 Kudos
3 Replies
TimP
Honored Contributor III
615 Views
Quoting - woshiwuxin
I observed the default optimization option for ifort is -O2, and I tried -O3 and I found the performance of the compiled binary could be improved. Thus, I want to know why not to set -O3 as the default option? Is it possible for the -O3 option to produce some unexpected numerical instability?

-O3 doesn't always improve performance, and may increase compile time. On a large application, it's likely to be necessary to find out which source files are best compiled at -O3.
I usually set -O3 -assume protect_parens,minus0 -prec-div -prec-sqrt so as to improve standards compliance and avoid risky optimizations which don't often improve performance on current CPUs.
0 Kudos
herger
Beginner
614 Views
Quoting - tim18
-O3 doesn't always improve performance, and may increase compile time. On a large application, it's likely to be necessary to find out which source files are best compiled at -O3.
I usually set -O3 -assume protect_parens,minus0 -prec-div -prec-sqrt so as to improve standards compliance and avoid risky optimizations which don't often improve performance on current CPUs.

Hi all.
I totally agree.
I hope I'm right: I knew that up to -O3 compilation, the compiler could increase computing performance without a deep "restructuring" of the code (which would take place with -O4 and more with -O5)...
I use -O3 almost every time and I have never had problems.
Surely the advice to set -O3 -assume protect_parens,minus0 -prec-div -prec-sqrt erases any possibility of risks.

Greetings

Herger

0 Kudos
TimP
Honored Contributor III
614 Views
Quoting - herger


I hope I'm right: I knew that up to -O3 compilation, the compiler could increase computing performance without a deep "restructuring" of the code (which would take place with -O4 and more with -O5)...
I use -O3 almost every time and I have never had problems.
Surely the advice to set -O3 -assume protect_parens,minus0 -prec-div -prec-sqrt erases any possibility of risks.

Many common compilers, including ifort and gfortran, give no special meaning to -O4 or -O5, so they may be taken as equivalent to -O3 or -O2 (your guess is as good as mine).
Intel compilers may be set for more aggressive interprocedural optimization by setting -ip or -ipo options; a less aggressive setting of -ip is included in -O2 and -O3.
Ifort already performs many loop restructuring optimizations at -O2, and more at -O3.
0 Kudos
Reply