The compiler detects some restrictions noted in the OpenMP* API. With OpenMP analysis, additional checks for misuse of the OpenMP API are performed.
Example 1: Incorrect usage of OpenMP directives
File f1.c contains the following lines:
1 #include <stdio.h>
2 #include <omp.h>
3
4 void fff(int ii) {
5 #pragma omp barrier
6 printf("Val = %d \n", ii);
7 }
8
9 int main(void) {
10 int i=3;
11 omp_set_num_threads(3);
12 #pragma omp parallel
13 #pragma omp master
14 fff(i);
15 return 0;
16 }
Source code analysis issues the following message:
f1.c(5): error #12200: BARRIER directive is not allowed in the dynamic extent of MASTER directive (file:f1.c line:13)
Example 2: Incorrect data dependency
To enable data dependency analysis for a parallel program, enable diagnostics at level 3 .
1 int main(void) {
2 int i,sum = 0;
3 int a[1000];
4
5 #pragma omp parallel for reduction(+:sum)
6 for (i=1; i<999; i++) {
7 a[i] = i;
8 sum = sum + a[i + 1];
9 }
10 }
Source code analysis issues the following message:
f1.c(8): warning #12247: anti data dependence from (file:f1.c line:8) to (file:f1.c line:7), due to "a" may lead to incorrect program execution in parallel mode
Example 3: Incorrect synchronization
File f1.c contains the following lines:
1 #include <stdio.h>
2 #include <omp.h>
3
4 int a[1000];
5 int sum = 0;
6
7 void moo() {
8 int i;
9
10 #pragma omp task
11 for (i=0; i<1000; i++) {
12 a[i] = i;
13 sum = sum + a[i];
14 }
15 }
16
17 void foo() {
18 printf("%d\n",sum);
19 }
20
21 int main(void) {
22 int i;
23
24 #pragma omp parallel shared(sum)
25 #pragma omp single
26 {
27 moo();
28 foo();
29 }
30 return 0;
31 }
Source code analysis issues the following message:
f1.c(18): error #12365: variable "sum" is defined at (file:f1.c line:13) in TASK region (file:f1.c line:10) and is used before synchronization