1// RUN: %clang %openmp_flags %flags-use-compiler-omp-h %s -o %t && %libomp-run
2// UNSUPPORTED: gcc-5, gcc-6, gcc-7, gcc-8
3// UNSUPPORTED: clang-5, clang-6, clang-7, clang-8, clang-9, clang-10
4// UNSUPPORTED: icc
5
6#include <stdio.h>
7#include <stdlib.h>
8#include <omp.h>
9#include "omp_my_sleep.h"
10
11int a, b;
12
13void mutexinoutset_task() {
14 if (b != 0) {
15 fprintf(stderr, format: "mutexinoutset_task: b != 0 at start of task\n");
16 exit(EXIT_FAILURE);
17 }
18 b++;
19 if (b != 1) {
20 fprintf(stderr, format: "mutexinoutset_task: b != 1\n");
21 exit(EXIT_FAILURE);
22 }
23 my_sleep(0.1);
24 b--;
25 if (b != 0) {
26 fprintf(stderr, format: "mutexinoutset_task: b != 0 at end of task\n");
27 exit(EXIT_FAILURE);
28 }
29}
30
31int main(int argc, char** argv) {
32 omp_depend_t dep_a_in;
33 omp_depend_t dep_a_out;
34 omp_depend_t dep_a_inout;
35 omp_depend_t dep_a_mutexinoutset;
36
37 a = 0;
38 b = 0;
39
40 #pragma omp depobj(dep_a_in) depend(in: a)
41 #pragma omp depobj(dep_a_out) depend(out: a)
42 #pragma omp depobj(dep_a_inout) depend(inout: a)
43 #pragma omp depobj(dep_a_mutexinoutset) depend(mutexinoutset: a)
44
45 #pragma omp parallel
46 {
47 #pragma omp single
48 {
49
50 #pragma omp task depend(depobj: dep_a_out)
51 {
52 my_sleep(0.1);
53 a = 10;
54 }
55
56 #pragma omp task depend(depobj: dep_a_inout)
57 {
58 my_sleep(0.1);
59 a++;
60 }
61
62 #pragma omp task depend(depobj: dep_a_mutexinoutset)
63 mutexinoutset_task();
64 #pragma omp task depend(depobj: dep_a_mutexinoutset)
65 mutexinoutset_task();
66 #pragma omp task depend(depobj: dep_a_mutexinoutset)
67 mutexinoutset_task();
68 #pragma omp task depend(depobj: dep_a_mutexinoutset)
69 mutexinoutset_task();
70 #pragma omp task depend(depobj: dep_a_mutexinoutset)
71 mutexinoutset_task();
72
73 #pragma omp task depend(depobj: dep_a_in)
74 { a += 10; }
75 }
76 }
77
78 if (a != 21) {
79 fprintf(stderr, format: "a (%d) != 21\n", a);
80 exit(EXIT_FAILURE);
81 }
82
83 #pragma omp depobj(dep_a_in) destroy
84 #pragma omp depobj(dep_a_out) destroy
85 #pragma omp depobj(dep_a_inout) destroy
86 #pragma omp depobj(dep_a_mutexinoutset) destroy
87
88 return EXIT_SUCCESS;
89}
90

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