Added a TBB_configuration class

This commit is contained in:
Clement Jamin 2013-01-22 17:21:03 +01:00
parent 7049ff02b2
commit ea37e2083e
3 changed files with 84 additions and 18 deletions

View File

@ -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 <tbb/tbb.h>
#include <tbb/task_scheduler_init.h>
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

View File

@ -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 <tbb/tbb.h>
# include <CGAL/tbb.h>
# include <tbb/compat/thread>
# 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;

View File

@ -56,6 +56,7 @@
#endif
#ifdef CGAL_LINKED_WITH_TBB
# include <CGAL/tbb.h>
# include <tbb/mutex.h>
# include <tbb/task.h>
#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