How to select to use OpenMP or Intel TBB?

Hello there. I have compiled OpenCV 3.4.16 with “WITH_TBB” and “WITH_OPENMP” flags enabled by using CMake 3.22.0. The TBB version I used was tbb2019_20191006. Then I built libraries for Release and Debug by using Visual Studio 2019 Community Edition. When I check
build information using cv::getBuildInformation( ) I don’t see any information about TBB, it only says OpenMP.

cv::getBuildInformation( ) results

Screenshot_3

Do I need to make separate builds for OpenMP and Intel TBB? If I don’t need to build them as separate builds, how do I activate/select to use OpenMP or Intel TBB in my OpenCV code?

i have meet the same question, how to activate/select to use OpenMP or Intel TBB in my OpenCV code, have you solve this problem?

There was a Stackoverflow post from 2015.

TLDR: You should build OpenCV with the parallel framework you want/intend to use.

But since this was a 7-year-old post, I don’t know if the same thing still applies or not.

thanks for reply, opencv did choose the parallel framework by the following order:

/* IMPORTANT: always use the same order of defines
   1. HAVE_TBB         - 3rdparty library, should be explicitly enabled
   2. HAVE_CSTRIPES    - 3rdparty library, should be explicitly enabled
   3. HAVE_OPENMP      - integrated to compiler, should be explicitly enabled
   4. HAVE_GCD         - system wide, used automatically        (APPLE only)
   5. HAVE_CONCURRENCY - part of runtime, used automatically    (Windows only - MSVS 10, MSVS 11)
*/

and i also find that we can explicit select by this api setParallelForBackend .
BTW, do you know which parallel framework is faster on windows with cpu?

1 Like

Well, I’ve never done a benchmark but I think we might consider that the TBB would yield better optimization for Intel CPUs than OpenMP.

thanks, i try to build opencv with tbb, i set -DWITH_TBB=ON, i also download TBB, how ca i tell opencv where to find tbb?is there some other cmake option to set?

You need to provide directories for TBB ( directories of include, lib, etc.), there is an option about that at CMake.

thanks a lot, i successfully compile opencv with tbb,however in my test, TBB is 1.5 or 2.0 slower than CONCURRENCY, is it reasonable?

What do you mean by “Concurrency”?

probably that, is my guess.

here:

/* IMPORTANT: always use the same order of defines
   1. HAVE_TBB         - 3rdparty library, should be explicitly enabled
   2. HAVE_CSTRIPES    - 3rdparty library, should be explicitly enabled
   3. HAVE_OPENMP      - integrated to compiler, should be explicitly enabled
   4. HAVE_GCD         - system wide, used automatically        (APPLE only)
   5. HAVE_CONCURRENCY - part of runtime, used automatically    (Windows only - MSVS 10, MSVS 11)
*/