1 // RUN: %libomp-compile-and-run
3 // Tests OMP 5.0 task dependences "mutexinoutset", emulates compiler codegen
4 // Mutually exclusive tasks get same input dependency info array
13 // task6 <-->task7 (these two are mutually exclusive)
22 #define mysleep(n) Sleep(n)
25 #define mysleep(n) usleep((n)*1000)
28 static int checker
= 0; // to check if two tasks run simultaneously
34 // ---------------------------------------------------------------------------
35 // internal data to emulate compiler codegen
36 typedef int(*entry_t
)(int, int**);
50 int thunk(int gtid
, int** pshareds
) {
52 int th
= omp_get_thread_num();
55 printf("task __%d, th %d\n", t
, th
);
58 printf("Error1, checker %d != 1\n", checker
);
63 printf("Error2, checker %d != 1\n", checker
);
73 int __kmpc_global_thread_num(id
*);
74 extern int** __kmpc_omp_task_alloc(id
*loc
, int gtid
, int flags
,
75 size_t sz
, size_t shar
, entry_t rtn
);
77 __kmpc_omp_task_with_deps(id
*loc
, int gtid
, int **task
, int nd
, dep
*dep_lst
,
78 int nd_noalias
, dep
*noalias_dep_lst
);
79 static id loc
= {0, 2, 0, 0, ";file;func;0;0;;"};
83 // End of internal data
84 // ---------------------------------------------------------------------------
89 omp_set_num_threads(2);
92 #pragma omp single nowait
96 int gtid
= __kmpc_global_thread_num(&loc
);
97 int t
= omp_get_thread_num();
98 #pragma omp task depend(in: i1, i2)
99 { int th
= omp_get_thread_num();
100 printf("task 0_%d, th %d\n", t
, th
);
102 #pragma omp task depend(in: i1, i3)
103 { int th
= omp_get_thread_num();
104 printf("task 1_%d, th %d\n", t
, th
);
106 #pragma omp task depend(in: i2) depend(out: i1)
107 { int th
= omp_get_thread_num();
108 printf("task 2_%d, th %d\n", t
, th
);
110 #pragma omp task depend(in: i1)
111 { int th
= omp_get_thread_num();
112 printf("task 3_%d, th %d\n", t
, th
);
114 #pragma omp task depend(out: i2)
115 { int th
= omp_get_thread_num();
116 printf("task 4_%d, th %d\n", t
, th
);
117 mysleep(DELAY
+5); } // wait a bit longer than task 3
118 #pragma omp task depend(out: i3)
119 { int th
= omp_get_thread_num();
120 printf("task 5_%d, th %d\n", t
, th
);
122 // compiler codegen start
124 ptr
= __kmpc_omp_task_alloc(&loc
, gtid
, 0, 28, 16, thunk
);
125 sdep
[0].addr
= (size_t)&i1
;
126 sdep
[0].len
= 0; // not used
127 sdep
[0].flags
= 4; // mx
128 sdep
[1].addr
= (size_t)&i4
;
129 sdep
[1].len
= 0; // not used
130 sdep
[1].flags
= 4; // mx
131 **ptr
= t
+ 10; // init single shared variable
132 __kmpc_omp_task_with_deps(&loc
, gtid
, ptr
, 2, sdep
, 0, 0);
135 ptr
= __kmpc_omp_task_alloc(&loc
, gtid
, 0, 28, 16, thunk
);
136 **ptr
= t
+ 20; // init single shared variable
137 __kmpc_omp_task_with_deps(&loc
, gtid
, ptr
, 2, sdep
, 0, 0);
138 // compiler codegen end
139 #pragma omp task depend(in: i1)
140 { int th
= omp_get_thread_num();
141 printf("task 8_%d, th %d\n", t
, th
);