Skip to content

Commit

Permalink
Create task arena on stack
Browse files Browse the repository at this point in the history
  • Loading branch information
avolkov-intel committed Nov 19, 2024
1 parent a25cb07 commit 119652d
Showing 1 changed file with 16 additions and 13 deletions.
29 changes: 16 additions & 13 deletions cpp/daal/src/threading/threading.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -268,19 +268,22 @@ DAAL_EXPORT void _daal_static_threader_for(size_t n, const void * a, daal::funct
const size_t nthreads = _daal_threader_get_max_threads();
const size_t nblocks_per_thread = n / nthreads + !!(n % nthreads);

tbb::parallel_for(
tbb::blocked_range<size_t>(0, nthreads, 1),
[&](tbb::blocked_range<size_t> r) {
const size_t tid = r.begin();
const size_t begin = tid * nblocks_per_thread;
const size_t end = n < begin + nblocks_per_thread ? n : begin + nblocks_per_thread;

for (size_t i = begin; i < end; ++i)
{
func(i, tid, a);
}
},
tbb::static_partitioner());
tbb::task_arena tmp_arena(nthreads);
tmp_arena.execute([&] {
tbb::parallel_for(
tbb::blocked_range<size_t>(0, nthreads, 1),
[&](tbb::blocked_range<size_t> r) {
const size_t tid = r.begin();
const size_t begin = tid * nblocks_per_thread;
const size_t end = n < begin + nblocks_per_thread ? n : begin + nblocks_per_thread;

for (size_t i = begin; i < end; ++i)
{
func(i, tid, a);
}
},
tbb::static_partitioner());
});
}
else
{
Expand Down

0 comments on commit 119652d

Please sign in to comment.