reduction-12.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. /* { dg-do run } */
  2. struct A { int t; };
  3. struct B { char t; };
  4. struct C { unsigned long long t; };
  5. struct D { long t; };
  6. void
  7. add (struct B *x, struct B *y)
  8. {
  9. x->t += y->t;
  10. }
  11. void
  12. zero (struct B *x)
  13. {
  14. x->t = 0;
  15. }
  16. void
  17. orit (struct C *x, struct C *y)
  18. {
  19. y->t |= x->t;
  20. }
  21. #pragma omp declare reduction(+:struct A:omp_out.t += omp_in.t)
  22. #pragma omp declare reduction(+:struct B:add (&omp_out, &omp_in)) initializer(zero (&omp_priv))
  23. #pragma omp declare reduction(*:struct A:omp_out.t *= omp_in.t) initializer(omp_priv = { 1 })
  24. #pragma omp declare reduction(|:struct C:orit (&omp_in, &omp_out))
  25. #pragma omp declare reduction(&:struct D:omp_out.t = omp_out.t & omp_in.t) initializer(omp_priv = { ~0L })
  26. #pragma omp declare reduction(maxb:short:omp_out = omp_in > omp_out ? omp_in : omp_out) initializer(omp_priv = -6)
  27. struct B z[10];
  28. __attribute__((noinline, noclone)) void
  29. foo (struct A (*x)[3][2], struct A *y, struct D w[1][2], int s, int t)
  30. {
  31. struct C a[9] = {};
  32. short b[5] = {};
  33. int i;
  34. #pragma omp parallel for reduction(+:x[-1:2][:][0:2], z[t + 2:4]) \
  35. reduction(*:y[-s:3]) reduction(|:a[s + 3:4]) \
  36. reduction(&:w[s + 1:1][t:2]) reduction(maxb:b[2:])
  37. for (i = 0; i < 128; i++)
  38. {
  39. x[i / 64 - 1][i % 3][(i / 4) & 1].t += i;
  40. if ((i & 15) == 1)
  41. y[1].t *= 3;
  42. if ((i & 31) == 2)
  43. y[2].t *= 7;
  44. if ((i & 63) == 3)
  45. y[3].t *= 17;
  46. z[i / 32 + 2].t += (i & 3);
  47. if (i < 4)
  48. z[i + 2].t += i;
  49. a[i / 32 + 2].t |= 1ULL << (i & 30);
  50. w[0][i & 1].t &= ~(1L << (i / 17 * 3));
  51. if ((i % 23) > b[2])
  52. b[2] = i % 23;
  53. if ((i % 85) > b[3])
  54. b[3] = i % 85;
  55. if ((i % 192) > b[4])
  56. b[4] = i % 192;
  57. }
  58. for (i = 0; i < 9; i++)
  59. if (a[i].t != ((i < 6 && i >= 2) ? 0x55555555ULL : 0))
  60. __builtin_abort ();
  61. if (b[0] != 0 || b[1] != 0 || b[2] != 22 || b[3] != 84 || b[4] != 127)
  62. __builtin_abort ();
  63. }
  64. int
  65. main ()
  66. {
  67. struct A a[4][3][2] = {};
  68. static int a2[4][3][2] = {{{ 0, 0 }, { 0, 0 }, { 0, 0 }},
  69. {{ 312, 381 }, { 295, 356 }, { 337, 335 }},
  70. {{ 1041, 975 }, { 1016, 1085 }, { 935, 1060 }},
  71. {{ 0, 0 }, { 0, 0 }, { 0, 0 }}};
  72. struct A y[5] = { { 0 }, { 1 }, { 1 }, { 1 }, { 0 } };
  73. int y2[5] = { 0, 6561, 2401, 289, 0 };
  74. char z2[10] = { 0, 0, 48, 49, 50, 51, 0, 0, 0, 0 };
  75. struct D w[1][2] = { { { ~0L }, { ~0L } } };
  76. foo (&a[2], y, w, -1, 0);
  77. int i, j, k;
  78. for (i = 0; i < 4; i++)
  79. for (j = 0; j < 3; j++)
  80. for (k = 0; k < 2; k++)
  81. if (a[i][j][k].t != a2[i][j][k])
  82. __builtin_abort ();
  83. for (i = 0; i < 5; i++)
  84. if (y[i].t != y2[i])
  85. __builtin_abort ();
  86. for (i = 0; i < 10; i++)
  87. if (z[i].t != z2[i])
  88. __builtin_abort ();
  89. if (w[0][0].t != ~0x249249L || w[0][1].t != ~0x249249L)
  90. __builtin_abort ();
  91. return 0;
  92. }