Drop the use of the TBB malloc proxy, use TBB allocators manually instead

The TBB's "malloc proxy", which allows to replace all calls to the standard
allocators by calls to the TBB scalable allocator, is not available on MacOS.
Instead, we use the TBB allocators manually, where relevant.
This commit is contained in:
Clement Jamin 2013-06-27 15:29:47 +02:00
parent c8afb5e76a
commit 2dc6c405b8
6 changed files with 34 additions and 50 deletions

View File

@ -45,14 +45,14 @@ namespace po = boost::program_options;
// BENCHMARK GENERAL PARAMETERS
// ==========================================================================
#define BENCHMARK_WITH_1_TO_MAX_THREADS
//#define BENCHMARK_WITH_1_TO_MAX_THREADS
//#define MESH_3_POLYHEDRON_WITH_FEATURES
//#define MESH_3_IMPLICIT_WITH_FEATURES
//#define MESH_3_BENCHMARK_EXPORT_TO_MAYA
//#define MESH_3_BENCHMARK_EXPORT_TO_MESH
//#define MESH_3_BENCHMARK_LLOYD
//#define MESH_3_BENCHMARK_PERTURB
#define MESH_3_BENCHMARK_EXUDE
//#define MESH_3_BENCHMARK_EXUDE
// ==========================================================================
// MESH_3 GENERAL PARAMETERS
@ -129,24 +129,17 @@ const int TET_SHAPE = 3;
// For profiling, etc.
# define CGAL_CONCURRENT_MESH_3_PROFILING
# define CGAL_DEBUG_FORCE_SEQUENTIAL_MESH_REFINEMENT
//# define CGAL_DEBUG_FORCE_SEQUENTIAL_MESH_REFINEMENT
// ==========================================================================
// TBB
// ==========================================================================
#if TBB_IMPLEMENT_CPP0X
# include <tbb/compat/thread>
#else
# include <thread>
#endif
# ifndef _DEBUG
// Use TBB malloc proxy (for all new/delete/malloc/free calls)
// Highly recommended
# include <tbb/tbbmalloc_proxy.h>
# if TBB_IMPLEMENT_CPP0X
# include <tbb/compat/thread>
# else
# include <thread>
# endif
// ==========================================================================
// SEQUENTIAL
// ==========================================================================

View File

@ -1,12 +1,5 @@
#include "config.h"
#ifdef CGAL_LINKED_WITH_TBB
// Use TBB malloc proxy (for all new/delete/malloc/free calls)
// Highly recommended
# include <tbb/tbbmalloc_proxy.h>
#endif
#include "MainWindow.h"
#include <QApplication>
#include <CGAL/Qt/resources.h>

View File

