Imported Upstream version 4.8.1
[platform/upstream/gcc48.git] / libgomp / testsuite / libgomp.c / pr26943-4.c
1 /* PR c++/26943 */
2 /* { dg-do run } */
3
4 extern int omp_set_dynamic (int);
5 extern int omp_get_thread_num (void);
6 extern void abort (void);
7 extern void GOMP_barrier (void);
8
9 int a = 8, b = 12, c = 16, d = 20, j = 0, l = 0;
10 char e[10] = "a", f[10] = "b", g[10] = "c", h[10] = "d";
11 volatile int k;
12
13 int
14 main (void)
15 {
16   int i;
17   omp_set_dynamic (0);
18   omp_set_nested (1);
19 #pragma omp parallel num_threads (2) reduction (+:l) \
20                      firstprivate (a, b, c, d, e, f, g, h, j)
21   if (k == omp_get_thread_num ())
22     {
23 #pragma omp parallel for shared (a, e) firstprivate (b, f) \
24                          lastprivate (c, g) private (d, h) \
25                          schedule (static, 1) num_threads (4) \
26                          reduction (+:j)
27       for (i = 0; i < 4; i++)
28         {
29           if (a != 8 || b != 12 || e[0] != 'a' || f[0] != 'b')
30             j++;
31           GOMP_barrier ();
32 #pragma omp atomic
33           a += i;
34           b += i;
35           c = i;
36           d = i;
37 #pragma omp atomic
38           e[0] += i;
39           f[0] += i;
40           g[0] = 'g' + i;
41           h[0] = 'h' + i;
42           GOMP_barrier ();
43           if (a != 8 + 6 || b != 12 + i || c != i || d != i)
44             j += 8;
45           if (e[0] != 'a' + 6 || f[0] != 'b' + i || g[0] != 'g' + i)
46             j += 64;
47           if (h[0] != 'h' + i)
48             j += 512;
49         }
50       if (j || a != 8 + 6 || b != 12 || c != 3 || d != 20)
51         ++l;
52       if (e[0] != 'a' + 6 || f[0] != 'b' || g[0] != 'g' + 3 || h[0] != 'd')
53         l += 8;
54     }
55   if (l)
56     abort ();
57   if (a != 8 || b != 12 || c != 16 || d != 20)
58     abort ();
59   if (e[0] != 'a' || f[0] != 'b' || g[0] != 'c' || h[0] != 'd')
60     abort ();
61   return 0;
62 }