'How do I use a increment operator in parallel in OpenMP
I want to increment count variable in all of my threads if a condition is met. Is there a better way to do this other than enclosing the count variable in a critical block or using count[] as an array?
pragma omp parallel for num_threads(number_of_threads)
int id = omp_get_thread_num();
for(i=1; i < ht; i++) {
for(j=1; j < wd; j++) {
// Some random code
double mag = sqrt(a[i] * a[i] + b[j] * b[j]);
if(mag > 100) {
#pragma omp critical
{
count++;
}
} else {
// do nothing
}
}
}
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
