Use this forum to discuss the book: Using OpenMP - Portable Shared Memory Parallel Programming, by Barbara Chapman, Gabriele Jost and Ruud van der Pas Read the viewtopic.php?f=8&t=465
for book info and to download the examples. Post your feedback about the book and examples to this forum
I am having problem(segmentation fault) with the following code snippet:
- Code: Select all
//create a pointer to the hitpoint
//loop over all the pixels in the image
#pragma omp parallel for schedule(dynamic,1), private(hitPoint)
for(int y = 0; y < height; ++y)
for(int x = 0; x < width; ++x)
hitPoint = traceAndCreateHitPoint(x,y);
//store the hit point inside the vector
#pragma omp critical
// Print progress approximately every 5%.
if ((y+1) % (height/20) == 0 || (y+1) == height)
std::cout << (100*(y+1)/height) << "% done" << std::endl;
Is there any issue that need to be resolved when using openmp with STL. If i comment the STL command , the code runs fine.
- Posts: 5
- Joined: Fri Jan 28, 2011 3:16 pm
None of the STL containers are guaranteed safe to access using multiple threads in this way. You need to make sure only one thread at a time calls push_back(): putting the call in a critical section should work, though this may not be the most optimal solution.
- Posts: 428
- Joined: Thu Jan 08, 2009 10:12 am
Return to Using OpenMP - The Book and Examples
Who is online
Users browsing this forum: No registered users and 1 guest