| 1 |
// { dg-require-effective-target size32plus } |
| 2 |
|
| 3 |
extern "C" void abort (); |
| 4 |
|
| 5 |
struct S { |
| 6 |
inline S (); |
| 7 |
inline ~S (); |
| 8 |
inline S (const S &); |
| 9 |
inline S & operator= (const S &); |
| 10 |
int s; |
| 11 |
}; |
| 12 |
|
| 13 |
S::S () : s (0) |
| 14 |
{ |
| 15 |
} |
| 16 |
|
| 17 |
S::~S () |
| 18 |
{ |
| 19 |
} |
| 20 |
|
| 21 |
S::S (const S &x) |
| 22 |
{ |
| 23 |
s = x.s; |
| 24 |
} |
| 25 |
|
| 26 |
S & |
| 27 |
S::operator= (const S &x) |
| 28 |
{ |
| 29 |
s = x.s; |
| 30 |
return *this; |
| 31 |
} |
| 32 |
|
| 33 |
static inline void |
| 34 |
ini (S &x) |
| 35 |
{ |
| 36 |
x.s = 0; |
| 37 |
} |
| 38 |
|
| 39 |
S r, a[1024], b[1024]; |
| 40 |
|
| 41 |
#pragma omp declare reduction (+: S: omp_out.s += omp_in.s) |
| 42 |
#pragma omp declare reduction (plus: S: omp_out.s += omp_in.s) initializer (ini (omp_priv)) |
| 43 |
|
| 44 |
__attribute__((noipa)) void |
| 45 |
foo (S *a, S *b, S &r) |
| 46 |
{ |
| 47 |
#pragma omp for reduction (inscan, +:r) |
| 48 |
for (int i = 0; i < 1024; i++) |
| 49 |
{ |
| 50 |
r.s += a[i].s; |
| 51 |
#pragma omp scan inclusive(r) |
| 52 |
b[i] = r; |
| 53 |
} |
| 54 |
} |
| 55 |
|
| 56 |
__attribute__((noipa)) S |
| 57 |
bar () |
| 58 |
{ |
| 59 |
S s; |
| 60 |
#pragma omp parallel |
| 61 |
#pragma omp for reduction (inscan, plus:s) |
| 62 |
for (int i = 0; i < 1024; i++) |
| 63 |
{ |
| 64 |
s.s += 2 * a[i].s; |
| 65 |
#pragma omp scan inclusive(s) |
| 66 |
b[i] = s; |
| 67 |
} |
| 68 |
return s; |
| 69 |
} |
| 70 |
|
| 71 |
__attribute__((noipa)) void |
| 72 |
baz (S *a, S *b, S &r) |
| 73 |
{ |
| 74 |
#pragma omp parallel for reduction (inscan, +:r) |
| 75 |
for (int i = 0; i < 1024; i++) |
| 76 |
{ |
| 77 |
r.s += a[i].s; |
| 78 |
#pragma omp scan inclusive(r) |
| 79 |
b[i] = r; |
| 80 |
} |
| 81 |
} |
| 82 |
|
| 83 |
__attribute__((noipa)) S |
| 84 |
qux () |
| 85 |
{ |
| 86 |
S s; |
| 87 |
#pragma omp parallel for reduction (inscan, plus:s) |
| 88 |
for (int i = 0; i < 1024; i++) |
| 89 |
{ |
| 90 |
s.s += 2 * a[i].s; |
| 91 |
#pragma omp scan inclusive(s) |
| 92 |
b[i] = s; |
| 93 |
} |
| 94 |
return s; |
| 95 |
} |
| 96 |
|
| 97 |
int |
| 98 |
main () |
| 99 |
{ |
| 100 |
S s; |
| 101 |
for (int i = 0; i < 1024; ++i) |
| 102 |
{ |
| 103 |
a[i].s = i; |
| 104 |
b[i].s = -1; |
| 105 |
asm ("" : "+g" (i)); |
| 106 |
} |
| 107 |
#pragma omp parallel |
| 108 |
foo (a, b, r); |
| 109 |
if (r.s != 1024 * 1023 / 2) |
| 110 |
abort (); |
| 111 |
for (int i = 0; i < 1024; ++i) |
| 112 |
{ |
| 113 |
s.s += i; |
| 114 |
if (b[i].s != s.s) |
| 115 |
abort (); |
| 116 |
else |
| 117 |
b[i].s = 25; |
| 118 |
} |
| 119 |
if (bar ().s != 1024 * 1023) |
| 120 |
abort (); |
| 121 |
s.s = 0; |
| 122 |
for (int i = 0; i < 1024; ++i) |
| 123 |
{ |
| 124 |
s.s += 2 * i; |
| 125 |
if (b[i].s != s.s) |
| 126 |
abort (); |
| 127 |
} |
| 128 |
r.s = 0; |
| 129 |
baz (a, b, r); |
| 130 |
if (r.s != 1024 * 1023 / 2) |
| 131 |
abort (); |
| 132 |
s.s = 0; |
| 133 |
for (int i = 0; i < 1024; ++i) |
| 134 |
{ |
| 135 |
s.s += i; |
| 136 |
if (b[i].s != s.s) |
| 137 |
abort (); |
| 138 |
else |
| 139 |
b[i].s = 25; |
| 140 |
} |
| 141 |
if (qux ().s != 1024 * 1023) |
| 142 |
abort (); |
| 143 |
s.s = 0; |
| 144 |
for (int i = 0; i < 1024; ++i) |
| 145 |
{ |
| 146 |
s.s += 2 * i; |
| 147 |
if (b[i].s != s.s) |
| 148 |
abort (); |
| 149 |
} |
| 150 |
} |