[llvm] Stop including unordered_map (NFC)
[llvm-project.git] / openmp / runtime / test / tasking / hidden_helper_task / taskgroup.cpp
blob551e4d3029469b05649a6e7e6d5ebfdd15dfa0bd
1 // RUN: %libomp-cxx-compile-and-run
3 /*
4 * This test aims to check whether hidden helper task can work with regular task
5 * in terms of dependences. It is equivalent to the following code:
7 * #pragma omp parallel
8 * for (int i = 0; i < N; ++i) {
9 * int data1 = 0, data2 = 0;
10 * #pragma omp taskgroup
11 * {
12 * #pragma omp hidden helper task shared(data1)
13 * {
14 * data1 = 1;
15 * }
16 * #pragma omp hidden helper task shared(data2)
17 * {
18 * data2 = 2;
19 * }
20 * }
21 * assert(data1 == 1);
22 * assert(data2 == 2);
23 * }
26 #include "common.h"
28 extern "C" {
29 struct kmp_task_t_with_privates {
30 kmp_task_t task;
33 struct anon {
34 int32_t *data;
38 template <int I>
39 kmp_int32 omp_task_entry(kmp_int32 gtid, kmp_task_t_with_privates *task) {
40 auto shareds = reinterpret_cast<anon *>(task->task.shareds);
41 auto p = shareds->data;
42 *p = I;
43 return 0;
46 int main(int argc, char *argv[]) {
47 constexpr const int N = 1024;
48 #pragma omp parallel for
49 for (int i = 0; i < N; ++i) {
50 int32_t gtid = __kmpc_global_thread_num(nullptr);
51 int32_t data1 = 0, data2 = 0;
52 __kmpc_taskgroup(nullptr, gtid);
54 auto task1 = __kmpc_omp_target_task_alloc(
55 nullptr, gtid, 1, sizeof(kmp_task_t_with_privates), sizeof(anon),
56 reinterpret_cast<kmp_routine_entry_t>(omp_task_entry<1>), -1);
57 auto shareds = reinterpret_cast<anon *>(task1->shareds);
58 shareds->data = &data1;
59 __kmpc_omp_task(nullptr, gtid, task1);
61 auto task2 = __kmpc_omp_target_task_alloc(
62 nullptr, gtid, 1, sizeof(kmp_task_t_with_privates), sizeof(anon),
63 reinterpret_cast<kmp_routine_entry_t>(omp_task_entry<2>), -1);
64 shareds = reinterpret_cast<anon *>(task2->shareds);
65 shareds->data = &data2;
66 __kmpc_omp_task(nullptr, gtid, task2);
68 __kmpc_end_taskgroup(nullptr, gtid);
70 assert(data1 == 1);
71 assert(data2 == 2);
74 std::cout << "PASS\n";
75 return 0;
78 // CHECK: PASS