- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Greetings,
I am using TBB 4.0 on Windows (VS 2010), and trying to to parallel a loop using parallel_for. However, I encountered a local variable initialization problem.
class getIteratorArrayBody
{
//some other private variable declarition
int *rOffsetArray;
public:
getIteratorArrayBody(..., int * r):rOffsetArray{}
void operator()( const tbb::blocked_range& range ) const
{
size_t iterator; // thread local variable
for (size_t j=range.begin(); j!=range.end(); j++)
{// code to do some calculation
iterator= ....
rOffsetArray = iterator;
}
...
}
............
int * IndexingEngine:: getIteratorArrayInParallel (..., tbb::affinity_partitioner &affinity)
{
int *rOffsetArray = new unsigned int [100000];
tbb::parallel_for( tbb::blocked_range( 0, vLBASpaceLength ), // Index space for loop
getIteratorArrayBody (...,rOffsetArray), // Body of loop
affinity ); // Affinity hint
returnrOffsetArray;
}
For the above code, if I specify number of threads to 1, then no problem to execute.However if I specify number of threads to 64, then it reports "The variable 'iterator' is being used without being initialized"
From this, it seems this problem is caused by conflict between threads. I did try some other methods to initialize it, however all failed.
Any suggestion to resovle this initizalition problem is very appreciated!!
Nai Yan.
Link Copied
- « Previous
-
- 1
- 2
- Next »
21 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I certainly agree, and most likely this causes all observed problematic sympthoms.Even if file processingroutines are "thread-safe" internally so that only one thread can work with the givenfile at any moment, the interleaving described by Raf remains quite possible.
Protect reading a page from the file with a lock, and check whether it solves your problems.
Protect reading a page from the file with a lock, and check whether it solves your problems.
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
- « Previous
-
- 1
- 2
- Next »