| 1 |
extern void abort (void); |
| 2 |
extern int omp_get_num_threads (void); |
| 3 |
|
| 4 |
struct Y |
| 5 |
{ |
| 6 |
int l[5][10]; |
| 7 |
}; |
| 8 |
|
| 9 |
struct X |
| 10 |
{ |
| 11 |
struct Y y; |
| 12 |
float b[10]; |
| 13 |
}; |
| 14 |
|
| 15 |
void |
| 16 |
parallel (int a, int b) |
| 17 |
{ |
| 18 |
int i, j; |
| 19 |
struct X A[10][5]; |
| 20 |
a = b = 3; |
| 21 |
|
| 22 |
for (i = 0; i < 10; i++) |
| 23 |
for (j = 0; j < 5; j++) |
| 24 |
A[i][j].y.l[3][3] = -10; |
| 25 |
|
| 26 |
#pragma omp parallel shared (a, b, A) num_threads (5) |
| 27 |
{ |
| 28 |
int i, j; |
| 29 |
|
| 30 |
#pragma omp atomic |
| 31 |
a += omp_get_num_threads (); |
| 32 |
|
| 33 |
#pragma omp atomic |
| 34 |
b += omp_get_num_threads (); |
| 35 |
|
| 36 |
#pragma omp for private (j) |
| 37 |
for (i = 0; i < 10; i++) |
| 38 |
for (j = 0; j < 5; j++) |
| 39 |
A[i][j].y.l[3][3] += 20; |
| 40 |
|
| 41 |
} |
| 42 |
|
| 43 |
for (i = 0; i < 10; i++) |
| 44 |
for (j = 0; j < 5; j++) |
| 45 |
if (A[i][j].y.l[3][3] != 10) |
| 46 |
abort (); |
| 47 |
|
| 48 |
if (a != 28) |
| 49 |
abort (); |
| 50 |
|
| 51 |
if (b != 28) |
| 52 |
abort (); |
| 53 |
} |
| 54 |
|
| 55 |
int |
| 56 |
main() |
| 57 |
{ |
| 58 |
parallel (1, 2); |
| 59 |
return 0; |
| 60 |
} |