From edd5efb5334441de38591afc00ea2154f0205282 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Jakub=20Klinkovsk=C3=BD?= <klinkjak@fjfi.cvut.cz>
Date: Fri, 5 Jul 2019 10:03:43 +0200
Subject: [PATCH] Improved build script to count physical cores on all NUMA
 nodes

---
 build | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/build b/build
index 58d4a11c38..e740fc13a0 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
-- 
GitLab