xref: /llvm-project/openmp/runtime/test/tasking/task_reduction1.c (revision 4457565757ea91207b7e5f2ce7b7bf173bfd2c0c)
1*44575657SPeyton, Jonathan L // RUN: %libomp-compile-and-run
2*44575657SPeyton, Jonathan L 
3*44575657SPeyton, Jonathan L // UNSUPPORTED: gcc-4, gcc-5, gcc-6, gcc-7, gcc-8
4*44575657SPeyton, Jonathan L 
5*44575657SPeyton, Jonathan L #include <stdio.h>
6*44575657SPeyton, Jonathan L #include <stdlib.h>
7*44575657SPeyton, Jonathan L 
8*44575657SPeyton, Jonathan L int a = 0, b = 1;
9*44575657SPeyton, Jonathan L 
main(int argc,char ** argv)10*44575657SPeyton, Jonathan L int main(int argc, char **argv) {
11*44575657SPeyton, Jonathan L 
12*44575657SPeyton, Jonathan L   #pragma omp parallel
13*44575657SPeyton, Jonathan L   #pragma omp single
14*44575657SPeyton, Jonathan L   {
15*44575657SPeyton, Jonathan L     #pragma omp taskgroup task_reduction(+: a) task_reduction(*: b)
16*44575657SPeyton, Jonathan L     {
17*44575657SPeyton, Jonathan L       int i;
18*44575657SPeyton, Jonathan L       for (i = 1; i <= 5; ++i) {
19*44575657SPeyton, Jonathan L         #pragma omp task in_reduction(+: a) in_reduction(*: b)
20*44575657SPeyton, Jonathan L         {
21*44575657SPeyton, Jonathan L           a += i;
22*44575657SPeyton, Jonathan L           b *= i;
23*44575657SPeyton, Jonathan L           #pragma omp task in_reduction(+: a)
24*44575657SPeyton, Jonathan L           {
25*44575657SPeyton, Jonathan L             a += i;
26*44575657SPeyton, Jonathan L           }
27*44575657SPeyton, Jonathan L         }
28*44575657SPeyton, Jonathan L       }
29*44575657SPeyton, Jonathan L     }
30*44575657SPeyton, Jonathan L   }
31*44575657SPeyton, Jonathan L 
32*44575657SPeyton, Jonathan L   if (a != 30) {
33*44575657SPeyton, Jonathan L     fprintf(stderr, "error: a != 30. Instead a = %d\n", a);
34*44575657SPeyton, Jonathan L     exit(EXIT_FAILURE);
35*44575657SPeyton, Jonathan L   }
36*44575657SPeyton, Jonathan L   if (b != 120) {
37*44575657SPeyton, Jonathan L     fprintf(stderr, "error: b != 120. Instead b = %d\n", b);
38*44575657SPeyton, Jonathan L     exit(EXIT_FAILURE);
39*44575657SPeyton, Jonathan L   }
40*44575657SPeyton, Jonathan L 
41*44575657SPeyton, Jonathan L   return EXIT_SUCCESS;
42*44575657SPeyton, Jonathan L }
43