diff --git a/Classification/include/CGAL/Classification/Feature_set.h b/Classification/include/CGAL/Classification/Feature_set.h index b234f380fdb..e225649cf84 100644 --- a/Classification/include/CGAL/Classification/Feature_set.h +++ b/Classification/include/CGAL/Classification/Feature_set.h @@ -19,7 +19,7 @@ #include #ifdef CGAL_LINKED_WITH_TBB -#include +#include #include #endif // CGAL_LINKED_WITH_TBB diff --git a/Classification/include/CGAL/Classification/Local_eigen_analysis.h b/Classification/include/CGAL/Classification/Local_eigen_analysis.h index b3849220d54..ad3b83c0eef 100644 --- a/Classification/include/CGAL/Classification/Local_eigen_analysis.h +++ b/Classification/include/CGAL/Classification/Local_eigen_analysis.h @@ -34,7 +34,8 @@ #include #include #include -#include +#include + #endif // CGAL_LINKED_WITH_TBB namespace CGAL { @@ -69,7 +70,7 @@ private: PointMap m_point_map; const NeighborQuery& m_neighbor_query; float& m_mean_range; - tbb::mutex& m_mutex; + std::mutex& m_mutex; public: @@ -78,7 +79,7 @@ private: PointMap point_map, const NeighborQuery& neighbor_query, float& mean_range, - tbb::mutex& mutex) + std::mutex& mutex) : m_eigen (eigen), m_input (input), m_point_map (point_map), m_neighbor_query (neighbor_query), m_mean_range (mean_range), m_mutex (mutex) { } @@ -120,7 +121,7 @@ private: const FaceListGraph& m_input; const NeighborQuery& m_neighbor_query; float& m_mean_range; - tbb::mutex& m_mutex; + std::mutex& m_mutex; public: @@ -128,7 +129,7 @@ private: const FaceListGraph& input, const NeighborQuery& neighbor_query, float& mean_range, - tbb::mutex& mutex) + std::mutex& mutex) : m_eigen (eigen), m_input (input), m_neighbor_query (neighbor_query), m_mean_range (mean_range), m_mutex (mutex) { } @@ -271,7 +272,7 @@ public: #else if (boost::is_convertible::value) { - tbb::mutex mutex; + std::mutex mutex; Compute_eigen_values f(out, input, point_map, neighbor_query, out.m_content->mean_range, mutex); tbb::parallel_for(tbb::blocked_range(0, input.size ()), f); @@ -361,7 +362,7 @@ public: #else if (boost::is_convertible::value) { - tbb::mutex mutex; + std::mutex mutex; Compute_eigen_values_graph f(out, input, neighbor_query, out.m_content->mean_range, mutex); diff --git a/Classification/include/CGAL/Classification/Mesh_feature_generator.h b/Classification/include/CGAL/Classification/Mesh_feature_generator.h index 5b90b74b379..d9baf699327 100644 --- a/Classification/include/CGAL/Classification/Mesh_feature_generator.h +++ b/Classification/include/CGAL/Classification/Mesh_feature_generator.h @@ -45,7 +45,7 @@ #ifdef CGAL_LINKED_WITH_TBB #include -#include +#include #endif // CGAL_LINKED_WITH_TBB namespace CGAL { diff --git a/Classification/include/CGAL/Classification/Sum_of_weighted_features_classifier.h b/Classification/include/CGAL/Classification/Sum_of_weighted_features_classifier.h index 5b7dc929185..4f17b7da445 100644 --- a/Classification/include/CGAL/Classification/Sum_of_weighted_features_classifier.h +++ b/Classification/include/CGAL/Classification/Sum_of_weighted_features_classifier.h @@ -33,7 +33,7 @@ #include #include #include -#include +#include #endif // CGAL_LINKED_WITH_TBB #define CLASSIFICATION_TRAINING_QUICK_ESTIMATION @@ -72,9 +72,9 @@ private: std::vector& m_true_positives; std::vector& m_false_positives; std::vector& m_false_negatives; - std::vector& m_tp_mutex; - std::vector& m_fp_mutex; - std::vector& m_fn_mutex; + std::vector& m_tp_mutex; + std::vector& m_fp_mutex; + std::vector& m_fn_mutex; public: @@ -85,9 +85,9 @@ private: std::vector& true_positives, std::vector& false_positives, std::vector& false_negatives, - std::vector& tp_mutex, - std::vector& fp_mutex, - std::vector& fn_mutex) + std::vector& tp_mutex, + std::vector& fp_mutex, + std::vector& fn_mutex) : m_training_set (training_set) , m_classifier (classifier) , m_label (label) @@ -901,9 +901,9 @@ private: #else if (boost::is_convertible::value) { - std::vector tp_mutex (m_labels.size()); - std::vector fp_mutex (m_labels.size()); - std::vector fn_mutex (m_labels.size()); + std::vector tp_mutex (m_labels.size()); + std::vector fp_mutex (m_labels.size()); + std::vector fn_mutex (m_labels.size()); Compute_iou f(training_sets[j], *this, j, true_positives, false_positives, false_negatives, tp_mutex, fp_mutex, fn_mutex); diff --git a/Classification/include/CGAL/Classification/classify.h b/Classification/include/CGAL/Classification/classify.h index 6fb787a43df..28ec87f5fdb 100644 --- a/Classification/include/CGAL/Classification/classify.h +++ b/Classification/include/CGAL/Classification/classify.h @@ -24,7 +24,7 @@ #include #include #include -#include +#include #endif // CGAL_LINKED_WITH_TBB namespace CGAL { diff --git a/Mesh_3/include/CGAL/Compact_mesh_cell_base_3.h b/Mesh_3/include/CGAL/Compact_mesh_cell_base_3.h index 077de31abcf..af4041ed3df 100644 --- a/Mesh_3/include/CGAL/Compact_mesh_cell_base_3.h +++ b/Mesh_3/include/CGAL/Compact_mesh_cell_base_3.h @@ -34,7 +34,7 @@ #ifdef CGAL_LINKED_WITH_TBB -# include +# include #endif namespace CGAL { @@ -152,7 +152,8 @@ public: { CGAL_precondition(facet>=0 && facet<4); char current_bits = bits_; - while (bits_.compare_and_swap(current_bits | char(1 << facet), current_bits) != current_bits) + + while (!bits_.compare_exchange_weak(current_bits, current_bits | char(1 << facet))) { current_bits = bits_; } @@ -165,7 +166,7 @@ public: char current_bits = bits_; char mask = char(15 & ~(1 << facet)); char wanted_value = current_bits & mask; - while (bits_.compare_and_swap(wanted_value, current_bits) != current_bits) + while (!bits_.compare_exchange_weak(current_bits, wanted_value)) { current_bits = bits_; } @@ -182,18 +183,19 @@ public: /// this function "deletes" cc void try_to_set_circumcenter(Point_3 *cc) const { - if (weighted_circumcenter_.compare_and_swap(cc, nullptr) != nullptr) + Point_3* base_test = nullptr; + if (!weighted_circumcenter_.compare_exchange_strong(base_test, cc)) delete cc; } private: - typedef tbb::atomic Erase_counter_type; + typedef std::atomic Erase_counter_type; Erase_counter_type m_erase_counter; /// Stores visited facets (4 first bits) - tbb::atomic bits_; + std::atomic bits_; protected: - mutable tbb::atomic weighted_circumcenter_; + mutable std::atomic weighted_circumcenter_; }; #endif // CGAL_LINKED_WITH_TBB diff --git a/Mesh_3/include/CGAL/Mesh_3/C3T3_helpers.h b/Mesh_3/include/CGAL/Mesh_3/C3T3_helpers.h index 3f4421ed3e9..b899ad8eeff 100644 --- a/Mesh_3/include/CGAL/Mesh_3/C3T3_helpers.h +++ b/Mesh_3/include/CGAL/Mesh_3/C3T3_helpers.h @@ -47,7 +47,7 @@ #ifdef CGAL_LINKED_WITH_TBB # include -# include +# include #endif #include @@ -595,7 +595,7 @@ public: protected: Lock_data_structure *m_lock_ds; - typedef tbb::mutex Mutex_type; + typedef std::mutex Mutex_type; mutable Mutex_type m_mut_outdated_cells; mutable Mutex_type m_mut_moving_vertices; mutable Mutex_type m_mut_vertex_to_proj; diff --git a/Mesh_3/include/CGAL/Mesh_3/Mesh_complex_3_in_triangulation_3_base.h b/Mesh_3/include/CGAL/Mesh_3/Mesh_complex_3_in_triangulation_3_base.h index e621c87d4b1..fc1e3e0763d 100644 --- a/Mesh_3/include/CGAL/Mesh_3/Mesh_complex_3_in_triangulation_3_base.h +++ b/Mesh_3/include/CGAL/Mesh_3/Mesh_complex_3_in_triangulation_3_base.h @@ -41,7 +41,7 @@ #ifdef CGAL_LINKED_WITH_TBB - #include + #include #include namespace CGAL { @@ -174,7 +174,7 @@ public: , manifold_info_initialized_(false) //TODO: parallel! { // We don't put it in the initialization list because - // tbb::atomic has no contructors + // std::atomic has no contructors number_of_facets_ = 0; number_of_cells_ = 0; } @@ -186,8 +186,9 @@ public: , edge_facet_counter_(rhs.edge_facet_counter_) , manifold_info_initialized_(rhs.manifold_info_initialized_) { - number_of_facets_ = rhs.number_of_facets_; - number_of_cells_ = rhs.number_of_cells_; + Init_number_of_elements init; + init(number_of_facets_, rhs.number_of_facets_); + init(number_of_cells_, rhs.number_of_cells_); } /// Destructor @@ -505,9 +506,10 @@ public: /// Swaps this & rhs void swap(Self& rhs) { - std::swap(rhs.number_of_facets_, number_of_facets_); + Swap_elements swapper; + swapper(rhs.number_of_facets_, number_of_facets_); tr_.swap(rhs.tr_); - std::swap(rhs.number_of_cells_, number_of_cells_); + swapper(rhs.number_of_cells_, number_of_cells_); } /// Returns bbox @@ -850,12 +852,55 @@ private: { typedef size_type type; }; + + template + struct Init_number_of_elements + { + template + void operator()(T& a, const T& b) + { + a = b; + } + }; + + template + struct Swap_elements + { + template + void operator()(T& a, T& b) + { + std::swap(a, b); + } + }; #ifdef CGAL_LINKED_WITH_TBB // Parallel: atomic template struct Number_of_elements { - typedef tbb::atomic type; + typedef std::atomic type; + }; + + template + struct Init_number_of_elements + { + template + void operator()(T& a, const T& b) + { + a = b.load(); + } + }; + + template + struct Swap_elements + { + template + void operator()(T& a, T& b) + { + T tmp; + tmp.exchange(a); + a.exchange(b); + b.exchange(tmp); + } }; #endif // CGAL_LINKED_WITH_TBB diff --git a/Mesh_3/include/CGAL/Mesh_3/Mesh_global_optimizer.h b/Mesh_3/include/CGAL/Mesh_3/Mesh_global_optimizer.h index 0e4145b26f7..a058ff1dd90 100644 --- a/Mesh_3/include/CGAL/Mesh_3/Mesh_global_optimizer.h +++ b/Mesh_3/include/CGAL/Mesh_3/Mesh_global_optimizer.h @@ -47,7 +47,8 @@ #include #ifdef CGAL_LINKED_WITH_TBB -# include +# include +# include # include # include #endif @@ -122,7 +123,7 @@ protected: typedef typename Tr::Lock_data_structure Lock_data_structure; typedef tbb::concurrent_vector > Moves_vector; - typedef tbb::atomic Nb_frozen_points_type ; + typedef std::atomic Nb_frozen_points_type ; Mesh_global_optimizer_base(const Bbox_3 &bbox, int num_grid_cells_per_axis) : big_moves_size_(0) @@ -136,7 +137,7 @@ protected: { if (++big_moves_current_size_ <= big_moves_size_ ) { - tbb::mutex::scoped_lock lock(m_big_moves_mutex); + std::lock_guard lock(m_big_moves_mutex); typename std::multiset::const_iterator it = big_moves_.insert(new_sq_move); // New smallest move of all big moves? @@ -149,7 +150,7 @@ protected: if( new_sq_move > big_moves_smallest_ ) { - tbb::mutex::scoped_lock lock(m_big_moves_mutex); + std::lock_guard lock(m_big_moves_mutex); // Test it again since it may have been modified by another // thread in the meantime if( new_sq_move > big_moves_smallest_ ) @@ -185,11 +186,11 @@ protected: public: protected: - tbb::atomic big_moves_current_size_; - tbb::atomic big_moves_smallest_; + std::atomic big_moves_current_size_; + std::atomic big_moves_smallest_; std::size_t big_moves_size_; std::multiset big_moves_; - tbb::mutex m_big_moves_mutex; + std::mutex m_big_moves_mutex; /// Lock data structure Lock_data_structure m_lock_ds; diff --git a/Mesh_3/include/CGAL/Mesh_3/Mesh_surface_cell_base_3.h b/Mesh_3/include/CGAL/Mesh_3/Mesh_surface_cell_base_3.h index e95510e101c..40b492c1467 100644 --- a/Mesh_3/include/CGAL/Mesh_3/Mesh_surface_cell_base_3.h +++ b/Mesh_3/include/CGAL/Mesh_3/Mesh_surface_cell_base_3.h @@ -27,7 +27,7 @@ #include #ifdef CGAL_LINKED_WITH_TBB -# include +# include #endif #ifdef _MSC_VER @@ -123,7 +123,7 @@ public: protected: /// Stores visited facets (4 first bits) - tbb::atomic bits_; + std::atomic bits_; }; #endif // CGAL_LINKED_WITH_TBB diff --git a/Mesh_3/include/CGAL/Mesh_3/Mesher_3.h b/Mesh_3/include/CGAL/Mesh_3/Mesher_3.h index e58a21ff397..479a1a51023 100644 --- a/Mesh_3/include/CGAL/Mesh_3/Mesher_3.h +++ b/Mesh_3/include/CGAL/Mesh_3/Mesher_3.h @@ -50,7 +50,7 @@ #endif #ifdef CGAL_LINKED_WITH_TBB -# include +# include #endif #include @@ -659,7 +659,7 @@ initialize() # endif Random_points_on_sphere_3 random_point(radius); const int NUM_PSEUDO_INFINITE_VERTICES = static_cast( - float(tbb::task_scheduler_init::default_num_threads()) + float(std::thread::hardware_concurrency()) * Concurrent_mesher_config::get().num_pseudo_infinite_vertices_per_core); for (int i = 0 ; i < NUM_PSEUDO_INFINITE_VERTICES ; ++i, ++random_point) r_c3t3_.add_far_point(r_c3t3_.triangulation().geom_traits().construct_weighted_point_3_object() diff --git a/Mesh_3/include/CGAL/Mesh_3/Worksharing_data_structures.h b/Mesh_3/include/CGAL/Mesh_3/Worksharing_data_structures.h index 8abc76f5a03..32b5816c83c 100644 --- a/Mesh_3/include/CGAL/Mesh_3/Worksharing_data_structures.h +++ b/Mesh_3/include/CGAL/Mesh_3/Worksharing_data_structures.h @@ -28,7 +28,7 @@ #include #include -#include +#include #include @@ -65,8 +65,8 @@ public: m_num_cells = num_grid_cells_per_axis*num_grid_cells_per_axis*num_grid_cells_per_axis; - m_occupation_grid = new tbb::atomic[m_num_cells]; - m_num_batches_grid = new tbb::atomic[m_num_cells]; + m_occupation_grid = new std::atomic[m_num_cells]; + m_num_batches_grid = new std::atomic[m_num_cells]; // Initialize grid for (int i = 0 ; i < m_num_cells ; ++i) { @@ -106,15 +106,15 @@ public: void add_batch(int cell_index, int to_add) { - m_num_batches_grid[cell_index].fetch_and_add(to_add); + m_num_batches_grid[cell_index].fetch_add(to_add); } void add_occupation(int cell_index, int to_add, int) { - m_occupation_grid[cell_index].fetch_and_add(to_add); + m_occupation_grid[cell_index].fetch_add(to_add); /*int new_occupation = - (m_occupation_grid[cell_index].fetch_and_add(to_add)) + (m_occupation_grid[cell_index].fetch_add(to_add)) + to_add; //m_num_batches_grid[cell_index] = num_items_in_work_queue; @@ -221,7 +221,7 @@ public: // Rotate - static tbb::atomic last_cell_index; + static std::atomic last_cell_index; //std::cerr << "last=" << last_cell_index << std::endl; int i = (last_cell_index + 1) % m_num_cells; for ( ; i != last_cell_index ; i = (i + 1) % m_num_cells) @@ -246,11 +246,11 @@ protected: int m_num_grid_cells_per_axis; int m_num_cells; - tbb::atomic * m_occupation_grid; - tbb::atomic * m_num_batches_grid; + std::atomic * m_occupation_grid; + std::atomic * m_num_batches_grid; - tbb::atomic m_laziest_cell_index; - tbb::atomic m_laziest_cell_occupation; + std::atomic m_laziest_cell_index; + std::atomic m_laziest_cell_occupation; }; @@ -504,7 +504,7 @@ public: { m_tls_work_buffers = new TLS_WorkBuffer[m_num_cells]; m_work_batches = new tbb::concurrent_queue[m_num_cells]; - m_num_batches = new tbb::atomic[m_num_cells]; + m_num_batches = new std::atomic[m_num_cells]; for (int i = 0 ; i < m_num_cells ; ++i) m_num_batches[i] = 0; @@ -673,7 +673,7 @@ protected: Work_statistics m_stats; TLS_WorkBuffer *m_tls_work_buffers; tbb::concurrent_queue *m_work_batches; - tbb::atomic *m_num_batches; + std::atomic *m_num_batches; }; @@ -822,7 +822,7 @@ protected: } const size_t NUM_WORK_ITEMS_PER_BATCH; - tbb::atomic m_cache_number_of_tasks; + std::atomic m_cache_number_of_tasks; TLS_WorkBuffer m_tls_work_buffers; }; diff --git a/Mesh_3/include/CGAL/Mesh_3/vertex_perturbation.h b/Mesh_3/include/CGAL/Mesh_3/vertex_perturbation.h index 82bafa3f43b..603fd7626b1 100644 --- a/Mesh_3/include/CGAL/Mesh_3/vertex_perturbation.h +++ b/Mesh_3/include/CGAL/Mesh_3/vertex_perturbation.h @@ -29,7 +29,7 @@ #include #ifdef CGAL_LINKED_WITH_TBB #include - #include + #include #endif #endif @@ -192,7 +192,7 @@ public: #endif { #ifdef CGAL_MESH_3_PERTURBER_VERBOSE - // Initialized here in case it's some tbb::atomic + // Initialized here in case it's some std::atomic total_counter_ = 0; total_time_ = 0; #endif @@ -353,8 +353,8 @@ private: mutable int counter_; #ifdef CGAL_LINKED_WITH_TBB mutable tbb::enumerable_thread_specific timer_; - tbb::atomic total_counter_; - tbb::atomic total_time_; + std::atomic total_counter_; + std::atomic total_time_; #else mutable CGAL::Timer timer_; int total_counter_; diff --git a/Mesh_3/include/CGAL/Mesh_cell_base_3.h b/Mesh_3/include/CGAL/Mesh_cell_base_3.h index 75e85ea869d..379bd4c6c54 100644 --- a/Mesh_3/include/CGAL/Mesh_cell_base_3.h +++ b/Mesh_3/include/CGAL/Mesh_cell_base_3.h @@ -33,7 +33,7 @@ #include #ifdef CGAL_LINKED_WITH_TBB -# include +# include #endif namespace CGAL { @@ -87,7 +87,7 @@ public: } protected: - typedef tbb::atomic Erase_counter_type; + typedef std::atomic Erase_counter_type; Erase_counter_type m_erase_counter; }; #endif // CGAL_LINKED_WITH_TBB diff --git a/Mesh_3/test/Mesh_3/CMakeLists.txt b/Mesh_3/test/Mesh_3/CMakeLists.txt index 03f021a7172..90d9e5e949e 100644 --- a/Mesh_3/test/Mesh_3/CMakeLists.txt +++ b/Mesh_3/test/Mesh_3/CMakeLists.txt @@ -73,6 +73,7 @@ if ( CGAL_FOUND ) test_backward_compatibility test_meshing_polyhedron test_meshing_polyhedral_complex + ) if(TBB_FOUND AND TARGET ${target}) CGAL_target_use_TBB(${target}) diff --git a/Mesh_3/test/Mesh_3/test_meshing_3D_gray_image.cpp b/Mesh_3/test/Mesh_3/test_meshing_3D_gray_image.cpp index 0055e50b125..4b232d42d20 100644 --- a/Mesh_3/test/Mesh_3/test_meshing_3D_gray_image.cpp +++ b/Mesh_3/test/Mesh_3/test_meshing_3D_gray_image.cpp @@ -13,7 +13,6 @@ //****************************************************************************** // File Description : //*************************************************************************** - #include "test_meshing_utilities.h" #include #include diff --git a/Mesh_3/test/Mesh_3/test_meshing_determinism.cpp b/Mesh_3/test/Mesh_3/test_meshing_determinism.cpp index e71c56853bd..e184d689e99 100644 --- a/Mesh_3/test/Mesh_3/test_meshing_determinism.cpp +++ b/Mesh_3/test/Mesh_3/test_meshing_determinism.cpp @@ -13,9 +13,9 @@ #include #include #include - #ifdef CGAL_LINKED_WITH_TBB -# include +#define TBB_PREVIEW_GLOBAL_CONTROL 1 +# include #endif // To avoid verbose function and named parameters call @@ -119,7 +119,7 @@ int main(int, char*[]) { test(); #ifdef CGAL_LINKED_WITH_TBB - tbb::task_scheduler_init init(1); + tbb::global_control c(tbb::global_control::max_allowed_parallelism, 1); test(); #endif } diff --git a/Point_set_processing_3/include/CGAL/bilateral_smooth_point_set.h b/Point_set_processing_3/include/CGAL/bilateral_smooth_point_set.h index e80d6a9be52..d69d85d9bf4 100644 --- a/Point_set_processing_3/include/CGAL/bilateral_smooth_point_set.h +++ b/Point_set_processing_3/include/CGAL/bilateral_smooth_point_set.h @@ -38,11 +38,12 @@ #include #ifdef CGAL_LINKED_WITH_TBB + #include #include #include #include -#include +#include #endif // CGAL_LINKED_WITH_TBB // Default allocator: use TBB allocators if available diff --git a/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/distance.h b/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/distance.h index de52cfac3f2..e6681cd3d9d 100644 --- a/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/distance.h +++ b/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/distance.h @@ -34,7 +34,7 @@ #ifdef CGAL_LINKED_WITH_TBB #include #include -#include +#include #endif // CGAL_LINKED_WITH_TBB #include @@ -78,13 +78,13 @@ struct Distance_computation{ const AABB_tree& tree; const PointRange& sample_points; Point_3 initial_hint; - tbb::atomic* distance; + std::atomic* distance; Distance_computation( const AABB_tree& tree, const Point_3& p, const PointRange& sample_points, - tbb::atomic* d) + std::atomic* d) : tree(tree) , sample_points(sample_points) , initial_hint(p) @@ -108,7 +108,8 @@ struct Distance_computation{ double current_value = *distance; while( current_value < hdist ) { - current_value = distance->compare_and_swap(hdist, current_value); + if(distance->compare_exchange_weak(current_value, hdist)) + current_value = hdist; } } }; @@ -129,7 +130,7 @@ double approximate_Hausdorff_distance_impl( #else if (boost::is_convertible::value) { - tbb::atomic distance; + std::atomic distance; distance=0; Distance_computation f(tree, hint, sample_points, &distance); tbb::parallel_for(tbb::blocked_range(0, sample_points.size()), f); diff --git a/Polyhedron/demo/Polyhedron/Plugins/Point_set/Point_set_selection_plugin.cpp b/Polyhedron/demo/Polyhedron/Plugins/Point_set/Point_set_selection_plugin.cpp index ebff326b116..ff0ef0d3f45 100644 --- a/Polyhedron/demo/Polyhedron/Plugins/Point_set/Point_set_selection_plugin.cpp +++ b/Polyhedron/demo/Polyhedron/Plugins/Point_set/Point_set_selection_plugin.cpp @@ -42,7 +42,7 @@ //#undef CGAL_LINKED_WITH_TBB #ifdef CGAL_LINKED_WITH_TBB #include -#include +#include #include #include #endif // CGAL_LINKED_WITH_TBB diff --git a/Polyhedron/demo/Polyhedron/Plugins/Point_set/Point_set_to_mesh_distance_plugin.cpp b/Polyhedron/demo/Polyhedron/Plugins/Point_set/Point_set_to_mesh_distance_plugin.cpp index 797a5ba644a..cc05ec26642 100644 --- a/Polyhedron/demo/Polyhedron/Plugins/Point_set/Point_set_to_mesh_distance_plugin.cpp +++ b/Polyhedron/demo/Polyhedron/Plugins/Point_set/Point_set_to_mesh_distance_plugin.cpp @@ -22,7 +22,7 @@ #ifdef CGAL_LINKED_WITH_TBB #include #include -#include +#include #endif // CGAL_LINKED_WITH_TBB #if defined(CGAL_LINKED_WITH_TBB) @@ -31,13 +31,13 @@ struct Distance_computation{ const AABB_tree& tree; const Point_set & point_set; Point_3 initial_hint; - tbb::atomic* distance; + std::atomic* distance; std::vector& output; Distance_computation(const AABB_tree& tree, const Point_3 p, const Point_set & point_set, - tbb::atomic* d, + std::atomic* d, std::vector& out ) : tree(tree) , point_set(point_set) @@ -96,7 +96,7 @@ double compute_distances(const Mesh& m, } return hdist; #else - tbb::atomic distance; + std::atomic distance; distance.store(0); Distance_computation f(tree, hint, point_set, &distance, out); tbb::parallel_for(tbb::blocked_range(point_set.begin(), point_set.end()), f); diff --git a/STL_Extension/include/CGAL/Spatial_lock_grid_3.h b/STL_Extension/include/CGAL/Spatial_lock_grid_3.h index b5bc64efb4f..467a4abac4e 100644 --- a/STL_Extension/include/CGAL/Spatial_lock_grid_3.h +++ b/STL_Extension/include/CGAL/Spatial_lock_grid_3.h @@ -18,7 +18,7 @@ #include -#include +#include #if TBB_IMPLEMENT_CPP0X # include #else @@ -452,12 +452,12 @@ class Spatial_lock_grid_3 public: // Constructors Spatial_lock_grid_3(const Bbox_3 &bbox, int num_grid_cells_per_axis) - : Base(bbox, num_grid_cells_per_axis) + : Base(bbox, num_grid_cells_per_axis), + m_grid(num_grid_cells_per_axis*num_grid_cells_per_axis*num_grid_cells_per_axis) { int num_cells = num_grid_cells_per_axis*num_grid_cells_per_axis*num_grid_cells_per_axis; - m_grid.resize(num_cells); // Initialize grid (useless?) for (int i = 0 ; i < num_cells ; ++i) m_grid[i] = false; @@ -475,7 +475,8 @@ public: template bool try_lock_cell_impl(int cell_index) { - bool old_value = m_grid[cell_index].compare_and_swap(true, false); + bool v1 = true, v2 = false; + bool old_value = m_grid[cell_index].compare_exchange_strong(v1,v2); if (old_value == false) { get_thread_local_grid()[cell_index] = true; @@ -492,7 +493,7 @@ public: protected: - std::vector > m_grid; + std::vector > m_grid; }; @@ -512,14 +513,14 @@ public: Spatial_lock_grid_3(const Bbox_3 &bbox, int num_grid_cells_per_axis) : Base(bbox, num_grid_cells_per_axis), - m_tls_thread_priorities(init_TLS_thread_priorities) + m_tls_thread_priorities(init_TLS_thread_priorities), + m_grid(num_grid_cells_per_axis*num_grid_cells_per_axis*num_grid_cells_per_axis) { int num_cells = num_grid_cells_per_axis*num_grid_cells_per_axis*num_grid_cells_per_axis; - m_grid.resize(num_cells); // Explicitly initialize the atomics - std::vector >::iterator it = m_grid.begin(); - std::vector >::iterator it_end = m_grid.end(); + std::vector >::iterator it = m_grid.begin(); + std::vector >::iterator it_end = m_grid.end(); for ( ; it != it_end ; ++it) *it = 0; } @@ -542,9 +543,8 @@ public: // NO SPIN if (no_spin) { - unsigned int old_value = - m_grid[cell_index].compare_and_swap(this_thread_priority, 0); - if (old_value == 0) + unsigned int old_value = 0; + if(!m_grid[cell_index].compare_exchange_strong(old_value, this_thread_priority)) { get_thread_local_grid()[cell_index] = true; m_tls_locked_cells.local().push_back(cell_index); @@ -556,9 +556,8 @@ public: { for(;;) { - unsigned int old_value = - m_grid[cell_index].compare_and_swap(this_thread_priority, 0); - if (old_value == 0) + unsigned int old_value =0; + if(m_grid[cell_index].compare_exchange_weak(old_value, this_thread_priority)) { get_thread_local_grid()[cell_index] = true; m_tls_locked_cells.local().push_back(cell_index); @@ -587,7 +586,7 @@ public: private: static unsigned int init_TLS_thread_priorities() { - static tbb::atomic last_id; + static std::atomic last_id; unsigned int id = ++last_id; // Ensure it is > 0 return (1 + id%((std::numeric_limits::max)())); @@ -595,7 +594,7 @@ private: protected: - std::vector > m_grid; + std::vector > m_grid; typedef tbb::enumerable_thread_specific TLS_thread_uint_ids; TLS_thread_uint_ids m_tls_thread_priorities; diff --git a/STL_Extension/include/CGAL/thread.h b/STL_Extension/include/CGAL/thread.h index 148b1b23664..665cc72744c 100644 --- a/STL_Extension/include/CGAL/thread.h +++ b/STL_Extension/include/CGAL/thread.h @@ -34,7 +34,7 @@ # include # if TBB_IMPLEMENT_CPP0X # include -# include +# include # include # define CGAL_USE_TBB_THREADS 1 # else @@ -83,8 +83,8 @@ namespace cpp11 { #if defined(CGAL_NO_ATOMIC) && defined(CGAL_LINKED_WITH_TBB) // If did not defined CGAL::cpp11::atomic, then use - // tbb::atomic as a fallback. - using tbb::atomic; + // std::atomic as a fallback. + using std::atomic; #endif } // cpp11 diff --git a/STL_Extension/test/STL_Extension/test_Concurrent_compact_container.cpp b/STL_Extension/test/STL_Extension/test_Concurrent_compact_container.cpp index 30e7f1106bb..8ec883d5f72 100644 --- a/STL_Extension/test/STL_Extension/test_Concurrent_compact_container.cpp +++ b/STL_Extension/test/STL_Extension/test_Concurrent_compact_container.cpp @@ -25,7 +25,7 @@ int main() # include # include -# include +# include #include @@ -139,12 +139,12 @@ template class Insert_and_erase_in_CCC_functor { typedef std::vector Iterators_vec; - typedef std::vector > Free_elts_vec; + typedef std::vector > Free_elts_vec; public: Insert_and_erase_in_CCC_functor( const Values_vec &values, Cont &cont, Iterators_vec &iterators, - Free_elts_vec &free_elements, tbb::atomic &num_erasures) + Free_elts_vec &free_elements, std::atomic &num_erasures) : m_values(values), m_cont(cont), m_iterators(iterators), m_free_elements(free_elements), m_num_erasures(num_erasures) {} @@ -176,7 +176,7 @@ private: Cont & m_cont; Iterators_vec & m_iterators; Free_elts_vec & m_free_elements; - tbb::atomic & m_num_erasures; + std::atomic & m_num_erasures; }; template < class Cont > @@ -372,14 +372,14 @@ void test(const Cont &) { Cont c12; Vect v12(1000000); - std::vector > free_elements(v12.size()); - for(typename std::vector >::iterator + std::vector > free_elements(v12.size()); + for(typename std::vector >::iterator it = free_elements.begin(), end = free_elements.end(); it != end; ++it) { *it = true; } - tbb::atomic num_erasures; + std::atomic num_erasures; num_erasures = 0; std::vector iterators(v12.size()); tbb::parallel_for( diff --git a/Triangulation_3/include/CGAL/Delaunay_triangulation_3.h b/Triangulation_3/include/CGAL/Delaunay_triangulation_3.h index 28d2b3f086f..70764f7bfa0 100644 --- a/Triangulation_3/include/CGAL/Delaunay_triangulation_3.h +++ b/Triangulation_3/include/CGAL/Delaunay_triangulation_3.h @@ -45,7 +45,7 @@ #ifdef CGAL_LINKED_WITH_TBB # include # include -# include +# include # include # include #endif @@ -289,7 +289,7 @@ private: bbox.zmin() + 0.5*zdelta); Random_points_on_sphere_3 random_point(radius); const int NUM_PSEUDO_INFINITE_VERTICES = static_cast( - tbb::task_scheduler_init::default_num_threads() * 3.5); + std::thread::hardware_concurrency() * 3.5); std::vector points_on_far_sphere; points_on_far_sphere.reserve(NUM_PSEUDO_INFINITE_VERTICES); diff --git a/Triangulation_3/include/CGAL/Regular_triangulation_3.h b/Triangulation_3/include/CGAL/Regular_triangulation_3.h index a4867cf9946..17cabad626a 100644 --- a/Triangulation_3/include/CGAL/Regular_triangulation_3.h +++ b/Triangulation_3/include/CGAL/Regular_triangulation_3.h @@ -32,7 +32,7 @@ #ifdef CGAL_LINKED_WITH_TBB # include # include -# include +# include # include # include #endif @@ -258,7 +258,7 @@ private: bbox.zmin() + 0.5*zdelta); Random_points_on_sphere_3 random_point(radius); const int NUM_PSEUDO_INFINITE_VERTICES = static_cast( - tbb::task_scheduler_init::default_num_threads() * 3.5); + std::thread::hardware_concurrency() * 3.5); typename Gt::Construct_weighted_point_3 cwp = geom_traits().construct_weighted_point_3_object();