diff --git a/build.sh b/build.sh
index fc9f7fdcf46c89d1f5ced43c2b52410fd9677aea..98a304b32202cdcc8726da9ded87747e0abd26ee 100755
--- a/build.sh
+++ b/build.sh
@@ -92,8 +92,12 @@ function run-make() {
 
     # 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.
+    if [ "$nthreads" = "unlimited" ]; then
+        nthreads=$njobs
+    else
+        local factor=16
+        nthreads=$((nthreads/factor)) # assume it is safe to divide by scale factor.
+    fi
     
     # min(njobs, nthreads)
     njobs=$((njobs<nthreads ?  njobs: nthreads))