5 #ifndef OPENCV_CORE_PARALLEL_FOR_TBB_HPP
6 #define OPENCV_CORE_PARALLEL_FOR_TBB_HPP
8 #include "opencv2/core/parallel/parallel_backend.hpp"
9 #include <opencv2/core/utils/logger.hpp>
11 #ifndef TBB_SUPPRESS_DEPRECATED_MESSAGES
12 #define TBB_SUPPRESS_DEPRECATED_MESSAGES 1
15 #if !defined(TBB_INTERFACE_VERSION)
16 #error "Unknows/unsupported TBB version"
19 #if TBB_INTERFACE_VERSION >= 8000
20 #include "tbb/task_arena.h"
23 namespace cv {
namespace parallel {
namespace tbb {
25 using namespace ::tbb;
27 #if TBB_INTERFACE_VERSION >= 8000
28 static tbb::task_arena& getArena()
30 static tbb::task_arena tbbArena(tbb::task_arena::automatic);
36 static tbb::task_scheduler_init tbbScheduler(tbb::task_scheduler_init::deferred);
54 CV_LOG_INFO(NULL,
"Initializing TBB parallel backend: TBB_INTERFACE_VERSION=" << TBB_INTERFACE_VERSION);
56 #if TBB_INTERFACE_VERSION >= 8000
68 void*
const callback_data;
72 : callback(callback_), callback_data(callback_data_), tasks(tasks_)
79 this->callback(
range.begin(),
range.end(), callback_data);
84 tbb::parallel_for(tbb::blocked_range<int>(0, tasks), *
this);
91 #if TBB_INTERFACE_VERSION >= 8000
92 getArena().execute(task);
100 #if TBB_INTERFACE_VERSION >= 9100
101 return tbb::this_task_arena::current_thread_index();
102 #elif TBB_INTERFACE_VERSION >= 8000
103 return tbb::task_arena::current_thread_index();
111 #if TBB_INTERFACE_VERSION >= 9100
112 return getArena().max_concurrency();
113 #elif TBB_INTERFACE_VERSION >= 8000
116 : tbb::task_scheduler_init::default_num_threads();
120 : tbb::task_scheduler_init::default_num_threads();
129 #if TBB_INTERFACE_VERSION >= 8000
130 auto& tbbArena = getArena();
131 if (tbbArena.is_active())
132 tbbArena.terminate();
137 if (tbbScheduler.is_active())
138 tbbScheduler.terminate();
142 return oldNumThreads;
Definition: parallel_backend.hpp:57
void(CV_API_CALL * FN_parallel_for_body_cb_t)(int start, int end, void *data)
Definition: parallel_backend.hpp:61
Definition: parallel_for.tbb.hpp:66
void operator()() const
Definition: parallel_for.tbb.hpp:82
CallbackProxy(int tasks_, FN_parallel_for_body_cb_t &callback_, void *callback_data_)
Definition: parallel_for.tbb.hpp:71
void operator()(const tbb::blocked_range< int > &range) const
Definition: parallel_for.tbb.hpp:77
Definition: parallel_for.tbb.hpp:47
virtual int setNumThreads(int nThreads) CV_OVERRIDE
Definition: parallel_for.tbb.hpp:124
virtual int getNumThreads() const CV_OVERRIDE
Definition: parallel_for.tbb.hpp:109
virtual void parallel_for(int tasks, FN_parallel_for_body_cb_t body_callback, void *callback_data) CV_OVERRIDE
Definition: parallel_for.tbb.hpp:88
ParallelForBackend()
Definition: parallel_for.tbb.hpp:52
virtual ~ParallelForBackend()
Definition: parallel_for.tbb.hpp:63
virtual int getThreadNum() const CV_OVERRIDE
Definition: parallel_for.tbb.hpp:98
int numThreads
Definition: parallel_for.tbb.hpp:49
int numThreadsMax
Definition: parallel_for.tbb.hpp:50
const char * getName() const CV_OVERRIDE
Definition: parallel_for.tbb.hpp:145
#define CV_LOG_INFO(tag,...)
Definition: logger.hpp:132
#define CV_OVERRIDE
Definition: cvdef.h:792
CvArr CvSize range
Definition: imgproc_c.h:781
static tbb::task_scheduler_init & getScheduler()
Definition: parallel_for.tbb.hpp:34
"black box" representation of the file storage associated with a file on disk.
Definition: calib3d.hpp:441