Poul K. Sørensen
Poul K. Sørensen

Reputation: 17530

Can both TBB, OpenMP and OpenCL be enabled in OpenCV build?

I am building OpenCV and was wondering if it makes sense to add all 3? Or if that would cause errors later because they all are used for parallel execution?

Upvotes: 4

Views: 1390

Answers (1)

ChK
ChK

Reputation: 186

I have recently wondered about the same thing, and my research has turned up the file modules\core\src\parallel.cpp, which contains the implementation of the parallel for loop, parallel_for_, and the corresponding data structures and thread control functions.

Judging by this file, OpenCV is prepared to support the following frameworks in this order of precedence:

/* 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)
*/

Only the framework enabled (and found on the system) which is topmost on this list is compiled into the library; the rest of the code is disabled by preprocessor directives.

To summarize, you should only enable the framework that you prefer to be used by OpenCV.
If you add more than one, the one appearing first on the above list should be selected automatically. The others would not provide an additional benefit, but should not cause any trouble either.

The documentation for the thread-related functions can be found in the Utility and System Functions and Macros section.

Hope that helps!

Upvotes: 4

Related Questions