我正在使用英特尔的tbb并行化循环,当我运行它时,它会在task.h中指向我的这个函数
//! Spawn task allocated by allocate_root, wait for it to complete, and deallocate it.
static void spawn_root_and_wait( task& root ) {
root.prefix().owner->spawn_root_and_wait( root, root.prefix().next );
}
我不明白这可能导致什么样的问题? 更多信息:我基本上试图做一些图像匹配..通过在左图像中形成一个感兴趣区域(ROI),然后在右图中找到相同的图像。这是我试图并行化的操作。 我的想法是,在特定的一行,我可以将左图像与右图像匹配的操作并行化,因为它们看起来与我无关。
这是我的主要功能(在每一行,即高度调用)
parallel_for(blocked_range<size_t> (2,left_image_width-2),ApplyMLR(left_image_width,right_image_width,leftImageROI,rightImageROI,i,j,curHeight));
这是MLR函数(ApplyMLR只是正文对象)。
void MLR( int curWidth,int left_image_width, int right_image_width, IplImage* leftImageROI,IplImage* rightImageROI, int i,int j, int curHeight){
CvPoint minloc, maxloc;
double minval, maxval;
// create 5 by 5 window of leftImageROI that is to be compared with the rightImageROI
cvSetImageROI(leftImageROI, cvRect(curWidth - 2, 0, 5, 5));
IplImage* currentROI = cvCreateImage(cvSize(5, 5), leftImageROI->depth, leftImageROI->nChannels);
cvCopy(leftImageROI, currentROI);
cvResetImageROI(leftImageROI);
// since we have no disparity values from a previous level, we have to compare across all of rightImageROI
if (j == tot_pyramid_levels[i/2] - 1) {
// For cvMatchTemplate: if rightImageROI is WxH and currentROI is wxh then result must be W-w+1xH-h+1.
IplImage* re = cvCreateImage(cvSize(rightImageROI->width - 5 + 1, 1), IPL_DEPTH_32F, 1); // the results will be stored in here
cvZero(re);
cvMatchTemplate(rightImageROI, currentROI, re, CV_TM_CCORR_NORMED);
cvMinMaxLoc(re, &minval, &maxval, &minloc, &maxloc);
cvReleaseImage(&re);
//printf("%4.4f\n", minval);
}
else { // we can use disparity of previous level to narrow down search area
//Similar to above part uses cvTemplate but difference is it uses reduced area for matching
maxloc.x = maxloc.x + left_limit; // to account for the limits set above
cvReleaseImage(&re);
}
disparity_map[i][j][curHeight][curWidth] = curWidth - (maxloc.x + 2);
cvReleaseImage(¤tROI);
}