How does -j switch in make work

Submitted by Haynes Mathew
on March 15, 2005 - 2:01am

hi..

I need to know how the -j switch in make works for a project..

Where can i get info about this?

The man page gives only what -j does not how it does;

thnks

Haynes Mathew

independent rules

strcmp
on
March 15, 2005 - 5:25am

As I understand it, independent rules are executed in parallel, i.e. in

prog: a.o b.o
        ld -o prog a.o b.o
a.o: a.c
        cc -c a.c
b.o: b.c
        cc -c b.c

(assumed the tabs are right) a.o and b.o can be 'made' in parallel. If both a.c and b.c are changed, the two cc commands can be started in parallel, after both of them exit, the ld can be started. As you can see, the level of parallelism depends on the makefile and what has to be done. In the example, assuming for simplicity both cc and ld need the same time, the maximal speedup (for every -j > 1) is 1.5.

independent rules

Wouter van Reeven (not verified)
on
March 15, 2005 - 8:56am

Besides that, it's possible to give a number along with the -j option. So, "make -j 2" will spawn to processes at the same time and add a new one as soon as one of the two finishes. Likewise, "make -j 3" spawns three processes etc. Without a number, so just "make -j", all processes are spawned at the same time and the kernel scheduler is working overtime to get all processes started in the right order. This is a great way of testing the stability of your system.

distcc

Anonymous (not verified)
on
March 15, 2005 - 9:52am

OK the docs refer to make but......

Haynes Mathew
on
March 22, 2005 - 3:14am

hi..

Following your link www.distcc.samba.org i read the design paper .. it mentions about make -j and how it handles dependencies using graphs .
but unfortuantely it's doesnot actually say how...

I am looking for that
Anyway thanks for the link . Seems i'll have to read the make source and understand afterall

anymore help greatly appreciated

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.