diff --git a/cpp/daal/src/threading/threading.cpp b/cpp/daal/src/threading/threading.cpp index 3b280229ee7..5f82f1b6a42 100644 --- a/cpp/daal/src/threading/threading.cpp +++ b/cpp/daal/src/threading/threading.cpp @@ -28,7 +28,8 @@ #define TBB_PREVIEW_GLOBAL_CONTROL 1 #define TBB_PREVIEW_TASK_ARENA 1 -#include // malloc and free +#include // std::min +#include // malloc and free #include #include #include @@ -263,9 +264,9 @@ DAAL_EXPORT int64_t _daal_parallel_reduce_int32ptr_int64_simple(const int32_t * DAAL_EXPORT void _daal_static_threader_for(size_t n, const void * a, daal::functype_static func) { - if (daal::threader_env()->getNumberOfThreads() > 1) + const size_t nthreads = std::min(daal::threader_env()->getNumberOfThreads(), static_cast(_daal_threader_get_max_threads())); + if (nthreads > 1) { - const size_t nthreads = _daal_threader_get_max_threads(); const size_t nblocks_per_thread = n / nthreads + !!(n % nthreads); tbb::parallel_for(