0

I am wondering how I can parallelise for loop below in a secure way. I found some possible solution like this . However I am limited to use OpenMP version 2.0 and Boost version 1.59.

algorithm explanation:

It iterates over all of my triangles which lie within the bounding box, then it checks possibility of the intersection (with a unique triangle) in _considerTriangle function. Finally in the _considerTriangle, if a triangle is intersected it inserts triangle to a set container intersectedTri.

//Iterating through every triangle
std::set<Triangle> intersectedTri;
for(IntersectedTrianglesIterator it=tree.Begin_IteratorByBoundingBox(bbox_min,bbox_max);it!=tree.End_IteratorByBoundingBox(bbox_min,bbox_max);++it)
            _ConsiderTriangle(it->GetTriangle());

I am wonderying how I can paralllise it safely.

Community
  • 1
  • 1
H'H
  • 1,638
  • 1
  • 15
  • 39
  • You have to provide more information about your code. It is completely unclear what the underlying data structures are (`tree`), how expensive certain operations are (`IntersectedTrianglesIterator::operator++` vs `_ConsiderTriangle`, `GetTriangel`), what state is modified during an iteration, whether `IntersectedTrianglesIterator` is a random access iterator, .... Pleas provide an [mcve]. – Zulan Oct 21 '16 at 15:15
  • BTW: OpenMP 2.0 is more than **14 years** old. Do you seriously have no newer version available? – Zulan Oct 21 '16 at 15:18
  • I use Visual Studio, and as you now even VS2015 wont support any newer version of the openMP. – H'H Oct 21 '16 at 15:29

1 Answers1

0

You can use any method, as long as you synchronize the insertion into intersectedTri.

// globals
boost::mutex mut;

// inside func
boost::mutex::scoped_lock lock(mut);
intersectedTri.insert(tri);
Sven Nilsson
  • 1,861
  • 10
  • 11