简体   繁体   中英

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

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.

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?

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.

It depends very heavily on what you mean by this:

Since my code is parallelizable I introduced multithreading

You need to be more specific in order to get help. What does it mean "you have introduced multithreading"? For example, none of the libraries you mention have parallel computation of Minkowski sums (or anything else) built in - you will need to parallelize it yourself.

With regard to Minkowski sums, it is possible to use a map-reduce approach: split the input data set into smaller parts, compute Minkowski sum for each in parallel (map) and union the intermediate results as they come in from independent workers (reduce). The requirements for this are a basic thread safety guarantee (which eg CGAL gives you) with read only access to the parameters of the computation.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM