_openmp_helpers.pxd 1.0 KB

123456789101112131415161718192021222324252627282930313233
  1. # Helpers to safely access OpenMP routines
  2. #
  3. # no-op implementations are provided for the case where OpenMP is not available.
  4. #
  5. # All calls to OpenMP routines should be cimported from this module.
  6. cdef extern from *:
  7. """
  8. #ifdef _OPENMP
  9. #include <omp.h>
  10. #define SKLEARN_OPENMP_PARALLELISM_ENABLED 1
  11. #else
  12. #define SKLEARN_OPENMP_PARALLELISM_ENABLED 0
  13. #define omp_lock_t int
  14. #define omp_init_lock(l) (void)0
  15. #define omp_destroy_lock(l) (void)0
  16. #define omp_set_lock(l) (void)0
  17. #define omp_unset_lock(l) (void)0
  18. #define omp_get_thread_num() 0
  19. #define omp_get_max_threads() 1
  20. #endif
  21. """
  22. bint SKLEARN_OPENMP_PARALLELISM_ENABLED
  23. ctypedef struct omp_lock_t:
  24. pass
  25. void omp_init_lock(omp_lock_t*) noexcept nogil
  26. void omp_destroy_lock(omp_lock_t*) noexcept nogil
  27. void omp_set_lock(omp_lock_t*) noexcept nogil
  28. void omp_unset_lock(omp_lock_t*) noexcept nogil
  29. int omp_get_thread_num() noexcept nogil
  30. int omp_get_max_threads() noexcept nogil