Intel® oneAPI Threading Building Blocks
Ask questions and share information about adding parallelism to your applications when using this threading library.
Announcements
This community is designed for sharing of public information. Please do not share Intel or third-party confidential information here.
2421 Discussions

per-thread data persisting through parallel task asignment

Brian_Budge
Beginner
160 Views
Hi all -

I hope someone can help me with this issue. I'm using the tbb::task library to perform a parallel post-order traversal. The problem I'm facing is that I need to generate random numbers as part of my traversal process. I already have a class to perform the calculations (SFMT derived), and I've used it in threaded programming before. The problem is that when using tbb::task, there is no access to a per-thread memory (at least not that I've found). Any ideas?

Thanks!
0 Kudos
4 Replies
Brian_Budge
Beginner
160 Views
I think what would be ideal for me from a performance standpoint would be to have an array of N (N is # running threads) SFMT states which can be referenced in the task. Then if I could get a thread index during traversal, I could use the appropriate SFMT state for that thread. Can this be done?
Alexey_K_Intel3
Employee
160 Views
Quoting - Brian Budge
Hi all -

I hope someone can help me with this issue. I'm using the tbb::task library to perform a parallel post-order traversal. The problem I'm facing is that I need to generate random numbers as part of my traversal process. I already have a class to perform the calculations (SFMT derived), and I've used it in threaded programming before. The problem is that when using tbb::task, there is no access to a per-thread memory (at least not that I've found). Any ideas?

Thanks!

Look at enumerable_thread_specific and combinable classes in TBB 2.2; they are designed to help in cases like yours.
Brian_Budge
Beginner
160 Views
Thanks for the answer Alexey. In the past when I've used tls with boost threads, the overhead was very large. Should I expect much overhead when using the enumerable tls data in tbb?
Bartlomiej
New Contributor I
160 Views
Quoting - Brian Budge
Thanks for the answer Alexey. In the past when I've used tls with boost threads, the overhead was very large. Should I expect much overhead when using the enumerable tls data in tbb?

I did only one program with enumerable_thread_specific, up to now, but there was no noticable difference with respect to compiler-specific API for the TLS. technically there must be some overhead, but it seems negligible.
Reply