mirror of https://github.com/CGAL/cgal
make static variable in remove thread_safe.
I choose this solution since making the container global variable of the class penalize classes that do not use remove functions. The overhead introduced is small (less than 2-3% of the total remove time).
This commit is contained in:
parent
894b8c36d5
commit
59b50cc467
|
|
@ -4171,6 +4171,7 @@ Testsuite/test/Testsuite/cgal_test_with_cmake eol=lf
|
|||
Testsuite/test/collect_cgal_testresults_from_cmake -text
|
||||
Testsuite/test/makefile2 -text
|
||||
Testsuite/test/run_testsuite_with_cmake -text
|
||||
Triangulation_2/benchmark/Triangulation_2/Delaunay_remove.cpp -text
|
||||
Triangulation_2/demo/Triangulation_2/qt3/help/cindex.html svneol=native#text/html
|
||||
Triangulation_2/demo/Triangulation_2/qt3/help/cinput_point_layer.gif -text svneol=unset#image/gif
|
||||
Triangulation_2/demo/Triangulation_2/qt3/help/conflict_zone.gif -text svneol=unset#image/gif
|
||||
|
|
|
|||
|
|
@ -26,6 +26,7 @@ if ( CGAL_FOUND )
|
|||
include_directories (BEFORE ../../../../experimental-packages/Triangulation_2-unrecursive/include)
|
||||
|
||||
create_single_source_cgal_program( "Triangulation_benchmark_2.cpp" )
|
||||
create_single_source_cgal_program( "Delaunay_remove.cpp" )
|
||||
|
||||
else()
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,52 @@
|
|||
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
|
||||
#include <CGAL/Delaunay_triangulation_2.h>
|
||||
#include <CGAL/Timer.h>
|
||||
#include <CGAL/point_generators_2.h>
|
||||
|
||||
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
typedef CGAL::Exact_predicates_inexact_constructions_kernel K;
|
||||
typedef CGAL::Delaunay_triangulation_2<K> Delaunay;
|
||||
typedef K::Point_2 Point;
|
||||
typedef CGAL::Creator_uniform_2<double,Point> Creator;
|
||||
|
||||
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
int n=1000000;
|
||||
int rep=100;
|
||||
if (argc>=2)
|
||||
n=atoi(argv[1]);
|
||||
if (argc>=3)
|
||||
rep=atoi(argv[2]);
|
||||
std::vector<Point> points;
|
||||
points.reserve(n);
|
||||
CGAL::Random_points_in_disc_2<Point,Creator> g(1);
|
||||
CGAL::copy_n( g, n, std::back_inserter(points));
|
||||
Delaunay original;
|
||||
original.insert(points.begin(),points.end());
|
||||
|
||||
double res=0;
|
||||
for (int r=0;r<rep;++r){
|
||||
Delaunay delaunay=original;
|
||||
CGAL::Timer t;
|
||||
t.start();
|
||||
for (int k=0;k<n;++k)
|
||||
delaunay.remove(delaunay.finite_vertices_begin());
|
||||
t.stop();
|
||||
res+=t.time();
|
||||
if (delaunay.number_of_vertices()!=0){
|
||||
std::cerr << "ERROR"<< std::endl;
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
std::cout << res/rep << std::endl;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -917,10 +917,27 @@ remove_and_give_new_faces(Vertex_handle v, OutputItFaces fit)
|
|||
afi++) *fit++ = afi;
|
||||
}
|
||||
else {
|
||||
#ifdef CGAL_HAS_THREADS
|
||||
static boost::thread_specific_ptr< int > maxd_ptr;
|
||||
static boost::thread_specific_ptr< std::vector<Face_handle> > f_ptr;
|
||||
static boost::thread_specific_ptr< std::vector<int> > i_ptr;
|
||||
static boost::thread_specific_ptr< std::vector<Vertex_handle> > w_ptr;
|
||||
if (maxd_ptr.get() == NULL) {
|
||||
maxd_ptr.reset(new int(30));
|
||||
f_ptr.reset(new std::vector<Face_handle>(*maxd_ptr));
|
||||
i_ptr.reset(new std::vector<int>(*maxd_ptr));
|
||||
w_ptr.reset(new std::vector<Vertex_handle>(*maxd_ptr));
|
||||
}
|
||||
int& maxd=*maxd_ptr;
|
||||
std::vector<Face_handle>& f=*f_ptr;
|
||||
std::vector<int>& i=*i_ptr;
|
||||
std::vector<Vertex_handle>& w=*w_ptr;
|
||||
#else
|
||||
static int maxd=30;
|
||||
static std::vector<Face_handle> f(maxd);
|
||||
static std::vector<int> i(maxd);
|
||||
static std::vector<Vertex_handle> w(maxd);
|
||||
#endif
|
||||
int d;
|
||||
remove_degree_init(v,f,w,i,d,maxd);
|
||||
remove_degree_triangulate(v,f,w,i,d);
|
||||
|
|
@ -944,10 +961,27 @@ remove(Vertex_handle v)
|
|||
|
||||
if ( this->dimension() <= 1) { Triangulation::remove(v); return; }
|
||||
|
||||
#ifdef CGAL_HAS_THREADS
|
||||
static boost::thread_specific_ptr< int > maxd_ptr;
|
||||
static boost::thread_specific_ptr< std::vector<Face_handle> > f_ptr;
|
||||
static boost::thread_specific_ptr< std::vector<int> > i_ptr;
|
||||
static boost::thread_specific_ptr< std::vector<Vertex_handle> > w_ptr;
|
||||
if (maxd_ptr.get() == NULL) {
|
||||
maxd_ptr.reset(new int(30));
|
||||
f_ptr.reset(new std::vector<Face_handle>(*maxd_ptr));
|
||||
i_ptr.reset(new std::vector<int>(*maxd_ptr));
|
||||
w_ptr.reset(new std::vector<Vertex_handle>(*maxd_ptr));
|
||||
}
|
||||
int& maxd=*maxd_ptr;
|
||||
std::vector<Face_handle>& f=*f_ptr;
|
||||
std::vector<int>& i=*i_ptr;
|
||||
std::vector<Vertex_handle>& w=*w_ptr;
|
||||
#else
|
||||
static int maxd=30;
|
||||
static std::vector<Face_handle> f(maxd);
|
||||
static std::vector<int> i(maxd);
|
||||
static std::vector<Vertex_handle> w(maxd);
|
||||
#endif
|
||||
remove_degree_init(v,f,w,i,d,maxd);
|
||||
if (d == 0) return; // dim is going down
|
||||
remove_degree_triangulate(v,f,w,i,d);
|
||||
|
|
@ -2090,10 +2124,27 @@ move_if_no_collision(Vertex_handle v, const Point &p) {
|
|||
|
||||
{
|
||||
int d;
|
||||
#ifdef CGAL_HAS_THREADS
|
||||
static boost::thread_specific_ptr< int > maxd_ptr;
|
||||
static boost::thread_specific_ptr< std::vector<Face_handle> > f_ptr;
|
||||
static boost::thread_specific_ptr< std::vector<int> > i_ptr;
|
||||
static boost::thread_specific_ptr< std::vector<Vertex_handle> > w_ptr;
|
||||
if (maxd_ptr.get() == NULL) {
|
||||
maxd_ptr.reset(new int(30));
|
||||
f_ptr.reset(new std::vector<Face_handle>(*maxd_ptr));
|
||||
i_ptr.reset(new std::vector<int>(*maxd_ptr));
|
||||
w_ptr.reset(new std::vector<Vertex_handle>(*maxd_ptr));
|
||||
}
|
||||
int& maxd=*maxd_ptr;
|
||||
std::vector<Face_handle>& f=*f_ptr;
|
||||
std::vector<int>& i=*i_ptr;
|
||||
std::vector<Vertex_handle>& w=*w_ptr;
|
||||
#else
|
||||
static int maxd=30;
|
||||
static std::vector<Face_handle> f(maxd);
|
||||
static std::vector<int> i(maxd);
|
||||
static std::vector<Vertex_handle> w(maxd);
|
||||
#endif
|
||||
remove_degree_init(v,f,w,i,d,maxd);
|
||||
remove_degree_triangulate(v,f,w,i,d);
|
||||
}
|
||||
|
|
@ -2308,10 +2359,27 @@ move_if_no_collision_and_give_new_faces(Vertex_handle v,
|
|||
|
||||
|
||||
{
|
||||
#ifdef CGAL_HAS_THREADS
|
||||
static boost::thread_specific_ptr< int > maxd_ptr;
|
||||
static boost::thread_specific_ptr< std::vector<Face_handle> > f_ptr;
|
||||
static boost::thread_specific_ptr< std::vector<int> > i_ptr;
|
||||
static boost::thread_specific_ptr< std::vector<Vertex_handle> > w_ptr;
|
||||
if (maxd_ptr.get() == NULL) {
|
||||
maxd_ptr.reset(new int(30));
|
||||
f_ptr.reset(new std::vector<Face_handle>(*maxd_ptr));
|
||||
i_ptr.reset(new std::vector<int>(*maxd_ptr));
|
||||
w_ptr.reset(new std::vector<Vertex_handle>(*maxd_ptr));
|
||||
}
|
||||
int& maxd=*maxd_ptr;
|
||||
std::vector<Face_handle>& f=*f_ptr;
|
||||
std::vector<int>& i=*i_ptr;
|
||||
std::vector<Vertex_handle>& w=*w_ptr;
|
||||
#else
|
||||
static int maxd=30;
|
||||
static std::vector<Face_handle> f(maxd);
|
||||
static std::vector<int> i(maxd);
|
||||
static std::vector<Vertex_handle> w(maxd);
|
||||
#endif
|
||||
int d;
|
||||
remove_degree_init(v,f,w,i,d,maxd);
|
||||
remove_degree_triangulate(v,f,w,i,d);
|
||||
|
|
|
|||
Loading…
Reference in New Issue