| 1 |
#include <omp.h> |
| 2 |
#include <stdlib.h> |
| 3 |
#include <stdint.h> |
| 4 |
|
| 5 |
struct S { int a, b; }; |
| 6 |
|
| 7 |
void |
| 8 |
foo (int &x, int &y, int &r, int &l, int (&l2)[4], int &l3, int &n, int *&p, |
| 9 |
int *&q, int &px, struct S &s, omp_allocator_handle_t h, int fl) |
| 10 |
{ |
| 11 |
int i; |
| 12 |
typedef int T[x]; |
| 13 |
T v, w; |
| 14 |
T &v2 = v; |
| 15 |
T &w2 = w; |
| 16 |
int r1[4] = { 0, 0, 0, 0 }; |
| 17 |
int (&r2)[4] = r1; |
| 18 |
int xo = x; |
| 19 |
for (i = 0; i < x; i++) |
| 20 |
w[i] = i; |
| 21 |
for (i = 0; i < 4; i++) |
| 22 |
p[i] = 0; |
| 23 |
for (i = 0; i < 3; i++) |
| 24 |
q[i] = 0; |
| 25 |
#pragma omp parallel private (y, v2) firstprivate (x) allocate (x, y, v2) |
| 26 |
{ |
| 27 |
int *volatile p1 = &x; |
| 28 |
int *volatile p2 = &y; |
| 29 |
if (x != 42) |
| 30 |
abort (); |
| 31 |
#pragma omp barrier |
| 32 |
*p2 = 1; |
| 33 |
p1[0]++; |
| 34 |
v2[0] = 7; |
| 35 |
v2[41] = 8; |
| 36 |
#pragma omp barrier |
| 37 |
if (x != 43 || y != 1) |
| 38 |
abort (); |
| 39 |
if (v2[0] != 7 || v2[41] != 8) |
| 40 |
abort (); |
| 41 |
if ((fl & 2) && (((uintptr_t) p1 | (uintptr_t) p2 |
| 42 |
| (uintptr_t) &v2[0]) & 63) != 0) |
| 43 |
abort (); |
| 44 |
} |
| 45 |
x = xo; |
| 46 |
#pragma omp teams |
| 47 |
#pragma omp parallel private (y) firstprivate (x, w2) allocate (h: x, y, w2) |
| 48 |
{ |
| 49 |
int *volatile p1 = &x; |
| 50 |
int *volatile p2 = &y; |
| 51 |
if (x != 42 || w2[17] != 17 || w2[41] != 41) |
| 52 |
abort (); |
| 53 |
#pragma omp barrier |
| 54 |
*p2 = 1; |
| 55 |
p1[0]++; |
| 56 |
w2[19]++; |
| 57 |
#pragma omp barrier |
| 58 |
if (x != 43 || y != 1 || w2[19] != 20) |
| 59 |
abort (); |
| 60 |
if ((fl & 1) && (((uintptr_t) p1 | (uintptr_t) p2 |
| 61 |
| (uintptr_t) &w2[0]) & 63) != 0) |
| 62 |
abort (); |
| 63 |
} |
| 64 |
x = xo; |
| 65 |
#pragma omp parallel for private (y) firstprivate (x) allocate (h: x, y, r, l, n) reduction(+: r) lastprivate (l) linear (n: 16) |
| 66 |
for (i = 0; i < 64; i++) |
| 67 |
{ |
| 68 |
if (x != 42) |
| 69 |
abort (); |
| 70 |
y = 1; |
| 71 |
l = i; |
| 72 |
n += y + 15; |
| 73 |
r += i; |
| 74 |
if ((fl & 1) && (((uintptr_t) &x | (uintptr_t) &y | (uintptr_t) &r |
| 75 |
| (uintptr_t) &l | (uintptr_t) &n) & 63) != 0) |
| 76 |
abort (); |
| 77 |
} |
| 78 |
x = xo; |
| 79 |
#pragma omp parallel |
| 80 |
{ |
| 81 |
#pragma omp for lastprivate (l2) allocate (h: l2, l3) lastprivate (conditional: l3) |
| 82 |
for (i = 0; i < 64; i++) |
| 83 |
{ |
| 84 |
l2[0] = i; |
| 85 |
l2[1] = i + 1; |
| 86 |
l2[2] = i + 2; |
| 87 |
l2[3] = i + 3; |
| 88 |
if (i < 37) |
| 89 |
l3 = i; |
| 90 |
if ((fl & 1) && (((uintptr_t) &l2[0] | (uintptr_t) &l3) & 63) != 0) |
| 91 |
abort (); |
| 92 |
} |
| 93 |
#pragma omp for reduction(+:p[2:px], q[:3], r2) allocate(h: p, q, r2) |
| 94 |
for (i = 0; i < 32; i++) |
| 95 |
{ |
| 96 |
p[2] += i; |
| 97 |
p[3] += 2 * i; |
| 98 |
q[0] += 3 * i; |
| 99 |
q[2] += 4 * i; |
| 100 |
r2[0] += 5 * i; |
| 101 |
r2[3] += 6 * i; |
| 102 |
/* Can't really rely on alignment of &p[0], the implementation could |
| 103 |
allocate the whole array or do what GCC does and allocate only part |
| 104 |
of it. */ |
| 105 |
if ((fl & 1) && (((uintptr_t) &q[0] | (uintptr_t) &r2[0]) & 63) != 0) |
| 106 |
abort (); |
| 107 |
} |
| 108 |
#pragma omp task private(y) firstprivate(x) allocate(x, y) |
| 109 |
{ |
| 110 |
int *volatile p1 = &x; |
| 111 |
int *volatile p2 = &y; |
| 112 |
if (x != 42) |
| 113 |
abort (); |
| 114 |
p1[0]++; |
| 115 |
p2[0] = 21; |
| 116 |
if (x != 43 || y != 21) |
| 117 |
abort (); |
| 118 |
if ((fl & 2) && (((uintptr_t) p1 | (uintptr_t) p2) & 63) != 0) |
| 119 |
abort (); |
| 120 |
} |
| 121 |
#pragma omp task private(y) firstprivate(x) allocate(h: x, y) |
| 122 |
{ |
| 123 |
int *volatile p1 = &x; |
| 124 |
int *volatile p2 = &y; |
| 125 |
if (x != 42) |
| 126 |
abort (); |
| 127 |
p1[0]++; |
| 128 |
p2[0] = 21; |
| 129 |
if (x != 43 || y != 21) |
| 130 |
abort (); |
| 131 |
if ((fl & 1) && (((uintptr_t) p1 | (uintptr_t) p2) & 63) != 0) |
| 132 |
abort (); |
| 133 |
} |
| 134 |
#pragma omp task private(y) firstprivate(s) allocate(s, y) |
| 135 |
{ |
| 136 |
int *volatile p1 = &s.a; |
| 137 |
int *volatile p2 = &s.b; |
| 138 |
int *volatile p3 = &y; |
| 139 |
if (s.a != 27 || s.b != 29) |
| 140 |
abort (); |
| 141 |
p1[0]++; |
| 142 |
p2[0]++; |
| 143 |
p3[0] = 21; |
| 144 |
if (s.a != 28 || s.b != 30 || y != 21) |
| 145 |
abort (); |
| 146 |
if ((fl & 2) && (((uintptr_t) p1 | (uintptr_t) p3) & 63) != 0) |
| 147 |
abort (); |
| 148 |
} |
| 149 |
#pragma omp task private(y) firstprivate(s) allocate(h: s, y) |
| 150 |
{ |
| 151 |
int *volatile p1 = &s.a; |
| 152 |
int *volatile p2 = &s.b; |
| 153 |
int *volatile p3 = &y; |
| 154 |
if (s.a != 27 || s.b != 29) |
| 155 |
abort (); |
| 156 |
p1[0]++; |
| 157 |
p2[0]++; |
| 158 |
p3[0] = 21; |
| 159 |
if (s.a != 28 || s.b != 30 || y != 21) |
| 160 |
abort (); |
| 161 |
if ((fl & 1) && (((uintptr_t) p1 | (uintptr_t) p3) & 63) != 0) |
| 162 |
abort (); |
| 163 |
} |
| 164 |
} |
| 165 |
if (r != 64 * 63 / 2 || l != 63 || n != 8 + 16 * 64) |
| 166 |
abort (); |
| 167 |
if (l2[0] != 63 || l2[1] != 63 + 1 || l2[2] != 63 + 2 || l2[3] != 63 + 3 || l3 != 36) |
| 168 |
abort (); |
| 169 |
if (p[2] != (32 * 31) / 2 || p[3] != 2 * (32 * 31) / 2 |
| 170 |
|| q[0] != 3 * (32 * 31) / 2 || q[2] != 4 * (32 * 31) / 2 |
| 171 |
|| r2[0] != 5 * (32 * 31) / 2 || r2[3] != 6 * (32 * 31) / 2) |
| 172 |
abort (); |
| 173 |
} |
| 174 |
|
| 175 |
int |
| 176 |
main () |
| 177 |
{ |
| 178 |
omp_alloctrait_t traits[3] |
| 179 |
= { { omp_atk_alignment, 64 }, |
| 180 |
{ omp_atk_fallback, omp_atv_null_fb } }; |
| 181 |
omp_allocator_handle_t a |
| 182 |
= omp_init_allocator (omp_default_mem_space, 2, traits); |
| 183 |
if (a == omp_null_allocator) |
| 184 |
abort (); |
| 185 |
omp_set_default_allocator (omp_default_mem_alloc); |
| 186 |
struct S s = { 27, 29 }; |
| 187 |
int p1[4], q1[3], px = 2; |
| 188 |
int *p = p1; |
| 189 |
int *q = q1; |
| 190 |
int x = 42, y = 0, r = 0, l, l2[4], l3, n = 8; |
| 191 |
foo (x, y, r, l, l2, l3, n, p, q, px, s, omp_null_allocator, 0); |
| 192 |
x = 42; y = 0; r = 0; l = -1; l2[0] = -1; l2[1] = -1; |
| 193 |
l2[2] = -1; l2[3] = -1; n = 8; |
| 194 |
foo (x, y, r, l, l2, l3, n, p, q, px, s, omp_default_mem_alloc, 0); |
| 195 |
x = 42; y = 0; r = 0; l = -1; l2[0] = -1; l2[1] = -1; |
| 196 |
l2[2] = -1; l2[3] = -1; n = 8; |
| 197 |
foo (x, y, r, l, l2, l3, n, p, q, px, s, a, 1); |
| 198 |
x = 42; y = 0; r = 0; l = -1; l2[0] = -1; l2[1] = -1; |
| 199 |
l2[2] = -1; l2[3] = -1; n = 8; |
| 200 |
omp_set_default_allocator (a); |
| 201 |
foo (x, y, r, l, l2, l3, n, p, q, px, s, omp_null_allocator, 3); |
| 202 |
x = 42; y = 0; r = 0; l = -1; l2[0] = -1; l2[1] = -1; |
| 203 |
l2[2] = -1; l2[3] = -1; n = 8; |
| 204 |
foo (x, y, r, l, l2, l3, n, p, q, px, s, omp_default_mem_alloc, 2); |
| 205 |
omp_destroy_allocator (a); |
| 206 |
return 0; |
| 207 |
} |