19 #ifndef LIBMESH_THREADS_TBB_H 20 #define LIBMESH_THREADS_TBB_H 24 #ifndef LIBMESH_SQUASH_HEADER_WARNING 25 # warning "This file is designed to be included through libmesh/threads.h" 28 #ifdef LIBMESH_HAVE_TBB_API 32 #ifdef LIBMESH_HAVE_ONETBB 40 #include "libmesh/ignore_warnings.h" 43 #ifdef LIBMESH_HAVE_ONETBB 46 # include "tbb/version.h" 47 # include "tbb/global_control.h" 50 # include "tbb/tbb_stddef.h" 51 # include "tbb/task_scheduler_init.h" 52 # include "tbb/atomic.h" 53 # include "tbb/tbb_thread.h" 54 # include "tbb/recursive_mutex.h" 58 #include "tbb/blocked_range.h" 59 #include "tbb/parallel_for.h" 60 #include "tbb/parallel_reduce.h" 61 #include "tbb/partitioner.h" 62 #include "tbb/spin_mutex.h" 63 #include "tbb/enumerable_thread_specific.h" 64 #include "tbb/task_arena.h" 66 #include "libmesh/restore_warnings.h" 68 #define TBB_VERSION_LESS_THAN(major,minor) \ 69 ((LIBMESH_DETECTED_TBB_VERSION_MAJOR < (major) || \ 70 (LIBMESH_DETECTED_TBB_VERSION_MAJOR == (major) && (LIBMESH_DETECTED_TBB_VERSION_MINOR < (minor)))) ? 1 : 0) 73 #define LIBMESH_TLS_TYPE(type) tbb::enumerable_thread_specific<type> 74 #define LIBMESH_TLS_REF(value) (value).local() 88 #ifndef LIBMESH_HAVE_ONETBB 89 typedef tbb::tbb_thread
Thread;
91 typedef std::thread
Thread;
101 #ifndef LIBMESH_HAVE_ONETBB 112 _gc = std::make_unique<tbb::global_control>(
113 tbb::global_control::max_allowed_parallelism,
114 static_cast<std::size_t
>(n));
120 _gc = std::make_unique<tbb::global_control>(
121 tbb::global_control::max_allowed_parallelism,
122 static_cast<std::size_t
>(n));
128 std::unique_ptr<tbb::global_control>
_gc;
130 #endif // LIBMESH_HAVE_ONETBB 142 template <
typename Range,
typename Body>
144 void parallel_for (
const Range & range,
const Body & body,
148 "Requested n_threads (" <<
n_threads <<
") exceeds the " 161 tbb::task_arena arena(static_cast<int>(
n_threads));
175 template <
typename Range,
typename Body,
typename Partitioner>
181 "Requested n_threads (" <<
n_threads <<
") exceeds the " 189 DisablePerfLogInScope disable_perf;
194 tbb::task_arena arena(static_cast<int>(
n_threads));
208 template <
typename Range,
typename Body>
214 "Requested n_threads (" <<
n_threads <<
") exceeds the " 222 DisablePerfLogInScope disable_perf;
227 tbb::task_arena arena(static_cast<int>(
n_threads));
241 template <
typename Range,
typename Body,
typename Partitioner>
243 void parallel_reduce (
const Range & range, Body & body,
const Partitioner & partitioner,
247 "Requested n_threads (" <<
n_threads <<
") exceeds the " 255 DisablePerfLogInScope disable_perf;
260 tbb::task_arena arena(static_cast<int>(
n_threads));
286 #ifndef LIBMESH_HAVE_ONETBB 312 #endif // LIBMESH_HAVE_ONETBB 322 #ifndef LIBMESH_HAVE_ONETBB 323 template <
typename T>
324 class atomic :
public tbb::atomic<T> {};
326 template <
typename T>
327 class atomic :
public std::atomic<T>
332 #endif // LIBMESH_HAVE_ONETBB 338 #endif // LIBMESH_HAVE_TBB_API 340 #endif // LIBMESH_SQUASH_HEADER_WARNING 342 #endif // LIBMESH_THREADS_TBB_H void parallel_for(const Range &range, const Body &body, unsigned int n_threads=libMesh::n_threads())
Execute the provided function object in parallel on the specified range.
void acquire(recursive_mutex &rm)
We use a class to turn Threads::in_threads on and off, to be exception-safe.
task_scheduler_init(int n=automatic)
The libMesh namespace provides an interface to certain functionality in the library.
std::unique_ptr< tbb::global_control > _gc
bool in_threads
A boolean which is true iff we are in a Threads:: function It may be useful to assert(!Threadsin_thre...
We use a class to turn perf logging off and on within threads, to be exception-safe and to avoid forc...
void initialize(int n=automatic)
The Partitioner class provides a uniform interface for partitioning algorithms.
tbb::task_scheduler_init task_scheduler_init
Scheduler to manage the TBB thread pool.
void parallel_reduce(const Range &range, Body &body, unsigned int n_threads=libMesh::n_threads())
Execute the provided reduction operation in parallel on the specified range.
tbb::spin_mutex spin_mutex
Spin mutex.
tbb::split split
Dummy "splitting object" used to distinguish splitting constructors from copy constructors.
Defines atomic operations which can only be executed on a single thread at a time.
scoped_lock(recursive_mutex &rm)
int active_threads
An integer which is set to the number of active threads when we are in a Threads:: parallel operation...
RAIIAcquire< bool, true, true > BoolAcquire
static const int automatic
void acquire(recursive_mutex &)
Scheduler to manage threads.
tbb::recursive_mutex recursive_mutex
Recursive mutex.
NonConcurrentThread Thread
Use the non-concurrent placeholder.