Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to: make -j x // where x is automatically determined

After reading answer to this question: Make "make" default to "make -j 8"

I am wondering if there is way to make the -j option automatically use the correct number of compile threads?

So I say make. And the make command itself uses 6 or 4 or 8 threads depending on the hardware?

like image 756
Ahmad Mushtaq Avatar asked Jun 08 '12 08:06

Ahmad Mushtaq


1 Answers

make does not look up the number of cores by itself if you just use make -j -- instead, it parallelizes to the max. However, you should be able to determine the number of cores by

grep -c "^processor" /proc/cpuinfo

or (as per Azor-Ahai's comment, if available on your system)

nproc

Hence:

make -j $(nproc)

See "How How to obtain the number of CPUs/cores in Linux from the command line?" for more details. Also, see GNU make: should the number of jobs equal the number of CPU cores in a system?

like image 96
krlmlr Avatar answered Nov 15 '22 07:11

krlmlr