| 1 |
/* { dg-do run } */ |
| 2 |
/* { dg-require-effective-target tls_runtime } */ |
| 3 |
/* { dg-additional-options "-std=gnu99" {target c } } */ |
| 4 |
|
| 5 |
#include <omp.h> |
| 6 |
#include <stdlib.h> |
| 7 |
|
| 8 |
int r, s, u, v, r2, s2, u2, v2, r3, s3, u3, v3; |
| 9 |
long long w, w2, w3, p, p2, p3; |
| 10 |
int *x, *x2, *x3; |
| 11 |
short y, y2, y3; |
| 12 |
int z; |
| 13 |
int thr1, thr2; |
| 14 |
#pragma omp threadprivate (thr1, thr2) |
| 15 |
|
| 16 |
void |
| 17 |
foo (int *a, long long int b, long long int c) |
| 18 |
{ |
| 19 |
int i; |
| 20 |
long long j; |
| 21 |
#pragma omp for lastprivate (conditional: u, x) nowait |
| 22 |
for (i = 15; i < 64; i++) |
| 23 |
{ |
| 24 |
if ((a[i] % 5) == 3) |
| 25 |
u = i; |
| 26 |
if ((a[i] % 7) == 2) |
| 27 |
x = &a[i]; |
| 28 |
} |
| 29 |
#pragma omp for nowait lastprivate (conditional: v) reduction (+:r, s) schedule (nonmonotonic: static) |
| 30 |
for (i = -3; i < 119; i += 2) |
| 31 |
{ |
| 32 |
++s; |
| 33 |
if ((a[i + 4] % 11) == 9) |
| 34 |
v = i; |
| 35 |
else |
| 36 |
++r; |
| 37 |
} |
| 38 |
#pragma omp for schedule (monotonic: static) lastprivate (conditional: w) nowait |
| 39 |
for (j = b; j < b + 115 * c; j += (b & 3) + 7) |
| 40 |
if ((a[j] % 13) == 5) |
| 41 |
w = j * 2; |
| 42 |
#pragma omp for schedule (auto) lastprivate (conditional: p) collapse(3) |
| 43 |
for (i = -5; i < (int) (b + 5); i += 2) |
| 44 |
for (j = b + 12 + c; j > b; --j) |
| 45 |
for (int k = 0; k < 5; k += c) |
| 46 |
if (((((i + 5) * 13 + (13 - j)) * 5 + k) % 17) == 6) |
| 47 |
p = i * 10000 + j * 100 + k; |
| 48 |
|
| 49 |
#pragma omp for schedule (nonmonotonic: static, 2) nowait lastprivate (conditional: u2, x2) |
| 50 |
for (i = 15; i < 64; i++) |
| 51 |
{ |
| 52 |
if ((a[i] % 5) == 3) |
| 53 |
u2 = i; |
| 54 |
if ((a[i] % 7) == 2) |
| 55 |
x2 = &a[i]; |
| 56 |
} |
| 57 |
#pragma omp for schedule (static, 3) lastprivate (conditional: v2) reduction (+:r2, s2) |
| 58 |
for (i = -3; i < 119; i += 2) |
| 59 |
{ |
| 60 |
++s2; |
| 61 |
if ((a[i + 4] % 11) == 9) |
| 62 |
v2 = i; |
| 63 |
else |
| 64 |
++r2; |
| 65 |
} |
| 66 |
#pragma omp for lastprivate (conditional: w2) schedule (static, 1) nowait |
| 67 |
for (j = b; j < b + 115 * c; j += (b & 3) + 7) |
| 68 |
if ((a[j] % 13) == 5) |
| 69 |
w2 = j * 2; |
| 70 |
#pragma omp for schedule (static, 3) collapse (3) lastprivate (conditional: p2) |
| 71 |
for (i = -5; i < (int) (b + 5); i += 2) |
| 72 |
for (j = b + 12 + c; j > b; --j) |
| 73 |
for (int k = 0; k < 5; k += c) |
| 74 |
if (((((i + 5) * 13 + (13 - j)) * 5 + k) % 17) == 6) |
| 75 |
p2 = i * 10000 + j * 100 + k; |
| 76 |
|
| 77 |
#pragma omp for lastprivate (conditional: u3, x3) nowait schedule (runtime) |
| 78 |
for (i = 15; i < 64; i++) |
| 79 |
{ |
| 80 |
if ((a[i] % 5) == 3) |
| 81 |
u3 = i; |
| 82 |
if ((a[i] % 7) == 2) |
| 83 |
x3 = &a[i]; |
| 84 |
} |
| 85 |
#pragma omp for nowait lastprivate (conditional: v3) reduction (+:r3, s3) schedule (nonmonotonic: dynamic) |
| 86 |
for (i = -3; i < 119; i += 2) |
| 87 |
{ |
| 88 |
++s3; |
| 89 |
if ((a[i + 4] % 11) == 9) |
| 90 |
v3 = i; |
| 91 |
else |
| 92 |
++r3; |
| 93 |
} |
| 94 |
#pragma omp for schedule (monotonic: guided, 3) lastprivate (conditional: w3) nowait |
| 95 |
for (j = b; j < b + 115 * c; j += (b & 3) + 7) |
| 96 |
if ((a[j] % 13) == 5) |
| 97 |
w3 = j * 2; |
| 98 |
#pragma omp for schedule (dynamic, 4) lastprivate (conditional: p3) collapse(3) |
| 99 |
for (i = -5; i < (int) (b + 5); i += 2) |
| 100 |
for (j = b + 12 + c; j > b; --j) |
| 101 |
for (int k = 0; k < 5; k += c) |
| 102 |
if (((((i + 5) * 13 + (13 - j)) * 5 + k) % 17) == 6) |
| 103 |
p3 = i * 10000 + j * 100 + k; |
| 104 |
|
| 105 |
/* Nasty testcase, verify that even a no-op assignment is accounted |
| 106 |
for in lastprivate(conditional:). */ |
| 107 |
#pragma omp for schedule (monotonic: static, 2) firstprivate (z) \ |
| 108 |
lastprivate (conditional: z) |
| 109 |
for (int k = -2000; k < 8000; ++k) |
| 110 |
{ |
| 111 |
if (k < 3000 && (k & 3) == 1) |
| 112 |
{ |
| 113 |
z = k; |
| 114 |
thr1 = k; |
| 115 |
} |
| 116 |
else if (k == 7931) |
| 117 |
{ |
| 118 |
z = z; |
| 119 |
thr2 = 1; |
| 120 |
} |
| 121 |
} |
| 122 |
|
| 123 |
if (thr2 && z != thr1) |
| 124 |
abort (); |
| 125 |
} |
| 126 |
|
| 127 |
int |
| 128 |
main () |
| 129 |
{ |
| 130 |
int a[128], i; |
| 131 |
volatile int j = 0; |
| 132 |
for (i = 0; i < 128; i++) |
| 133 |
a[i] = i; |
| 134 |
w = 1234; |
| 135 |
#pragma omp parallel |
| 136 |
foo (a, j, j + 1); |
| 137 |
if (u != 63 || v != 115 || w != 140 || x != &a[58] || r != 55 || s != 61 || p != 30104) |
| 138 |
abort (); |
| 139 |
if (u2 != 63 || v2 != 115 || w2 != 140 || x2 != &a[58] || r2 != 55 || s2 != 61 || p2 != 30104) |
| 140 |
abort (); |
| 141 |
if (u3 != 63 || v3 != 115 || w3 != 140 || x3 != &a[58] || r3 != 55 || s3 != 61 || p3 != 30104) |
| 142 |
abort (); |
| 143 |
return 0; |
| 144 |
} |