LLVM OpenMP 20.0.0git
taskgroup.cpp
Go to the documentation of this file.
1// RUN: %libomp-cxx-compile-and-run
2
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:
6 *
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 * }
24 */
25
26#include "common.h"
27
28extern "C" {
31};
32
33struct anon {
34 int32_t *data;
35};
36}
37
38template <int I>
40 auto shareds = reinterpret_cast<anon *>(task->task.shareds);
41 auto p = shareds->data;
42 *p = I;
43 return 0;
44}
45
46int 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);
53
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);
60
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);
67
68 __kmpc_end_taskgroup(nullptr, gtid);
69
70 assert(data1 == 1);
71 assert(data2 == 2);
72 }
73
74 std::cout << "PASS\n";
75 return 0;
76}
77
78// CHECK: PASS
#define N
Definition: bug54082.c:13
kmp_int32(*)(kmp_int32, void *) kmp_routine_entry_t
Definition: common.h:11
KMP_EXPORT kmp_int32 __kmpc_global_thread_num(ident_t *)
void const char const char int ITT_FORMAT __itt_group_sync p
KMP_EXPORT kmp_int32 __kmpc_omp_task(ident_t *loc_ref, kmp_int32 gtid, kmp_task_t *new_task)
KMP_EXPORT void __kmpc_end_taskgroup(ident_t *loc, int gtid)
KMP_EXPORT void __kmpc_taskgroup(ident_t *loc, int gtid)
KMP_EXPORT kmp_task_t * __kmpc_omp_target_task_alloc(ident_t *loc_ref, kmp_int32 gtid, kmp_int32 flags, size_t sizeof_kmp_task_t, size_t sizeof_shareds, kmp_routine_entry_t task_entry, kmp_int64 device_id)
#define i
Definition: kmp_stub.cpp:87
int32_t kmp_int32
int32_t * data
Definition: affinity.cpp:52
Definition: kmp.h:2472
void ** shareds
void task2()
Definition: taskdep_if0.c:15
void task1()
Definition: taskdep_if0.c:10
kmp_int32 omp_task_entry(kmp_int32 gtid, kmp_task_t_with_privates *task)
Definition: taskgroup.cpp:39
int main()
Definition: test-touch.c:21