1 #include <stdlib.h> 2 #include <omp.h> 3 4 void dep(omp_depend_t & d1,omp_depend_t * d2)5dep (omp_depend_t &d1, omp_depend_t *d2) 6 { 7 int x = 1; 8 #pragma omp depobj (d1) depend(in: x) 9 #pragma omp depobj (*d2) depend(in: x) 10 11 #pragma omp depobj (d2[0]) update(out) 12 #pragma omp parallel 13 #pragma omp single 14 { 15 #pragma omp task shared (x) depend(depobj:*d2) 16 x = 2; 17 #pragma omp task shared (x) depend(depobj : d1) 18 if (x != 2) 19 abort (); 20 } 21 #pragma omp depobj (d2[0]) destroy 22 #pragma omp depobj (d1) destroy 23 } 24 25 template <typename T> 26 void dep2(T & d2)27dep2 (T &d2) 28 { 29 T d1; 30 #pragma omp parallel 31 #pragma omp single 32 { 33 int x = 1; 34 #pragma omp depobj (d1) depend(out: x) 35 #pragma omp depobj (*&d2) depend (in:x) 36 #pragma omp depobj(d2)update(in) 37 #pragma omp task shared (x) depend(depobj :d1) 38 x = 2; 39 #pragma omp task shared (x) depend(depobj: d2) 40 if (x != 2) 41 abort (); 42 #pragma omp taskwait 43 #pragma omp depobj(d1)destroy 44 #pragma omp depobj((&d2)[0]) destroy 45 } 46 } 47 48 template <typename T> 49 void dep3(void)50dep3 (void) 51 { 52 T d[2]; 53 #pragma omp parallel 54 { 55 int x = 1; 56 #pragma omp single 57 { 58 #pragma omp depobj(d[0]) depend(out:x) 59 #pragma omp depobj(d[1]) depend(in: x) 60 #pragma omp task shared (x) depend(depobj:*d) 61 x = 2; 62 #pragma omp task shared (x) depend(depobj:*(d + 1)) 63 if (x != 2) 64 abort (); 65 } 66 } 67 #pragma omp depobj(d[0]) destroy 68 #pragma omp depobj(d[1]) destroy 69 } 70 71 int xx; 72 omp_depend_t dd1, dd2; 73 74 template <int N> 75 void antidep(void)76antidep (void) 77 { 78 xx = 1; 79 #pragma omp parallel 80 #pragma omp single 81 { 82 #pragma omp task shared(xx) depend(depobj:dd2) 83 if (xx != 1) 84 abort (); 85 #pragma omp task shared(xx) depend(depobj:dd1) 86 xx = 2; 87 } 88 } 89 90 int main()91main () 92 { 93 omp_depend_t d1, d2, d3; 94 dep (d1, &d2); 95 dep2 <omp_depend_t> (d3); 96 dep3 <omp_depend_t> (); 97 #pragma omp depobj (dd1) depend (inout: xx) 98 #pragma omp depobj (dd2) depend (in : xx) 99 antidep <0> (); 100 #pragma omp depobj (dd2) destroy 101 #pragma omp depobj (dd1) destroy 102 return 0; 103 } 104