| 1 |
/* { dg-do run } */ |
| 2 |
|
| 3 |
/* Like imperfect2.c, but enables offloading. */ |
| 4 |
|
| 5 |
static int f1count[3], f2count[3]; |
| 6 |
static int g1count[3], g2count[3]; |
| 7 |
#pragma omp declare target enter (f1count, f2count) |
| 8 |
#pragma omp declare target enter (g1count, g2count) |
| 9 |
|
| 10 |
#ifndef __cplusplus |
| 11 |
extern void abort (void); |
| 12 |
#else |
| 13 |
extern "C" void abort (void); |
| 14 |
#endif |
| 15 |
|
| 16 |
int f1 (int depth, int iter) |
| 17 |
{ |
| 18 |
#pragma omp atomic |
| 19 |
f1count[depth]++; |
| 20 |
return iter; |
| 21 |
} |
| 22 |
|
| 23 |
int f2 (int depth, int iter) |
| 24 |
{ |
| 25 |
#pragma omp atomic |
| 26 |
f2count[depth]++; |
| 27 |
return iter; |
| 28 |
} |
| 29 |
|
| 30 |
int g1 (int depth, int iter) |
| 31 |
{ |
| 32 |
#pragma omp atomic |
| 33 |
g1count[depth]++; |
| 34 |
return iter; |
| 35 |
} |
| 36 |
|
| 37 |
int g2 (int depth, int iter) |
| 38 |
{ |
| 39 |
#pragma omp atomic |
| 40 |
g2count[depth]++; |
| 41 |
return iter; |
| 42 |
} |
| 43 |
|
| 44 |
void s1 (int a1, int a2, int a3) |
| 45 |
{ |
| 46 |
int i, j, k; |
| 47 |
|
| 48 |
#pragma omp target parallel for collapse(3) map(always, tofrom:f1count, f2count, g1count, g2count) |
| 49 |
for (i = 0; i < a1; i++) |
| 50 |
{ |
| 51 |
f1 (0, i); |
| 52 |
{ |
| 53 |
g1 (0, i); |
| 54 |
for (j = 0; j < a2; j++) |
| 55 |
{ |
| 56 |
f1 (1, j); |
| 57 |
{ |
| 58 |
g1 (1, j); |
| 59 |
for (k = 0; k < a3; k++) |
| 60 |
{ |
| 61 |
f1 (2, k); |
| 62 |
{ |
| 63 |
g1 (2, k); |
| 64 |
g2 (2, k); |
| 65 |
} |
| 66 |
f2 (2, k); |
| 67 |
} |
| 68 |
g2 (1, j); |
| 69 |
} |
| 70 |
f2 (1, j); |
| 71 |
} |
| 72 |
g2 (0, i); |
| 73 |
} |
| 74 |
f2 (0, i); |
| 75 |
} |
| 76 |
} |
| 77 |
|
| 78 |
int |
| 79 |
main (void) |
| 80 |
{ |
| 81 |
f1count[0] = 0; |
| 82 |
f1count[1] = 0; |
| 83 |
f1count[2] = 0; |
| 84 |
f2count[0] = 0; |
| 85 |
f2count[1] = 0; |
| 86 |
f2count[2] = 0; |
| 87 |
|
| 88 |
g1count[0] = 0; |
| 89 |
g1count[1] = 0; |
| 90 |
g1count[2] = 0; |
| 91 |
g2count[0] = 0; |
| 92 |
g2count[1] = 0; |
| 93 |
g2count[2] = 0; |
| 94 |
|
| 95 |
s1 (3, 4, 5); |
| 96 |
|
| 97 |
/* All intervening code at the same depth must be executed the same |
| 98 |
number of times. */ |
| 99 |
if (f1count[0] != f2count[0]) abort (); |
| 100 |
if (f1count[1] != f2count[1]) abort (); |
| 101 |
if (f1count[2] != f2count[2]) abort (); |
| 102 |
if (g1count[0] != f1count[0]) abort (); |
| 103 |
if (g2count[0] != f1count[0]) abort (); |
| 104 |
if (g1count[1] != f1count[1]) abort (); |
| 105 |
if (g2count[1] != f1count[1]) abort (); |
| 106 |
if (g1count[2] != f1count[2]) abort (); |
| 107 |
if (g2count[2] != f1count[2]) abort (); |
| 108 |
|
| 109 |
/* Intervening code must be executed at least as many times as the loop |
| 110 |
that encloses it. */ |
| 111 |
if (f1count[0] < 3) abort (); |
| 112 |
if (f1count[1] < 3 * 4) abort (); |
| 113 |
|
| 114 |
/* Intervening code must not be executed more times than the number |
| 115 |
of logical iterations. */ |
| 116 |
if (f1count[0] > 3 * 4 * 5) abort (); |
| 117 |
if (f1count[1] > 3 * 4 * 5) abort (); |
| 118 |
|
| 119 |
/* Check that the innermost loop body is executed exactly the number |
| 120 |
of logical iterations expected. */ |
| 121 |
if (f1count[2] != 3 * 4 * 5) abort (); |
| 122 |
} |