Skip to content

Commit

Permalink
try to fix openmp on osx
Browse files Browse the repository at this point in the history
  • Loading branch information
marscher committed Jun 22, 2018
1 parent d2cd713 commit 41b9d90
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
9 changes: 6 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,11 +236,14 @@ def build_extensions(self):
opts.append('/DVERSION_INFO=\\"%s\\"' % self.distribution.get_version())

# setup OpenMP support
openmp_enabled, needs_gomp = detect_openmp(self.compiler)
openmp_enabled, additional_libs = detect_openmp(self.compiler)
if openmp_enabled:
warnings.warn('enabled openmp')
omp_compiler_args = ['-fopenmp']
omp_libraries = ['-lgomp'] if needs_gomp else []
if sys.platform == 'darwin':
omp_compiler_args = ['-fopenmp=libiomp5']
else:
omp_compiler_args = ['-fopenmp']
omp_libraries = additional_libs
omp_defines = [('USE_OPENMP', None)]
# debug
dbg_flag = ['-g0' if not self.debug else '-g']
Expand Down
15 changes: 11 additions & 4 deletions setup_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,17 +90,24 @@ def has_function(cc, funcname, headers):


def detect_openmp(compiler):
from copy import deepcopy
compiler = deepcopy(compiler) # avoid side-effects
with stdchannel_redirected(sys.stderr, os.devnull), \
stdchannel_redirected(sys.stdout, os.devnull):
has_openmp = has_function(compiler, 'omp_get_num_threads', headers='omp.h')
print('[OpenMP] compiler {} has builtin support'.format(compiler))
needs_gomp = has_openmp
additional_libs = []
if not has_openmp:
print('[OpenMP] compiler {} needs library support'.format(compiler))
compiler.add_library('gomp')
if sys.platform == 'darwin':
compiler.add_library('iomp5')
elif sys.platform == 'linux2':
compiler.add_library('gomp')
has_openmp = has_function(compiler, 'omp_get_num_threads', headers='omp.h')
needs_gomp = has_openmp
return has_openmp, needs_gomp
if has_openmp:
additional_libs = compiler.libraries[-1]
print('[OpenMP] added library {}'.format(additional_libs))
return has_openmp, additional_libs


# has_flag and cpp_flag taken from https://github.com/pybind/python_example/blob/master/setup.py
Expand Down

0 comments on commit 41b9d90

Please sign in to comment.