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[j] = 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.



