Getting core ID during tbb program execution ?

Getting core ID during tbb program execution ?


I would like to build an animation showing the // execution of a TBB kernel. I tought that It would be nice to use different colors in order to identify which core is doing what. For this purpose I would need the ID of the core that executes a given part of my programm (and dump it in an execution log file).

Is it possible in the TBB context ?





7 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.


Thanx !

Sorry, that wasn't entirely the right answer. It will give you the thread id, and, as a task is always fully executed on one specific thread, that may well be enough for your purposes. But it is still different from what you were actually asking.

A thread may migrate across cores at the discretion of the operating system, even during the execution of a task. Knowing the exact core is probably not relevant, although you would be missing out on migration events. On a NUMA processor, the distance between cores might also be relevant.

Core id information is not available from TBB; you will have to consult your operating-system documentation, instead, e.g., on Linux it would be sched_getcpu(). This is for a synchronous query, and by the time the function returns the thread might already have migrated (not likely, but it's always possible). I'm not sure that thread migration notifications are available at all.

Thank you again !

I guess that the cost of the sched_getcpu() function must be much higher than tbb::this_thread::get_id().

I will try.

Counting the thread migration with "perf" tool maybe OK for my purpose.

Is there a specific reason for using core id rather than thread id?

I want to understand the performance of a // algorithm  implemented with the TBBs (and compare this shared memory approach to an MPI implementation). For this purpose, It could be relevant to evaluate the cost of potential thread migrations. If this cost can be neglected, the thread IDs will be just fine.

Leave a Comment

Please sign in to add a comment. Not a member? Join today