Intel® C++ Compiler
Community support and assistance for creating C++ code that runs on platforms based on Intel® processors.
7956 Discussions

Floting point problems MS vs. Intel compiler

danglover
Beginner
487 Views
Hello!
I'm realy new in testing other compilers, therefore sorry if i ask some stupid questions.
My problem:
I have an Microsoft Visual Studio 6 Project (mostly using WinApi) with a lot of mathematics in it.
There are a lot of matrix operations with floating point values.
Because of trying to improve performance I tryed the intel C++ compiler V8.
The problem is that if I'm using the same compiler flags as in Visual Studio with MS compiler at the beginning i get little floating point differences tht are getting bigger and bigger. The results at the end are not completely different but a lot. I also tryed the following otions to improve my result, but it doesn't make it better.
The MS options are:
/nologo /ML /GX /O2 /Ob2 /I ".sourceinclude" /I ".sourceincludeconstr" /I ".sourceincludekf" /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /FR"Release/" /Fo"Release/" /Fd"Release/" /FD /c
Whit intel i tryed also:
/Qfpstkchk /Qvc6 /Qpc64 /Qprec_div /c
in different combinations.
My result was always bad. Most of the times the Intel vs. Intel Result was exactly the same only whit /op and whitout /Qpc64 i got different results.
I used every time an Intel Pentium 4 with Windows XP
Can anyone help me to solve the problem?
thank you
Daniel
0 Kudos
7 Replies
John_O_Intel
Employee
487 Views
Hi Daniel,
You can try different compiler switches that change the FP behavior. The User's Guide hasmore details as well.
/Op[-] enable/disable better floating-point precision
/Qpc32 set internal FPU precision to 24 bit significand
/Qpc64 set internal FPU precision to 53 bit significand (DEFAULT)
/Qpc80 set internal FPU precision to 64 bit significand
/QIfist[-] enable/disable(DEFAULT) fast float-to-int conversions (*M)
/Qrcd same as /QIfist
/Qprec improve floating-point precision (speed impact less than /Op)
/Qprec_div improve precision of FP divides (some speed impact)
/Qfp_port round fp results at assignments & casts (some speed impact)
Regards,
John
0 Kudos
danglover
Beginner
487 Views
Hi John,
thank you for Your answer. The following flags are new to me the other ones i've always tested. Il try the new ones in the next days , if they will work for me.
/QIfist[-] enable/disable(DEFAULT) fast float-to-int conversions (*M)
/Qrcd same as /QIfist
/Qfp_port round fp results at assignments & casts (some speed impact)
Regards,
daniel
0 Kudos
TimP
Honored Contributor III
487 Views
The options /Qlfist /Qrcd change casts from float to int types as if they were done with lrint() and the like. You should fix the source code, if that's what you mean to do. When generating x87 code, without the SSE3 option, those can bring a big improvement in performance, but the results aren't the same. The options aren't relevant if you use SSE/SSE2 code; then you can do either round to nearest or "round toward zero" with equal efficiency.
/Qfp_port is most likely to have an effect when using x87 code with float variables. Without it, many of your intermediates are promoted to double, in order to improve performance and (usually) accuracy. Using SSE/SSE2 code generation options usually takes care of the performance aspect of fp_port, and makes sure that you don't get extra precision without asking.
/Op includes fp_port, at a higher cost in performance.
0 Kudos
danglover
Beginner
487 Views

Hello!

There are no SSE/SSE2/SSE3 instructions inmy application.

I think than the suggested flags won't work for me.

This is an C++ project without processor specific code.

Daniel

0 Kudos
TimP
Honored Contributor III
487 Views

Sorry if I confused you.

/Qrcd /Qifist do apply to x87 code, but they change the results. I would still recommend changing the source to use lrint() and the like, if this is what you want. These can certainly improve performance, if you are unable to use SSE options.

/Qfp_port assures that casts from double to float are not disregarded. Performance loss can be significant, if you are unable to use SSE.

0 Kudos
danglover
Beginner
487 Views

Hello!
Thank you for your help.
Sorry if i explained my problem not in the right way. There are no "float" values in this application, there are only a lot of matrixes with "double" values.
A lot of multiplications and additions are made there. This application uses neural networks and my problem begins in the preselection phase.
After some matrix operation i get little differences to the results of the withMicrosoft compiled application. Until now i tryed a lot of the Options the Intel compiler offers, but everytime the result was different to Microsofts.
Could ist be that Intel uses another rounding mode than Microsoft?

daniel

0 Kudos
TimP
Honored Contributor III
487 Views
No, the Intel compiler doesn't change the rounding modes from the Microsoft compiler, unless you specifically request. It does perform optimizations which affect numerical results, unless you use /Op, which you mentioned previously. Even then, itmay beimpractical to get identical results with different compilers.
0 Kudos
Reply