(root)/
gcc-13.2.0/
libgomp/
testsuite/
libgomp.c-c++-common/
reduction-6.c
       1  /* { dg-additional-options "-foffload-options=nvptx-none=-latomic" { target { offload_target_nvptx } } } */
       2  /* C / C++'s logical AND and OR operators take any scalar argument
       3     which compares (un)equal to 0 - the result 1 or 0 and of type int.
       4  
       5     In this testcase, the int result is again converted to an integer complex
       6     type.
       7  
       8     While having a floating-point/complex array element with || and && can make
       9     sense, having a complex reduction variable is odd but valid.
      10  
      11     Test: int complex reduction variable + int complex array.
      12           as reduction-4.c but with target.  */
      13  
      14  #define N 1024
      15  _Complex char rcc[N];
      16  _Complex short rcs[N];
      17  _Complex int rci[N];
      18  _Complex long long rcl[N];
      19  
      20  int
      21  reduction_or ()
      22  {
      23    _Complex char orc = 0;
      24    _Complex short ors = 0;
      25    _Complex int ori = 0;
      26    _Complex long orl = 0;
      27  
      28    #pragma omp target parallel reduction(||: orc) map(orc)
      29    for (int i=0; i < N; ++i)
      30      orc = orc || rcl[i];
      31  
      32    #pragma omp target parallel for reduction(||: ors) map(ors)
      33    for (int i=0; i < N; ++i)
      34      ors = ors || rci[i];
      35  
      36    #pragma omp target parallel for simd reduction(||: ori) map(ori)
      37    for (int i=0; i < N; ++i)
      38      ori = ori || rcs[i];
      39  
      40    #pragma omp target parallel loop reduction(||: orl) map(orl)
      41    for (int i=0; i < N; ++i)
      42      orl = orl || rcc[i];
      43  
      44    return __real__ (orc + ors + ori + orl) + __imag__ (orc + ors + ori + orl);
      45  }
      46  
      47  int
      48  reduction_or_teams ()
      49  {
      50    _Complex char orc = 0;
      51    _Complex short ors = 0;
      52    _Complex int ori = 0;
      53    _Complex long orl = 0;
      54  
      55    #pragma omp target teams distribute parallel for reduction(||: orc) map(orc)
      56    for (int i=0; i < N; ++i)
      57      orc = orc || rcc[i];
      58  
      59    #pragma omp target teams distribute parallel for simd reduction(||: ors) map(ors)
      60    for (int i=0; i < N; ++i)
      61      ors = ors || rcs[i];
      62  
      63    #pragma omp target teams distribute parallel for reduction(||: ori) map(ori)
      64    for (int i=0; i < N; ++i)
      65      ori = ori || rci[i];
      66  
      67    #pragma omp target teams distribute parallel for simd reduction(||: orl) map(orl)
      68    for (int i=0; i < N; ++i)
      69      orl = orl || rcl[i];
      70  
      71    return __real__ (orc + ors + ori + orl) + __imag__ (orc + ors + ori + orl);
      72  }
      73  
      74  int
      75  reduction_and ()
      76  {
      77    _Complex char andc = 1;
      78    _Complex short ands = 1;
      79    _Complex int andi = 1;
      80    _Complex long andl = 1;
      81  
      82    #pragma omp target parallel reduction(&&: andc) map(andc)
      83    for (int i=0; i < N; ++i)
      84      andc = andc && rcc[i];
      85  
      86    #pragma omp target parallel for reduction(&&: ands) map(ands)
      87    for (int i=0; i < N; ++i)
      88      ands = ands && rcs[i];
      89  
      90    #pragma omp target parallel for simd reduction(&&: andi) map(andi)
      91    for (int i=0; i < N; ++i)
      92      andi = andi && rci[i];
      93  
      94    #pragma omp target parallel loop reduction(&&: andl) map(andl)
      95    for (int i=0; i < N; ++i)
      96      andl = andl && rcl[i];
      97  
      98    return __real__ (andc + ands + andi + andl)
      99  	 + __imag__ (andc + ands + andi + andl);
     100  }
     101  
     102  int
     103  reduction_and_teams ()
     104  {
     105    _Complex char andc = 1;
     106    _Complex short ands = 1;
     107    _Complex int andi = 1;
     108    _Complex long andl = 1;
     109  
     110    #pragma omp target teams distribute parallel for reduction(&&: andc) map(andc)
     111    for (int i=0; i < N; ++i)
     112      andc = andc && rcl[i];
     113  
     114    #pragma omp target teams distribute parallel for simd reduction(&&: ands) map(ands)
     115    for (int i=0; i < N; ++i)
     116      ands = ands && rci[i];
     117  
     118    #pragma omp target teams distribute parallel for reduction(&&: andi) map(andi)
     119    for (int i=0; i < N; ++i)
     120      andi = andi && rcs[i];
     121  
     122    #pragma omp target teams distribute parallel for simd reduction(&&: andl) map(andl)
     123    for (int i=0; i < N; ++i)
     124      andl = andl && rcc[i];
     125  
     126    return __real__ (andc + ands + andi + andl)
     127  	 + __imag__ (andc + ands + andi + andl);
     128  }
     129  
     130  int
     131  main ()
     132  {
     133    for (int i = 0; i < N; ++i)
     134      {
     135        rcc[i] = 0;
     136        rcs[i] = 0;
     137        rci[i] = 0;
     138        rcl[i] = 0;
     139      }
     140  
     141    if (reduction_or () != 0)
     142      __builtin_abort ();
     143    if (reduction_or_teams () != 0)
     144      __builtin_abort ();
     145    if (reduction_and () != 0)
     146      __builtin_abort ();
     147    if (reduction_and_teams () != 0)
     148      __builtin_abort ();
     149  
     150    rcc[10] = 1.0;
     151    rcs[15] = 1.0i;
     152    rci[10] = 1.0;
     153    rcl[15] = 1.0i;
     154  
     155    if (reduction_or () != 4)
     156      __builtin_abort ();
     157    if (reduction_or_teams () != 4)
     158      __builtin_abort ();
     159    if (reduction_and () != 0)
     160      __builtin_abort ();
     161    if (reduction_and_teams () != 0)
     162      __builtin_abort ();
     163  
     164    for (int i = 0; i < N; ++i)
     165      {
     166        rcc[i] = 1;
     167        rcs[i] = 1i;
     168        rci[i] = 1;
     169        rcl[i] = 1 + 1i;
     170      }
     171  
     172    if (reduction_or () != 4)
     173      __builtin_abort ();
     174    if (reduction_or_teams () != 4)
     175      __builtin_abort ();
     176    if (reduction_and () != 4)
     177      __builtin_abort ();
     178    if (reduction_and_teams () != 4)
     179      __builtin_abort ();
     180  
     181    rcc[10] = 0.0;
     182    rcs[15] = 0.0;
     183    rci[10] = 0.0;
     184    rcl[15] = 0.0;
     185  
     186    if (reduction_or () != 4)
     187      __builtin_abort ();
     188    if (reduction_or_teams () != 4)
     189      __builtin_abort ();
     190    if (reduction_and () != 0)
     191      __builtin_abort ();
     192    if (reduction_and_teams () != 0)
     193      __builtin_abort ();
     194  
     195    return 0;
     196  }