xref: /llvm-project/openmp/runtime/test/tasking/omp_record_replay_taskloop.cpp (revision 36d4e4c9b5f6cd0577b6029055b825caaec2dd11)
1 // REQUIRES: ompx_taskgraph
2 // RUN: %libomp-cxx-compile-and-run
3 #include <iostream>
4 #include <cassert>
5 
6 #define NT 20
7 #define N 128*128
8 
9 typedef struct ident {
10     void* dummy;
11 } ident_t;
12 
13 
14 #ifdef __cplusplus
15 extern "C" {
16   int __kmpc_global_thread_num(ident_t *);
17   int __kmpc_start_record_task(ident_t *, int, int, int);
18   void __kmpc_end_record_task(ident_t *, int, int , int);
19 }
20 #endif
21 
main()22 int main() {
23   int num_tasks = 0;
24 
25   int array[N];
26   for (int i = 0; i < N; ++i)
27     array[i] = 1;
28 
29   long sum = 0;
30   #pragma omp parallel
31   #pragma omp single
32   for (int iter = 0; iter < NT; ++iter) {
33     int gtid = __kmpc_global_thread_num(nullptr);
34     int res =  __kmpc_start_record_task(nullptr, gtid, /* kmp_tdg_flags */0,  /* tdg_id */0);
35     if (res) {
36       num_tasks++;
37       #pragma omp taskloop reduction(+:sum) num_tasks(4096)
38       for (int i = 0; i < N; ++i) {
39         sum += array[i];
40       }
41     }
42     __kmpc_end_record_task(nullptr, gtid, /* kmp_tdg_flags */0,  /* tdg_id */0);
43   }
44   assert(sum==N*NT);
45   assert(num_tasks==1);
46 
47   std::cout << "Passed" << std::endl;
48   return 0;
49 }
50 // CHECK: Passed
51