Static Analysis Problem Type Reference
CRITICAL directives with the same name must not be dynamically nested.
The CRITICAL directive establishes a critical region with a given name. This ensures that only one thread can execute the region at a time. Unlike critical sections in the native threading libraries, OpenMP* critical sections are not reentrant. That is, if the same physical thread attempts to enter the critical region twice without leaving first then it would deadlock with itself.
|
ID |
Code Location |
Description |
|---|---|---|
|
1 |
OpenMP usage error |
The place where the CRITICAL directive that is executed second (illegally) |
|
2 |
Definition |
The place where the CRITICAL directive is executed first (legally) |
#include <stdio.h>
void mysub(int ii, int * jj) {
// bad nesting here
#pragma omp critical (sum)
*jj += ii;
}
int main(int argc, char **argv)
{
int i, j;
#pragma omp parallel for private(j) ordered
for (i = 1; i < 10; i++) {
j = 0;
#pragma omp critical (not_sum)
mysub(i, &j);
#pragma omp critical (sum)
mysub(i, &j);
#pragma omp ordered
printf("%d\n", j);
}
return 0;
}