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

optimization /O3 changes program semantics

Tobias_Loew
Novice
171 Views
I've got code works correct in debug-mode but produces wrong result when compiled with /O3 optimization. I distilled out a small project that reproduces this behaviour and added the files. Note that the wrong result only show up in the "Release_O3" configuration. If I just use the standard (/O2) optimization ("Release" configuration) or specify /O3 and /Oipo ("Release_O3_ipo" configuration) it works correctly.

The correct output in the command window should be nothing, whereas in "Release_O3" I get the following output:

[fxfortran]
   s3zwxyz    2     2       15518265.05223      376660064.00000
       zwy    3     2         144514.52001      361286304.00000
   s3zwxyz    3     2         289030.29092      722575744.00000
       zwy    4     2         144515.77064      361289440.00000
   s3zwxyz    4     2         289032.80655      722582016.00000
       zwy    5     2         144517.03564      361292576.00000
   s3zwxyz    5     2         289035.32217      722588288.00000
       zwy    6     2         144518.28626      361295712.00000
   s3zwxyz    6     2         289037.83780      722594560.00000
       zwy    7     2         144519.55126      361298848.00000
   s3zwxyz    7     2         289040.35342      722600896.00000
       zwy    8     2         144520.80189      361302016.00000
   s3zwxyz    8     2      361449652.08272      722607168.00000[/fxfortran]



I'm running an MS Windows Server 2003 R2/SP2 with Intel Xeon X5460 @ 3.16 GHz processors. I'm using VS 2008 with
Intel Visual Fortran Package ID: w_fcompxe_2011.1.127
Intel Visual Fortran Composer XE 2011 Integration for Microsoft Visual Studio* 2008, 12.0.3470.2008, Copyright (C) 2002-2010 Intel Corporation

I've attached the test project that produced the above ouput on my machine.
0 Kudos
1 Reply
Steven_L_Intel1
Employee
171 Views
I apologize for the delay in responding.

It would appear that your application requires strict adherence to the IEEE FP standard. The default "FP model" is "fast", which loosens the rules a bit to get faster code, such as allowing reassociation, or doing multiply by inverse rather than divide. If you change the option Fortran > Floating Point > Floating Point Model to either Strict or Source, you'll get the results you want. Source is probably the better choice for you as it does not inhibit quite as many optimizations.
0 Kudos
Reply