Ask Your Question
0

Does OpenCV functions really use OpenMP

asked 2015-12-16 14:45:13 -0600

Controls Weenie gravatar image

I recompiled opencv 2.4.11 on Linux using the OpenMP mode. I ran my test code and I did not see any change in speed. I watch my cores utilization and there is only one core being used.

I read a camera image and perform the following function calls: cvtColor, inRange, threshold, findContours and approxPolyDP. I figured I would see pragma statements in the opencv source code for these function but I have only seen "#pragma omp parallel" in the haart training and some other modules.

Why doesn't opencv functions contain "#pragma omp parallel". It seems that a cvtColor(), inRange() and threshold() could benefit enormously from using multithreads.

Thoughts?

edit retag flag offensive close merge delete

Comments

" I figured I would see pragma statements" - instead look for parallel_for_ , which is a wrapper around multiple alternative ways for doing parallelism

berak gravatar imageberak ( 2015-12-17 01:16:34 -0600 )edit

Hello Controls Weenie, I follow the same problem as you : my program seems to run only on one core and I don't feel any speed changes. Did you manage to solve it ?

Major Squirrel gravatar imageMajor Squirrel ( 2016-06-08 13:40:05 -0600 )edit

2 answers

Sort by ยป oldest newest most voted
1

answered 2015-12-16 23:32:06 -0600

Tetragramm gravatar image

It does indeed use OpenMP. However, if you open parallel.cpp, you can see that it first uses tbb, then cstripes, then openmp. In the definition for the OpenMP version, there you see the #pragma omp parallel.

So if you had either of the other two, then it would have been using those. Also, it's possible that if the functions you called have Intel IPP, which may or may not use a parallel version by default.

To test the effects of parallelization, there's a setNumThreads function. If you set it to 0, it will disable threading entirely. You can do this at run-time, in your program. Setting it to <0 will reset the value to default.

edit flag offensive delete link more
0

answered 2015-12-18 16:47:00 -0600

Controls Weenie gravatar image

updated 2015-12-20 08:38:00 -0600

I have an update on my issue. I can get my code operating with multiple threads at work. However, my home computer will not perform multithreaded openmp. I just found a difference in compilers. My work computer has OpenMP 2.5 and my home has OpenMP 3.0. My home computer is a PCDuino 8 running Ubuntu 14.

I tried to include my src code but the attachment tool would only let me include image suffixes.

Thanks

Another question: Should I add some other flags or env variables for OpenMP 3.1. My work computer works fine with OpenMP 2.5 but my home PCDuino8 does not work with OpenMP 3.1. Maybe OpenCV is not setup for OpenMP 3.1. Has anyone had success with OpenMP 3.1 and OpenCV?

edit flag offensive delete link more

Comments

Are you building from source or installing the pre-compiled libraries? If you're building from source, you need to double check that WITH_OPENMP is checked and that it finds the necessary bits.

Try OpenMP C flag = [/openmp]

Performing Test OpenMP_FLAG_DETECTED

Performing Test OpenMP_FLAG_DETECTED - Success

Try OpenMP CXX flag = [/openmp]

Performing Test OpenMP_FLAG_DETECTED

Performing Test OpenMP_FLAG_DETECTED - Success

Found OpenMP: /openmp

Tetragramm gravatar imageTetragramm ( 2015-12-18 23:22:05 -0600 )edit

Question Tools

2 followers

Stats

Asked: 2015-12-16 14:45:13 -0600

Seen: 6,145 times

Last updated: Dec 20 '15