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

numeric stability

David_F_1
Beginner
803 Views

Hello,

   I'm working in a quite complex algorithm. I try to improve the performance using iFort. With gfortran I obtain same numeric results if I use -O0, -O1, -O2 or O3 optimization flags. With a old version (2013?) of iFort and only could reproduce this values if I use -O0. With newer version (2014 and 2015) I can reproduce the values using -O0 or -O1 but if I try to use -O2 or -O3 I can't. I understand that -O2 should has same results but quicker (I fact is much quicker but different results). When I say that results are different I say they are "little bit" different but it is important to know why. Could you give some ideas or advices about how to proceed? I should forget use ifort or there is tools for understand what is going on and improve it. Also, I think that could be a compiler bug because with older version I can't obtain same results with -O1 (only with -O0) and with new version I can. Without change the code. 

   Anyway, I have to say that ifort with -O1 is already faster than gfortran.

 

Thanks 

0 Kudos
2 Replies
TimP
Honored Contributor III
803 Views

We've discussed the subject of comparable options between gfortran and ifort several times, so I'll try to be brief with reminders.  You can't really understand it without reading the document pages carefully for both.

ifort -O2 -assume protect-_parens is roughly equivalent to gfortran -O3 -ffast-math -fno-cx-limited-range .  ifort -O1 -fp-model source might give results similar to gfortran -O2.

ifort -fp-model source and precise are the same. -fp-model strict is required for full Fortran standards compliance, if using ieee_arithmetic, but that's probably beyond your interests.

If you're compiling for 32-bit mode, ifort defaults to -msse2, while gfortran defaults to -march=i486, implying extra precision evaluation of expressions, so there are many opportunities for differences due to inconsistent options.

Some points, for emphasis: 

ifort requires additional options to be compliant with standard.  Some of these are collected under -standard-semantics.

ifort -fp-model fast (default) and gfortran -ffast-math (not a default, not tied with -O3) enable optimizations where results may vary slightly with data alignment or differ from non-optimized result.

If you don't specify order of expression evaluation by parentheses etc. (and set the ifort option protect_parens), Fortran rules permit various orders of expression evaluation which have consequences including numerical differences.

0 Kudos
David_F_1
Beginner
803 Views

Thank you for the answer. It was very useful.

0 Kudos
Reply