| 1 |
/* { dg-do run } */ |
| 2 |
/* { dg-options "-O2" } */ |
| 3 |
/* { dg-additional-options "-std=c99" { target c } } */ |
| 4 |
/* { dg-additional-options "-msse2" { target sse2_runtime } } */ |
| 5 |
/* { dg-additional-options "-mavx" { target avx_runtime } } */ |
| 6 |
|
| 7 |
#include <omp.h> |
| 8 |
#include <stdlib.h> |
| 9 |
|
| 10 |
#define N 64 |
| 11 |
|
| 12 |
int |
| 13 |
main () |
| 14 |
{ |
| 15 |
int p, *q, i, l; |
| 16 |
int a[N]; |
| 17 |
q = a; |
| 18 |
#pragma omp parallel master num_threads(4) private (p) shared(a) |
| 19 |
{ |
| 20 |
int i; |
| 21 |
p = omp_get_thread_num (); |
| 22 |
if (p != 0) |
| 23 |
abort (); |
| 24 |
#pragma omp taskloop nogroup |
| 25 |
for (i = 0; i < N; ++i) |
| 26 |
{ |
| 27 |
if (omp_get_thread_num () >= 4) |
| 28 |
abort (); |
| 29 |
a[i] = i; |
| 30 |
} |
| 31 |
} |
| 32 |
#pragma omp parallel num_threads(4) |
| 33 |
{ |
| 34 |
#pragma omp master taskloop lastprivate (i, l) firstprivate (q) |
| 35 |
for (i = 0; i != N; i = i + 1) |
| 36 |
l = q[i]; |
| 37 |
} |
| 38 |
if (i != N || l != N - 1) |
| 39 |
abort (); |
| 40 |
#pragma omp parallel master taskloop num_threads(4) \ |
| 41 |
lastprivate (i, l) firstprivate (q) |
| 42 |
for (i = 0; i < N - 5; i += 2) |
| 43 |
if (q[i] != i) |
| 44 |
abort (); |
| 45 |
else |
| 46 |
l = q[i]; |
| 47 |
if (i != N - 4 || l != N - 6) |
| 48 |
abort (); |
| 49 |
#pragma omp parallel master taskloop simd num_threads(4) |
| 50 |
for (i = 0; i < N; i++) |
| 51 |
a[i] = 2 * a[i]; |
| 52 |
if (i != N) |
| 53 |
abort (); |
| 54 |
#pragma omp parallel num_threads(4) |
| 55 |
{ |
| 56 |
int j; |
| 57 |
#pragma omp master taskloop simd collapse(2) |
| 58 |
for (i = 0; i < 2; i += 2) |
| 59 |
for (j = 0; j < N; j++) |
| 60 |
a[j] = a[j] + 1; |
| 61 |
} |
| 62 |
for (i = 0; i < N; i++) |
| 63 |
if (a[i] != 2 * i + 1) |
| 64 |
abort (); |
| 65 |
return 0; |
| 66 |
} |