File tree Expand file tree Collapse file tree 6 files changed +69
-30
lines changed Expand file tree Collapse file tree 6 files changed +69
-30
lines changed Original file line number Diff line number Diff 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 :
Original file line number Diff line number Diff 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"
Original file line number Diff line number Diff line change 55If ever we want to do anything clever, we should use one of
66the supported python packages
77"""
8+
89import os
910
1011from .. import state , utils
Original file line number Diff line number Diff line change 55If ever we want to do anything clever, we should use one of
66the supported svn/python packages
77"""
8+
89import os
910import re
1011
Original file line number Diff line number Diff line change 33If ever we want to do anything clever, we should use one of
44the supported svn/python packages
55"""
6+
67import os
78import re
89import sys
Original file line number Diff line number Diff 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
2541if __name__ == "__main__" :
2642 unittest .main ()
You can’t perform that action at this time.
0 commit comments