How can I disable parallelism in OpenCV?

I built OpenCV using Intel IPP, so I suppose I used it whenever possible (e.g. matrix multiplication).

I want to test the scalability of my parallel application by comparing it to the serial version. For this, when I do this:

omp_set_num_threads(1);
cv::setNumThreads(1);

      

However, by tracking CPU usage, I can see that there are still multiple processors in use. Why is this? And how can I force the execution of the program to use only one processor?

+3


source to share


3 answers


add ippSetNumThreads(1);

before the first IPP call in your code. This should set the number of OpenMP threads to IPP to 1. More information can be found here under OpenMP Thread Control in Intel IPP Primitives, section



0


source


Are you using opencv from multiple threads? You should disable opencv multithreading from every thread, at least in my experience with it.



Opencv 'parallel_for functions create multiple threads to distribute work across.

0


source


Rebuilding OpenCV from source with the following CMake options should work:

cmake .. -DWITH_IPP=OFF -DWITH_TBB=OFF -DWITH_OPENMP=OFF -DWITH_PTHREADS_PF=OFF

      

and you will find that the CV_PARALLEL_FRAMEWORK macro is no longer defined for anything in modules / core / src / parallel.cpp :

#if defined HAVE_TBB
#  define CV_PARALLEL_FRAMEWORK "tbb"
#elif defined HAVE_HPX
#  define CV_PARALLEL_FRAMEWORK "hpx"
#elif defined HAVE_OPENMP
#  define CV_PARALLEL_FRAMEWORK "openmp"
#elif defined HAVE_GCD
#  define CV_PARALLEL_FRAMEWORK "gcd"
#elif defined WINRT
#  define CV_PARALLEL_FRAMEWORK "winrt-concurrency"
#elif defined HAVE_CONCURRENCY
#  define CV_PARALLEL_FRAMEWORK "ms-concurrency"
#elif defined HAVE_PTHREADS_PF
#  define CV_PARALLEL_FRAMEWORK "pthreads"
#endif

      

0


source







All Articles