Skip to content

Commit

Permalink
build(setup): add -march option
Browse files Browse the repository at this point in the history
Closes #85
  • Loading branch information
nritsche committed Sep 9, 2020
1 parent cc6c112 commit f7241ef
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
VERSION = VERSION + ".dev%d" % VERSION_DEV


COMPILE_FLAGS = ['-O3', '-ffast-math', '-march=native', '-std=c99']
COMPILE_FLAGS = ['-O3', '-ffast-math', '-std=c99']
# Cython breaks strict aliasing rules.
COMPILE_FLAGS += ['-fno-strict-aliasing']
COMPILE_FLAGS += ['-fPIC']
Expand All @@ -40,6 +40,7 @@


H5PLUGINS_DEFAULT = '/usr/local/hdf5/lib/plugin'
MARCH_DEFAULT = 'native'

# OSX's clang compliler does not support OpenMP.
if sys.platform == 'darwin':
Expand Down Expand Up @@ -223,13 +224,16 @@ def run(self):
class build_ext(build_ext_):
user_options = build_ext_.user_options + [
('omp=', None, "Whether to compile with OpenMP threading. Default"
" on current system is %s." % str(OMP_DEFAULT))
" on current system is %s." % str(OMP_DEFAULT)),
('march=', None,
'Generate instructions for a specific machine type. Default is %s.' % MARCH_DEFAULT),
]
boolean_options = build_ext_.boolean_options + ['omp']

def initialize_options(self):
build_ext_.initialize_options(self)
self.omp = OMP_DEFAULT
self.march = MARCH_DEFAULT

def finalize_options(self):
# For some reason this gets run twice. Careful to print messages and
Expand Down Expand Up @@ -269,7 +273,7 @@ def build_extensions(self):
compileflags = COMPILE_FLAGS_MSVC
else:
openmpflag = '-fopenmp'
compileflags = COMPILE_FLAGS
compileflags = COMPILE_FLAGS + ['-march=%s' % self.march]
for e in self.extensions:
e.extra_compile_args = list(set(e.extra_compile_args).union(compileflags))
if openmpflag not in e.extra_compile_args:
Expand Down

0 comments on commit f7241ef

Please sign in to comment.