scan-7.C 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. // { dg-require-effective-target size32plus }
  2. extern "C" void abort ();
  3. int r, a[1024], b[1024], q;
  4. #pragma omp declare reduction (foo: int: omp_out += omp_in) initializer (omp_priv = 0)
  5. __attribute__((noipa)) void
  6. foo (int *a, int *b, int &r)
  7. {
  8. #pragma omp for reduction (inscan, foo:r)
  9. for (int i = 0; i < 1024; i++)
  10. {
  11. b[i] = r;
  12. #pragma omp scan exclusive(r)
  13. r += a[i];
  14. }
  15. }
  16. __attribute__((noipa)) int
  17. bar (void)
  18. {
  19. int &s = q;
  20. q = 0;
  21. #pragma omp parallel
  22. #pragma omp for reduction (inscan, foo:s) nowait
  23. for (int i = 0; i < 1024; i++)
  24. {
  25. b[i] = s;
  26. #pragma omp scan exclusive(s)
  27. s += 2 * a[i];
  28. }
  29. return s;
  30. }
  31. __attribute__((noipa)) void
  32. baz (int *a, int *b, int &r)
  33. {
  34. #pragma omp parallel for reduction (inscan, foo:r)
  35. for (int i = 0; i < 1024; i++)
  36. {
  37. b[i] = r;
  38. #pragma omp scan exclusive(r)
  39. r += a[i];
  40. }
  41. }
  42. __attribute__((noipa)) int
  43. qux (void)
  44. {
  45. int &s = q;
  46. q = 0;
  47. #pragma omp parallel for reduction (inscan, foo:s)
  48. for (int i = 0; i < 1024; i++)
  49. {
  50. b[i] = s;
  51. #pragma omp scan exclusive(s)
  52. s += 2 * a[i];
  53. }
  54. return s;
  55. }
  56. int
  57. main ()
  58. {
  59. int s = 0;
  60. for (int i = 0; i < 1024; ++i)
  61. {
  62. a[i] = i;
  63. b[i] = -1;
  64. asm ("" : "+g" (i));
  65. }
  66. #pragma omp parallel
  67. foo (a, b, r);
  68. if (r != 1024 * 1023 / 2)
  69. abort ();
  70. for (int i = 0; i < 1024; ++i)
  71. {
  72. if (b[i] != s)
  73. abort ();
  74. else
  75. b[i] = 25;
  76. s += i;
  77. }
  78. if (bar () != 1024 * 1023)
  79. abort ();
  80. s = 0;
  81. for (int i = 0; i < 1024; ++i)
  82. {
  83. if (b[i] != s)
  84. abort ();
  85. else
  86. b[i] = -1;
  87. s += 2 * i;
  88. }
  89. r = 0;
  90. baz (a, b, r);
  91. if (r != 1024 * 1023 / 2)
  92. abort ();
  93. s = 0;
  94. for (int i = 0; i < 1024; ++i)
  95. {
  96. if (b[i] != s)
  97. abort ();
  98. else
  99. b[i] = -25;
  100. s += i;
  101. }
  102. if (qux () != 1024 * 1023)
  103. abort ();
  104. s = 0;
  105. for (int i = 0; i < 1024; ++i)
  106. {
  107. if (b[i] != s)
  108. abort ();
  109. s += 2 * i;
  110. }
  111. }