diff --git a/build b/build index 58d4a11c3820cc2c97f1fcb1a97494a77b51ee44..e740fc13a0dd7d4f4a21340e8729f1591f2a7b87 100755 --- a/build +++ b/build @@ -206,18 +206,22 @@ if [[ ${CMAKE_ONLY} == "yes" ]]; then exit 0 fi +# get the number of physical cores present on the system, even with multiple NUMA nodes +# see https://unix.stackexchange.com/a/279354 +SYSTEM_CORES=$(lscpu --all --parse=CORE,SOCKET | grep -Ev "^#" | sort -u | wc -l) + if [[ "$make" == "make" ]]; then if [[ -n ${BUILD_JOBS} ]]; then # override $MAKEFLAGS from parent environment export MAKEFLAGS=-j${BUILD_JOBS} elif [[ -z ${MAKEFLAGS} ]]; then # $BUILD_JOBS and $MAKEFLAGS are not set => set default value - BUILD_JOBS=$(grep "core id" /proc/cpuinfo | sort -u | wc -l) + BUILD_JOBS=$SYSTEM_CORES export MAKEFLAGS=-j${BUILD_JOBS} fi else if [[ -z ${BUILD_JOBS} ]]; then - BUILD_JOBS=$(grep "core id" /proc/cpuinfo | sort -u | wc -l) + BUILD_JOBS=$SYSTEM_CORES fi make="$make -j$BUILD_JOBS" fi