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

Discrepancies between results from 32- and 64-bit executables

ocean
Beginner
257 Views

My question has more to do with the VisualStudio C++ compiler than with Fortran itself, but I hope someone can help.

I am looking into an issue that has to do with getting different results from a piece of code that has been compiled as a 32- and 64-bitexecutable using VisualStudio 2005.

Here's the source code:

#include

double a, b, c;

a = -73.66266;
b = 0.017453292519943295;
c = sin(a * b);

printf("sin(c) = %0.17f\n", c);

To run this code just create a console project within VisualStudio and configure it for 32 and 64-bit executables. Use default compiler settings. I performed this test on anIntel machine running Win Server 2008 64-bit, with optimization disabled (I believe the same behavior can be reproduced using Win XP 64-bit).These two executables produce slightly differentresults:

Output from 32-bit code = -0.95962217600146471
Output from 64-bit code = -0.95962217600146482

Converting the above code to Fortran(IVF 10.0)and running it on the same machine, the output produced by the 32-bit version is identical to that produced by the 64-bit version. It should be mentioned, however, that the Fortran output is different from the C++, which is understandable taking into account we are dealing with two different compilers.

My question is if anyone has run into this situation, and if there's a way of forcing the C++ compiler to produce floating point results that are identical for both 32- and 64-bit executables? I have played with the compiler settings (/fp:precise, /fp:strict, and /fp:fast), but it does not appear to affect the results.

Thanks

0 Kudos
1 Reply
TimP
Honored Contributor III
257 Views
Like the Intel compilers prior to 11.0, the Microsoft compilers default to x87 32-bit and SSE2 64-bit code. /arch:SSE2 /fp:fast would be required to approach numerical consistency between 32- and 64-bit. It's still unrealistic to expect identical bit-wise results, particularly from a transcendental function, where the x87 mode uses 80-bit operands.
Microsoft compilers default to /fp:precise, which, like Intel C++ but unlike Intel Fortran, promotes float expressions to double evaluation, even for SSE2. Microsoft /fp:fast is analogous to Intel /fp:source (including observance of parentheses), if you disable vectorization on the Intel compilers. There is no way, other than parentheses, to enforce left-to-right evaluation in Microsoft C or Intel Fortran.
Your C constants are doubles; do you take care to specify your Fortran constants in kind=8 ?
0 Kudos
Reply