Skip to content

Commit af6abe9

Browse files
committed
PKG: Suppress error for double initialisation of OpenMP
1 parent 34c0d3a commit af6abe9

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

src/sparse_dot_topn/__init__.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,24 @@
11
# Copyright (c) 2023 ING Analytics Wholesale Banking
22
import importlib.metadata
3+
import os
4+
5+
# Setting the following environment variable allows multiple OpenMP
6+
# libraries to be loaded. This is also used without issue by Scikit-learn.
7+
# OpenMP error msg:
8+
# /* OMP: Error #15: Initializing libomp.dylib, but found libomp.dylib already initialized.
9+
# * OMP: Hint This means that multiple copies of the OpenMP runtime have been linked into the program.
10+
# * That is dangerous, since it can degrade performance or cause incorrect results.
11+
# * The best thing to do is to ensure that only a single OpenMP runtime is linked into the process,
12+
# * e.g. by avoiding static linking of the OpenMP runtime in any library.
13+
# * As an unsafe, unsupported, undocumented workaround you can set the environment variable KMP_DUPLICATE_LIB_OK=TRUE
14+
# * to allow the program to continue to execute, but that may cause crashes or silently produce incorrect results.
15+
# * For more information, please see http://openmp.llvm.org/
16+
# */
17+
os.environ.setdefault("KMP_DUPLICATE_LIB_OK", "True")
18+
19+
# Workaround issue discovered in intel-openmp 2019.5:
20+
# https://github.com/ContinuumIO/anaconda-issues/issues/11294
21+
os.environ.setdefault("KMP_INIT_AT_FORK", "FALSE")
322

423
__version__ = importlib.metadata.version("sparse_dot_topn")
524
from sparse_dot_topn.api import awesome_cossim_topn, sp_matmul, sp_matmul_topn, zip_sp_matmul_topn

0 commit comments

Comments
 (0)