]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
nproc: support OMP_THREAD_LIMIT to set a max value
authorPádraig Brady <P@draigBrady.com>
Sun, 26 Feb 2017 16:05:25 +0000 (08:05 -0800)
committerPádraig Brady <P@draigBrady.com>
Sun, 26 Feb 2017 17:31:50 +0000 (09:31 -0800)
This comes from the latest gnulib.
Also handling of OMP_NUM_THREADS has been adjusted
to support comma separated values indicating a nesting level,
in which case the first value is taken.  Also OMP_NUM_THREADS=0
is now ignored instead of being treated as 1, to match
the behavior of libgomp.

* NEWS: Mention the OMP_THREAD_LIMIT improvement,
and OMP_NUM_THREADS now handling nested values.
* doc/coreutils.texi (nproc invocation): Describe OMP_THREAD_LIMIT
as a way to set the max value, with OMP_THREAD_LIMIT setting the min.
* tests/misc/nproc-override.sh: A new test to exercise the
updated gnulib code with all combinations of these OMP variables.
* tests/local.mk: Reference the new test.

NEWS
doc/coreutils.texi
tests/local.mk
tests/misc/nproc-override.sh [new file with mode: 0755]

diff --git a/NEWS b/NEWS
index b066c61e3ee5386632deabe49fd6d79a8aae7c6f..11931a48b51ced2ae2578fb37e0b1b0adb37af89 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -2,12 +2,6 @@ GNU coreutils NEWS                                    -*- outline -*-
 
 * Noteworthy changes in release ?.? (????-??-??) [?]
 
-** Improvements
-
-  If the file B already exists, commands like 'ln -f A B' and
-  'cp -fl A B' no longer remove B before creating the new link.
-  That is, there is no longer a brief moment when B does not exist.
-
 ** Bug fixes
 
   cp --parents will now set an SELinux context for created directories,
@@ -52,9 +46,18 @@ GNU coreutils NEWS                                    -*- outline -*-
   and the time zone abbreviation begins with "-", indicating that the
   time zone is indeterminate.
 
+  nproc now honors the OMP_THREAD_LIMIT environment variable to
+  set the maximum returned value.  OMP_NUM_THREADS continues to
+  set the minimum returned value, but is updated to support the
+  nested level syntax allowed in this variable.
+
   stty now validates arguments before interacting with the device,
   ensuring there are no side effects to specifying an invalid option.
 
+  If the file B already exists, commands like 'ln -f A B' and
+  'cp -fl A B' no longer remove B before creating the new link.
+  That is, there is no longer a brief moment when B does not exist.
+
 
 * Noteworthy changes in release 8.26 (2016-11-30) [stable]
 
index 2356a3f8a054ee899df73f7b09e4b7c6956f8b01..d72760bff97be92143378b1af9cf71388b8856b2 100644 (file)
@@ -15808,8 +15808,9 @@ not rely on its existence.
 Print the number of processing units available to the current process,
 which may be less than the number of online processors.
 If this information is not accessible, then print the number of
-processors installed.  If the @env{OMP_NUM_THREADS} environment variable is
-set, then it will determine the returned value.  The result is guaranteed to be
+processors installed.  If the @env{OMP_NUM_THREADS} or @env{OMP_THREAD_LIMIT}
+environment variables are set, then they will determine the minimum
+and maximum returned value respectively.  The result is guaranteed to be
 greater than zero.  Synopsis:
 
 @example
@@ -15824,7 +15825,8 @@ The program accepts the following options.  Also see @ref{Common options}.
 @opindex --all
 Print the number of installed processors on the system, which may
 be greater than the number online or available to the current process.
-The @env{OMP_NUM_THREADS} environment variable is not honored in this case.
+The @env{OMP_NUM_THREADS} or @env{OMP_THREAD_LIMIT} environment variables
+are not honored in this case.
 
 @item --ignore=@var{number}
 @opindex --ignore
index 27170240e935751000d81cbe45cd3bb9373bdf32..9f1a853a855153174a1d29e4cd3b855215597452 100644 (file)
@@ -309,6 +309,7 @@ all_tests =                                 \
   tests/misc/nohup.sh                          \
   tests/misc/nproc-avail.sh                    \
   tests/misc/nproc-positive.sh                 \
+  tests/misc/nproc-override.sh                 \
   tests/misc/numfmt.pl                         \
   tests/misc/od-N.sh                           \
   tests/misc/od-j.sh                           \
diff --git a/tests/misc/nproc-override.sh b/tests/misc/nproc-override.sh
new file mode 100755 (executable)
index 0000000..7870956
--- /dev/null
@@ -0,0 +1,58 @@
+#!/bin/sh
+# Test the various OpenMP override options
+
+# Copyright (C) 2017 Free Software Foundation, Inc.
+
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src
+print_ver_ nproc
+
+unset OMP_NUM_THREADS
+unset OMP_THREADS_LIMIT
+
+avail=$(nproc) || fail=1
+test $(($avail > 0)) || fail=1
+
+#OMP_THREAD_LIMIT       OMP_NUM_THREADS     NPROC
+echo "\
+ -                      -                   $avail
+ 1                      -                   1
+ 1                      0                   1
+ -                      0                   $avail
+ -                      2,2,1               2
+ -                      2,ignored           2
+ -                      2bad                $avail
+ -                      -2                  $avail
+ 1                      2,2,1               1
+ 0                      2,2,1               2
+ 1bad                   2,2,1               2
+ 1bad                   $(($avail+1)),2,1   $(($avail+1))
+ 1                      $(($avail+1))       1
+ $(($avail+2))          $(($avail+1))       $(($avail+1))
+ $(($avail+1))          $(($avail+2))       $(($avail+1))
+ -                      $(($avail+1))       $(($avail+1))" |
+
+while read OMP_THREAD_LIMIT OMP_NUM_THREADS NPROC; do
+  test $OMP_THREAD_LIMIT = '-' && unset OMP_THREAD_LIMIT
+  test $OMP_NUM_THREADS = '-' && unset OMP_NUM_THREADS
+  export OMP_THREAD_LIMIT
+  export OMP_NUM_THREADS
+  test $(nproc) = $NPROC ||
+    echo "[$OMP_THREAD_LIMIT] [$OMP_NUM_THREADS]" >> failed
+done
+
+test -e failed && fail=1
+
+Exit $fail