我有一个嵌套循环,im混淆了应该共享还是私有的变量。我认为i和j应该是私有的,但我对其他变量是否也需要在代码中共享或私有化感到困惑:
y = p->yMax;
#pragma omp parallel for private(i,j)
for (i = 0; i < p->height; i++) {
x = p->xMin;
for (j = 0; j < p->width; j++) {
p->carray[i * p->width + j] = x + y * I;
x += p->step;
}
y -= p->step;
}
for (i = 0; i < p->maxIter; i++) {
p->histogram[i] = 0;
}
}干杯
发布于 2022-09-22 11:07:12
不是x和y的选项。
#pragma omp parallel for shared(p)
for (size_t i = 0; i < p->height; i++) {
auto x = p->xMin;
auto y = p->yMax;
for (size_t j = 0; j < p->width; j++) {
p->carray[i * p->width + j] = x + y * I;
x += p->step;
}
y -= p->step;
}
//This one isn't in the parallel region
for (size_t i = 0; i < p->maxIter; i++) {
p->histogram[i] = 0;
}https://stackoverflow.com/questions/73812404
复制相似问题