Skip to content

Commit d7af20c

Browse files
lesteveglemaitre
andauthored
MAINT Fix build when SKLEARN_OPENMP_PARALLELISM_ENABLED=False (scikit-learn#24682)
Co-authored-by: Guillaume Lemaitre <[email protected]>
1 parent 6eb4633 commit d7af20c

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

doc/developers/performance.rst

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -341,9 +341,16 @@ memory alignment, direct blas calls...
341341
Using OpenMP
342342
------------
343343

344-
Since scikit-learn can be built without OpenMP, it's necessary to
345-
protect each direct call to OpenMP. This can be done using the following
346-
syntax::
344+
Since scikit-learn can be built without OpenMP, it's necessary to protect each
345+
direct call to OpenMP.
346+
347+
There are some helpers in
348+
[sklearn/utils/_openmp_helpers.pyx](https://github.com/scikit-learn/scikit-learn/blob/main/sklearn/utils/_openmp_helpers.pyx)
349+
that you can reuse for the main useful functionalities and already have the
350+
necessary protection to be built without OpenMP.
351+
352+
If the helpers are not enough, you need to protect your OpenMP code using the
353+
following syntax::
347354

348355
# importing OpenMP
349356
IF SKLEARN_OPENMP_PARALLELISM_ENABLED:

sklearn/metrics/_pairwise_distances_reduction/_base.pyx.tp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
cimport numpy as cnp
2-
cimport openmp
32

43
from cython cimport final
54
from cython.operator cimport dereference as deref
@@ -73,7 +72,8 @@ cpdef DTYPE_t[::1] _sqeuclidean_row_norms32(
7372
)
7473

7574
with nogil, parallel(num_threads=num_threads):
76-
thread_num = openmp.omp_get_thread_num()
75+
thread_num = _openmp_thread_num()
76+
7777
for i in prange(n, schedule='static'):
7878
# Upcasting the i-th row of X from float32 to float64
7979
for j in range(d):

0 commit comments

Comments
 (0)