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