Merge from mainline
[official-gcc.git] / libgomp / testsuite / libgomp.c / appendix-a / a.19.1.c
blob65ffe624c2576b1dbcd339f15b5c1d09d3b04c8a
1 /* { dg-do run } */
3 int x, *p = &x;
4 extern void abort (void);
5 void
6 f1 (int *q)
8 *q = 1;
9 #pragma omp flush
10 /* x, p, and *q are flushed */
11 /* because they are shared and accessible */
12 /* q is not flushed because it is not shared. */
15 void
16 f2 (int *q)
18 #pragma omp barrier
19 *q = 2;
20 #pragma omp barrier
21 /* a barrier implies a flush */
22 /* x, p, and *q are flushed */
23 /* because they are shared and accessible */
24 /* q is not flushed because it is not shared. */
27 int
28 g (int n)
30 int i = 1, j, sum = 0;
31 *p = 1;
32 #pragma omp parallel reduction(+: sum) num_threads(2)
34 f1 (&j);
35 /* i, n and sum were not flushed */
36 /* because they were not accessible in f1 */
37 /* j was flushed because it was accessible */
38 sum += j;
39 f2 (&j);
40 /* i, n, and sum were not flushed */
41 /* because they were not accessible in f2 */
42 /* j was flushed because it was accessible */
43 sum += i + j + *p + n;
45 return sum;
48 int
49 main ()
51 int result = g (10);
52 if (result != 30)
53 abort ();
54 return 0;