LinuxQuestions.org
View the Most Wanted LQ Wiki articles.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices

Reply
 
Search this Thread
Old 06-08-2006, 09:09 AM   #1
cryptopodium
LQ Newbie
 
Registered: Jun 2006
Posts: 4

Rep: Reputation: 0
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.
 
Old 06-08-2006, 10:19 AM   #2
ghatamos
Member
 
Registered: Nov 2003
Posts: 35

Rep: Reputation: 15
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.
 
Old 06-08-2006, 03:41 PM   #3
cryptopodium
LQ Newbie
 
Registered: Jun 2006
Posts: 4

Original Poster
Rep: Reputation: 0
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!
 
Old 06-08-2006, 11:07 PM   #4
osor
HCL Maintainer
 
Registered: Jan 2006
Distribution: (H)LFS, Gentoo
Posts: 2,450

Rep: Reputation: 70
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).

Last edited by osor; 06-08-2006 at 11:08 PM.
 
Old 06-09-2006, 01:41 AM   #5
cryptopodium
LQ Newbie
 
Registered: Jun 2006
Posts: 4

Original Poster
Rep: Reputation: 0
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.
 
Old 06-09-2006, 02:08 AM   #6
cryptopodium
LQ Newbie
 
Registered: Jun 2006
Posts: 4

Original Poster
Rep: Reputation: 0
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?
 
Old 06-09-2006, 02:33 AM   #7
daihard
Member
 
Registered: Jul 2003
Location: Lynnwood, WA
Distribution: Kubuntu 10.10
Posts: 912

Rep: Reputation: 32
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.
 
Old 06-09-2006, 03:48 AM   #8
cs-cam
Senior Member
 
Registered: May 2004
Location: Australia
Distribution: Gentoo
Posts: 3,544
Blog Entries: 4

Rep: Reputation: 56
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.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Optimizing drive speed linuxhippy Fedora 10 07-22-2005 05:00 AM
optimizing drive speed with raid linuxhippy Fedora 5 07-22-2005 04:59 AM
Optimizing boot speed gunnix Debian 14 06-03-2005 01:06 PM
question on optimizing fedora 2 CFLAGS to speed up programs opioid Linux - Software 1 11-21-2004 09:58 AM
Optimizing flags compiling question wrc1944 Linux - Newbie 14 08-13-2002 09:55 AM


All times are GMT -5. The time now is 10:59 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration