Skip to content

Commit 30fe544

Browse files
authored
Merge pull request #118 from lsst/tickets/DM-42799
Turn off implicit multithreading via env vars for all uses of sconsUtils
2 parents 80c3e6a + 6d7afe0 commit 30fe544

File tree

6 files changed

+69
-30
lines changed

6 files changed

+69
-30
lines changed

python/lsst/sconsUtils/state.py

Lines changed: 47 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -187,33 +187,49 @@ def _initEnvironment():
187187
"""Construction and basic setup of the state.env variable."""
188188

189189
ourEnv = {}
190-
preserveVars = """
191-
DYLD_LIBRARY_PATH
192-
EUPS_DIR
193-
EUPS_LOCK_PID
194-
EUPS_PATH
195-
EUPS_SHELL
196-
EUPS_USERDATA
197-
LD_LIBRARY_PATH
198-
PATH
199-
SHELL
200-
TEMP
201-
TERM
202-
TMP
203-
TMPDIR
204-
XPA_PORT
205-
CONDA_BUILD_SYSROOT
206-
SDKROOT
207-
""".split()
208-
209-
codeCheckerVars = """
210-
LD_PRELOAD
211-
CC_LOGGER_FILE
212-
CC_LOGGER_GCC_LIKE
213-
CC_LIB_DIR
214-
CC_DATA_FILES_DIR
215-
CC_LOGGER_BIN
216-
""".split()
190+
preserveVars = [
191+
"DYLD_LIBRARY_PATH",
192+
"EUPS_DIR",
193+
"EUPS_LOCK_PID",
194+
"EUPS_PATH",
195+
"EUPS_SHELL",
196+
"EUPS_USERDATA",
197+
"LD_LIBRARY_PATH",
198+
"PATH",
199+
"SHELL",
200+
"TEMP",
201+
"TERM",
202+
"TMP",
203+
"TMPDIR",
204+
"XPA_PORT",
205+
"CONDA_BUILD_SYSROOT",
206+
"SDKROOT",
207+
]
208+
209+
codeCheckerVars = [
210+
"LD_PRELOAD",
211+
"CC_LOGGER_FILE",
212+
"CC_LOGGER_GCC_LIKE",
213+
"CC_LIB_DIR",
214+
"CC_DATA_FILES_DIR",
215+
"CC_LOGGER_BIN",
216+
]
217+
218+
# The list of implicit multithreading environment variables here
219+
# is taken from lsst.utils.disable_implicit_threading(), but
220+
# has to be put here for dependency ordering reasons, and
221+
# to ensure these are set prior to any instantiation of pytest
222+
# or any code that may implicitly spawn threads.
223+
implicitMultithreadingVars = [
224+
"OPENBLAS_NUM_THREADS",
225+
"GOTO_NUM_THREADS",
226+
"OMP_NUM_THREADS",
227+
"MKL_NUM_THREADS",
228+
"MKL_DOMAIN_NUM_THREADS",
229+
"MPI_NUM_THREADS",
230+
"NUMEXPR_NUM_THREADS",
231+
"NUMEXPR_MAX_THREADS",
232+
]
217233

218234
for key in preserveVars:
219235
if key in os.environ:
@@ -225,6 +241,10 @@ def _initEnvironment():
225241
if key in os.environ:
226242
ourEnv[key] = os.environ[key]
227243

244+
# Turn off implicit multithreading.
245+
for key in implicitMultithreadingVars:
246+
ourEnv[key] = "1"
247+
228248
# Find and propagate EUPS environment variables.
229249
cfgPath = []
230250
for k in os.environ:

python/lsst/sconsUtils/tools/cuda.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,9 @@ def generate(env):
5252
env["NVCCCMDLINE"] = ""
5353

5454
# default NVCC commands
55-
env[
56-
"STATICNVCCCMD"
57-
] = "$NVCC -o $TARGET -c $NVCCFLAGS $_CPPINCFLAGS $STATICNVCCFLAGS $NVCCCMDLINE $SOURCES"
55+
env["STATICNVCCCMD"] = (
56+
"$NVCC -o $TARGET -c $NVCCFLAGS $_CPPINCFLAGS $STATICNVCCFLAGS $NVCCCMDLINE $SOURCES"
57+
)
5858
env["SHAREDNVCCCMD"] = (
5959
"$NVCC -o $TARGET -c $NVCCFLAGS $_CPPINCFLAGS $SHAREDNVCCFLAGS"
6060
" $ENABLESHAREDNVCCFLAG $NVCCCMDLINE $SOURCES"

python/lsst/sconsUtils/vcs/git.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
If ever we want to do anything clever, we should use one of
66
the supported python packages
77
"""
8+
89
import os
910

1011
from .. import state, utils

python/lsst/sconsUtils/vcs/hg.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
If ever we want to do anything clever, we should use one of
66
the supported svn/python packages
77
"""
8+
89
import os
910
import re
1011

python/lsst/sconsUtils/vcs/svn.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
If ever we want to do anything clever, we should use one of
44
the supported svn/python packages
55
"""
6+
67
import os
78
import re
89
import sys

tests/test_simple.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,22 @@ def testEnvironment(self):
2121
self.assertIn(envVar, os.environ)
2222
self.assertTrue(os.path.exists(os.environ[envVar]), f"Check path {os.environ[envVar]}")
2323

24+
def testNoImplicitMultithreading(self):
25+
"""Test that the environment has turned off implicit
26+
multithreading.
27+
"""
28+
envVar = "OMP_NUM_THREADS"
29+
self.assertIn(envVar, os.environ)
30+
self.assertEqual(os.environ[envVar], "1")
31+
32+
try:
33+
import numexpr
34+
except ImportError:
35+
numexpr = None
36+
37+
if numexpr:
38+
self.assertEqual(numexpr.utils.get_num_threads(), 1)
39+
2440

2541
if __name__ == "__main__":
2642
unittest.main()

0 commit comments

Comments
 (0)