1 // RUN: %libomp-compile-and-run 2 3 // Parsing error until gcc8: 4 // UNSUPPORTED: gcc-4, gcc-5, gcc-6, gcc-7, gcc-8 5 6 // Parsing error until clang11: 7 // UNSUPPORTED: clang-10, clang-9, clang-8, clang-7 8 9 // Missing GOMP_taskgroup_reduction_(un)register in LLVM/OpenMP 10 // Should be removed once the functions are implemented 11 // XFAIL: gcc-9, gcc-10 12 13 #include <stdio.h> 14 #include <omp.h> 15 16 int r; 17 18 int work(int k, int l) 19 { 20 return k + l + 1; 21 } 22 void bar(int i) { 23 #pragma omp taskgroup task_reduction(+:r) 24 { int th_gen = omp_get_thread_num(); 25 #pragma omp task in_reduction(+:r) firstprivate(i, th_gen) 26 { 27 r += work(i, 0); 28 printf("executing task (%d, 0), th %d (gen by th %d)\n", i, omp_get_thread_num(), th_gen); 29 } 30 #pragma omp task in_reduction(+:r) firstprivate(i, th_gen) 31 { 32 r += work(i, 1); 33 printf("executing task (%d, 1), th %d (gen by th %d)\n", i, omp_get_thread_num(), th_gen); 34 } 35 } 36 } 37 int foo() { 38 int i; 39 int th_gen = omp_get_thread_num(); 40 #pragma omp taskgroup task_reduction(+:r) 41 { 42 bar(0); 43 } 44 printf("th %d passed bar0\n", th_gen); 45 #pragma omp taskloop reduction(+:r) firstprivate(th_gen) 46 for (i = 1; i < 4; ++i) { 47 bar(i); 48 printf("th %d (gen by th %d) passed bar%d in taskloop\n", omp_get_thread_num(), th_gen, i); 49 #pragma omp task in_reduction(+:r) 50 r += i; 51 } 52 return 0; 53 } 54 // res = 2*((1+2)+(2+3)+(3+4)+(4+5)+1+2+3) = 60 55 #define res 60 56 int main() 57 { 58 r = 0; 59 #pragma omp parallel num_threads(2) 60 foo(); 61 if (r == res) { 62 return 0; 63 } else { 64 printf("error r = %d (!= %d)\n", r, res); 65 return 1; 66 } 67 } 68