diff options
Diffstat (limited to 'openmp/runtime/test/tasking/omp_record_replay_multiTDGs.cpp')
-rw-r--r-- | openmp/runtime/test/tasking/omp_record_replay_multiTDGs.cpp | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/openmp/runtime/test/tasking/omp_record_replay_multiTDGs.cpp b/openmp/runtime/test/tasking/omp_record_replay_multiTDGs.cpp new file mode 100644 index 000000000000..03252843689c --- /dev/null +++ b/openmp/runtime/test/tasking/omp_record_replay_multiTDGs.cpp @@ -0,0 +1,76 @@ +// REQUIRES: ompx_taskgraph +// RUN: %libomp-cxx-compile-and-run +#include <iostream> +#include <cassert> +#define NT 20 +#define MULTIPLIER 100 +#define DECREMENT 5 + +// Compiler-generated code (emulation) +typedef struct ident { + void* dummy; +} ident_t; + +int val; +#ifdef __cplusplus +extern "C" { + int __kmpc_global_thread_num(ident_t *); + int __kmpc_start_record_task(ident_t *, int, int, int); + void __kmpc_end_record_task(ident_t *, int, int , int); +} +#endif + +void sub() { + #pragma omp atomic + val -= DECREMENT; +} + +void add() { + #pragma omp atomic + val += DECREMENT; +} + +void mult() { + // no atomicity needed, can only be executed by 1 thread + // and no concurrency with other tasks possible + val *= MULTIPLIER; +} + +int main() { + int num_tasks = 0; + int *x, *y; + #pragma omp parallel + #pragma omp single + for (int iter = 0; iter < NT; ++iter) { + int gtid = __kmpc_global_thread_num(nullptr); + int res = __kmpc_start_record_task(nullptr, gtid, /* kmp_tdg_flags */ 0, /* tdg_id */0); + if (res) { + num_tasks++; + #pragma omp task depend(out:y) + add(); + #pragma omp task depend(out:x) + sub(); + #pragma omp task depend(in:x,y) + mult(); + } + __kmpc_end_record_task(nullptr, gtid, /* kmp_tdg_flags */0, /* tdg_id */0); + res = __kmpc_start_record_task(nullptr, gtid, /* kmp_tdg_flags */ 0, /* tdg_id */1); + if (res) { + num_tasks++; + #pragma omp task depend(out:y) + add(); + #pragma omp task depend(out:x) + sub(); + #pragma omp task depend(in:x,y) + mult(); + } + __kmpc_end_record_task(nullptr, gtid, /* kmp_tdg_flags */0, /* tdg_id */1); + } + + assert(num_tasks==2); + assert(val==0); + + std::cout << "Passed" << std::endl; + return 0; +} +// CHECK: Passed |