A variable is being incorrectly shared in the OpenMP datascoping clauses.
Change the data scope of the variable from shared to private.
Specifying an invalid scope for a variable may introduce race conditions and produce incorrect results. For instance, when a variable is written from parallel threads and the specified scoping is shared instead of private.
In the following code no variable is privatized:
void example(int **result, unsigned rows, unsigned cols) {
int i, j;
// j is implicitly shared and it should be private!
#pragma omp parallel for shared(result)
for (i = 0; i < rows; i++) {
for (j = 0; j < cols; j++) {
result[i][j] = 0;
}
}
}
This introduced a data race due to j
being shared among threads. It should be
privatized:
void example(int **result, unsigned rows, unsigned cols) {
int i, j;
// j is implicitly shared and it should be private!
#pragma omp parallel for shared(result) private(j)
for (i = 0; i < rows; i++) {
for (j = 0; j < cols; j++) {
result[i][j] = 0;
}
}
}
- Data-Sharing Attribute Clauses - OPENMP API Specification: Version 5.0 November 2018 [last checked August 2021]