summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPádraig Brady <P@draigBrady.com>2017-02-26 16:05:25 (GMT)
committerPádraig Brady <P@draigBrady.com>2017-02-26 17:31:50 (GMT)
commit9404382f6b98606f98b5cd736f5bf6b0aff9d1e7 (patch)
tree92a88ed7ca388e0116ed22de41b30b1a30bf504f
parente1d1b4f4971419b50659d199af87681b66868c5d (diff)
downloadcoreutils-9404382f6b98606f98b5cd736f5bf6b0aff9d1e7.zip
coreutils-9404382f6b98606f98b5cd736f5bf6b0aff9d1e7.tar.gz
coreutils-9404382f6b98606f98b5cd736f5bf6b0aff9d1e7.tar.bz2
nproc: support OMP_THREAD_LIMIT to set a max value
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.
-rw-r--r--NEWS15
-rw-r--r--doc/coreutils.texi8
-rw-r--r--tests/local.mk1
-rwxr-xr-xtests/misc/nproc-override.sh58
4 files changed, 73 insertions, 9 deletions
diff --git a/NEWS b/NEWS
index b066c61..11931a4 100644
--- 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]
diff --git a/doc/coreutils.texi b/doc/coreutils.texi
index 2356a3f..d72760b 100644
--- a/doc/coreutils.texi
+++ b/doc/coreutils.texi
@@ -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
diff --git a/tests/local.mk b/tests/local.mk
index 2717024..9f1a853 100644
--- a/tests/local.mk
+++ b/tests/local.mk
@@ -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
index 0000000..7870956
--- /dev/null
+++ b/tests/misc/nproc-override.sh
@@ -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