(root)/
gcc-13.2.0/
libgomp/
testsuite/
libgomp.c/
depend-2.c
       1  #include <stdlib.h>
       2  #include <unistd.h>
       3  
       4  void
       5  foo (int do_sleep)
       6  {
       7    int a[64], i, *p = a + 4, x = 0;
       8    asm volatile ("" : "+r" (p));
       9    for (i = 0; i < 64; i++)
      10      a[i] = i + 8;
      11    #pragma omp parallel private (i)
      12    {
      13      #pragma omp single nowait
      14      {
      15        for (i = 0; i < 8; i++)
      16  	{
      17  	  #pragma omp task depend(out: a[i * 8 : 4])
      18  	    a[i * 8] += (i + 2) * 9;
      19  	  #pragma omp task depend(out: p[i * 8 : 2])
      20  	    p[i * 8] += (i + 3) * 10;
      21  	  #pragma omp task depend(out: x)
      22  	    x = 1;
      23  	}
      24        for (i = 0; i < 8; i++)
      25  	#pragma omp task depend(in: a[i * 8 : 4]) \
      26  			 depend(inout: a[i * 8 + 4 : 2]) \
      27  			 depend(in: a[0 : 4]) depend(in: x)
      28  	{
      29  	  if (a[0] != 8 + 2 * 9 || x != 1)
      30  	    abort ();
      31  	  if (a[i * 8] != i * 8 + 8 + (i + 2) * 9)
      32  	    abort ();
      33  	  if (a[4 + i * 8] != 4 + i * 8 + 8 + (i + 3) * 10)
      34  	    abort ();
      35  	  p[i * 8] += a[i * 8];
      36  	}
      37        for (i = 0; i < 8; i++)
      38  	#pragma omp task depend(inout: a[i * 8 : 4]) \
      39  			 depend(in: p[i * 8 : 2]) \
      40  			 depend(in: p[0 : 2], x)
      41  	{
      42  	  if (p[0] != 4 + 8 + 3 * 10 + 0 + 8 + 2 * 9 || x != 1)
      43  	    abort ();
      44  	  if (a[i * 8] != i * 8 + 8 + (i + 2) * 9)
      45  	    abort ();
      46  	  if (a[4 + i * 8] != (4 + i * 8 + 8 + (i + 3) * 10
      47  			       + i * 8 + 8 + (i + 2) * 9))
      48  	    abort ();
      49  	  a[i * 8] += 2;
      50  	}
      51        for (i = 0; i < 4; i++)
      52  	#pragma omp task depend(in: a[i * 16 : 4], a[i * 16 + 8 : 4], x)
      53  	{
      54  	  if (a[i * 16] != i * 16 + 8 + (2 * i + 2) * 9 + 2 || x != 1)
      55  	    abort ();
      56  	  if (p[i * 16 + 4] != i * 16 + 8 + 8 + (2 * i + 1 + 2) * 9 + 2)
      57  	    abort ();
      58  	}
      59      }
      60      if (do_sleep)
      61        sleep (1);
      62    }
      63  }
      64  
      65  int
      66  main ()
      67  {
      68    foo (1);
      69    foo (0);
      70    return 0;
      71  }