fortran: Factor the evaluation of MINLOC/MAXLOC's BACK argument
[official-gcc.git] / libgomp / testsuite / libgomp.c / scan-9.c
blob822752306ae81eb5a19d53b96697819972f433d7
1 /* { dg-require-effective-target size32plus } */
3 extern void abort (void);
4 int r, a[1024], b[1024], x, y, z;
6 __attribute__((noipa)) void
7 foo (int *a, int *b)
9 #pragma omp for reduction (inscan, +:r) lastprivate (conditional: z) firstprivate (x) private (y)
10 for (int i = 0; i < 1024; i++)
12 { y = a[i]; r += y + x + 12; }
13 #pragma omp scan inclusive(r)
14 { b[i] = r; if ((i & 1) == 0 && i < 937) z = r; }
18 __attribute__((noipa)) int
19 bar (void)
21 int s = 0;
22 #pragma omp parallel
23 #pragma omp for reduction (inscan, +:s) firstprivate (x) private (y) lastprivate (z)
24 for (int i = 0; i < 1024; i++)
26 { y = 2 * a[i]; s += y; z = y; }
27 #pragma omp scan inclusive(s)
28 { y = s; b[i] = y + x + 12; }
30 return s;
33 __attribute__((noipa)) void
34 baz (int *a, int *b)
36 #pragma omp parallel for reduction (inscan, +:r) firstprivate (x) lastprivate (x)
37 for (int i = 0; i < 1024; i++)
39 { r += a[i] + x + 12; if (i == 1023) x = 29; }
40 #pragma omp scan inclusive(r)
41 b[i] = r;
45 __attribute__((noipa)) int
46 qux (void)
48 int s = 0;
49 #pragma omp parallel for reduction (inscan, +:s) lastprivate (conditional: x, y)
50 for (int i = 0; i < 1024; i++)
52 { s += 2 * a[i]; if ((a[i] & 1) == 1 && i < 825) x = a[i]; }
53 #pragma omp scan inclusive(s)
54 { b[i] = s; if ((a[i] & 1) == 0 && i < 829) y = a[i]; }
56 return s;
59 int
60 main ()
62 int s = 0;
63 x = -12;
64 for (int i = 0; i < 1024; ++i)
66 a[i] = i;
67 b[i] = -1;
68 asm ("" : "+g" (i));
70 #pragma omp parallel
71 foo (a, b);
72 if (r != 1024 * 1023 / 2 || x != -12 || z != b[936])
73 abort ();
74 for (int i = 0; i < 1024; ++i)
76 s += i;
77 if (b[i] != s)
78 abort ();
79 else
80 b[i] = 25;
82 if (bar () != 1024 * 1023 || x != -12 || z != 2 * 1023)
83 abort ();
84 s = 0;
85 for (int i = 0; i < 1024; ++i)
87 s += 2 * i;
88 if (b[i] != s)
89 abort ();
90 else
91 b[i] = -1;
93 r = 0;
94 baz (a, b);
95 if (r != 1024 * 1023 / 2 || x != 29)
96 abort ();
97 s = 0;
98 for (int i = 0; i < 1024; ++i)
100 s += i;
101 if (b[i] != s)
102 abort ();
103 else
104 b[i] = -25;
106 if (qux () != 1024 * 1023 || x != 823 || y != 828)
107 abort ();
108 s = 0;
109 for (int i = 0; i < 1024; ++i)
111 s += 2 * i;
112 if (b[i] != s)
113 abort ();
115 return 0;