LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   optimizing compiling for speed (https://www.linuxquestions.org/questions/linux-software-2/optimizing-compiling-for-speed-452824/)

cryptopodium 06-08-2006 09:09 AM

optimizing compiling for speed
 
Hi, I'm effectively a complete unix newbie, although I did play around with it a bit about 15 years ago. I've just installed linux (mandriva 64bit) on my home system (athlon 64 laptop, 1Gb), principally because I want to run some intensive number-crunching, command-line driven, scientific apps as fast as possible. I had assumed that these sorts of programs running in full 64bit Linux would be considerably faster than in 32bit Windows... However, so far I am having difficulty getting any significant performance benefits.

The program I am playing with at the moment is called MrBayes. It is distributed as compilable code with a makefile. At this point I should reiterate that although I am familiar with some general concepts in IT and have done a very little programming a very long time ago, I have almost no practical experience of unix. I didn't know what a makefile was until yesterday!

Anyway, when I first compiled the program using the supplied makefile it actually ran about 5% slower than in 32 bit windows... I have now done some research and added some flags to optimise the compilation and it does now run faster than in windows, although only by a bit more than 5%. Here is the original bit in the makefile that specifies the flags for compiling :

#OPTFLAGS = -O2 -march=pentium4 -mfpmath=sse -fomit-frame-pointers
OPTFLAGS ?= -O3

And here is what I currently have it set to :

OPTFLAGS ?= -O3 -march=athlon64 -ffast-math -mfpmath=sse -fomit-frame-pointer

I know that some of those may be redundant, in that some are effectively subsets of others, but I'm not certain which and I am assuming it doesn't do any harm to over specify. The only one that I am certain made any difference was "-ffast-math".

So - is there ANYTHING else I can do to get the program running faster, either in the compilation process or in my system in general? I am running it outside of "X". For all I know there could be something really basic I haven't done at the OS level. Any advice appreciated! Thanx.

ghatamos 06-08-2006 10:19 AM

Here's a list of optimization options you can go with GCC.

http://gcc.gnu.org/onlinedocs/gcc/Optimize-Options.html

Just add the flags that you think is useful to you.

cryptopodium 06-08-2006 03:41 PM

Thanks, that's a useful reference.

Unfortunately, I've absolutely no idea what most of these things mean - e.g. :

"Always pop the arguments to each function call as soon as that function returns. For machines which must pop arguments after a function call, the compiler normally lets arguments accumulate on the stack for several function calls and pops them all at once."

Do I want to do that? I would be better qualified to guess the colour of the Pope's underpants. :)

If anyone can tell me which of those flags is actually likley to offer significant performance benefits in my particular situation, I would be most grateful!

osor 06-08-2006 11:07 PM

If you're looking for performance gains, I would suggest moving completely to Gentoo. Not only will your entire system run faster, but there are many howto's describing what flags are safe for compiling what packages on what processors.

Here's a quote from this page:
Code:

CHOST="x86_64-pc-linux-gnu"
CFLAGS="-march=athlon64 -O2"
CXXFLAGS="${CFLAGS}"

For example, your Mandriva is probably compiled with -mtune=x86_64 (for compatibility reasons), whereas if you compile yourself, -march=althon64 enables more optimizations. You usually don't have to worry about things like popping etc., since they are in the default -O, -O2, or -O3. Also, -fomit-frame-pointer is not required on athlon64. The gentoo page above describes the `safe flags' (those you should use to compile big things like binutils, gcc, etc.). For other stuff, you could probably afford to be more aggressive. Remember, if you can tune the kernel, the c library, etc., it might offer more performance gain than just tuning your program.

Also, just using 64bit mode doesn't automatically make a program run super-fast. Some projects are tweaked for 32-bit processors. Others, by their theoretical nature, should notice no difference in performance with a processor switching modes. Also, number-crunching code usually uses high-performance libraries/extensions (e.g., MPI, HPF, etc.), some of which may not be free (as in speech).

cryptopodium 06-09-2006 01:41 AM

Thanks, that's great. Of course being a novice, I installed mandriva from a relatively idiot-proof DVD setup program ("powerpack"). I hadn't realised, or had forgotten, that the OS itself is actually compiled specifically for each installation.

I'll need to do a lot more homework if I am to do things that way. Should be fun though. :D

cryptopodium 06-09-2006 02:08 AM

I've looked at the Gentoo installation guide:
http://www.gentoo.org/doc/en/handboo...d64.xml?full=1
and can see that it's a lot of work. I'm not sure I have the time to get to grips with all of that at the moment. This may be a silly question, but I don't suppose it's an easy matter just to recompile the important bits of of my mandriva system (core?) while leaving the bulk of the installation intact?

daihard 06-09-2006 02:33 AM

Being a software developer myself, I can tell you that performance optimization is a lot more than just specifying/omitting certain compile flags. Aggressive flags like -O3 can often result in no performance gain since they tend to increase the code size. Also, running a program on a 64-bit platform does not automatically boost performance compare to it being run on a comparable 32-bit platform, especially when the program is originally designed for a 32-bit architecture and simply compiled on a 64-bit system.

cs-cam 06-09-2006 03:48 AM

Quote:

Aggressive flags like -O3 can often result in no performance gain since they tend to increase the code size.
They can also cause crashes and instability.


All times are GMT -5. The time now is 06:24 PM.