Ask Your Question
1

Turn on/off multithreading?

asked 2014-07-01 12:19:19 -0600

ben2316 gravatar image

I just noticed that GridAdaptedFeatureDetector::detectImpl (in modules/features2d/src/detectors.cpp) uses cv::parallel_for_ in its implementation. I'm assuming that means that it uses multithreading to speed up the feature detection process. My question is: is there a way I can force this to run in serial? The motivation to turn off multithreading is to do performance testing, to see how my code runs faster or slower, serially, based on different code changes. Is there a compile flag or function call I need to do?

edit retag flag offensive close merge delete

Comments

it's all done in the cmake stage, when building the libs. if you don't enable anything (like openmp or similar) there, it will run single-threaded anyway.

berak gravatar imageberak ( 2014-07-01 14:18:36 -0600 )edit

How about if I didn't compile OpenCV from source?

ben2316 gravatar imageben2316 ( 2014-07-01 19:39:40 -0600 )edit
sturkmen gravatar imagesturkmen ( 2020-07-06 12:38:05 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
1

answered 2014-07-02 03:37:55 -0600

If your OpenCV version was compiled with TBB, then the answer is no way, I suppose. Because in that case, there is some where in the compiled code, the task_scheduler_init initialized the number of threads based on your hardware configuration (it is usually with more than 1 core) and due to the information from this link, other calls will be ignored, this means you can not change that number. In case your OpenCV was compiled with OpenMP, the code below may be a try:

int num_threads = 1;
omp_set_dynamic(0);
omp_set_num_threads(num_threads);
edit flag offensive delete link more

Comments

Does anyone know if the OpenCV pre-built Windows libraries are compiled with TBB?

ben2316 gravatar imageben2316 ( 2014-07-02 11:20:19 -0600 )edit

Question Tools

Stats

Asked: 2014-07-01 12:19:19 -0600

Seen: 6,364 times

Last updated: Jul 02 '14