3
我想使用OpenMP對IplImage進行一些轉換。這是簡單的轉換,將圖像顛倒。 OpenMP的代碼與沒有的代碼運行相同。這並不重要。使用OpenMP的並行IplImage轉換
void UpsideDownFilter::filter(IplImage* dstImage) {
uchar temp;
int j;
int i;
#pragma omp parallel shared(dstImage) private(j, i, temp)
{
// std::cout << omp_get_thread_num() << std::endl;
#pragma omp for schedule(static, 30) nowait
for(j = 0; j < dstImage->height/2; ++j) {
for(i = 0; i < dstImage->widthStep; ++i) {
temp = dstImage->imageData[i + j * dstImage->widthStep];
dstImage->imageData[i + j * dstImage->widthStep] =
dstImage->imageData[i + (dstImage->height - 1 - j) *
dstImage->widthStep];
dstImage->imageData[i + (dstImage->height - 1 - j) *
dstImage->widthStep] = temp;
}
}
}
}
我已經將#pragma omp推到內部循環。當我不知道什麼是錯的時候,我做了所有其他的魔術(刪除這個,加上)。這是我如何從我的代碼中調用該方法:
for (vector<filter_ptr>::iterator it = filters.begin();
it != filters.end(); ++it) {
(*it)->filter(dstImage);
}
有人能告訴我我做錯了什麼嗎?
你用-openmp編譯嗎?你爲什麼使用nowait? – Tudor 2012-01-17 19:52:35
您可以擁有多個CPU核心,但仍然只有一條內存總線。這裏的約束是,你只是移動字節。 – 2012-01-18 05:01:14
如果您不相信它,請添加有關您正在運行的進程數量的檢查,請參閱int omp_get_num_threads()' – Bort 2012-01-18 09:51:52