Skip to content

Commit

Permalink
FIX: Fix incorrect mapping of thread IDs (#3048)
Browse files Browse the repository at this point in the history
* fix incorrect mapping of thread IDs

* avoid using more threads than system will support

* linter

* linter version14
  • Loading branch information
david-cortes-intel authored Jan 23, 2025
1 parent 5d3d62c commit 96370cc
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions cpp/daal/src/threading/threading.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@
#define TBB_PREVIEW_GLOBAL_CONTROL 1
#define TBB_PREVIEW_TASK_ARENA 1

#include <stdlib.h> // malloc and free
#include <algorithm> // std::min
#include <stdlib.h> // malloc and free
#include <tbb/tbb.h>
#include <tbb/spin_mutex.h>
#include <tbb/scalable_allocator.h>
Expand Down Expand Up @@ -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<size_t>(_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(
Expand Down

0 comments on commit 96370cc

Please sign in to comment.