EstervQrCode 2.0.0
Library for qr code manipulation
Loading...
Searching...
No Matches
parallel_for.openmp.hpp
1// This file is part of OpenCV project.
2// It is subject to the license terms in the LICENSE file found in the top-level directory
3// of this distribution and at http://opencv.org/license.html.
4
5#ifndef OPENCV_CORE_PARALLEL_FOR_OPENMP_HPP
6#define OPENCV_CORE_PARALLEL_FOR_OPENMP_HPP
7
8#include "opencv2/core/parallel/parallel_backend.hpp"
9
10#if !defined(_OPENMP) && !defined(OPENCV_SKIP_OPENMP_PRESENSE_CHECK)
11#error "This file must be compiled with enabled OpenMP"
12#endif
13
14#include <omp.h>
15
16namespace cv { namespace parallel { namespace openmp {
17
24{
25protected:
28public:
30 {
31 numThreads = 0;
32 numThreadsMax = omp_get_max_threads();
33 }
34
36
37 virtual void parallel_for(int tasks, FN_parallel_for_body_cb_t body_callback, void* callback_data) CV_OVERRIDE
38 {
39#pragma omp parallel for schedule(dynamic) num_threads(numThreads > 0 ? numThreads : numThreadsMax)
40 for (int i = 0; i < tasks; ++i)
41 body_callback(i, i + 1, callback_data);
42 }
43
44 virtual int getThreadNum() const CV_OVERRIDE
45 {
46 return omp_get_thread_num();
47 }
48
49 virtual int getNumThreads() const CV_OVERRIDE
50 {
51 return numThreads > 0
54 }
55
56 virtual int setNumThreads(int nThreads) CV_OVERRIDE
57 {
58 int oldNumThreads = numThreads;
59 numThreads = nThreads;
60 // nothing needed as numThreads is used in #pragma omp parallel for directly
61 return oldNumThreads;
62 }
63
64 const char* getName() const CV_OVERRIDE
65 {
66 return "openmp";
67 }
68};
69
70}}} // namespace
71
72#endif // OPENCV_CORE_PARALLEL_FOR_OPENMP_HPP
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.openmp.hpp:24
const char * getName() const CV_OVERRIDE
Definition parallel_for.openmp.hpp:64
virtual int setNumThreads(int nThreads) CV_OVERRIDE
Definition parallel_for.openmp.hpp:56
ParallelForBackend()
Definition parallel_for.openmp.hpp:29
virtual void parallel_for(int tasks, FN_parallel_for_body_cb_t body_callback, void *callback_data) CV_OVERRIDE
Definition parallel_for.openmp.hpp:37
virtual ~ParallelForBackend()
Definition parallel_for.openmp.hpp:35
virtual int getNumThreads() const CV_OVERRIDE
Definition parallel_for.openmp.hpp:49
int numThreads
Definition parallel_for.openmp.hpp:26
int numThreadsMax
Definition parallel_for.openmp.hpp:27
virtual int getThreadNum() const CV_OVERRIDE
Definition parallel_for.openmp.hpp:44
#define CV_OVERRIDE
Definition cvdef.h:792
"black box" representation of the file storage associated with a file on disk.
Definition calib3d.hpp:441