Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use RTLD_GLOBAL for libgomp #4353

Merged
merged 3 commits into from
May 15, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 14 additions & 11 deletions pycbc/scheme.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,6 @@
import logging
from .libutils import get_ctypes_library

try:
_libgomp = get_ctypes_library("gomp", ['gomp'])
except:
# Should we fail or give a warning if we cannot import
# libgomp? Seems to work even for MKL scheme, but
# not entirely sure why...
_libgomp = None

class _SchemeManager(object):
_single = None
Expand Down Expand Up @@ -129,17 +122,27 @@ def __init__(self, num_threads=1):
else:
import multiprocessing
self.num_threads = multiprocessing.cpu_count()
self._libgomp = None

def __enter__(self):
Scheme.__enter__(self)
try:
self._libgomp = get_ctypes_library("gomp", ['gomp'],
mode=ctypes.RTLD_GLOBAL)
except:
# Should we fail or give a warning if we cannot import
# libgomp? Seems to work even for MKL scheme, but
# not entirely sure why...
pass

os.environ["OMP_NUM_THREADS"] = str(self.num_threads)
if _libgomp is not None:
_libgomp.omp_set_num_threads( int(self.num_threads) )
if self._libgomp is not None:
self._libgomp.omp_set_num_threads( int(self.num_threads) )

def __exit__(self, type, value, traceback):
os.environ["OMP_NUM_THREADS"] = "1"
if _libgomp is not None:
_libgomp.omp_set_num_threads(1)
if self._libgomp is not None:
self._libgomp.omp_set_num_threads(1)
Scheme.__exit__(self, type, value, traceback)

class MKLScheme(CPUScheme):
Expand Down