Multi CPU Compiling ( SMP with GCC )

Well, I went on google tonight, because I realized I was being a dumbass and not utiliting all my CPUs when compiling using GCC. I looked for a while before finding an answer after using several terms that don't match the title of this article. I'm basically posting this for anyone who happens to look for SMP compiling on google, so it'll actually show something useful.

In a nutshell, to compile with GCC using multiple CPUs you use the -j flag.
So for two CPUs, -j 2 and for three CPUs, -j3
(Before you comment that there aren't any system with 3 CPUs, my Netfinity worked quite fine with 3 while I was replacing a VRM.)

So the basic idea for compiling anything would be something like this.

make -j 4

This allows 4 gcc processes to run at the same time, hopefully using up most if not all of your CPU time.

The difference is amazing, over an hour for a kernel compile, or 10 minutes.

Here's another example for the Kernel:
make clean
make -j 4 dep
make -j 4 modules
make -j 4 bzImage

Start: Sun Jul 1 01:48:54 EDT 2007
Finish: Sun Jul 1 02:02:29 EDT 2007

Compare this to a single CPU compile:

Start: Sun Jul 1 02:15:41 EDT 2007
Finish: Sun Jul 1 03:06:36 EDT 2007

Quite a large difference, expecially when you're waiting on the machine.

While you may think I'm a tard for not knowing this before, I did actually know the flag, that's how I found it. I just wanted to make sure I was right.

Tests were performed on a Quad Xeon 550 Mhz (512K cache) Netfinity 5500 M20 with 768MB of RAM. 151 lbs of IBM Iron.


Written by Dan on 2007-07-01 08:13:41

Login to NerdNOS
Register with NerdNOS