For example, would it not be beneficial to have -jN > nrcpus during the configure phase, where CPU load is low? Then have -jN = nrcpus during compilation, where load should be evenly distributed to each CPU?
How difficult would this be to implement in a build environment? Would it require changing each configuration file for each step? Is it possible to automate for multiple projects, given they use the same "make" program?
This is assuming that the workload is never I/O bound.
configure
script is a single threaded shell script, so there is nothing to be gained from tellingmake
that it can run multiple jobs. To answer the question in the title, look at the-l
option to make. This limits jobs being started if the load average (which is a crude approximation to CPU load if the workload is not I/O bound) is too high. – icarus Dec 22 '19 at 04:31configure
. The [tag:configure] tag was added by a moderator, and the original [tag:cmake] tag removed. That being said, I don't know ifcmake
supports that kind of parallelism, but I knowcmake
supports not onlymake
, but also other build systems likeninja
. – Dec 22 '19 at 23:12mkdir build ; cd build ; cmake ..
which does the generation based on ../CMakeLists.txt, and then just usemake
as required. There is a lot more to it of course, support for cross compiling, caching build flags and rebuilding if they change etc. This invocation of cmake does a lot of the same things that a typical configure script does, e.g. finding installed optional libraries. – icarus Dec 23 '19 at 02:57-j
flag to cmake. – icarus Dec 23 '19 at 03:00Makefile
, which will automatically callconfigure
/cmake
/meson
/whatever into subprojects (sometimes even download them viagit
); that can be run withmake -j
. I usually use justnice -n19 make -j32
(on a machine with 4 cores) and let the system handle it ;-) – Dec 23 '19 at 03:23nice -n19 make -j32
(with aj
> the number of cores) will do for "evenly distributing the load", keeping the cores busy even when some make actions are blocked in i/o, and not letmake
hog the whole system ;-) – Dec 23 '19 at 04:39