1// RUN: %libomp-compile-and-run
2
3// test checks IN dep kind in depend clause on taskwait nowait
4// uses codegen emulation
5// Note: no outlined task routine used
6#include <stdio.h>
7#include <omp.h>
8// ---------------------------------------------------------------------------
9// internal data to emulate compiler codegen
10#define TIED 1
11typedef struct DEP {
12 size_t addr;
13 size_t len;
14 unsigned char flags;
15} _dep;
16typedef struct ID {
17 int reserved_1;
18 int flags;
19 int reserved_2;
20 int reserved_3;
21 char *psource;
22} _id;
23typedef struct task {
24 void** shareds;
25 void* entry;
26 int part_id;
27 void* destr_thunk;
28 int priority;
29 long long device_id;
30 int f_priv;
31} task_t;
32typedef int(*entry_t)(int, task_t*);
33
34#ifdef __cplusplus
35extern "C" {
36#endif
37extern int __kmpc_global_thread_num(_id*);
38task_t *__kmpc_omp_task_alloc(_id *loc, int gtid, int flags,
39 size_t sz, size_t shar, entry_t rtn);
40int __kmpc_omp_task_with_deps(_id *loc, int gtid, task_t *task, int ndeps,
41 _dep *dep_lst, int nd_noalias, _dep *noalias_l);
42#ifdef __cplusplus
43} // extern "C"
44#endif
45
46int main()
47{
48 int i1,i2,i3;
49 omp_set_num_threads(2);
50 printf(format: "addresses: %p %p %p\n", &i1, &i2, &i3);
51 #pragma omp parallel
52 {
53 int t = omp_get_thread_num();
54 printf(format: "thread %d enters parallel\n", t);
55 #pragma omp single
56 {
57 #pragma omp task depend(in: i3)
58 {
59 int th = omp_get_thread_num();
60 printf(format: "task 0 created by th %d, executed by th %d\n", t, th);
61 }
62 #pragma omp task depend(in: i2)
63 {
64 int th = omp_get_thread_num();
65 printf(format: "task 1 created by th %d, executed by th %d\n", t, th);
66 }
67// #pragma omp taskwait depend(in: i1, i2) nowait
68 {
69 _dep sdep[2];
70 static _id loc = {0, 2, 0, 0, ";test.c;func;67;0;;"};
71 int gtid = __kmpc_global_thread_num(&loc);
72// instead of creating an empty task function we can now send NULL to runtime
73 task_t *ptr = __kmpc_omp_task_alloc(loc: &loc, gtid, TIED,
74 sz: sizeof(task_t), shar: 0, NULL);
75 sdep[0].addr = (size_t)&i2;
76 sdep[0].flags = 1; // 1-in, 2-out, 3-inout, 4-mtx, 8-inoutset
77 sdep[1].addr = (size_t)&i1;
78 sdep[1].flags = 1; // in
79 __kmpc_omp_task_with_deps(loc: &loc, gtid, task: ptr, ndeps: 2, dep_lst: sdep, nd_noalias: 0, NULL);
80 }
81 printf(format: "single done\n");
82 }
83 }
84 printf(format: "passed\n");
85 return 0;
86}
87

source code of openmp/runtime/test/tasking/kmp_taskwait_nowait.c