diff --git a/Installation/include/CGAL/tbb.h b/Installation/include/CGAL/tbb.h new file mode 100644 index 00000000000..331879f0738 --- /dev/null +++ b/Installation/include/CGAL/tbb.h @@ -0,0 +1,76 @@ +// Copyright (c) 2013 +// INRIA Sophia-Antipolis (France). All rights reserved. +// +// This file is part of CGAL (www.cgal.org); you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public License as +// published by the Free Software Foundation; either version 3 of the License, +// or (at your option) any later version. +// +// Licensees holding a valid commercial license may use this file in +// accordance with the commercial license agreement provided with the software. +// +// This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE +// WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. +// +// $URL$ +// $Id$ +// +// +// Author(s) : Clement Jamin + +#ifndef CGAL_TBB_H +#define CGAL_TBB_H + +#ifdef CGAL_LINKED_WITH_TBB + +#include +#include + +namespace CGAL { + +/*! +\ingroup Installation + +\brief The class TBB_configuration provides control over TBB. +*/ +class TBB_configuration +{ +public: + /*! + \brief Set the maximum number of threads that TBB may create. + \details If max_num_threads <= 0, TBB will decide the number of threads, + which is typically the number of hardware threads. + */ + static void set_max_number_of_threads(int max_num_threads = -1) + { + static tbb::task_scheduler_init init(tbb::task_scheduler_init::deferred); + + if (init.is_active()) + init.terminate(); + + if (max_num_threads > 0) + init.initialize(max_num_threads); + else + init.initialize(); + } + + /*! + \brief Returns the number of threads TBB scheduler would create if initialized by + default. + \details This number is typically the number of hardware threads (logical + processors). + */ + static int get_default_number_of_threads() + { + return tbb::task_scheduler_init::default_num_threads(); + } + +protected: + // We don't want this class to be instantiated by an user + TBB_configuration() {} +}; + +} //namespace CGAL + +#endif // CGAL_LINKED_WITH_TBB +#endif // CGAL_TBB_H diff --git a/Mesh_3/benchmark/Mesh_3/concurrency.cpp b/Mesh_3/benchmark/Mesh_3/concurrency.cpp index 7c428ec28be..9447116dcd1 100644 --- a/Mesh_3/benchmark/Mesh_3/concurrency.cpp +++ b/Mesh_3/benchmark/Mesh_3/concurrency.cpp @@ -96,13 +96,13 @@ const int TET_SHAPE = 3; // Concurrency config // ========================================================================== -#ifdef WINVER +# ifdef WINVER const char * const CONFIG_FILENAME = "D:/INRIA/CGAL/workingcopy/Mesh_3/demo/Mesh_3/concurrent_mesher_config.cfg"; -#else +# else const char * const CONFIG_FILENAME = "/home/cjamin/CGAL/Mesh_3-parallel-cjamin/Mesh_3/demo/Mesh_3/concurrent_mesher_config.cfg"; -#endif +# endif //# define CGAL_MESH_3_ACTIVATE_GRID_INDEX_CACHE_IN_VERTEX // DOES NOT WORK YET @@ -141,8 +141,7 @@ const int TET_SHAPE = 3; // ========================================================================== // TBB // ========================================================================== - -# include +# include # include # ifndef _DEBUG // Use TBB malloc proxy (for all new/delete/malloc/free calls) @@ -928,13 +927,7 @@ int main() #ifdef CONCURRENT_MESH_3 Concurrent_mesher_config::load_config_file(CONFIG_FILENAME, true); - - tbb::task_scheduler_init init(tbb::task_scheduler_init::deferred); - if (num_threads > 0) - init.initialize(num_threads); - else - init.initialize(); - + CGAL::TBB_configuration::set_max_number_of_threads(num_threads); #endif std::ifstream script_file; @@ -956,11 +949,7 @@ int main() #endif { #ifdef CONCURRENT_MESH_3 - init.terminate(); - if (num_threads > 0) - init.initialize(num_threads); - else - init.initialize(); + CGAL::TBB_configuration::set_max_number_of_threads(num_threads); #endif std::cerr << "Script file '" << BENCHMARK_SCRIPT_FILENAME << "' found." << std::endl; diff --git a/Mesh_3/include/CGAL/Mesh_3/Sliver_perturber.h b/Mesh_3/include/CGAL/Mesh_3/Sliver_perturber.h index 15a487d9f52..621b04abd8f 100644 --- a/Mesh_3/include/CGAL/Mesh_3/Sliver_perturber.h +++ b/Mesh_3/include/CGAL/Mesh_3/Sliver_perturber.h @@ -56,6 +56,7 @@ #endif #ifdef CGAL_LINKED_WITH_TBB +# include # include # include #endif @@ -362,7 +363,7 @@ protected: , m_worksharing_ds(bbox) { //CJTODO TEST - //static tbb::task_scheduler_init init(1); + //CGAL::TBB_configuration::set_max_number_of_threads(1); } LockDataStructureType *get_lock_data_structure() const