@ -30,6 +30,8 @@
#include <tbb/task.h>
#include <tbb/enumerable_thread_specific.h>
#include <tbb/concurrent_vector.h>
#include <tbb/scalable_allocator.h>
#include <vector>
#ifdef CGAL_MESH_3_TASK_SCHEDULER_SORTED_BATCHES_WITH_MULTISET
@ -269,7 +271,7 @@ class WorkItem
public:
WorkItem() {}
// Derived class defines the actual work.
virtual void run() const = 0;
virtual void run() = 0;
virtual bool less_than(const WorkItem &) const = 0;
};
@ -296,10 +298,10 @@ public:
: m_func(func), m_quality(quality)
{}
void run() const
void run()
{
m_func();
delete this;
tbb::scalable_allocator<MeshRefinementWorkItem<Func, Quality> >().deallocate(this, 1);
}
bool less_than (const WorkItem &other) const
@ -340,10 +342,10 @@ public:
: m_func(func)
{}
void run() const
void run()
{
m_func();
delete this;
tbb::scalable_allocator<SimpleFunctorWorkItem<Func> >().deallocate(this, 1);
}
// Irrelevant here
@ -368,16 +370,16 @@ class WorkBatch
public:
#ifdef CGAL_MESH_3_TASK_SCHEDULER_SORTED_BATCHES_WITH_MULTISET
typedef std::multiset<const WorkItem *, CompareTwoWorkItems> Batch;
typedef std::multiset<WorkItem *, CompareTwoWorkItems> Batch;
#else
typedef std::vector<const WorkItem *> Batch;
typedef std::vector<WorkItem *> Batch;
#endif
typedef Batch::const_iterator BatchConstIterator;
typedef Batch::iterator BatchIterator;
WorkBatch() {}
void add_work_item(const WorkItem *p_item)
void add_work_item(WorkItem *p_item)
{
#ifdef CGAL_MESH_3_TASK_SCHEDULER_SORTED_BATCHES_WITH_MULTISET
m_batch.insert(p_item);
@ -402,8 +404,8 @@ public:
#ifdef CGAL_MESH_3_TASK_SCHEDULER_SORTED_BATCHES_WITH_SORT
std::sort(m_batch.begin(), m_batch.end(), CompareTwoWorkItems());
#endif
BatchConstIterator it = m_batch.begin();
BatchConstIterator it_end = m_batch.end();
BatchIterator it = m_batch.begin();
BatchIterator it_end = m_batch.end();
for ( ; it != it_end ; ++it)
(*it)->run();
}
@ -434,7 +436,7 @@ class WorkItemTask
: public tbb::task
{
public:
WorkItemTask(const WorkItem *pwi)
WorkItemTask(WorkItem *pwi)
: m_pwi(pwi)
{
}
@ -442,7 +444,7 @@ public:
private:
/*override*/inline tbb::task* execute();
const WorkItem *m_pwi;
WorkItem *m_pwi;
};
@ -467,13 +469,15 @@ public:
template <typename Func>
void enqueue_work(Func f, tbb::task &parent_task) const
{
WorkItem *p_item = new SimpleFunctorWorkItem<Func>(f);
//WorkItem *p_item = new SimpleFunctorWorkItem<Func>(f);
WorkItem *p_item = tbb::scalable_allocator<SimpleFunctorWorkItem<Func> >().allocate(1);
new (p_item) SimpleFunctorWorkItem<Func>(f);
enqueue_task(create_task(p_item, parent_task));
}
protected:
WorkItemTask *create_task(const WorkItem *pwi, tbb::task &parent_task) const
WorkItemTask *create_task(WorkItem *pwi, tbb::task &parent_task) const
{
return new(tbb::task::allocate_additional_child_of(parent_task)) WorkItemTask(pwi);
}
@ -769,7 +773,9 @@ public:
template <typename Func, typename Quality>
void enqueue_work(Func f, const Quality &quality, tbb::task &parent_task)
{
WorkItem *p_item = new MeshRefinementWorkItem<Func, Quality>(f, quality);
//WorkItem *p_item = new MeshRefinementWorkItem<Func, Quality>(f, quality);
WorkItem *p_item = tbb::scalable_allocator<MeshRefinementWorkItem<Func, Quality> >().allocate(1);
new (p_item) MeshRefinementWorkItem<Func, Quality>(f, quality);
WorkBatch &workbuffer = m_tls_work_buffers.local();
workbuffer.add_work_item(p_item);
if (workbuffer.size() >= NUM_WORK_ITEMS_PER_BATCH)

View File

@ -27,12 +27,6 @@
// - replace drand48() by CGAL Generators
// - move/document Time_accumulator to CGAL/Profiling_tools (?)
#ifdef CGAL_LINKED_WITH_TBB
// Use TBB malloc proxy (for all new/delete/malloc/free calls)
// Highly recommended
# include <tbb/tbbmalloc_proxy.h>
#endif
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include <CGAL/Exact_predicates_exact_constructions_kernel.h>
#include <CGAL/Bbox_3.h>

View File

@ -23,12 +23,6 @@
#include <CGAL/basic.h>
#ifdef CGAL_LINKED_WITH_TBB
// Use TBB malloc proxy (for all new/delete/malloc/free calls)
// Highly recommended
# include <tbb/tbbmalloc_proxy.h>
#endif
#ifdef CGAL_CONCURRENT_TRIANGULATION_3_PROFILING
# define CGAL_PROFILE
# include <CGAL/Profile_counter.h>

View File

@ -58,6 +58,10 @@
# endif
#endif
#ifdef CGAL_LINKED_WITH_TBB
# include <tbb/scalable_allocator.h>
#endif
#include <boost/foreach.hpp>
#include <boost/type_traits/is_convertible.hpp>
@ -136,7 +140,7 @@ public:
<
boost::is_convertible<Concurrency_tag, Parallel_tag>::value,
Concurrent_compact_container<
Cell, Default, Cell_container_strategy>,
Cell, tbb::scalable_allocator<Cell>, Cell_container_strategy>,
Compact_container<
Cell, Default, Cell_container_strategy>
>::type Cell_range;
@ -153,7 +157,7 @@ public:
<
boost::is_convertible<Concurrency_tag, Parallel_tag>::value,
Concurrent_compact_container<
Vertex, Default, Vertex_container_strategy>,
Vertex, tbb::scalable_allocator<Vertex>, Vertex_container_strategy>,
Compact_container<
Vertex, Default, Vertex_container_strategy>
>::type Vertex_range;