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?
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?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With