Skip to content

Commit 630f4ba

Browse files
committed
Cleanup setup.py to compile linux openmp
1 parent f0aac51 commit 630f4ba

File tree

1 file changed

+26
-14
lines changed

1 file changed

+26
-14
lines changed

setup.py

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,53 @@
11
import glob
22
from setuptools import setup
3-
from pybind11.setup_helpers import Pybind11Extension, build_ext
3+
from pybind11.setup_helpers import (
4+
Pybind11Extension,
5+
build_ext,
6+
ParallelCompile,
7+
naive_recompile
8+
)
49
from pathlib import Path
510

611
import platform
712

813
debug = False
914
openmp = True
1015

16+
ParallelCompile("NPY_NUM_BUILD_JOBS", needs_recompile=naive_recompile).install()
17+
18+
cpp_args = []
19+
linkargs = []
20+
libs = []
21+
1122
if platform.system() == "Windows":
12-
cpp_args=['/std:c++20', '/MD']
13-
linkargs = []
23+
cpp_args.extend(['/std:c++20', '/MD'])
24+
1425
if debug:
1526
cpp_args.extend(['/Od','/Zi'])
1627
linkargs.extend(['/DEBUG'])
28+
1729
else:
1830
cpp_args.extend(['/O2', '/Ot'])
31+
1932
if openmp:
2033
cpp_args.append('/openmp')
2134

2235
elif platform.system() == "Linux":
23-
cpp_args = ['-std=c++20']
24-
linkargs = []
36+
cpp_args.extend(['-std=c++20'])
37+
2538
if debug:
2639
cpp_args.extend(['-O0'])
40+
2741
else:
2842
cpp_args.extend(['-O3'])
43+
2944
if openmp:
30-
pass
31-
# TODO: non-monotonic dynamic loop in gcc introduced recently causing issues with linux build
32-
# cpp_args.append('-fopenmp')
33-
# linkargs.append('-lgomp')
34-
linkargs = []
45+
cpp_args.append('-fopenmp')
46+
libs.append('gomp')
47+
3548
else:
3649
# disable openmp for non-linux/windows systems
37-
cpp_args = ['-std=c++20', '-O3']
38-
linkargs = []
50+
cpp_args.extend(['-std=c++20', '-O3'])
3951

4052

4153
roughness_cppimpl_sources = [
@@ -61,7 +73,8 @@
6173
include_dirs=roughness_cppimpl_includes,
6274
language='c++',
6375
extra_compile_args=cpp_args,
64-
extra_link_args=linkargs
76+
extra_link_args=linkargs,
77+
libraries=libs
6578
)
6679

6780
setup(
@@ -77,7 +90,6 @@
7790
'surface_roughness':'surface_roughness',
7891
'surface_roughness._roughness_pyimpl':'surface_roughness/_roughness_pyimpl'},
7992
packages=['surface_roughness','surface_roughness._roughness_pyimpl'],
80-
# ext_package='surface_roughness',
8193
ext_modules=[roughness_cppimpl],
8294
install_requires=[
8395
'scipy',

0 commit comments

Comments
 (0)