OpenCV 4.5.3(日本語機械翻訳)
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
16 namespace cv { namespace parallel { namespace openmp {
17
24{
25 protected:
26 int numThreads;
27 int numThreadsMax;
28 public:
30 {
31 numThreads = 0;
32 numThreadsMax = omp_get_max_threads();
33 }
34
35 virtual ~ParallelForBackend() {}
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
52 ? numThreads
53 : numThreadsMax;
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
Definition: parallel_for.openmp.hpp:24
cv
"black box" representation of the file storage associated with a file on disk.
Definition: aruco.hpp:75