views:

58

answers:

2

Do you know which of the GCC optimization flags are the most appropriate to build an application, which uses double floating point and calculates a lot in real-time and it uses -lm. A target hardware is two Dual-Xeons with Linux on-board. Thanks in advance!

+1  A: 

Depending on whether it is safe and appropriate for your given application you could consider -ffast-math. Please read the warnings on the man page for this before using it though.

I know from experience that it can make quite a difference with programs running numerical simulations. Of course you have to do some sanity checks to make sure the output is not altered.

Troubadour
gcc 4.1 Optimization Flag docs: http://gcc.gnu.org/onlinedocs/gcc-4.1.0/gcc/Optimize-Options.html
Brian
I don't think that's a good idea... just -O2 is probably fine
Spudd86
@Brian: Not sure why you commented with just that link.
Troubadour
@spudd86: Yes, -O2 is probably fine, hence my answer. I didn't explicitly mention the -O options because even the most cursory inspection of the documentation will reveal these options so I assumed wasn't really what was being asked about. I was simply pointing out a more esoteric option that seemed pertinent to this specific question.
Troubadour
@Troubadour: "Please read the warnings on the man page" made me feel the urge to post a link to something that had such warnings.
Brian
+2  A: 

"Dual-Xeon" is not a precise specification of the processors you're targetting - "Xeon" is more a marketing brand name than a specific model. "Xeon" doesn't even tell you if you're targetting the IA32 or x86-64 architecture.

This is important, because the optimisation can be significantly improved by targetting a specific CPU family. There are many options described in the GCC documentation; in particular, start with -march to generate code for a particular instruction set.

If you are not targetting x86-64, then use -mfpmath=sse (if supported by your CPU type) to use SSE instructions for floating point, rather than 387 (this option is the default on x86-64). Likewise, -malign-double can give a speedup (but is only default on x86-64).

Also, if the functions you use in libmath are shown as a hotspot when you profile, then recompiling that library with more specific optimisation flags may be of benefit.

caf
Thank you, -mfpmath=sse has helped. Now my application is about 10 times faster.
psihodelia