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

How do I get the most accurate results when doing floating-point calculations?

vfallfuel
Beginner
697 Views

Hello!

I have a question regarding how to get the most accurate result when doing floating-point calculations.

In the documentation for the Intel Fortran Compiler it says: "Improved floating-point consistency is not enabled. This setting provides better accuracy and run-time performance at the expense of less consistent floating-point results."

It feels a bit ambiguous to say that with -fltconsistency off it provides better accuracy but less consistent floating-point results. Doesn't improved consistency mean better accuracy in the floating-point calculations? Or doesn't the floating-point consistency have anything to do with the most accurate calculation result?

So the question is: Should the compiler option -fltconsistency be used to get the most accurate results when doing floating-point calculations?

Thanks!

Best regards,
Andreas

 

0 Kudos
2 Replies
Steven_L_Intel1
Employee
697 Views
This option primarily relates to the use of the extended precision x87 floating point registers which is the default on IA-32 unless you use -xW or a "higher" CPU switch. In this mode, intermediate calculations are usually done and kept in higher precision than "declared precision", and rounded to declared precision on a store to memory. This can cause inconsistent results (not the same binary value for the same calculation) depending on when that rounding takes place. However, the longer that the extended precision values are used, the more accurate the calculation is.

-fltconsistency (now replaced with -fp-model precise) tells the compiler to store to memory more often, making results more consistent at the loss of the extended accuracy.

When using SSE registers for floating point, as you would with -xW, none of this matters as all is done in declared precision. So I would suggest enabling -xW or the highest mode available for your processor to get both the best performance (SSE is faster) and the most consistent results. Accuracy will be a bit less than it might be, but will be more in line with what non-IA-32 processors do.
0 Kudos
TimP
Honored Contributor III
697 Views
As Steve said, the wording of the description of the consistency option pertains more to the non-SSE (x87) code options. The wording also caters to the C compiler, which has more confusing possibilities.
The default (-fp-model fast), unfortunately, allows the compiler to ignore parentheses in some situations during evaluation of parentheses. In x87 code, this was sometimes needed in order to optimize poorly written code, and often could be accepted in view of the extra precision compensating for changed order of evaluation.
ifort 10.0 has introduced the option -assume protect_parens, which requires the compiler to observe parentheses, without removing other performance optimizations. In properly written code, this can help give both best accuracy and performance.
0 Kudos
Reply