8000 MAINT: Fix OpenMP runtime error on mac (#13294) · scikit-learn/scikit-learn@ffd27c8 · GitHub
[go: up one dir, main page]

Skip to content

Commit ffd27c8

Browse files
jeremiedbbglemaitre
authored andcommitted
MAINT: Fix OpenMP runtime error on mac (#13294)
1 parent 798e1df commit ffd27c8

File tree

3 files changed

+12
-6
lines changed

3 files changed

+12
-6
lines changed

build_tools/azure/install.sh

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,6 @@ if [[ "$UNAMESTR" == "Darwin" ]]; then
1616
export CXXFLAGS="$CXXFLAGS -I/usr/local/opt/libomp/include"
1717
export LDFLAGS="$LDFLAGS -L/usr/local/opt/libomp/lib -lomp"
1818
export DYLD_LIBRARY_PATH=/usr/local/opt/libomp/lib
19-
20-
# avoid error due to multiple OpenMP libraries loaded simultaneously
21-
export KMP_DUPLICATE_LIB_OK=TRUE
2219
fi
2320

2421
make_conda() {

build_tools/travis/install.sh

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,6 @@ then
3838
export CXXFLAGS="$CXXFLAGS -I/usr/local/opt/libomp/include"
3939
export LDFLAGS="$LDFLAGS -L/usr/local/opt/libomp/lib -lomp"
4040
export DYLD_LIBRARY_PATH=/usr/local/opt/libomp/lib
41-
42-
# avoid error due to multiple OpenMP libraries loaded simultaneously
43-
export KMP_DUPLICATE_LIB_OK=TRUE
4441
fi
4542

4643
make_conda() {

sklearn/__init__.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import re
1717
import warnings
1818
import logging
19+
import os
1920

2021
from ._config import get_config, set_config, config_context
2122

@@ -47,6 +48,17 @@
4748
__version__ = '0.21.dev0'
4849

4950

51+
# On OSX, we can get a runtime error due to multiple OpenMP libraries loaded
52+
# simultaneously. This can happen for instance when calling BLAS inside a
53+
# prange. Setting the following environment variable allows multiple OpenMP
54+
# libraries to be loaded. It should not degrade performances since we manually
55+
# take care of potential over-subcription performance issues, in sections of
56+
# the code where nested OpenMP loops can happen, by dynamically reconfiguring
57+
# the inner OpenMP runtime to temporarily disable it while under the scope of
58+
# the outer OpenMP parallel section.
59+
os.environ.setdefault("KMP_DUPLICATE_LIB_OK", "True")
60+
61+
5062
try:
5163
# This variable is injected in the __builtins__ by the build
5264
# process. It is used to enable importing subpackages of sklearn when

0 commit comments

Comments
 (0)
0