0

I have a code that I want to port from Windows 32 bits to Linux 64 bits. This code makes a lot of calculations using basic floating point operations with double type numbers and I try to keep same results on both environments.

On Windows, I use VisualC++ to compile the code with the /fp:strict option. My first step was to port the code to Linux 32 bits (in fact compiling the code in 32 bits on a X86-64 Linux environment). The problem has already been widely addressed here (for example in this question). As advised, I've compiled the code using gcc and the options -msse2 -mfpmath=sse and the results were exactly the same between Windows 32 bits and Linux 32 bits.

I finally compiled the code in 64bits, expecting to conserve the same results... but there were a lot of differences. That matter has also been discussed (see here and there), but as I already use SSE floating point units thanks to gcc options, I normally should have observed the same results between Linux 32 and 64 bits.

So I'm a little stuck now. The only remaining explanation I can think of is that the problem lies within the code (stuff like comparing two double for equality - hope there isn't but can't be absolutely sure). What do you think ? Am I missing a point somewhere ? Is there another explanation I missed ?

Any advice will be greatly appreciated.

Note1 : I also tried the option -ffloat-store but it didn't help me get the results close to each other.

Community
  • 1
  • 1
  • How significant are the differences ? If they are sufficiently small then you might just want to learn to live with this and incorporate suitable tolerances into your test procedures. If they are too large to ignore then you may have numerical stability issues in your code. – Paul R Feb 26 '15 at 13:15
  • I guess you'll have to investigate where exactly the values diverge... Do you see the difference even at -O0? – Marc Glisse Feb 27 '15 at 11:55
  • 64-bit programs and floating-point calculations: http://www.viva64.com/en/b/0074/ –  Mar 01 '15 at 09:31
  • @PaulR The differences are not "that" significant. The problem I have is more to justify/explain the existence of differences rather than quantifying their impact. – Louis Morazzani Mar 04 '15 at 14:55
  • @MarcGlisse Yes the difference exist even at -O0. – Louis Morazzani Mar 04 '15 at 14:56
  • @AndreyCpp Thanks for your link, but in the article the problem is due to precision with float variables (double in my case) and different sets of instructions (I use sse2 in both cases). If you were pointing out the PVS -Studio analyser, I had heard of it, but sadly I can't afford it and the evaluation version seems too limited for my needs. – Louis Morazzani Mar 04 '15 at 14:56
  • @LouisMorazzani The demo version of PVS-Studio is fully functional. The only limitation is the number of jumps from diagnostic messages to the associated code fragments. But the analyzer doesn't diagnose issues related to differences in floating-point calculations. It's because there are actually no such problems at all. It's just a misunderstanding of how one should work with these data types. –  Mar 05 '15 at 11:21
  • 1
    Possible duplicate of [64 bit floating point porting issues](http://stackoverflow.com/questions/1076190/64-bit-floating-point-porting-issues) – phuclv Jan 01 '17 at 10:39

0 Answers0