Intel® oneAPI Threading Building Blocks
Ask questions and share information about adding parallelism to your applications when using this threading library.

Is enumerable_thread_specific reuseable?

cake
Beginner
486 Views

Hi I would like to reuse thread local storage in multiple parallel_for as following:

 

```

tbb::enumerable_thread_specific<T> ParallelT;
tbb::parallel_for(tbb::blocked_range<int>(0, n)), [&](const tbb::blocked_range<int> &r) {
  tbb::enumerable_thread_specific<T>::reference local_T = ParallelT.local();
  for (auto i = r.begin(); i < r.end(); i++) {
     /// local_T changed and stored
  });
}
 
// Then I do some work, and try to reuse the ParallelT via iterating them.
tbb::parallel_for_each( ParallelT.begin(), ParallelT.end(), [&](...) {
  // Question: do I still get the thread local storage in this parallel_for_each?
}
});
```
 
As shown, I want to reuse my built TLS in another parallel_for_each. Do I get the TLS correctly without calling `.local` function? Is here a parallel_for_each or a parallel_for a correct behavior to reuse the TLS?
0 Kudos
3 Replies
SeshaP_Intel
Moderator
434 Views

Hi,


Thank you for posting in Intel Communities.


The Class enumerable_thread_specific(ETS) provides thread local storage that acts like an STL container with one element per thread.

You can get the thread local storage in the tbb::parallel_for_each block. You can use another reference and call the .local() function in tbb::parallel_for_each block.

You can refer to the OneTBB Pro Textbook, page no:165.


Thanks and Regards,

Pendyala Sesha Srinivas


0 Kudos
SeshaP_Intel
Moderator
411 Views

Hi,


Has the information provided above helped? If yes, could you please confirm whether we can close this thread from our end?


Thanks and Regards,

Pendyala Sesha Srinivas


0 Kudos
SeshaP_Intel
Moderator
373 Views

Hi,


We assume that your issue is resolved. If you need any additional information, please post a new question as this thread will no longer be monitored by Intel.


Thanks and Regards,

Pendyala Sesha Srinivas


0 Kudos
Reply