Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TBB: Possible to get Thread IDs?

Tags:

c++

tbb

I have a very simple parallel_for loop

    tbb::parallel_for(tbb::blocked_range<int>(0, values.size()),
    [&](tbb::blocked_range<int> r)
    {
        for (int i = r.begin(); i < r.end(); ++i)
        {
            values[i] = std::sin(i * 0.001);
        }
    });

Where 'values' is a vector of doubles. What I'd like to know is which threads work on which range in the loop. Is it possible to get a thread ID of some kind from TBB?

like image 323
easythrees Avatar asked Dec 24 '19 02:12

easythrees


1 Answers

Also, if you want to know a relative number of worker thread in current task_arena, which goes from 0 to the arena concurrency level, use this:

int worker_index = tbb::task_arena::current_thread_index();

The range of index values can be contiguous if all the threads will get to work at the same time.

like image 163
Anton Avatar answered Sep 20 '22 10:09

Anton