| 1 |
#include <omp.h> |
| 2 |
#include <stdlib.h> |
| 3 |
|
| 4 |
#pragma omp declare target |
| 5 |
__attribute__((noinline)) |
| 6 |
void |
| 7 |
foo (int x, int y, int z, int *a, int *b) |
| 8 |
{ |
| 9 |
if (x == 0) |
| 10 |
{ |
| 11 |
int i, j; |
| 12 |
for (i = 0; i < 64; i++) |
| 13 |
#pragma omp parallel for shared (a, b) |
| 14 |
for (j = 0; j < 32; j++) |
| 15 |
foo (3, i, j, a, b); |
| 16 |
} |
| 17 |
else if (x == 1) |
| 18 |
{ |
| 19 |
int i, j; |
| 20 |
#pragma omp distribute dist_schedule (static, 1) |
| 21 |
for (i = 0; i < 64; i++) |
| 22 |
#pragma omp parallel for shared (a, b) |
| 23 |
for (j = 0; j < 32; j++) |
| 24 |
foo (3, i, j, a, b); |
| 25 |
} |
| 26 |
else if (x == 2) |
| 27 |
{ |
| 28 |
int j; |
| 29 |
#pragma omp parallel for shared (a, b) |
| 30 |
for (j = 0; j < 32; j++) |
| 31 |
foo (3, y, j, a, b); |
| 32 |
} |
| 33 |
else |
| 34 |
{ |
| 35 |
#pragma omp atomic |
| 36 |
b[y] += z; |
| 37 |
#pragma omp atomic |
| 38 |
*a += 1; |
| 39 |
} |
| 40 |
} |
| 41 |
|
| 42 |
__attribute__((noinline)) |
| 43 |
int |
| 44 |
bar (int x, int y, int z) |
| 45 |
{ |
| 46 |
int a, b[64], i; |
| 47 |
a = 8; |
| 48 |
for (i = 0; i < 64; i++) |
| 49 |
b[i] = i; |
| 50 |
foo (x, y, z, &a, b); |
| 51 |
if (x == 0) |
| 52 |
{ |
| 53 |
if (a != 8 + 64 * 32) |
| 54 |
return 1; |
| 55 |
for (i = 0; i < 64; i++) |
| 56 |
if (b[i] != i + 31 * 32 / 2) |
| 57 |
return 1; |
| 58 |
} |
| 59 |
else if (x == 1) |
| 60 |
{ |
| 61 |
int c = omp_get_num_teams (); |
| 62 |
int d = omp_get_team_num (); |
| 63 |
int e = d; |
| 64 |
int f = 0; |
| 65 |
for (i = 0; i < 64; i++) |
| 66 |
if (i == e) |
| 67 |
{ |
| 68 |
if (b[i] != i + 31 * 32 / 2) |
| 69 |
return 1; |
| 70 |
f++; |
| 71 |
e = e + c; |
| 72 |
} |
| 73 |
else if (b[i] != i) |
| 74 |
return 1; |
| 75 |
if (a < 8 || a > 8 + f * 32) |
| 76 |
return 1; |
| 77 |
} |
| 78 |
else if (x == 2) |
| 79 |
{ |
| 80 |
if (a != 8 + 32) |
| 81 |
return 1; |
| 82 |
for (i = 0; i < 64; i++) |
| 83 |
if (b[i] != i + (i == y ? 31 * 32 / 2 : 0)) |
| 84 |
return 1; |
| 85 |
} |
| 86 |
else if (x == 3) |
| 87 |
{ |
| 88 |
if (a != 8 + 1) |
| 89 |
return 1; |
| 90 |
for (i = 0; i < 64; i++) |
| 91 |
if (b[i] != i + (i == y ? z : 0)) |
| 92 |
return 1; |
| 93 |
} |
| 94 |
return 0; |
| 95 |
} |
| 96 |
#pragma omp end declare target |
| 97 |
|
| 98 |
int |
| 99 |
main () |
| 100 |
{ |
| 101 |
int i, j, err = 0; |
| 102 |
#pragma omp target map(tofrom:err) |
| 103 |
#pragma omp teams reduction(+:err) |
| 104 |
err += bar (0, 0, 0); |
| 105 |
if (err) |
| 106 |
abort (); |
| 107 |
#pragma omp target map(tofrom:err) |
| 108 |
#pragma omp teams reduction(+:err) |
| 109 |
err += bar (1, 0, 0); |
| 110 |
if (err) |
| 111 |
abort (); |
| 112 |
#pragma omp target map(tofrom:err) |
| 113 |
#pragma omp teams reduction(+:err) |
| 114 |
#pragma omp distribute |
| 115 |
for (i = 0; i < 64; i++) |
| 116 |
err += bar (2, i, 0); |
| 117 |
if (err) |
| 118 |
abort (); |
| 119 |
#pragma omp target map(tofrom:err) |
| 120 |
#pragma omp teams reduction(+:err) |
| 121 |
#pragma omp distribute |
| 122 |
for (i = 0; i < 64; i++) |
| 123 |
#pragma omp parallel for reduction(+:err) |
| 124 |
for (j = 0; j < 32; j++) |
| 125 |
err += bar (3, i, j); |
| 126 |
if (err) |
| 127 |
abort (); |
| 128 |
return 0; |
| 129 |
} |