1 /* PR middle-end/30494 */
2 /* { dg-do run } */
3
4 #include <omp.h>
5
6 int errors;
7
8 int
check(int m,int i,int * v,int * w)9 check (int m, int i, int *v, int *w)
10 {
11 int j;
12 int n = omp_get_thread_num ();
13 for (j = 0; j < m; j++)
14 if (v[j] != j + n)
15 #pragma omp atomic
16 errors += 1;
17 for (j = 0; j < m * 3 + i; j++)
18 if (w[j] != j + 10 + n)
19 #pragma omp atomic
20 errors += 1;
21 }
22
23 int
foo(int n,int m)24 foo (int n, int m)
25 {
26 int i;
27 #pragma omp for
28 for (i = 0; i < 6; i++)
29 {
30 int v[n], w[n * 3 + i], j;
31 for (j = 0; j < n; j++)
32 v[j] = j + omp_get_thread_num ();
33 for (j = 0; j < n * 3 + i; j++)
34 w[j] = j + 10 + omp_get_thread_num ();
35 check (m, i, v, w);
36 }
37 return 0;
38 }
39
40 int
bar(int n,int m)41 bar (int n, int m)
42 {
43 int i;
44 #pragma omp parallel for num_threads (4)
45 for (i = 0; i < 6; i++)
46 {
47 int v[n], w[n * 3 + i], j;
48 for (j = 0; j < n; j++)
49 v[j] = j + omp_get_thread_num ();
50 for (j = 0; j < n * 3 + i; j++)
51 w[j] = j + 10 + omp_get_thread_num ();
52 check (m, i, v, w);
53 }
54 return 0;
55 }
56
57 int
main(void)58 main (void)
59 {
60 #pragma omp parallel num_threads (3)
61 foo (128, 128);
62 bar (256, 256);
63 return 0;
64 }
65