LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   Alias make to automatically use multiple cores? (https://www.linuxquestions.org/questions/linux-software-2/alias-make-to-automatically-use-multiple-cores-785227/)

damgar 01-27-2010 10:53 PM

Alias make to automatically use multiple cores?
 
Newbie question here. I just realized that I can tell make to use multiple cores to compile by doing
PHP Code:

make -j X 

which is just awesome on a quad core with hyperthreading (I just compiled 2.6.33-rc5 in under 5 minutes!)

I know aliases are possible, though I've never had much need. What I would like to know now, is if it would be safe to alias make to mean
PHP Code:

make -j 6 

so that by default I use 6 of the procesors when building or if there would be occasions that compiling on multiple processors would be a bad thing?

I realize it's maybe not necessary, but it I'm forgetful and impatient and something about it just seems cool to me.....

kbp 01-27-2010 11:26 PM

It's not necessarily 'compiling' on multiple cores, just running multiple make commands. The performance increase would depend on how many tasks could be run synchronously ( parallel ) inside the one makefile or whether you're building multiple applications at once.

A bit of testing may help decide whether it's worth it

cheers

damgar 01-27-2010 11:52 PM

If the kernel build was any indication, it is DEFINITELY worth it, provided there are no serious risks. it was easily 3 to 4 times faster with
PHP Code:

make -j 4 


kbp 01-28-2010 06:31 AM

I doubt there would be any risk.. but it depends on what else the computer is used for - other processes may suffer.

i.e if you're doing this at work then don't run it on a production server :)

cheers

damgar 01-28-2010 07:44 AM

It's actually just my tinker-toy so while building something I'm generally just surfing around for info on whatever it is I'm doing. The OS perceives my machine to have 8 cores so even at 4 cores being used to build the kernel, top indicates under 50% CPU load which seemed like a waste to me.

Thanks for the replies.

brianL 01-28-2010 07:55 AM

I've read recently (somewhere?) the best practice is:
Code:

make -j number of cores + 1

damgar 01-28-2010 08:31 AM

Quote:

Originally Posted by brianL (Post 3843576)
I've read recently (somewhere?) the best practice is:
Code:

make -j number of cores + 1

Do you have any idea where you read that? That seems counter intuitive to me, but I'd definitely be interested in the read.:)

AlucardZero 01-28-2010 09:10 AM

Instead, set the environment variable MAKEFLAGS, for example in your ~/.bashrc:
export MAKEFLAGS=-j5

To temporarily remove it, issue: unset MAKEFLAGS

brianL 01-28-2010 09:20 AM

Quote:

Originally Posted by damgar (Post 3843634)
Do you have any idea where you read that? That seems counter intuitive to me, but I'd definitely be interested in the read.:)

Sorry, can't remember exactly, but it was probably while I was browsing through one of these two:

http://delicious.com/tag/linux

http://www.reddit.com/r/linux/

damgar 01-28-2010 02:27 PM

I did find reference to the +1 here http://blogs.koolwal.net/2009/04/20/tip-compile-your-programs-fasters-with-multiple-processor-machines/ I'll definitely have to give that a shot with my next build.

Thanks for the tip.

damgar 01-28-2010 02:37 PM

Quote:

Originally Posted by AlucardZero (Post 3843694)
Instead, set the environment variable MAKEFLAGS, for example in your ~/.bashrc:
export MAKEFLAGS=-j5

To temporarily remove it, issue: unset MAKEFLAGS

On a Slack system with no .bashrc by default, can that just be added to /etc/profile?


All times are GMT -5. The time now is 03:08 AM.