0

I have a large Fortran/C++ project that assembles hundreds of Fortran intermediate files into a single executive. When I monitor some of the global single precision floating point variables, I get different results when I run the executive on a Windows 7 x64 machine vs a Windows XP SP2 x86 machine. The differences are as much as 1-2%.

The project was built on the x86 machine and not rebuilt before testing on the x64 machine, although I am using the exact same compiler (compaq visual fortran 6.6), and development studio (visual studio 6.0), and identical code for both machines. The x64 machine has a Pentium E5400, the x86 machine has a pentium 4 dual core. Could this be an example of Deterministic Lockstep?.

I know this is vague - I wish I could provide some code, but there's over 1 million lines. All of the variables are REAL*4 and are calculated in the Fortran code several hundred times per second. The c++ MFC code assembles it into the executive.

Community
  • 1
  • 1
Alex
  • 689
  • 1
  • 8
  • 22
  • What compiler version are you using? – Filip Roséen - refp Mar 11 '15 at 11:43
  • Passing [`/Op`](https://msdn.microsoft.com/en-us/library/aa278532%28v=vs.60%29.aspx) to the compiler could circumvent the problem you are facing, if you are running a newer compiler [`/arch:IA32`](https://msdn.microsoft.com/en-us/library/7t5yh4fd.aspx) will prevent the compiler to emit *SSE{,2}* instructions (which might also cause what is going on). – Filip Roséen - refp Mar 11 '15 at 11:48
  • Compiler version is 6.6. Very interesting, thank you for the explanation, I will look into this. – Alex Mar 11 '15 at 11:53
  • /Op works, /arch:IA32 gives the error that IA32 is an unrecognized option for /arch. Just to clarify, these commands prevent the x64 machine from emitting SSE2 instructions? – Alex Mar 11 '15 at 12:03
  • No, `/Op` prevents the compiler from emitting optimized floating-point instructions (the program might be slower, but more accurate) - where as `/arch:IA32` says that it shouldn't emit any *SSE{,2}* instructions (since the result of these may differ between architectures). – Filip Roséen - refp Mar 11 '15 at 12:08

1 Answers1

1

Introduction

The difference you are observing are (probably) due to the fact that your executable includes optimized floating-point instructions, and the result of these instructions can be different between different architectures.



Enable float-point consistency

Note: The following only applies to older (6.0) versions of msvc++.

Unless you explicitly tell the compiler that you don't want it to optimize floating-point operations (where the trade-off might be some slight inaccuracy), it will do so.

Passing /Op as a flag to the compiler enables the "'consistency' floating-point model"; effectively disabling the previous mentioned optimization.

The equivalent flag, /fp:strict, is the default option in VS2008.



Turn off SSE2

Note: The following only applies to newer versions of msvc++.

Unless you explicitly say that you don't want the msvc++ to generate SSE{,2} instructions for your floating-point calculations, such will be included in your executable.

You can force the compiler to disable generation of SSE and SSE2 instructions by passing the flag /arch:IA32 to it.

Community
  • 1
  • 1
Filip Roséen - refp
  • 62,493
  • 20
  • 150
  • 196
  • Thanks Filip, this is great information. I will compile my several hundred files and retest it. – Alex Mar 11 '15 at 12:26
  • Great information, but the results were the exact same after compiling every source file with /Op and rebuilding. – Alex Mar 11 '15 at 13:11
  • @AlexB could you create a small *testcase*? All you really need to do is write a simple application that does some floating-point arithmetic, and that shows different behavior on the two architectures. – Filip Roséen - refp Mar 11 '15 at 13:34
  • Doing this. You seem to know a lot about Compaq visual fortran compiler options. Is there a manual of available options? I can't find anything anywhere... – Alex Mar 11 '15 at 16:29
  • @AlexB 5 seconds of simple googling http://jp.xlsoft.com/documents/intel/cvf/cvf_pg.pdf You should have received it when you bought the compiler BTW. – Vladimir F Героям слава Mar 11 '15 at 18:35
  • @VladimirF I believe the compiler options he was referring to were the cvf compiler options. I compile the fortran source into intermediates before building the c++ project. I did not buy the compiler (is it even sold anymore?), it's legacy software that has been here long before me. Thanks for the document, I guess you're a better googler than me. – Alex Mar 11 '15 at 19:01
  • @VladimirF I see - as it happens, these are also cvf compiler options (except /arch:IA32) – Alex Mar 11 '15 at 19:07