Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Thread-safe triangulation library

I'm writing a C++ software which needs fast Minkowski sum computations. An implementation based on double suffices.

I evaluated some geometric libraries such as

  • CGAL
  • LEDA
  • boost::geometry (doesn't have the Minkowski sum implementation, but there is a tutorial explaining how to implement it)

but I ended up using another third-party library which is very fast compared to the previous ones and which uses the FIST library for triangulation.

My code works more or less in the following way:

  • I read my polygons
  • I compute the Minkowski sums I need
  • For n times
    • I decide which polygons to use in the following computation
    • I do some stuff based on the Minkowski sums
    • I give a value to the result
  • I take the result with the best value as the final result

Since the computations within the loop are independent from round to round, I parallelized the loop and everything worked fine.

Then I decided to move the Minkowski sum computation in each parallel round:

  • I read my polygons
  • For number_of_threads(=n) times
    • I decide which polygons to use in the following computation
    • I compute the Minkowski sums I need in this round
    • I do some stuff based on the Minkowski sums
    • I give a value to the result
  • I take the result with the best value as the final result

but the third-party library worked no more.

I get number_of_threads - 1 error messages saying

Assertion Failed.

The files causing the assertion failure change from run to run and from thread to thread, but they all are c-files having same name as the FIST headers (while I have the source code of the third-party library, I have only a .lib and the headers of the FIST library)

As stated before, I tried to compute all the Minkowski sums I need outside the parallelized code and use the results within it. This was ok. So I'm almost sure that the problems come from FIST.

I have two questions:

  • Do you know if the FIST library is thread safe?

  • If not, could you please suggest me a thread-safe (C or, better,) C++ triangulation library to replace FIST (possibly with comparable performances)?

edit:

Actually, I don't know if "thread-safe" is exactly what I want: I only need a tringulation library able to compute many independent triangulations at the same time.

I think that if the library had not global variables and if it had a class without static variables

class triangulation
{
    // no static variables

    void execute_triangulation();
}

it could be enough. So I could use different instances of that class and run in parallel their method.

like image 764
888 Avatar asked Jan 24 '13 08:01

888


2 Answers

You can probably use the 2D triangulation package of CGAL to replace FIST, and then use it as the input of that third-party library that does Minskowski sums. The CGAL triangulations are very fast, and reliable. You can triangulate polygons and complex shapes using constrained Delaunay triangulation.

By the way, which Minkowsky library do you use?

like image 61
lrineau Avatar answered Sep 21 '22 02:09

lrineau


One possible and immediately testable solution is to place a mutex around the code that invokes the Minkowski calculations. If that sounds interesting and you don't know how to do it, add a comment detailing the platform you're using and I, or someone else, will outline how to do it.

At the very least, that will show you whether you have correctly identified the problem. If the calculations form a small part of your total bandwidth, then it may turn out to be a good solution - otherwise just a step on the road.

like image 35
FatalFlaw Avatar answered Sep 17 '22 02:09

FatalFlaw