| 1 |
/* { dg-do run } */ |
| 2 |
/* { dg-additional-options "-foffload-options=nvptx-none=-latomic" { target offload_target_nvptx } } */ |
| 3 |
|
| 4 |
#include <stdlib.h> |
| 5 |
|
| 6 |
#define N 512 |
| 7 |
|
| 8 |
#define GENERATE_TEST(T) \ |
| 9 |
int test_##T (void) \ |
| 10 |
{ \ |
| 11 |
T a[N], res = 0; \ |
| 12 |
\ |
| 13 |
for (int i = 0; i < N; ++i) \ |
| 14 |
a[i] = i & 1; \ |
| 15 |
\ |
| 16 |
_Pragma("omp target teams distribute reduction(||:res) defaultmap(tofrom:scalar)") \ |
| 17 |
for (int i = 0; i < N; ++i) \ |
| 18 |
res = res || a[i]; \ |
| 19 |
\ |
| 20 |
/* res should be non-zero. */\ |
| 21 |
if (!res) \ |
| 22 |
return 1; \ |
| 23 |
\ |
| 24 |
_Pragma("omp target teams distribute reduction(&&:res) defaultmap(tofrom:scalar)") \ |
| 25 |
for (int i = 0; i < N; ++i) \ |
| 26 |
res = res && a[i]; \ |
| 27 |
\ |
| 28 |
/* res should be zero. */ \ |
| 29 |
return res; \ |
| 30 |
} |
| 31 |
|
| 32 |
GENERATE_TEST(char) |
| 33 |
GENERATE_TEST(short) |
| 34 |
GENERATE_TEST(int) |
| 35 |
GENERATE_TEST(long) |
| 36 |
#ifdef __SIZEOF_INT128__ |
| 37 |
GENERATE_TEST(__int128) |
| 38 |
#endif |
| 39 |
|
| 40 |
int main(void) |
| 41 |
{ |
| 42 |
if (test_char ()) |
| 43 |
abort (); |
| 44 |
if (test_short ()) |
| 45 |
abort (); |
| 46 |
if (test_int ()) |
| 47 |
abort (); |
| 48 |
if (test_long ()) |
| 49 |
abort (); |
| 50 |
#ifdef __SIZEOF_INT128__ |
| 51 |
if (test___int128 ()) |
| 52 |
abort (); |
| 53 |
#endif |
| 54 |
} |