reduction-16.c 1.1 KB

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