(root)/
gcc-13.2.0/
libgomp/
testsuite/
libgomp.c-c++-common/
task-reduction-15.c
       1  /* PR middle-end/101167 */
       2  
       3  extern
       4  #ifdef __cplusplus
       5  "C"
       6  #endif
       7  void abort (void);
       8  
       9  struct S { int a, b, c[2]; };
      10  
      11  void
      12  init (struct S *x)
      13  {
      14    x->a = 0;
      15    x->b = 0;
      16    x->c[0] = 0;
      17    x->c[1] = 0;
      18  }
      19  
      20  void
      21  merge (struct S *x, struct S *y)
      22  {
      23    x->a += y->a;
      24    x->b += y->b;
      25  }
      26  
      27  #pragma omp declare reduction (+: struct S : merge (&omp_out, &omp_in)) initializer (init (&omp_priv))
      28  
      29  void
      30  foo (struct S x)
      31  {
      32    #pragma omp taskgroup task_reduction (+: x)
      33    {
      34      #pragma omp task in_reduction (+: x)
      35      {
      36        x.a++;
      37        x.b++;
      38      }
      39      #pragma omp task in_reduction (+: x)
      40      {
      41        x.a += 4;
      42        x.b += 14;
      43      }
      44      #pragma omp task in_reduction (+: x)
      45      {
      46        x.a += 9;
      47        x.b += 19;
      48      }
      49    }
      50    if (x.a != 56 || x.b != 86)
      51      abort ();
      52  }
      53  
      54  int
      55  main ()
      56  {
      57    struct S x = { 42, 52 };
      58    #pragma omp parallel master num_threads(3)
      59    foo (x);
      60    return 0;
      61  }