c++ - OpenMP doesn't run this for loop in different threads, how can I fix it -


i have code:

#pragma omp parallel for( i=0;i<(int)table.size();i++) {     vec3b bgrpixel;     tableelement element=table[i];     bgrpixel = inputimage.at<vec3b>(element.inputpixel.y,element.inputpixel.x);     outputimage.at<vec4b>(element.outputpixel.y,element.outputpixel.x)[0] = bgrpixel[0];     outputimage.at<vec4b>(element.outputpixel.y,element.outputpixel.x)[1] = bgrpixel[1];     outputimage.at<vec4b>(element.outputpixel.y,element.outputpixel.x)[2] = bgrpixel[2];     outputimage.at<vec4b>(element.outputpixel.y,element.outputpixel.x)[3] = 255; } 

when run it, can see 25% of processors power used. believe not run in parallel. why not run in parallel , how can improve performance?

images opencv mat objects.

it suggested in comments, mat::at might kind of locking. checked opencv source, , does'nt seem case. 1 version of mat::at reproduced below:

template<typename _tp> inline _tp& mat::at(int i0, int i1) {     cv_dbgassert( dims <= 2 && data && (unsigned)i0 < (unsigned)size.p[0] &&         (unsigned)(i1*datatype<_tp>::channels) < (unsigned)(size.p[1]*channels(⇉         cv_elem_size1(datatype<_tp>::depth) == elemsize1());     return ((_tp*)(data + step.p[0]*i0))[i1]; } 

it seem me suggested in comments, reason low cpu usage code doesn't have cpu. code simple memory assignments, code memory, not cpu bound. suggestion not copying data (the opencv mat format flexible pointing same data 2 matrices creating new header). if inputpixel , outputpixel values uncorrelated or have compex correlation, need resign fact accessing memory randomly (i.e. lots of cache misses) going take time.


Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -