Skip to content

Commit

Permalink
Add one more variable to set in set_thread_envvars (DM-38815)
Browse files Browse the repository at this point in the history
When set to "false" the envvar `OMP_PROC_BIND` should stop OpenMP from
setting CPU affinity.
  • Loading branch information
andy-slac committed Apr 25, 2023
1 parent 7069b80 commit 0dce87b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
6 changes: 6 additions & 0 deletions python/lsst/utils/threads.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,12 @@ def set_thread_envvars(num_threads: int = 1, override: bool = False) -> None:
if override or var not in os.environ:
os.environ[var] = str(num_threads)

# Also specify an explicit value for OMP_PROC_BIND to tell OpenMP not to
# set CPU affinity.
var = "OMP_PROC_BIND"
if override or var not in os.environ:
os.environ[var] = "false"


def disable_implicit_threading() -> None:
"""Do whatever is necessary to try to prevent implicit threading.
Expand Down
1 change: 1 addition & 0 deletions tests/test_threads.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ def testDisable(self):

disable_implicit_threading()
self.assertEqual(os.environ["OMP_NUM_THREADS"], "1")
self.assertEqual(os.environ["OMP_PROC_BIND"], "false")

# Check that we have only one thread.
if numexpr:
Expand Down

0 comments on commit 0dce87b

Please sign in to comment.