I have a nested loop and im confused on which variables should be shared or private. I believe that i
and j
should be private but im confused on whether other variables also need to be shared or privated in my code:
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;
}
}
Cheers
``
#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;
}