I'm new to TBB and have the following two questions:
1.Doesomp_get_thread_num( )work in TBB?
2.Is there a routine like omp_get_thread_num( )provided byTBB?
1. No. omp_get_thread_num() is an OpenMP call, may not even be present if the module has not been compiled with the appropriate OpenMP switch
2. Mmmmmm, no. There is a method to this. One of the goals of TBB is minimize as much as possible the programmers need to be concerned about thread scheduling: because in the landscape moving forward, you can't predict how many threads will be available. Letting thread scheduling fall to some automatic process that can adapt makes more sense. That said, you can always hack to get the underlying thread ID (OS dependent), and there has been some talk of providing an initialization function for pool threads for a variety of purposes. You could use this to generate thread local storage and/or assigning an ID.
Are you interested in understanding better the scheduling of threads for your own education, or are you trying to institutionalize a thread ID for some other purpose?
A bit of background: Early drafts of the TBB specification had a way to get a thread ID, but our OpenMP group vehementlyargued to remove it, based on experience with OpenMP programs. So we removed it. The root problem is that omp_get_thread_num is intrinsically tied to the notion of a thread team, an inheritance from flat SPMD (Singe Program Multiple Data) programming.
TBB targets non-flat nested and recursive parallelism, and very dynamic parallelism where the "number of threads" might change while a program runs.
So I'd be interested too in hearing your use case for omp_get_thread_num. We tried in TBB to provide the power to avoid it (e.g., sometimes where it is used in OpenMP can be done more elegantly with parallel_reduce over a user-defined type). But I realize we did not address all use cases, and so your cases would be an important contribution t what gaps we need to cover.