(root)/
gcc-13.2.0/
libgomp/
testsuite/
libgomp.oacc-c-c++-common/
par-reduction-1.c
       1  /* { dg-additional-options "-Wopenacc-parallelism" } for testing/documenting
       2     aspects of that functionality.  */
       3  
       4  #include <assert.h>
       5  
       6  /* Test of reduction on parallel directive.  */
       7  
       8  #define ACTUAL_GANGS 256
       9  
      10  int
      11  main (int argc, char *argv[])
      12  {
      13    int res, res1 = 0, res2 = 0;
      14  
      15  #if defined(ACC_DEVICE_TYPE_host)
      16  # define GANGS 1
      17  #else
      18  # define GANGS 256
      19  #endif
      20    #pragma acc parallel num_gangs(GANGS) num_workers(32) vector_length(32) \
      21      reduction(+:res1) copy(res2, res1)
      22    /* { dg-bogus "warning: region is gang partitioned but does not contain gang partitioned code" "TODO 'reduction', 'atomic'" { xfail { ! openacc_host_selected } } .-2 } */
      23    /* { dg-warning "region is worker partitioned but does not contain worker partitioned code" "" { target *-*-* } .-3 } */
      24    /* { dg-warning "region is vector partitioned but does not contain vector partitioned code" "" { target *-*-* } .-4 } */
      25    {
      26      res1 += 5;
      27  
      28      #pragma acc atomic
      29      res2 += 5;
      30    }
      31    res = GANGS * 5;
      32  
      33    assert (res == res1);
      34    assert (res == res2);
      35  #undef GANGS
      36  
      37    res = res1 = res2 = 1;
      38  
      39  #if defined(ACC_DEVICE_TYPE_host)
      40  # define GANGS 1
      41  #else
      42  # define GANGS 8
      43  #endif
      44    #pragma acc parallel num_gangs(GANGS) num_workers(32) vector_length(32) \
      45      reduction(*:res1) copy(res1, res2)
      46    /* { dg-bogus "warning: region is gang partitioned but does not contain gang partitioned code" "TODO 'reduction', 'atomic'" { xfail { ! openacc_host_selected } } .-2 } */
      47    /* { dg-warning "region is worker partitioned but does not contain worker partitioned code" "" { target *-*-* } .-3 } */
      48    /* { dg-warning "region is vector partitioned but does not contain vector partitioned code" "" { target *-*-* } .-4 } */
      49    {
      50      res1 *= 5;
      51  
      52      #pragma acc atomic
      53      res2 *= 5;
      54    }
      55    for (int i = 0; i < GANGS; ++i)
      56      res *= 5;
      57  
      58    assert (res == res1);
      59    assert (res == res2);
      60  #undef GANGS
      61  
      62    return 0;
      63  }