Skip to Content.
Sympa Menu

cgal-discuss - Re: [cgal-discuss] BUG: Multi-threaded Delaunay_Triangulation_2 crashing...

Subject: CGAL users discussion list

List archive

Re: [cgal-discuss] BUG: Multi-threaded Delaunay_Triangulation_2 crashing...


Chronological Thread 
  • From: Marc Glisse <>
  • To:
  • Subject: Re: [cgal-discuss] BUG: Multi-threaded Delaunay_Triangulation_2 crashing...
  • Date: Mon, 12 Dec 2011 22:10:42 +0100 (CET)

On Mon, 12 Dec 2011, Jan Rüegg wrote:

I tried using a Delaunay_Triangulation_2 in a multithreaded environment. I'm
using arch linux, 64-bit, and CGAL 3.9-2, boost 1.48.0-2

My code is something like this:

---------------------------------------------------------------------------------------

#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include <CGAL/Delaunay_triangulation_2.h>
#include <CGAL/Triangulation_vertex_base_with_info_2.h>
#include <CGAL/Triangulation_face_base_with_info_2.h>

typedef CGAL::Triangulation_vertex_base_with_info_2<voronoi_data, K> Vb;
typedef CGAL::Triangulation_face_base_with_info_2<face_data, K> Fb;
typedef CGAL::Triangulation_data_structure_2<Vb, Fb> Tds;
typedef CGAL::Delaunay_triangulation_2<K, Tds> Triangulation;

...

void GetColor(Triangulation *t, ...) {
...
Vertex new_v = t->insert(current_point);
t->remove(new_v);
...
}

...

void main() {

#pragma omp parallel for
// Reconstruct image
for (int y = 0; y < height_; y++) {
for (int x = 0; x < width_; x++) {
GetColor(&(ts_[omp_get_thread_num()]), ...);
}
}

...
}

---------------------------------------------------------------------------------------

Here, ts_ is a vector of "Triangulation", where each triangulation is
independently set up. That means, each thread has its OWN cgal objects!

When I run this, I get a segmentation fault. However, using:
#pragma omp critical
t->remove(new_v);

instead, makes it work! That means, the remove function must do something
that is not thread-safe, though every thread operates on its own
triangulation...

The code for remove (I haven't checked whether it is really this version that is called, but the others are likely similar) contains:

static int maxd=30;
static std::vector<Face_handle> f(maxd);
static std::vector<int> i(maxd);
static std::vector<Vertex_handle> w(maxd);

which is obviously not thread-safe if you work on several triangulations of the same type. Does removing enough "static" help? I guess it probably slows down the code a bit.

One possible trick to work around it is to derive a number of types from K, use them to define artificially different triangulation types, and make sure each thread uses its own type. Not so nice...

--
Marc Glisse



Archive powered by MHonArc 2.6.16.

Top of Page