| 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 *p, int *q, int px, omp_allocator_handle_t h, int fl) |
| 9 |
{ |
| 10 |
int y = 0, r = 0, i, i1, l, l2[4], l3, n = 8; |
| 11 |
int i2, j2, n2 = 9, l4; |
| 12 |
int i3, j3, n3 = 10, l5; |
| 13 |
int i4, j4, n4 = 11, l6; |
| 14 |
int i5, n5; |
| 15 |
int v[x], w[x]; |
| 16 |
int r2[4] = { 0, 0, 0, 0 }; |
| 17 |
int xo = x; |
| 18 |
struct S s = { 27, 29 }; |
| 19 |
for (i = 0; i < 4; i++) |
| 20 |
p[i] = 0; |
| 21 |
for (i = 0; i < 3; i++) |
| 22 |
q[i] = 0; |
| 23 |
for (i = 0; i < x; i++) |
| 24 |
w[i] = i; |
| 25 |
#pragma omp parallel private (y, v) firstprivate (x) allocate (align (32) : x) allocate (align (128) : y) allocate (v) |
| 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 |
v[0] = 7; |
| 35 |
v[41] = 8; |
| 36 |
#pragma omp barrier |
| 37 |
if (x != 43 || y != 1) |
| 38 |
abort (); |
| 39 |
if (v[0] != 7 || v[41] != 8) |
| 40 |
abort (); |
| 41 |
if ((fl & 2) && (((uintptr_t) p1 | (uintptr_t) p2 |
| 42 |
| (uintptr_t) &v[0]) & 63) != 0) |
| 43 |
abort (); |
| 44 |
if ((((uintptr_t) p1) & 31) != 0) |
| 45 |
abort (); |
| 46 |
if ((((uintptr_t) p2) & 127) != 0) |
| 47 |
abort (); |
| 48 |
} |
| 49 |
x = xo; |
| 50 |
#pragma omp teams |
| 51 |
#pragma omp parallel private (y) firstprivate (x, w) allocate (allocator (h), align (32) : x) allocate (align (128), allocator (h):y) allocate(allocator(h):w) |
| 52 |
{ |
| 53 |
int *volatile p1 = &x; |
| 54 |
int *volatile p2 = &y; |
| 55 |
if (x != 42 || w[17] != 17 || w[41] != 41) |
| 56 |
abort (); |
| 57 |
#pragma omp barrier |
| 58 |
*p2 = 1; |
| 59 |
p1[0]++; |
| 60 |
w[19]++; |
| 61 |
#pragma omp barrier |
| 62 |
if (x != 43 || y != 1 || w[19] != 20) |
| 63 |
abort (); |
| 64 |
if ((fl & 1) && (((uintptr_t) p1 | (uintptr_t) p2 |
| 65 |
| (uintptr_t) &w[0]) & 63) != 0) |
| 66 |
abort (); |
| 67 |
if ((((uintptr_t) p1) & 31) != 0) |
| 68 |
abort (); |
| 69 |
if ((((uintptr_t) p2) & 127) != 0) |
| 70 |
abort (); |
| 71 |
} |
| 72 |
x = xo; |
| 73 |
#pragma omp parallel for private (y) firstprivate (x) allocate (allocator (h), align (32) : x, y, r) allocate (align (128), allocator (h) : l, n) reduction(+: r) lastprivate (l) linear (n: 16) |
| 74 |
for (i = 0; i < 64; i++) |
| 75 |
{ |
| 76 |
if (x != 42) |
| 77 |
abort (); |
| 78 |
y = 1; |
| 79 |
l = i; |
| 80 |
n += y + 15; |
| 81 |
r += i; |
| 82 |
if ((fl & 1) && (((uintptr_t) &x | (uintptr_t) &y | (uintptr_t) &r |
| 83 |
| (uintptr_t) &l | (uintptr_t) &n) & 63) != 0) |
| 84 |
abort (); |
| 85 |
if ((((uintptr_t) &x | (uintptr_t) &y | (uintptr_t) &r) & 31) != 0) |
| 86 |
abort (); |
| 87 |
if ((((uintptr_t) &l | (uintptr_t) &n) & 127) != 0) |
| 88 |
abort (); |
| 89 |
} |
| 90 |
x = xo; |
| 91 |
#pragma omp parallel |
| 92 |
{ |
| 93 |
#pragma omp for lastprivate (l2) private (i1) allocate (allocator (h): l2, l3) allocate (allocator (h),align(16): i1) lastprivate (conditional: l3) |
| 94 |
for (i1 = 0; i1 < 64; i1++) |
| 95 |
{ |
| 96 |
l2[0] = i1; |
| 97 |
l2[1] = i1 + 1; |
| 98 |
l2[2] = i1 + 2; |
| 99 |
l2[3] = i1 + 3; |
| 100 |
if (i1 < 37) |
| 101 |
l3 = i1; |
| 102 |
if ((fl & 1) && (((uintptr_t) &l2[0] | (uintptr_t) &l3 | (uintptr_t) &i1) & 63) != 0) |
| 103 |
abort (); |
| 104 |
if ((((uintptr_t) &i1) & 15) != 0) |
| 105 |
abort (); |
| 106 |
} |
| 107 |
#pragma omp for collapse(2) lastprivate(l4, i2, j2) linear (n2:17) allocate (allocator (h), align (8): n2, l4, i2, j2) |
| 108 |
for (i2 = 3; i2 < 5; i2++) |
| 109 |
for (j2 = 17; j2 < 22; j2 += 2) |
| 110 |
{ |
| 111 |
n2 += 17; |
| 112 |
l4 = i2 * 31 + j2; |
| 113 |
if ((fl & 1) && (((uintptr_t) &l4 | (uintptr_t) &n2 |
| 114 |
| (uintptr_t) &i2 | (uintptr_t) &j2) & 63) != 0) |
| 115 |
abort (); |
| 116 |
if ((((uintptr_t) &l4 | (uintptr_t) &n2 | (uintptr_t) &i2 | (uintptr_t) &j2) & 7) != 0) |
| 117 |
abort (); |
| 118 |
} |
| 119 |
#pragma omp for collapse(2) lastprivate(l5, i3, j3) linear (n3:17) schedule (static, 3) allocate (align (16): n3, l5, i3, j3) |
| 120 |
for (i3 = 3; i3 < 5; i3++) |
| 121 |
for (j3 = 17; j3 < 23; j3 += 2) |
| 122 |
{ |
| 123 |
n3 += 17; |
| 124 |
l5 = i3 * 31 + j3; |
| 125 |
if ((fl & 2) && (((uintptr_t) &l5 | (uintptr_t) &n3 |
| 126 |
| (uintptr_t) &i3 | (uintptr_t) &j3) & 63) != 0) |
| 127 |
abort (); |
| 128 |
if ((((uintptr_t) &l5 | (uintptr_t) &n3 | (uintptr_t) &i3 | (uintptr_t) &j3) & 15) != 0) |
| 129 |
abort (); |
| 130 |
} |
| 131 |
#pragma omp for collapse(2) lastprivate(l6, i4, j4) linear (n4:17) schedule (dynamic) allocate (align (16), allocator (h): n4, l6, i4, j4) |
| 132 |
for (i4 = 3; i4 < 5; i4++) |
| 133 |
for (j4 = 17; j4 < 22; j4 += 2) |
| 134 |
{ |
| 135 |
n4 += 17; |
| 136 |
l6 = i4 * 31 + j4; |
| 137 |
if ((fl & 1) && (((uintptr_t) &l6 | (uintptr_t) &n4 |
| 138 |
| (uintptr_t) &i4 | (uintptr_t) &j4) & 63) != 0) |
| 139 |
abort (); |
| 140 |
if ((((uintptr_t) &l6 | (uintptr_t) &n4 | (uintptr_t) &i4 | (uintptr_t) &j4) & 15) != 0) |
| 141 |
abort (); |
| 142 |
} |
| 143 |
#pragma omp for lastprivate (i5) allocate (align (32): i5) |
| 144 |
for (i5 = 1; i5 < 17; i5 += 3) |
| 145 |
{ |
| 146 |
if ((fl & 2) && (((uintptr_t) &i5) & 63) != 0) |
| 147 |
abort (); |
| 148 |
if ((((uintptr_t) &i5) & 31) != 0) |
| 149 |
abort (); |
| 150 |
} |
| 151 |
#pragma omp for reduction(+:p[2:px], q[:3], r2) allocate(align (16), allocator (h): p, q, r2) |
| 152 |
for (i = 0; i < 32; i++) |
| 153 |
{ |
| 154 |
p[2] += i; |
| 155 |
p[3] += 2 * i; |
| 156 |
q[0] += 3 * i; |
| 157 |
q[2] += 4 * i; |
| 158 |
r2[0] += 5 * i; |
| 159 |
r2[3] += 6 * i; |
| 160 |
/* Can't really rely on alignment of &p[0], the implementation could |
| 161 |
allocate the whole array or do what GCC does and allocate only part |
| 162 |
of it. */ |
| 163 |
if ((fl & 1) && (((uintptr_t) &q[0] | (uintptr_t) &r2[0]) & 63) != 0) |
| 164 |
abort (); |
| 165 |
if ((((uintptr_t) &q[0] | (uintptr_t) &r2[0]) & 15) != 0) |
| 166 |
abort (); |
| 167 |
} |
| 168 |
#pragma omp task private(y) firstprivate(x) allocate(align (8) : x, y) |
| 169 |
{ |
| 170 |
int *volatile p1 = &x; |
| 171 |
int *volatile p2 = &y; |
| 172 |
if (x != 42) |
| 173 |
abort (); |
| 174 |
p1[0]++; |
| 175 |
p2[0] = 21; |
| 176 |
if (x != 43 || y != 21) |
| 177 |
abort (); |
| 178 |
if ((fl & 2) && (((uintptr_t) p1 | (uintptr_t) p2) & 63) != 0) |
| 179 |
abort (); |
| 180 |
if ((((uintptr_t) p1 | (uintptr_t) p2) & 7) != 0) |
| 181 |
abort (); |
| 182 |
} |
| 183 |
#pragma omp task private(y) firstprivate(x) allocate(allocator (h),align(32): x, y) |
| 184 |
{ |
| 185 |
int *volatile p1 = &x; |
| 186 |
int *volatile p2 = &y; |
| 187 |
if (x != 42) |
| 188 |
abort (); |
| 189 |
p1[0]++; |
| 190 |
p2[0] = 21; |
| 191 |
if (x != 43 || y != 21) |
| 192 |
abort (); |
| 193 |
if ((fl & 1) && (((uintptr_t) p1 | (uintptr_t) p2) & 63) != 0) |
| 194 |
abort (); |
| 195 |
if ((((uintptr_t) p1 | (uintptr_t) p2) & 31) != 0) |
| 196 |
abort (); |
| 197 |
} |
| 198 |
#pragma omp task private(y) firstprivate(s) allocate(align(16): s, y) |
| 199 |
{ |
| 200 |
int *volatile p1 = &s.a; |
| 201 |
int *volatile p2 = &s.b; |
| 202 |
int *volatile p3 = &y; |
| 203 |
if (s.a != 27 || s.b != 29) |
| 204 |
abort (); |
| 205 |
p1[0]++; |
| 206 |
p2[0]++; |
| 207 |
p3[0] = 21; |
| 208 |
if (s.a != 28 || s.b != 30 || y != 21) |
| 209 |
abort (); |
| 210 |
if ((fl & 2) && (((uintptr_t) p1 | (uintptr_t) p3) & 63) != 0) |
| 211 |
abort (); |
| 212 |
if ((((uintptr_t) p1 | (uintptr_t) p3) & 15) != 0) |
| 213 |
abort (); |
| 214 |
} |
| 215 |
#pragma omp task private(y) firstprivate(s) allocate(allocator (h): s, y) |
| 216 |
{ |
| 217 |
int *volatile p1 = &s.a; |
| 218 |
int *volatile p2 = &s.b; |
| 219 |
int *volatile p3 = &y; |
| 220 |
if (s.a != 27 || s.b != 29) |
| 221 |
abort (); |
| 222 |
p1[0]++; |
| 223 |
p2[0]++; |
| 224 |
p3[0] = 21; |
| 225 |
if (s.a != 28 || s.b != 30 || y != 21) |
| 226 |
abort (); |
| 227 |
if ((fl & 1) && (((uintptr_t) p1 | (uintptr_t) p3) & 63) != 0) |
| 228 |
abort (); |
| 229 |
} |
| 230 |
} |
| 231 |
if (r != 64 * 63 / 2 || l != 63 || n != 8 + 16 * 64) |
| 232 |
abort (); |
| 233 |
if (l2[0] != 63 || l2[1] != 63 + 1 || l2[2] != 63 + 2 || l2[3] != 63 + 3 || l3 != 36) |
| 234 |
abort (); |
| 235 |
if (i2 != 5 || j2 != 23 || n2 != 9 + 6 * 17 || l4 != 4 * 31 + 21) |
| 236 |
abort (); |
| 237 |
if (i3 != 5 || j3 != 23 || n3 != 10 + 6 * 17 || l5 != 4 * 31 + 21) |
| 238 |
abort (); |
| 239 |
if (i4 != 5 || j4 != 23 || n4 != 11 + 6 * 17 || l6 != 4 * 31 + 21) |
| 240 |
abort (); |
| 241 |
if (i5 != 19) |
| 242 |
abort (); |
| 243 |
if (p[2] != (32 * 31) / 2 || p[3] != 2 * (32 * 31) / 2 |
| 244 |
|| q[0] != 3 * (32 * 31) / 2 || q[2] != 4 * (32 * 31) / 2 |
| 245 |
|| r2[0] != 5 * (32 * 31) / 2 || r2[3] != 6 * (32 * 31) / 2) |
| 246 |
abort (); |
| 247 |
r = 0; |
| 248 |
x = xo; |
| 249 |
#pragma omp parallel shared (x, y, r, n5) firstprivate (h) |
| 250 |
{ |
| 251 |
#pragma omp masked |
| 252 |
n5 = omp_get_num_threads (); |
| 253 |
#pragma omp scope private (y) firstprivate (x) reduction(+:r) \ |
| 254 |
allocate (allocator (h), align (32): x) \ |
| 255 |
allocate (align (128), allocator (h): y) \ |
| 256 |
allocate (align (32), allocator (h): r) |
| 257 |
{ |
| 258 |
int *volatile p1 = &x; |
| 259 |
int *volatile p2 = &y; |
| 260 |
if (x != 42) |
| 261 |
abort (); |
| 262 |
#pragma omp barrier |
| 263 |
*p2 = 1; |
| 264 |
p1[0]++; |
| 265 |
r++; |
| 266 |
#pragma omp barrier |
| 267 |
if (x != 43 || y != 1 || r != 1) |
| 268 |
abort (); |
| 269 |
if ((fl & 1) && (((uintptr_t) p1 | (uintptr_t) p2 |
| 270 |
| (uintptr_t) &r) & 63) != 0) |
| 271 |
abort (); |
| 272 |
if ((((uintptr_t) p1 | (uintptr_t) &r) & 31) != 0) |
| 273 |
abort (); |
| 274 |
if ((((uintptr_t) p2) & 127) != 0) |
| 275 |
abort (); |
| 276 |
} |
| 277 |
} |
| 278 |
if (x != 42 || r != n5) |
| 279 |
abort (); |
| 280 |
} |
| 281 |
|
| 282 |
void |
| 283 |
bar (int x, omp_allocator_handle_t h) |
| 284 |
{ |
| 285 |
int y = 0, r = 0, i, i1, l, l2[4], l3, n = 8; |
| 286 |
int i2, j2, n2 = 9, l4; |
| 287 |
int i3, j3, n3 = 10, l5; |
| 288 |
int i4, j4, n4 = 11, l6; |
| 289 |
int i5; |
| 290 |
struct S s = { 27, 29 }; |
| 291 |
int xo = x; |
| 292 |
#pragma omp parallel private (y) firstprivate (x) allocate (x, y) |
| 293 |
{ |
| 294 |
if (x != 42) |
| 295 |
abort (); |
| 296 |
#pragma omp barrier |
| 297 |
y = 1; |
| 298 |
x++; |
| 299 |
#pragma omp barrier |
| 300 |
if (x != 43 || y != 1) |
| 301 |
abort (); |
| 302 |
} |
| 303 |
x = xo; |
| 304 |
#pragma omp teams |
| 305 |
#pragma omp parallel private (y) firstprivate (x) allocate (allocator (h): x, y) |
| 306 |
{ |
| 307 |
if (x != 42) |
| 308 |
abort (); |
| 309 |
#pragma omp barrier |
| 310 |
y = 1; |
| 311 |
x++; |
| 312 |
#pragma omp barrier |
| 313 |
if (x != 43 || y != 1) |
| 314 |
abort (); |
| 315 |
} |
| 316 |
x = xo; |
| 317 |
#pragma omp parallel for private (y) firstprivate (x) allocate (allocator (h): x, y, r, l, n) reduction(+: r) lastprivate (l) linear (n: 16) |
| 318 |
for (i = 0; i < 64; i++) |
| 319 |
{ |
| 320 |
if (x != 42) |
| 321 |
abort (); |
| 322 |
y = 1; |
| 323 |
l = i; |
| 324 |
n += y + 15; |
| 325 |
r += i; |
| 326 |
} |
| 327 |
x = xo; |
| 328 |
#pragma omp parallel |
| 329 |
{ |
| 330 |
#pragma omp for lastprivate (l2) private (i1) allocate (allocator (h): l2, l3, i1) lastprivate (conditional: l3) |
| 331 |
for (i1 = 0; i1 < 64; i1++) |
| 332 |
{ |
| 333 |
l2[0] = i1; |
| 334 |
l2[1] = i1 + 1; |
| 335 |
l2[2] = i1 + 2; |
| 336 |
l2[3] = i1 + 3; |
| 337 |
if (i1 < 37) |
| 338 |
l3 = i1; |
| 339 |
} |
| 340 |
#pragma omp for collapse(2) lastprivate(l4, i2, j2) linear (n2:17) allocate (allocator (h): n2, l4, i2, j2) |
| 341 |
for (i2 = 3; i2 < 5; i2++) |
| 342 |
for (j2 = 17; j2 < 22; j2 += 2) |
| 343 |
{ |
| 344 |
n2 += 17; |
| 345 |
l4 = i2 * 31 + j2; |
| 346 |
} |
| 347 |
#pragma omp for collapse(2) lastprivate(l5, i3, j3) linear (n3:17) schedule (static, 3) allocate (n3, l5, i3, j3) |
| 348 |
for (i3 = 3; i3 < 5; i3++) |
| 349 |
for (j3 = 17; j3 < 23; j3 += 2) |
| 350 |
{ |
| 351 |
n3 += 17; |
| 352 |
l5 = i3 * 31 + j3; |
| 353 |
} |
| 354 |
#pragma omp for collapse(2) lastprivate(l6, i4, j4) linear (n4:17) schedule (dynamic) allocate (allocator (h): n4, l6, i4, j4) |
| 355 |
for (i4 = 3; i4 < 5; i4++) |
| 356 |
for (j4 = 17; j4 < 22; j4 += 2) |
| 357 |
{ |
| 358 |
n4 += 17; |
| 359 |
l6 = i4 * 31 + j4; |
| 360 |
} |
| 361 |
#pragma omp for lastprivate (i5) allocate (i5) |
| 362 |
for (i5 = 1; i5 < 17; i5 += 3) |
| 363 |
; |
| 364 |
#pragma omp task private(y) firstprivate(x) allocate(x, y) |
| 365 |
{ |
| 366 |
if (x != 42) |
| 367 |
abort (); |
| 368 |
x++; |
| 369 |
y = 21; |
| 370 |
if (x != 43 || y != 21) |
| 371 |
abort (); |
| 372 |
} |
| 373 |
#pragma omp task private(y) firstprivate(x) allocate(allocator (h): x, y) |
| 374 |
{ |
| 375 |
if (x != 42) |
| 376 |
abort (); |
| 377 |
x++; |
| 378 |
y = 21; |
| 379 |
if (x != 43 || y != 21) |
| 380 |
abort (); |
| 381 |
} |
| 382 |
#pragma omp task private(y) firstprivate(s) allocate(s, y) |
| 383 |
{ |
| 384 |
if (s.a != 27 || s.b != 29) |
| 385 |
abort (); |
| 386 |
s.a++; |
| 387 |
s.b++; |
| 388 |
y = 21; |
| 389 |
if (s.a != 28 || s.b != 30 || y != 21) |
| 390 |
abort (); |
| 391 |
} |
| 392 |
#pragma omp task private(y) firstprivate(s) allocate(allocator (h), align (16): s, y) |
| 393 |
{ |
| 394 |
if (s.a != 27 || s.b != 29) |
| 395 |
abort (); |
| 396 |
s.a++; |
| 397 |
s.b++; |
| 398 |
y = 21; |
| 399 |
if (s.a != 28 || s.b != 30 || y != 21) |
| 400 |
abort (); |
| 401 |
} |
| 402 |
} |
| 403 |
if (r != 64 * 63 / 2 || l != 63 || n != 8 + 16 * 64) |
| 404 |
abort (); |
| 405 |
if (l2[0] != 63 || l2[1] != 63 + 1 || l2[2] != 63 + 2 || l2[3] != 63 + 3 || l3 != 36) |
| 406 |
abort (); |
| 407 |
if (i2 != 5 || j2 != 23 || n2 != 9 + 6 * 17 || l4 != 4 * 31 + 21) |
| 408 |
abort (); |
| 409 |
if (i3 != 5 || j3 != 23 || n3 != 10 + 6 * 17 || l5 != 4 * 31 + 21) |
| 410 |
abort (); |
| 411 |
if (i4 != 5 || j4 != 23 || n4 != 11 + 6 * 17 || l6 != 4 * 31 + 21) |
| 412 |
abort (); |
| 413 |
if (i5 != 19) |
| 414 |
abort (); |
| 415 |
} |
| 416 |
|
| 417 |
int |
| 418 |
main () |
| 419 |
{ |
| 420 |
omp_alloctrait_t traits[3] |
| 421 |
= { { omp_atk_alignment, 64 }, |
| 422 |
{ omp_atk_fallback, omp_atv_null_fb } }; |
| 423 |
omp_allocator_handle_t a |
| 424 |
= omp_init_allocator (omp_default_mem_space, 2, traits); |
| 425 |
int p[4], q[3]; |
| 426 |
if (a == omp_null_allocator) |
| 427 |
abort (); |
| 428 |
omp_set_default_allocator (omp_default_mem_alloc); |
| 429 |
foo (42, p, q, 2, omp_null_allocator, 0); |
| 430 |
foo (42, p, q, 2, omp_default_mem_alloc, 0); |
| 431 |
foo (42, p, q, 2, a, 1); |
| 432 |
omp_set_default_allocator (a); |
| 433 |
foo (42, p, q, 2, omp_null_allocator, 3); |
| 434 |
foo (42, p, q, 2, omp_default_mem_alloc, 2); |
| 435 |
bar (42, a); |
| 436 |
omp_destroy_allocator (a); |
| 437 |
return 0; |
| 438 |
} |