Autodetect processing units with -j

wrotycz <[email protected]> Wed, 25 Jun 2025 13:34:11 +0200
Newsgroups gmane.comp.gnu.make.bugs
Message-ID <[email protected]>
Autodetect processing units with -j    At the moment, though this moment lasts for decades now, -j/--jobs without argument starts infinite number of parallel jobs.  Practice shows that compilation with jobs bigger than number of available threads is not faster in any way, only uses more memory and more processor too.   Try to compile kernel or gcc with -j. And if one misses infinite jobs so much why not use -j999; it&#39;s the same thing, only makes you aware of it.    Therefore I propose to use -j without argument as autodetect of available processing units and modify jobs accordingly to that number.   One could argue that optimal number of jobs is nproc+1 (or at most +2) although some propose nproc*2, which is overkill and close to -j&lt;infinity&gt; in reality.   I have attached patch and test script that allows to show how compilation time changes with jobs growing above available number.  I have tested it myself, tried it online and used few friends to test it too, and result is always the same - jobs bigger than nproc does not make compilation any faster. It actually makes it slower.    Hope you find these arguments convincing and change useful.    Regards.
gmake-jN2.sh (text/x-sh, 590 B)
#!/bin/sh

URL=http://ftp.gnu.org/gnu/make/make-4.4.1.tar.gz
FILE=`basename $URL`
[ -f "$FILE" ] || wget $URL

DIR=${FILE/.tar.gz/}
[ -d "$DIR" ] || tar -xzf $FILE


(
cd $DIR

[ -f "config.status" ] || sh configure > /dev/null 2>&1

nproc=`nproc`

echo uname -a
uname -a
echo nproc
nproc
echo
for i in `seq $nproc $((nproc*2))`; do
    make clean V=0 > /dev/null 2>&1
    CMD="make -j$i V=0"
    echo $CMD
    time eval $CMD > /dev/null 2>&1
    echo
    sleep $i
done

    make clean V=0 > /dev/null 2>&1
    CMD="make -j V=0"
    echo $CMD
    time eval $CMD > /dev/null 2>&1
    echo
)
make-4.4.1-jnproc.diff.zip (application/zip, 955 B) - not displayed