(root)/
gcc-13.2.0/
libgomp/
testsuite/
libgomp.oacc-c-c++-common/
kernels-private-vars-loop-worker-7.c
       1  /* Test of worker-private variables declared on loop directive, broadcasting
       2     to vector-partitioned mode.  Array worker variable.  */
       3  
       4  /* { dg-additional-options "--param=openacc-kernels=decompose" } */
       5  
       6  /* { dg-additional-options "-fopt-info-omp-all" }
       7     { dg-additional-options "-foffload=-fopt-info-omp-all" } */
       8  
       9  /* { dg-additional-options "--param=openacc-privatization=noisy" }
      10     { dg-additional-options "-foffload=--param=openacc-privatization=noisy" }
      11     Prune a few: uninteresting:
      12     { dg-prune-output {note: variable 'D\.[0-9]+' declared in block isn't candidate for adjusting OpenACC privatization level: not addressable} } */
      13  
      14  /* It's only with Tcl 8.5 (released in 2007) that "the variable 'varName'
      15     passed to 'incr' may be unset, and in that case, it will be set to [...]",
      16     so to maintain compatibility with earlier Tcl releases, we manually
      17     initialize counter variables:
      18     { dg-line l_dummy[variable c_compute 0 c_loop_i 0 c_loop_j 0 c_loop_k 0] }
      19     { dg-message "dummy" "" { target iN-VAl-Id } l_dummy } to avoid
      20     "WARNING: dg-line var l_dummy defined, but not used".  */
      21  
      22  #include <assert.h>
      23  
      24  int
      25  main (int argc, char* argv[])
      26  {
      27    int i, arr[32 * 32 * 32];
      28    int pt[2];
      29  
      30    for (i = 0; i < 32 * 32 * 32; i++)
      31      arr[i] = i;
      32  
      33    /* "pt" is treated as "present_or_copy" on the kernels directive because it
      34       is an array variable.  */
      35    #pragma acc kernels copy(arr) /* { dg-line l_compute[incr c_compute] } */
      36    /* [PR104784] For some reason, for C++, the OpenACC 'kernels' decomposition
      37       decides that a data region is needed for 'j', and subsequently requests it
      38       to be made addressable.
      39       { dg-note {OpenACC 'kernels' decomposition: variable 'j' declared in block requested to be made addressable} {} { target c++ } l_compute$c_compute }
      40       { dg-note {variable 'j' made addressable} {} { target c++ } l_compute$c_compute }
      41       { dg-note {variable 'j' declared in block is candidate for adjusting OpenACC privatization level} {} { target c++ } l_compute$c_compute } */
      42    {
      43      int j;
      44  
      45      /* { dg-note {forwarded loop nest in OpenACC 'kernels' region to 'parloops' for analysis} {} { target *-*-* } .+1 } */
      46      #pragma acc loop gang(num:32) /* { dg-line l_loop_i[incr c_loop_i] } */
      47      /* { dg-note {variable 'j' declared in block isn't candidate for adjusting OpenACC privatization level: not addressable} {} { target c } l_loop_i$c_loop_i } */
      48      /* { dg-note {variable 'i' in 'private' clause isn't candidate for adjusting OpenACC privatization level: not addressable} {} { target *-*-* } l_loop_i$c_loop_i } */
      49      for (i = 0; i < 32; i++)
      50        {
      51          /* But here, it is made private per-worker.  */
      52          #pragma acc loop worker(num:32) private(pt) /* { dg-line l_loop_j[incr c_loop_j] } */
      53  	/* { dg-note {variable 'pt' in 'private' clause isn't candidate for adjusting OpenACC privatization level: not addressable} {} { target *-*-* } l_loop_j$c_loop_j } */
      54  	/* { dg-note {variable 'j' in 'private' clause isn't candidate for adjusting OpenACC privatization level: not addressable} {} { target *-*-* } l_loop_j$c_loop_j } */
      55  	/* { dg-note {variable 'k' declared in block isn't candidate for adjusting OpenACC privatization level: not addressable} {} { target *-*-* } l_loop_j$c_loop_j } */
      56  	for (j = 0; j < 32; j++)
      57  	  {
      58  	    int k;
      59  	    
      60  	    pt[0] = i ^ j * 3;
      61  
      62  	    #pragma acc loop vector(length:32) /* { dg-line l_loop_k[incr c_loop_k] } */
      63  	    /* { dg-note {variable 'k' in 'private' clause isn't candidate for adjusting OpenACC privatization level: not addressable} {} { target *-*-* } l_loop_k$c_loop_k } */
      64  	    for (k = 0; k < 32; k++)
      65  	      arr[i * 1024 + j * 32 + k] += pt[0] * k;
      66  
      67  	    pt[1] = i | j * 5;
      68  	    
      69  	    #pragma acc loop vector(length:32) /* { dg-line l_loop_k[incr c_loop_k] } */
      70  	    /* { dg-note {variable 'k' in 'private' clause isn't candidate for adjusting OpenACC privatization level: not addressable} {} { target *-*-* } l_loop_k$c_loop_k } */
      71  	    for (k = 0; k < 32; k++)
      72  	      arr[i * 1024 + j * 32 + k] += pt[1] * k;
      73  	  }
      74        }
      75      /* { dg-optimized {assigned OpenACC seq loop parallelism} {} { target *-*-* } l_loop_i$c_loop_i } */
      76    }
      77  
      78    for (i = 0; i < 32; i++)
      79      for (int j = 0; j < 32; j++)
      80        for (int k = 0; k < 32; k++)
      81          {
      82  	  int idx = i * 1024 + j * 32 + k;
      83            assert (arr[idx] == idx + (i ^ j * 3) * k + (i | j * 5) * k);
      84  	}
      85  
      86    return 0;
      87  }