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