reduction-6.c 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. /* { dg-additional-options "-foffload-options=nvptx-none=-latomic" { target { offload_target_nvptx } } } */
  2. /* C / C++'s logical AND and OR operators take any scalar argument
  3. which compares (un)equal to 0 - the result 1 or 0 and of type int.
  4. In this testcase, the int result is again converted to an integer complex
  5. type.
  6. While having a floating-point/complex array element with || and && can make
  7. sense, having a complex reduction variable is odd but valid.
  8. Test: int complex reduction variable + int complex array.
  9. as reduction-4.c but with target. */
  10. #define N 1024
  11. _Complex char rcc[N];
  12. _Complex short rcs[N];
  13. _Complex int rci[N];
  14. _Complex long long rcl[N];
  15. int
  16. reduction_or ()
  17. {
  18. _Complex char orc = 0;
  19. _Complex short ors = 0;
  20. _Complex int ori = 0;
  21. _Complex long orl = 0;
  22. #pragma omp target parallel reduction(||: orc) map(orc)
  23. for (int i=0; i < N; ++i)
  24. orc = orc || rcl[i];
  25. #pragma omp target parallel for reduction(||: ors) map(ors)
  26. for (int i=0; i < N; ++i)
  27. ors = ors || rci[i];
  28. #pragma omp target parallel for simd reduction(||: ori) map(ori)
  29. for (int i=0; i < N; ++i)
  30. ori = ori || rcs[i];
  31. #pragma omp target parallel loop reduction(||: orl) map(orl)
  32. for (int i=0; i < N; ++i)
  33. orl = orl || rcc[i];
  34. return __real__ (orc + ors + ori + orl) + __imag__ (orc + ors + ori + orl);
  35. }
  36. int
  37. reduction_or_teams ()
  38. {
  39. _Complex char orc = 0;
  40. _Complex short ors = 0;
  41. _Complex int ori = 0;
  42. _Complex long orl = 0;
  43. #pragma omp target teams distribute parallel for reduction(||: orc) map(orc)
  44. for (int i=0; i < N; ++i)
  45. orc = orc || rcc[i];
  46. #pragma omp target teams distribute parallel for simd reduction(||: ors) map(ors)
  47. for (int i=0; i < N; ++i)
  48. ors = ors || rcs[i];
  49. #pragma omp target teams distribute parallel for reduction(||: ori) map(ori)
  50. for (int i=0; i < N; ++i)
  51. ori = ori || rci[i];
  52. #pragma omp target teams distribute parallel for simd reduction(||: orl) map(orl)
  53. for (int i=0; i < N; ++i)
  54. orl = orl || rcl[i];
  55. return __real__ (orc + ors + ori + orl) + __imag__ (orc + ors + ori + orl);
  56. }
  57. int
  58. reduction_and ()
  59. {
  60. _Complex char andc = 1;
  61. _Complex short ands = 1;
  62. _Complex int andi = 1;
  63. _Complex long andl = 1;
  64. #pragma omp target parallel reduction(&&: andc) map(andc)
  65. for (int i=0; i < N; ++i)
  66. andc = andc && rcc[i];
  67. #pragma omp target parallel for reduction(&&: ands) map(ands)
  68. for (int i=0; i < N; ++i)
  69. ands = ands && rcs[i];
  70. #pragma omp target parallel for simd reduction(&&: andi) map(andi)
  71. for (int i=0; i < N; ++i)
  72. andi = andi && rci[i];
  73. #pragma omp target parallel loop reduction(&&: andl) map(andl)
  74. for (int i=0; i < N; ++i)
  75. andl = andl && rcl[i];
  76. return __real__ (andc + ands + andi + andl)
  77. + __imag__ (andc + ands + andi + andl);
  78. }
  79. int
  80. reduction_and_teams ()
  81. {
  82. _Complex char andc = 1;
  83. _Complex short ands = 1;
  84. _Complex int andi = 1;
  85. _Complex long andl = 1;
  86. #pragma omp target teams distribute parallel for reduction(&&: andc) map(andc)
  87. for (int i=0; i < N; ++i)
  88. andc = andc && rcl[i];
  89. #pragma omp target teams distribute parallel for simd reduction(&&: ands) map(ands)
  90. for (int i=0; i < N; ++i)
  91. ands = ands && rci[i];
  92. #pragma omp target teams distribute parallel for reduction(&&: andi) map(andi)
  93. for (int i=0; i < N; ++i)
  94. andi = andi && rcs[i];
  95. #pragma omp target teams distribute parallel for simd reduction(&&: andl) map(andl)
  96. for (int i=0; i < N; ++i)
  97. andl = andl && rcc[i];
  98. return __real__ (andc + ands + andi + andl)
  99. + __imag__ (andc + ands + andi + andl);
  100. }
  101. int
  102. main ()
  103. {
  104. for (int i = 0; i < N; ++i)
  105. {
  106. rcc[i] = 0;
  107. rcs[i] = 0;
  108. rci[i] = 0;
  109. rcl[i] = 0;
  110. }
  111. if (reduction_or () != 0)
  112. __builtin_abort ();
  113. if (reduction_or_teams () != 0)
  114. __builtin_abort ();
  115. if (reduction_and () != 0)
  116. __builtin_abort ();
  117. if (reduction_and_teams () != 0)
  118. __builtin_abort ();
  119. rcc[10] = 1.0;
  120. rcs[15] = 1.0i;
  121. rci[10] = 1.0;
  122. rcl[15] = 1.0i;
  123. if (reduction_or () != 4)
  124. __builtin_abort ();
  125. if (reduction_or_teams () != 4)
  126. __builtin_abort ();
  127. if (reduction_and () != 0)
  128. __builtin_abort ();
  129. if (reduction_and_teams () != 0)
  130. __builtin_abort ();
  131. for (int i = 0; i < N; ++i)
  132. {
  133. rcc[i] = 1;
  134. rcs[i] = 1i;
  135. rci[i] = 1;
  136. rcl[i] = 1 + 1i;
  137. }
  138. if (reduction_or () != 4)
  139. __builtin_abort ();
  140. if (reduction_or_teams () != 4)
  141. __builtin_abort ();
  142. if (reduction_and () != 4)
  143. __builtin_abort ();
  144. if (reduction_and_teams () != 4)
  145. __builtin_abort ();
  146. rcc[10] = 0.0;
  147. rcs[15] = 0.0;
  148. rci[10] = 0.0;
  149. rcl[15] = 0.0;
  150. if (reduction_or () != 4)
  151. __builtin_abort ();
  152. if (reduction_or_teams () != 4)
  153. __builtin_abort ();
  154. if (reduction_and () != 0)
  155. __builtin_abort ();
  156. if (reduction_and_teams () != 0)
  157. __builtin_abort ();
  158. return 0;
  159. }