udr-1.c 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /* { dg-do run } */
  2. extern
  3. #ifdef __cplusplus
  4. "C"
  5. #endif
  6. void abort ();
  7. struct S { int s; struct S *t; };
  8. void
  9. foo (struct S *out, struct S *in)
  10. {
  11. out->s += in->s;
  12. }
  13. void
  14. bar (struct S *x)
  15. {
  16. if (x->s != 6) abort ();
  17. x->s = 15;
  18. }
  19. void
  20. baz (struct S *x, struct S *y)
  21. {
  22. x->s = 6;
  23. x->t = x;
  24. (void) y;
  25. }
  26. #pragma omp declare reduction (foo: struct S: foo (&omp_out, &omp_in)) \
  27. initializer (omp_priv = { 8, &omp_priv })
  28. #pragma omp declare reduction (foo: char, int, short: omp_out += omp_in - 4) \
  29. initializer (omp_priv = 4)
  30. #pragma omp declare reduction (+: struct S: foo (&omp_out, &omp_in)) \
  31. initializer (baz (&omp_priv, &omp_orig))
  32. void
  33. test (struct S s, struct S t)
  34. {
  35. int q = 0;
  36. #pragma omp parallel num_threads (4) reduction (+: s, q) reduction (foo: t)
  37. {
  38. if (s.s != 6 || s.t != &s || t.s != 8 || t.t != &t)
  39. abort ();
  40. s.s = 2;
  41. t.s = 3;
  42. q = 1;
  43. }
  44. if (s.s != 12 + 2 * q || t.s != 14 + 3 * q)
  45. abort ();
  46. }
  47. int
  48. main ()
  49. {
  50. struct S s, t;
  51. s.s = 9; t.s = 10;
  52. int h = 30, v = 2, q = 0;
  53. #pragma omp declare reduction (foo: struct S: omp_out.s *= omp_in.s) \
  54. initializer (omp_priv = omp_orig)
  55. {
  56. #pragma omp declare reduction (foo: struct S: omp_out.s += omp_in.s) \
  57. initializer (omp_priv = omp_orig)
  58. #pragma omp parallel num_threads (4) reduction (+: t, q) \
  59. reduction (min: h) reduction (foo: s, v)
  60. {
  61. if (s.s != 9 || t.s != 6 || v != 4 || h != __INT_MAX__) abort ();
  62. asm volatile ("" : "+m" (s.s), "+m" (t.s));
  63. asm volatile ("" : "+r" (h), "+r" (v));
  64. h = t.s; s.s++; t.s++; v++; q++;
  65. }
  66. }
  67. if (h != 6 || s.s != 9 + q * 10 || t.s != 10 + q * 7 || v != 2 + q)
  68. abort ();
  69. s.s = 12;
  70. t.s = 14;
  71. test (s, t);
  72. return 0;
  73. }