- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hey,
I'm new in parallel programing but I've got the mission to convert this peace of code (method) from OPENMP to TBB
So far searching in here as well as other places I've done this:
The code is executing and the program is running without errors but I'm wondering if the private variable is implemented right.Thanks.
I'm new in parallel programing but I've got the mission to convert this peace of code (method) from OPENMP to TBB
[cpp]void carMoving() { int j; #pragma omp parallel for private(j) for (int i = 0; i < circleSize; i++) { j = ((i + 1) % circleSize); if (circle == -1 || circle == j) { newCircle= -1; } else { newCircle = circle; newCircle = -1; } } }[/cpp]
So far searching in here as well as other places I've done this:
[cpp]class CarMoving { int m_j; public: CarMoving ():m_j() {}; void operator () ( const tbb::blocked_range& range) const{ for ( int i = range.begin(); i != range.end(); ++i) { int j; j = ((i + 1) % circleSize); if (circle == -1 || circle == j) { newCircle = -1; } else { newCircle = circle; newCircle = -1; } } } }; void carMoving() { CarMoving carmoving; tbb::parallel_for(tbb::blocked_range (0, circleSize), carmoving, tbb::auto_partitioner()); }[/cpp]
The code is executing and the program is running without errors but I'm wondering if the private variable is implemented right.Thanks.
Link Copied
3 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
That seems quite all right (although I would go for "const int j = ((i + 1) % circleSize);").
Being less familiar with OpenMP myself, I wonder if shared/private couldn't be determined simply by the location of the declaration instead, and, if not, why not (maybe that's how it inevitably works in Fortran and the designers had the unfortunate idea to make OpenMP behave exactly alike in both languages)?
Being less familiar with OpenMP myself, I wonder if shared/private couldn't be determined simply by the location of the declaration instead, and, if not, why not (maybe that's how it inevitably works in Fortran and the designers had the unfortunate idea to make OpenMP behave exactly alike in both languages)?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
In the first (omp) example, j was declared outside the scope of the parallel region... but was declared private, thus importing the declaration inside the parallel region.
In the second (tbb) ecample, j was declared inside the parallel region, thus making it private to that region.
BTW, you could have written the omp example with placing int j= ((i+1)%circleSize); inside the parallel region.
Is your code correct? In particular lines 15, and 16.
When the compiler optimizes that loop, the if and its two branches will be replaced with
newCircle = -1;
Jim Dempsey
In the second (tbb) ecample, j was declared inside the parallel region, thus making it private to that region.
BTW, you could have written the omp example with placing int j= ((i+1)%circleSize); inside the parallel region.
Is your code correct? In particular lines 15, and 16.
When the compiler optimizes that loop, the if and its two branches will be replaced with
newCircle
Jim Dempsey
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Yes many thanks my mistake,
else block contains only the first statement (newCircle = circle)
else block contains only the first statement (newCircle
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