Ask Your Question
1

How opencv use openmp thread to get performance?

asked 2016-10-05 07:18:34 -0600

krish22 gravatar image

I have installed OpenCV 2.4.13 -D WITH_OPENMP=ON (openmp enable). I want to know built-in functions provided by opencv that use OPENMP so I can show some performance between with openmp and without openmp enabled version. Do I need to change my openCV program to run with openmp? I did not find any example program that shows how Opencv use openmp. I did grep -R '#pragma omp' in the root of the OpenCV source tree and found some of .cpp file contain "# pragma Omp parallel for". one of such file is modules/contrib/src/spinimages.cpp: #pragma omp parallel for num_threads(nthreads). when i look inside the file function void computeSpinImages(......) useed this #pragma. How can I use this function in my program .

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
1

answered 2016-10-05 08:28:07 -0600

kbarni gravatar image

updated 2016-10-05 08:29:38 -0600

Building OpenCV with the WITH_OPENMP flag means that the internal functions will use OpenMP to parallelize some of the algorithms.

In OpenCV, an algorithm can have a sequential (slowest) implementation; a parallel implementation using OpenMP or TBB; and a GPU implementation using OpenCL or CUDA (fastest). You can decide with the WITH_...flags which version to use.

Of course, not every algorithm can be parallelized.

Now, if you want to parallelize your methods with OpenMP, you have to implement it yourself.

A typical image processing function looks like:

for(int y=0;y<image.rows;y++)
    for(int x=0;x<image.cols;x++)
         //do something with pixel (x,y)

Typically it's the outer loop that gets parallelized; so you have to transform the for(y...) loop to a parallel for loop. I never used OpenMP, but it seems it's done with the #pragma omp for directive; something like:

#pragma omp for
for(int y=0;y<image.rows;y++)
    for(int x=0;x<image.cols;x++)
         //do something with pixel (x,y)
edit flag offensive delete link more

Comments

can u tell me name of algorithm that are parallelized using openmp in openCV

krish22 gravatar imagekrish22 ( 2016-10-05 22:37:17 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2016-10-05 07:18:34 -0600

Seen: 9,084 times

Last updated: Oct 05 '16