Loading...
Searching...
No Matches
Parallel backends API
Classes | |
class | cv::parallel::ParallelForAPI |
class | cv::parallel::openmp::ParallelForBackend |
class | cv::parallel::tbb::ParallelForBackend |
Functions | |
void | cv::parallel::setParallelForBackend (const std::shared_ptr< ParallelForAPI > &api, bool propagateNumThreads=true) |
Replace OpenCV parallel_for backend. | |
bool | cv::parallel::setParallelForBackend (const std::string &backendName, bool propagateNumThreads=true) |
Change OpenCV parallel_for backend. | |
Detailed Description
API below is provided to resolve problem of CPU resource over-subscription by multiple thread pools from different multi-threading frameworks. This is common problem for cases when OpenCV compiled threading framework is different from the Users Applications framework.
Applications can replace OpenCV parallel_for()
backend with own implementation (to reuse Application's thread pool).
Backend API usage examples
Intel TBB
- include header with simple implementation of TBB backend:
- execute backend replacement code: cv::parallel::setParallelForBackend(std::make_shared<cv::parallel::tbb::ParallelForBackend>());void setParallelForBackend(const std::shared_ptr< ParallelForAPI > &api, bool propagateNumThreads=true)Replace OpenCV parallel_for backend.
- configuration of compiler/linker options is responsibility of Application's scripts
OpenMP
- include header with simple implementation of OpenMP backend:
- execute backend replacement code: //omp_set_dynamic(1);cv::parallel::setParallelForBackend(std::make_shared<cv::parallel::openmp::ParallelForBackend>());
- Configuration of compiler/linker options is responsibility of Application's scripts
Plugins support
Runtime configuration options:
- change backend priority:
OPENCV_PARALLEL_PRIORITY_<backend>=9999
- disable backend:
OPENCV_PARALLEL_PRIORITY_<backend>=0
- specify list of backends with high priority (>100000):
OPENCV_PARALLEL_PRIORITY_LIST=TBB,OPENMP
. Unknown backends are registered as new plugins.
Function Documentation
◆ setParallelForBackend() [1/2]
void cv::parallel::setParallelForBackend | ( | const std::shared_ptr< ParallelForAPI > & | api, |
bool | propagateNumThreads = true |
||
) |
#include <opencv2/core/parallel/parallel_backend.hpp>
Replace OpenCV parallel_for backend.
Application can replace OpenCV parallel_for()
backend with own implementation.
- Note
- This call is not thread-safe. Consider calling this function from the
main()
before any other OpenCV processing functions (and without any other created threads).
◆ setParallelForBackend() [2/2]
bool cv::parallel::setParallelForBackend | ( | const std::string & | backendName, |
bool | propagateNumThreads = true |
||
) |
#include <opencv2/core/parallel/parallel_backend.hpp>
Change OpenCV parallel_for backend.
- Note
- This call is not thread-safe. Consider calling this function from the
main()
before any other OpenCV processing functions (and without any other created threads).