【发布时间】:2019-05-09 22:22:06
【问题描述】:
我正在尝试使用 openMP 并行化这个折叠循环,但这就是我得到的: "smooth.c:47:6: 错误:'sum' sum = 0 之前没有足够的完美嵌套循环;"
有人知道并行化这个的好方法吗?我在这个问题上被困了 2 天。
这是我的循环:
long long int sum;
#pragma omp parallel for collapse(3) default(none) shared(DY, DX) private(dx, dy) reduction(+:sum)
for (y = 0; y < height; y++) {
for (x = 0; x < width; x++) {
sum = 0;
for (d = 0; d < 9; d++) {
dx = x + DX[d];
dy = y + DY[d];
if (dx >= 0 && dx < width && dy >= 0 && dy < height)
sum += image(dy, dx);
}
smooth(y, x) = sum / 9;
}
}
【问题讨论】:
标签: c multithreading for-loop openmp reduction