(root)/
gcc-13.2.0/
libgomp/
testsuite/
libgomp.oacc-c-c++-common/
default-1.c
       1  /* { dg-additional-options "--param=openacc-kernels=decompose" } */
       2  
       3  /* { dg-additional-options "-fopt-info-all-omp" }
       4     { dg-additional-options "-foffload=-fopt-info-all-omp" } */
       5  
       6  /* { dg-additional-options "--param=openacc-privatization=noisy" }
       7     { dg-additional-options "-foffload=--param=openacc-privatization=noisy" }
       8     Prune a few: uninteresting, and potentially varying depending on GCC configuration (data types):
       9     { dg-prune-output {note: variable 'D\.[0-9]+' declared in block isn't candidate for adjusting OpenACC privatization level: not addressable} } */
      10  
      11  /* It's only with Tcl 8.5 (released in 2007) that "the variable 'varName'
      12     passed to 'incr' may be unset, and in that case, it will be set to [...]",
      13     so to maintain compatibility with earlier Tcl releases, we manually
      14     initialize counter variables:
      15     { dg-line l_dummy[variable c_compute 0 c_loop_i 0] }
      16     { dg-message dummy {} { target iN-VAl-Id } l_dummy } to avoid
      17     "WARNING: dg-line var l_dummy defined, but not used".  */
      18  
      19  #include  <openacc.h>
      20  
      21  int test_parallel ()
      22  {
      23    int ok = 1;
      24    int val = 2;
      25    int ary[32];
      26    int ondev = 0;
      27  
      28    for (int i = 0; i < 32; i++)
      29      ary[i] = ~0;
      30  
      31    /* val defaults to firstprivate, ary defaults to copy.  */
      32  #pragma acc parallel num_gangs (32) copy (ok) copy(ondev) /* { dg-line l_compute[incr c_compute] } */
      33    /* { dg-note {variable 'i' declared in block isn't candidate for adjusting OpenACC privatization level: not addressable} {} { target *-*-* } l_compute$c_compute } */
      34    {
      35      ondev = acc_on_device (acc_device_not_host);
      36      /* { dg-optimized {assigned OpenACC seq loop parallelism} {} { target { c++ && { ! __OPTIMIZE__ } } } .-1 }
      37         ..., as without optimizations, we're not inlining the C++ 'acc_on_device' wrapper.  */
      38  #pragma acc loop gang(static:1) /* { dg-line l_loop_i[incr c_loop_i] } */
      39      /* { dg-note {variable 'i' in 'private' clause isn't candidate for adjusting OpenACC privatization level: not addressable} {} { target *-*-* } l_loop_i$c_loop_i } */
      40      /* { dg-optimized {assigned OpenACC gang loop parallelism} {} { target *-*-* } l_loop_i$c_loop_i } */
      41      for (unsigned i = 0; i < 32; i++)
      42        {
      43  	if (val != 2)
      44  	  ok = 0;
      45  	val += i;
      46  	ary[i] = val;
      47        }
      48    }
      49  
      50    if (ondev)
      51      {
      52        if (!ok)
      53  	return 1;
      54        if (val != 2)
      55  	return 1;
      56  
      57        for (int i = 0; i < 32; i++)
      58  	if (ary[i] != 2 + i)
      59  	  return 1;
      60      }
      61    
      62    return 0;
      63  }
      64  
      65  int test_kernels ()
      66  {
      67    int val = 2;
      68    int ary[32];
      69    int ondev = 0;
      70  
      71    for (int i = 0; i < 32; i++)
      72      ary[i] = ~0;
      73  
      74    /* val defaults to copy, ary defaults to copy.  */
      75  #pragma acc kernels copy(ondev) /* { dg-line l_compute[incr c_compute] } */
      76    /* { dg-note {OpenACC 'kernels' decomposition: variable 'val' in 'copy' clause requested to be made addressable} {} { target *-*-* } l_compute$c_compute }
      77       { dg-note {variable 'val' made addressable} {} { target *-*-* } l_compute$c_compute } */
      78    /* { dg-note {variable 'ondev\.[0-9]+' declared in block isn't candidate for adjusting OpenACC privatization level: not addressable} {} { target *-*-* } l_compute$c_compute } */
      79    {
      80      /* { dg-note {beginning 'gang-single' part in OpenACC 'kernels' region} {} { target *-*-* } .+1 } */
      81      ondev = acc_on_device (acc_device_not_host);
      82      /* { dg-optimized {assigned OpenACC seq loop parallelism} {} { target { c++ && { ! __OPTIMIZE__ } } } .-1 }
      83         ..., as without optimizations, we're not inlining the C++ 'acc_on_device' wrapper.  */
      84  #pragma acc loop /* { dg-line l_loop_i[incr c_loop_i] } */
      85      /* { dg-note {forwarded loop nest in OpenACC 'kernels' region to 'parloops' for analysis} {} { target *-*-* } l_loop_i$c_loop_i } */
      86      /* { dg-note {variable 'i' declared in block isn't candidate for adjusting OpenACC privatization level: not addressable} {} { target *-*-* } l_loop_i$c_loop_i } */
      87      /* { dg-note {variable 'i' in 'private' clause isn't candidate for adjusting OpenACC privatization level: not addressable} {} { target *-*-* } l_loop_i$c_loop_i } */
      88      /* { dg-optimized {assigned OpenACC seq loop parallelism} {} { target *-*-* } l_loop_i$c_loop_i } */
      89      for (unsigned i = 0; i < 32; i++)
      90        {
      91  	ary[i] = val;
      92  	val++;
      93        }
      94    }
      95  
      96    if (ondev)
      97      {
      98        if (val != 2 + 32)
      99  	return 1;
     100  
     101        for (int i = 0; i < 32; i++)
     102  	if (ary[i] != 2 + i)
     103  	  return 1;
     104      }
     105    
     106    return 0;
     107  }
     108  
     109  int main ()
     110  {
     111    if (test_parallel ())
     112      return 1;
     113  
     114    if (test_kernels ())
     115      return 1;
     116  
     117    return 0;
     118  }