From 2215df3236bea0afc1f1aac8b4e361fb426010f6 Mon Sep 17 00:00:00 2001 From: lintao <lintao@ihep.ac.cn> Date: Wed, 18 Sep 2024 10:21:55 +0800 Subject: [PATCH 1/2] Allow users to limit number of cores using NJOBS envvar. --- build.sh | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/build.sh b/build.sh index 85934189..704efb0c 100755 --- a/build.sh +++ b/build.sh @@ -83,7 +83,14 @@ function run-cmake() { } function run-make() { - local njobs=-j$(nproc) + # User can limit the number of cores by setting NJOBS envvar. + # For example: NJOBS=8 ./build.sh + local njobs=$NJOBS + if [ -z "$njobs" ]; then + njobs=$(nproc) + fi + njobs=-j${njobs} + cmake --build . $njobs } -- GitLab From 6cc08cf173524d8c5ee34a6a7664056f6cfcc18f Mon Sep 17 00:00:00 2001 From: lintao <lintao@ihep.ac.cn> Date: Wed, 18 Sep 2024 11:07:06 +0800 Subject: [PATCH 2/2] Need to get the min of njobs and nthreads/factor. --- build.sh | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/build.sh b/build.sh index 704efb0c..fc9f7fdc 100755 --- a/build.sh +++ b/build.sh @@ -85,12 +85,21 @@ function run-cmake() { function run-make() { # User can limit the number of cores by setting NJOBS envvar. # For example: NJOBS=8 ./build.sh - local njobs=$NJOBS + local njobs=${NJOBS} if [ -z "$njobs" ]; then njobs=$(nproc) fi - njobs=-j${njobs} + # following is IHEP specific hack due to the limitation of nthreads 150. + local nthreads=$(ulimit -u) + local factor=16 + nthreads=$((nthreads/factor)) # assume it is safe to divide by scale factor. + + # min(njobs, nthreads) + njobs=$((njobs<nthreads ? njobs: nthreads)) + + njobs=-j${njobs} + echo "njobs: $njobs" cmake --build . $njobs } -- GitLab