easythrees
easythrees

Reputation: 1650

TBB: Possible to get Thread IDs?

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?

Upvotes: 6

Views: 3402

Answers (2)

Anton
Anton

Reputation: 6537

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.

Upvotes: 10

easythrees
easythrees

Reputation: 1650

Looks like the solution is to use

tbb::this_tbb_thread::get_id()

in tbb_thread.h. See this for more details:

https://software.intel.com/en-us/node/506336

Upvotes: 3

Related Questions