Linux-admin Development Archive on lore.kernel.org
 help / color / mirror / Atom feed
* Optimizing a compiler?
@ 2002-10-21 15:20 Paul Furness
  2002-10-21 16:08 ` Glynn Clements
  0 siblings, 1 reply; 2+ messages in thread
From: Paul Furness @ 2002-10-21 15:20 UTC (permalink / raw)
  To: linux-admin

Sorry, this might be a little bit OT, but can anyone point me at some
useful info about how to compile code so that it uses the best speed
features of a given type of CPU?

I know that I can recompile the _kernel_ for and Athlon processor or an
intel P4 etc, but how do I optimize my own code which has nothing to do
with the kernel?

Do I need to change the code itself, or can I give gcc (in this case
g++) some options that tell it to use the best possible number crunching
code for my Athlon servers?

We're doing some research into video pattern recognition, so need to get
the absolute maximum possible number munching from our servers as a
single run take us at least 18 hours; every saved clock cycle adds up.

Thanks.

Paul.

-- 
Paul Furness

Systems Manager

2+2=5 for extremely large values of 2.


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: Optimizing a compiler?
  2002-10-21 15:20 Optimizing a compiler? Paul Furness
@ 2002-10-21 16:08 ` Glynn Clements
  0 siblings, 0 replies; 2+ messages in thread
From: Glynn Clements @ 2002-10-21 16:08 UTC (permalink / raw)
  To: Paul Furness; +Cc: linux-admin


Paul Furness wrote:

> Sorry, this might be a little bit OT, but can anyone point me at some
> useful info about how to compile code so that it uses the best speed
> features of a given type of CPU?
> 
> I know that I can recompile the _kernel_ for and Athlon processor or an
> intel P4 etc, but how do I optimize my own code which has nothing to do
> with the kernel?
> 
> Do I need to change the code itself, or can I give gcc (in this case
> g++) some options that tell it to use the best possible number crunching
> code for my Athlon servers?

Select the specific choice of CPU via "-mcpu=" and "-march=".

Select optimisations and code generation options via various "-f"
switches, as described in the "Optimize Options" and "Code Gen
Options" pages of the GCC Info file (under "Invoking GCC").

The issue of which optimisations will actually make a difference
depends upon the type of code being executed. For FP-intensive code,
-ffast-math may help (but is potentially risky). -fomit-frame-pointer
frees up an extra register, which can be quite significant on the
register-starved x86 architecture, but prevents debugging.

If a significant amount of time is spent in library functions,
consider static linking (the position-independent code used in shared
libraries may add ~5% to execution times).

However, if your code has any significant algorithmic inefficiencies,
the performance gain from improving the algorithms will dwarf anything
which you will achieve through compilation switches. Incidentally,
it's much easier to overlook potential sources of inefficiency when
using C++ than with C.

Also, consider using a profiler to identify sections of the code which
warrant maximum scrutiny.

-- 
Glynn Clements <glynn.clements@virgin.net>

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2002-10-21 16:08 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2002-10-21 15:20 Optimizing a compiler? Paul Furness
2002-10-21 16:08 ` Glynn Clements

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox