Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
Announcements
FPGA community forums and blogs on community.intel.com are migrating to the new Altera Community and are read-only. For urgent support needs during this transition, please visit the FPGA Design Resources page or contact an Altera Authorized Distributor.
29298 Discussions

Optimizer bypasses round-to-single-precision steps

Steve_Nuchia
New Contributor I
515 Views

We are in the process of comparing test case outputs after porting a large amount of legacy code from Digital Visual Fortran 6 to IVF 10.

We have a case where we compute a value using a real*8 function and assign the result to a real*4 local variable. Later we use that variable in an expression, all the other values in which are real*8 (including the result). In the old compiler this particular code compiles to use the in-memory single-precision value but the new compiler, unless you disable optimization, keeps the computed real*8 value in a register and uses that instead.

We found the intrinsic SNGL() function, which claims to produce a default-precision output from any FP input and our default (legacy code, remember) is real*4. But injecting this into the code had no effect whatsoever.

In this particular case we'll probably change the leftover intermediate variable to a real*8 and update the baseline dataset. But it raises the question: If I want to force rounding to single precision at a particular point in a computation, how do I do it? Other than by putting a real*8 -> real*4 "identity" function in a C++ support library, I mean. In C++ I'd mark the intermediate as volatile, is there an equivalent in fortran?

I feel kinda dumb compaining about the optimizer being so good, but there it is. Sometimes you value reproducible results more than speed. And occasionally numerical analysis calls for explicit control of rounding.

Thank you,

-swn

0 Kudos
2 Replies
TimP
Honored Contributor III
515 Views
If you want x87 code (available only in the 32-bit compiler), the original ifort option for forcing narrowing is /Qfp-port. The more up to date option is /fp:precise. If you need to support only CPUs produced in the last 5 years, /QxW would be the normal option. /QxB (32-bit only) is a compromise, but it is "deprecated," as it retains some x87 extra precision effects.
0 Kudos
Steven_L_Intel1
Employee
515 Views
/fp:source is the option I would recommend - /fp:precise has the same meaning but will get you an informational message.
0 Kudos
Reply