| 1 |
#include <omp.h> |
| 2 |
#include <stdlib.h> |
| 3 |
#include <unistd.h> |
| 4 |
|
| 5 |
int |
| 6 |
main () |
| 7 |
{ |
| 8 |
int a[8] = {}; |
| 9 |
omp_depend_t d1, d2; |
| 10 |
#pragma omp depobj (d1) depend(inoutset: a) |
| 11 |
#pragma omp depobj (d2) depend(inout: a) |
| 12 |
#pragma omp depobj (d2) update(inoutset) |
| 13 |
#pragma omp parallel |
| 14 |
{ |
| 15 |
#pragma omp barrier |
| 16 |
#pragma omp master |
| 17 |
{ |
| 18 |
#pragma omp task shared(a) depend(out: a) |
| 19 |
{ |
| 20 |
usleep (5000); |
| 21 |
a[0] = 1; a[1] = 2; a[2] = 3; a[3] = 4; |
| 22 |
} |
| 23 |
/* The above task needs to finish first. */ |
| 24 |
#pragma omp task shared(a) depend(in: a) |
| 25 |
{ |
| 26 |
if (a[0] != 1 || a[1] != 2 || a[2] != 3 || a[3] != 4) |
| 27 |
abort (); |
| 28 |
usleep (5000); |
| 29 |
a[4] = 42; |
| 30 |
} |
| 31 |
#pragma omp task shared(a) depend(in: a) |
| 32 |
{ |
| 33 |
if (a[0] != 1 || a[1] != 2 || a[2] != 3 || a[3] != 4) |
| 34 |
abort (); |
| 35 |
usleep (5000); |
| 36 |
a[5] = 43; |
| 37 |
} |
| 38 |
#pragma omp task shared(a) depend(in: a) |
| 39 |
{ |
| 40 |
if (a[0] != 1 || a[1] != 2 || a[2] != 3 || a[3] != 4) |
| 41 |
abort (); |
| 42 |
usleep (5000); |
| 43 |
a[6] = 44; |
| 44 |
} |
| 45 |
#pragma omp task shared(a) depend(in: a) |
| 46 |
{ |
| 47 |
if (a[0] != 1 || a[1] != 2 || a[2] != 3 || a[3] != 4) |
| 48 |
abort (); |
| 49 |
usleep (5000); |
| 50 |
a[7] = 45; |
| 51 |
} |
| 52 |
/* The above 4 tasks can be scheduled in any order but need to wait |
| 53 |
for the depend(out: a) task. */ |
| 54 |
#pragma omp task shared(a) depend(inoutset: a) |
| 55 |
{ |
| 56 |
if (a[4] != 42 || a[5] != 43 || a[6] != 44 || a[7] != 45) |
| 57 |
abort (); |
| 58 |
usleep (5000); |
| 59 |
a[0] = 42; |
| 60 |
} |
| 61 |
#pragma omp task shared(a) depend(iterator(i=1:3:2), inoutset: a) |
| 62 |
{ |
| 63 |
if (a[4] != 42 || a[5] != 43 || a[6] != 44 || a[7] != 45) |
| 64 |
abort (); |
| 65 |
usleep (5000); |
| 66 |
a[1] = 43; |
| 67 |
} |
| 68 |
#pragma omp task shared(a) depend(depobj: d1) |
| 69 |
{ |
| 70 |
if (a[4] != 42 || a[5] != 43 || a[6] != 44 || a[7] != 45) |
| 71 |
abort (); |
| 72 |
usleep (5000); |
| 73 |
a[2] = 44; |
| 74 |
} |
| 75 |
#pragma omp task shared(a) depend(depobj: d2) |
| 76 |
{ |
| 77 |
if (a[4] != 42 || a[5] != 43 || a[6] != 44 || a[7] != 45) |
| 78 |
abort (); |
| 79 |
usleep (5000); |
| 80 |
a[3] = 45; |
| 81 |
} |
| 82 |
/* The above 4 tasks can be scheduled in any order but need to wait |
| 83 |
for all the above depend(in: a) tasks. */ |
| 84 |
#pragma omp task shared(a) depend(in: a) |
| 85 |
{ |
| 86 |
if (a[0] != 42 || a[1] != 43 || a[2] != 44 || a[3] != 45) |
| 87 |
abort (); |
| 88 |
usleep (5000); |
| 89 |
a[4] = 46; |
| 90 |
} |
| 91 |
#pragma omp task shared(a) depend(in: a) |
| 92 |
{ |
| 93 |
if (a[0] != 42 || a[1] != 43 || a[2] != 44 || a[3] != 45) |
| 94 |
abort (); |
| 95 |
usleep (5000); |
| 96 |
a[5] = 47; |
| 97 |
} |
| 98 |
#pragma omp task shared(a) depend(in: a) |
| 99 |
{ |
| 100 |
if (a[0] != 42 || a[1] != 43 || a[2] != 44 || a[3] != 45) |
| 101 |
abort (); |
| 102 |
usleep (5000); |
| 103 |
a[6] = 48; |
| 104 |
} |
| 105 |
#pragma omp task shared(a) depend(in: a) |
| 106 |
{ |
| 107 |
if (a[0] != 42 || a[1] != 43 || a[2] != 44 || a[3] != 45) |
| 108 |
abort (); |
| 109 |
usleep (5000); |
| 110 |
a[7] = 49; |
| 111 |
} |
| 112 |
/* The above 4 tasks can be scheduled in any order but need to wait |
| 113 |
for all the above depend(inoutset: a), |
| 114 |
depend(iterator(i=1:3:2), inoutset: a), depend(depobj: d1) and |
| 115 |
depend(depobj: d2) tasks. */ |
| 116 |
#pragma omp task shared(a) depend(inoutset: a) |
| 117 |
{ |
| 118 |
if (a[4] != 46|| a[5] != 47 || a[6] != 48 || a[7] != 49) |
| 119 |
abort (); |
| 120 |
usleep (5000); |
| 121 |
a[0] = 50; |
| 122 |
} |
| 123 |
/* The above task needs to wait for all the above 4 depend(in: a) |
| 124 |
tasks. */ |
| 125 |
#pragma omp task shared(a) depend(out: a) |
| 126 |
{ |
| 127 |
if (a[0] != 50 || a[4] != 46|| a[5] != 47 || a[6] != 48 || a[7] != 49) |
| 128 |
abort (); |
| 129 |
usleep (5000); |
| 130 |
a[0] = 51; |
| 131 |
} |
| 132 |
/* The above task needs to wait for the above depend(inoutset: a) task. */ |
| 133 |
#pragma omp task shared(a) depend(inoutset: a) |
| 134 |
{ |
| 135 |
if (a[0] != 51 || a[4] != 46|| a[5] != 47 || a[6] != 48 || a[7] != 49) |
| 136 |
abort (); |
| 137 |
usleep (5000); |
| 138 |
a[0] = 52; |
| 139 |
} |
| 140 |
/* The above task needs to wait for the above depend(out: a) task. */ |
| 141 |
#pragma omp task shared(a) depend(mutexinoutset: a) |
| 142 |
{ |
| 143 |
if (a[0] != 52 || a[4] != 46|| a[5] != 47 || a[6] != 48 || a[7] != 49) |
| 144 |
abort (); |
| 145 |
usleep (5000); |
| 146 |
a[0] = 53; |
| 147 |
} |
| 148 |
/* The above task needs to wait for the above depend(inoutset: a) task. */ |
| 149 |
#pragma omp task shared(a) depend(inoutset: a) |
| 150 |
{ |
| 151 |
if (a[0] != 53 || a[4] != 46|| a[5] != 47 || a[6] != 48 || a[7] != 49) |
| 152 |
abort (); |
| 153 |
usleep (5000); |
| 154 |
a[0] = 54; |
| 155 |
} |
| 156 |
/* The above task needs to wait for the above |
| 157 |
depend(mutexinoutset: a) task. */ |
| 158 |
} |
| 159 |
} |
| 160 |
if (a[0] != 54 || a[1] != 43 || a[2] != 44 || a[3] != 45 |
| 161 |
|| a[4] != 46|| a[5] != 47 || a[6] != 48 || a[7] != 49) |
| 162 |
abort (); |
| 163 |
return 0; |
| 164 |
} |