Click here to Skip to main content
15,887,267 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi all,

I detected some diferences in my program results between Release and Debug versions. After some research I realized that some floating point optimizations are causing those differences. I have solved the problem by using fenv_access pragma for disabling some optimizations for some critical methods.

Thinking about it, I realized that, probably, is better to use fp:strict model instead of fp:precise in my program because of its characteristics but I am worried about performance. I have tried to find some information about performance issues of fp:strict or the differences in performance between precise and strict model but I have find very little information.

Is there anay significant difference between the two models??

Thanks in advance.
Posted
Updated 21-Jun-11 0:53am
v2

(same answer I gave on SO.)

It's absolutely normal to see performance difference between a Debug and Release version.

The compiler and run-times will do a lot more additional sanity checks in debug version; don't compare one to the other, especially in regards to performance; compare release vs. release with different compiler switches.

On the other hand, if the results are different between the 2 versions, then you will have to go in and check for programming errors (most probably).
 
Share this answer
 
Comments
Alex_GR 21-Jun-11 8:50am    
First of all thank you for your answer.
I´m sorry but probably I didn´t explain my problem correctly.
As you said, Debug and release performance aren´t comparable. And I don´t want to compare this.
On the other hand, I had differents results between debug and release versions. Now I had solved this, the differences were due to some floating point optimizations, to be more specific, some that affect FPU flags and mode. I disable those optimizations using the fenv_access directive. Using fp:strict model those optimizations are disabled too.

My doubt is because probably is better to use fp:strict as floating point model for my program. So What I am looking for is some kind of analysis or general overview of the performance issues of the fp:strict model and its differences with fp:precise.
Sergey Alexandrovich Kryukov 21-Jun-11 18:28pm    
My 5. Comparison between strict and precise performance is a delicate thing. See OP's comment. I would speculate that the difference is not essential, but it should be tested. How about that?
--SA
Alex_GR 22-Jun-11 6:47am    
What I am going to do is to write a test program that performs floating point operations that is said to be optimized under fp:precise and not under fp:strict and then measure performance, is not what I was looking for but is better than nothing. From stuff I have already read probably there is a little difference in performance between precise and strict model. I will post here my results. Thanks to everybody.
You might be focusing on the wrong issue here.

If you are using floating point calculations, then you should never consider all the digits significant. An answer of 49.99999 should be considered equivalent to an answer of 50.00001.

If you really do want as precise an answer as possible then fp:precise will have less rounding error. (And from what I can see should probably be slightly faster as well.)

The only scenario under which I can imagine you'd want fp:strict is if your program is supposed to come up with results that exactly match the results from another program. Like if you have a redundant system in some military satellite that performs the same operation on two different computers (that aren't the same hardware) and have to get the same answer on both systems.

And if that's your situation, you might want to consider doing some sort of fixed point arithmetic so there is absolutely no doubt about how many significant digits there are in you answer.

Floating point arithmetic is only appropriate for dealing with real world values. Real world values are never measured precisely and only have a certain precision -- no calculation based on them ever has any more precision than the original measurement and will have less precision when you are multiplying or dividing numbers with limited precision.

The questions you need to ask are:

What's the precision of the original input?

What's the maximum precision I can expect on the output?

Am I losing any precision because of the way I'm doing the calculation?

Does it matter?

Example: What's the area of a square?

length = 12.25 inches ( +/- 1/16th )
width = 4.0 inches ( +/- 1/16th )

area = 12.25 * 4.0 = 49 sq in ( +/- approx 1 sq inch. )

Given that the original input precision is only +/- 1/16th the actual value could be as much as +/1 off either way. So worrying about 49 vs 49.01 vs 49.999 is silly.

If, on the other hand, your original input was measured with a laser micrometer and is accurate to 32 significant decimal places, then you are throwing away precision by doing floating point arithmentic no matter what model you use.

In that case, you have to ask, how much precision is needed in the output?

If you are using it to decide how many sq yards of carpet to buy, you don't care.

If you are using it to aim a telescope you might (but you are probably better off with less precision and more iterative feedback in order to actually hit your target).
 
Share this answer
 
Comments
Alex_GR 22-Jun-11 6:53am    
In fact what the program do is to perform calculus over big data series, I assume that this operations was acumulating small errors that at the end cause the problem. Now I have solved this, I have correct results, my doubt is what is the better way to achieve this results, disabling some optimizations for the critical methods (that is what I have already done) or use fp:strict mode in my program (in that mode optimizations that affect my code is also disabled).
TRK3 22-Jun-11 11:21am    
So you end up using fp:precise (which is faster by your test, and more precise by definition) and just disabling the optimizations where they affect your calculation?

Sounds like a good solution.
I am not sure if this is a solution but is what I have :).
As I have post previously I have wrote a test program that performs floating point operations that is said to be optimized under fp:precise and not under fp:strict and then measure performance. I run it 10000 times and, in average, fp:strict is 2.85% slower than fp:precise.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900