(root)/
gcc-13.2.0/
libgomp/
testsuite/
libgomp.c-c++-common/
lastprivate-conditional-4.c
       1  #include <stdlib.h>
       2  
       3  int x;
       4  long long y;
       5  int r, s, t;
       6  
       7  void
       8  foo (const char *a)
       9  {
      10    #pragma omp sections lastprivate (conditional: x, y)
      11    {
      12      if (a[0])
      13        x = a[0];
      14      #pragma omp section
      15      {
      16        if (a[1])
      17  	x = a[1];
      18        if (a[2])
      19  	y = a[2];
      20      }
      21      #pragma omp section
      22      if (a[3])
      23        y = a[3];
      24      #pragma omp section
      25      if (a[4])
      26        x = a[4];
      27      #pragma omp section
      28      {
      29        if (a[5])
      30  	x = a[5];
      31        if (a[6])
      32  	y = a[6];
      33      }
      34    }
      35  }
      36  
      37  void
      38  bar (const char *a)
      39  {
      40    #pragma omp sections lastprivate (conditional: x, y) reduction (task, +: t)
      41    {
      42      if (a[0])
      43        x = a[0];
      44      #pragma omp section
      45      {
      46        if (a[1])
      47  	x = a[1];
      48        if (a[2])
      49  	y = a[2];
      50        #pragma omp task in_reduction (+: t)
      51        t++;
      52      }
      53      #pragma omp section
      54      if (a[3])
      55        y = a[3];
      56      #pragma omp section
      57      if (a[4])
      58        x = a[4];
      59      #pragma omp section
      60      {
      61        #pragma omp task in_reduction (+: t)
      62        ++t;
      63        if (a[5])
      64  	x = a[5];
      65        if (a[6])
      66  	y = a[6];
      67      }
      68    }
      69  }
      70  
      71  void
      72  baz (const char *a)
      73  {
      74    #pragma omp sections lastprivate (conditional: x, y) reduction (+: r, s)
      75    {
      76      if (a[0])
      77        x = a[0];
      78      #pragma omp section
      79      {
      80        if (a[1])
      81  	x = a[1];
      82        ++r;
      83        ++s;
      84        if (a[2])
      85  	y = a[2];
      86      }
      87      #pragma omp section
      88      if (a[3])
      89        y = a[3];
      90      #pragma omp section
      91      {
      92        ++s;
      93        if (a[4])
      94  	x = a[4];
      95      }
      96      #pragma omp section
      97      {
      98        if (a[5])
      99  	x = a[5];
     100        if (a[6])
     101  	y = a[6];
     102        ++s;
     103      }
     104    }
     105  }
     106  
     107  int
     108  main ()
     109  {
     110    #pragma omp parallel
     111    {
     112      foo ("\0\1\2\3\0\5");
     113      if (x != 5 || y != 3)
     114        abort ();
     115      #pragma omp barrier
     116      foo ("\6\0\0\0\0\0\7");
     117      if (x != 6 || y != 7)
     118        abort ();
     119      #pragma omp barrier
     120      foo ("\7\6\5\4\3\2\1");
     121      if (x != 2 || y != 1)
     122        abort ();
     123      #pragma omp barrier
     124      foo ("\0\0\4\3\0\7");
     125      if (x != 7 || y != 3)
     126        abort ();
     127      #pragma omp barrier
     128      bar ("\0\1\2\4\0\5");
     129      if (x != 5 || y != 4 || t != 2)
     130        abort ();
     131      #pragma omp barrier
     132      bar ("\6\0\0\0\0\0\7");
     133      if (x != 6 || y != 7 || t != 4)
     134        abort ();
     135      #pragma omp barrier
     136      bar ("\7\6\5\4\3\2\1");
     137      if (x != 2 || y != 1 || t != 6)
     138        abort ();
     139      #pragma omp barrier
     140      bar ("\0\0\4\3\0\7");
     141      if (x != 7 || y != 3 || t != 8)
     142        abort ();
     143      #pragma omp barrier
     144      baz ("\0\1\2\4\0\5");
     145      if (x != 5 || y != 4 || r != 1 || s != 3)
     146        abort ();
     147      #pragma omp barrier
     148      baz ("\6\0\0\0\0\0\7");
     149      if (x != 6 || y != 7 || r != 2 || s != 6)
     150        abort ();
     151      #pragma omp barrier
     152      baz ("\7\6\5\4\3\2\1");
     153      if (x != 2 || y != 1 || r != 3 || s != 9)
     154        abort ();
     155      #pragma omp barrier
     156      baz ("\0\0\4\3\0\7");
     157      if (x != 7 || y != 3 || r != 4 || s != 12)
     158        abort ();
     159    }
     160    return 0;
     161  }