- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I have a thread unsafe class, which is rather expensive to initialize.
I'd like to create an array with instances of the class, size of array equal to the number of threads.
ThenI should be able to call methods of thearray elementsfrom a parallel_for cycles safely without any locks if each thread accessed it's own array element.
Unfortunately there appears to be no way to get a thread index.
Is there a way to do this somehow?
I'd like to create an array with instances of the class, size of array equal to the number of threads.
ThenI should be able to call methods of thearray elementsfrom a parallel_for cycles safely without any locks if each thread accessed it's own array element.
Unfortunately there appears to be no way to get a thread index.
Is there a way to do this somehow?
Link Copied
5 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Look at tbb::enumerable_thread_specific and tbb::combinable classes in TBB 2.2. Those were designed to support the paradigm you want to develop using an array and thread indexes.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Indeed. And in this thread:
http://software.intel.com/en-us/forums/showthread.php?t=68135
you can even found an actual code to get the ids.
The second thing is: do you really need it? You've written (possibly I misunderstood you) that you traverse the array by a parallel_for. In this case you need no locks nor thread-affinity; chunks of the array will be distributed under the covers.
http://software.intel.com/en-us/forums/showthread.php?t=68135
you can even found an actual code to get the ids.
The second thing is: do you really need it? You've written (possibly I misunderstood you) that you traverse the array by a parallel_for. In this case you need no locks nor thread-affinity; chunks of the array will be distributed under the covers.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks, Alexey, Bartlomiej. Looks like enumerable_thread_specific is the way to go.
I believe I do. I want to reuse my class instances between chunks. Thus I need a way to make sure concurrently processed chunks access different instances.
Or am I missing something?
Quoting - Bartlomiej
The second thing is: do you really need it? You've written (possibly I misunderstood you) that you traverse the array by a parallel_for. In this case you need no locks nor thread-affinity; chunks of the array will be distributed under the covers.
I believe I do. I want to reuse my class instances between chunks. Thus I need a way to make sure concurrently processed chunks access different instances.
Or am I missing something?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Quoting - avermel
Thanks, Alexey, Bartlomiej. Looks like enumerable_thread_specific is the way to go.
I believe I do. I want to reuse my class instances between chunks. Thus I need a way to make sure concurrently processed chunks access different instances.
Or am I missing something?
I believe I do. I want to reuse my class instances between chunks. Thus I need a way to make sure concurrently processed chunks access different instances.
Or am I missing something?
I might tell something obvious here -pardon me if so :) but don't use ETS for storing thread IDs, instead use it to store your thread-specific class instances directly.
Just guessing - are those instances for some temporaries that are expensive to re-create?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Quoting - Alexey Kukanov (Intel)
I might tell something obvious here -pardon me if so :) but don't use ETS for storing thread IDs, instead use it to store your thread-specific class instances directly.
Quoting - Alexey Kukanov (Intel)
Just guessing - are those instances for some temporaries that are expensive to re-create?
Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page