]> Savannah Git Hosting - gnulib.git/commitdiff
nproc: Optimize.
authorBruno Haible <bruno@clisp.org>
Thu, 20 Mar 2025 13:28:54 +0000 (14:28 +0100)
committerBruno Haible <bruno@clisp.org>
Thu, 20 Mar 2025 13:28:54 +0000 (14:28 +0100)
* lib/nproc.c (num_processors): Optimize away the
num_processors_ignoring_omp (query) call when possible.

ChangeLog
lib/nproc.c

index 8a788702e687c70ffcfdd457b7ff605fb9f71652..f7049270d2a69d40a077dad568c1a789fd623e60 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2025-03-20  Bruno Haible  <bruno@clisp.org>
+
+       nproc: Optimize.
+       * lib/nproc.c (num_processors): Optimize away the
+       num_processors_ignoring_omp (query) call when possible.
+
 2025-03-19  Paul Eggert  <eggert@cs.ucla.edu>
 
        nproc, openmp-init: omit unnecessary strtol code
index 051426a6f00372b30db4da7f3750ad7a29b05605..83439aa0eb2bc56ea780d1fd156cfa459ebdbde6 100644 (file)
@@ -434,6 +434,9 @@ num_processors (enum nproc_query query)
       query = NPROC_CURRENT;
     }
   /* Here query is one of NPROC_ALL, NPROC_CURRENT.  */
+  if (omp_env_limit == 1)
+    /* No need to even call num_processors_ignoring_omp (query).  */
+    return 1;
   {
     unsigned long nprocs = num_processors_ignoring_omp (query);
     return MIN (nprocs, omp_env_limit);