diff --git a/compiledtrees/code_gen.py b/compiledtrees/code_gen.py index f013b21..6cceb42 100644 --- a/compiledtrees/code_gen.py +++ b/compiledtrees/code_gen.py @@ -20,6 +20,16 @@ CXX_COMPILER = sysconfig.get_config_var('CXX') delete_files = True +# detect OpenMP support +if platform.system() == 'Darwin': + c_ver = subprocess.check_output([CXX_COMPILER, '--version']).decode('ascii') + if c_ver.find('clang') >= 0: # Xcode clang does not support OpenMP + OPENMP_SUPPORT = False + else: # GCC supports OpenMP + OPENMP_SUPPORT = True +else: + OPENMP_SUPPORT = True + EVALUATE_FN_NAME = "evaluate" ALWAYS_INLINE = "__attribute__((__always_inline__))" diff --git a/compiledtrees/tests/test_compiled.py b/compiledtrees/tests/test_compiled.py index 79a122f..8987a85 100644 --- a/compiledtrees/tests/test_compiled.py +++ b/compiledtrees/tests/test_compiled.py @@ -5,6 +5,7 @@ import os from sklearn import ensemble, tree from compiledtrees.compiled import CompiledRegressionPredictor +from compiledtrees.code_gen import OPENMP_SUPPORT from sklearn.utils.testing import (assert_array_almost_equal, assert_raises, assert_equal, assert_allclose, @@ -145,22 +146,23 @@ def test_openmp(self): rf1_compiled.predict(X1, n_jobs=2), decimal=10) - # On travis/appveyor check for any speedup Be less generous otherwise. - if 'TRAVIS' in os.environ or 'APPVEYOR' in os.environ: - target = 0.9 - else: - target = 0.6 - # multi sample scaling - parallel samples - start = datetime.now() - rf1_compiled.predict(X1, n_jobs=1) - t_single = (datetime.now() - start).microseconds - - start = datetime.now() - rf1_compiled.predict(X1, n_jobs=2) - t_double = (datetime.now() - start).microseconds - - # ensure almost linear speedup, 0.5 = liear - assert_greater(target, t_double / t_single) # Parallel samples + if OPENMP_SUPPORT: + # On travis/appveyor check for any speedup Be less generous otherwise. + if 'TRAVIS' in os.environ or 'APPVEYOR' in os.environ: + target = 0.9 + else: + target = 0.6 + # multi sample scaling - parallel samples + start = datetime.now() + rf1_compiled.predict(X1, n_jobs=1) + t_single = (datetime.now() - start).microseconds + + start = datetime.now() + rf1_compiled.predict(X1, n_jobs=2) + t_double = (datetime.now() - start).microseconds + + # ensure almost linear speedup, 0.5 = liear + assert_greater(target, t_double / t_single) # Parallel samples def test_predictions_with_invalid_input(self): num_features = 100