1.23
2.0
acw/focus-triggers
main
test-branch
| Line | |
|---|
| 1 | /* The outmost loop is parallelized.
|
|---|
| 2 | But the inner level loop has out of bound access for b[i][j]
|
|---|
| 3 | when j==0.
|
|---|
| 4 | This will case memory access of a previous row's last element.
|
|---|
| 5 |
|
|---|
| 6 | For example, an array of 4x4:
|
|---|
| 7 | j=0 1 2 3
|
|---|
| 8 | i=0 x x x x
|
|---|
| 9 | 1 x x x x
|
|---|
| 10 | 2 x x x x
|
|---|
| 11 | 3 x x x x
|
|---|
| 12 |
|
|---|
| 13 | outer loop: i=2,
|
|---|
| 14 | inner loop: j=0
|
|---|
| 15 | array element accessed b[i][j-1] becomes b[2][-1], which in turn is b[1][3]
|
|---|
| 16 | due to linearized row-major storage of the 2-D array.
|
|---|
| 17 |
|
|---|
| 18 | This causes loop-carried data dependence between i=2 and i=1.
|
|---|
| 19 | */
|
|---|
| 20 | #include <stdio.h>
|
|---|
| 21 | int main(int argc, char* argv[])
|
|---|
| 22 | {
|
|---|
| 23 | int i,j;
|
|---|
| 24 | int n=100, m=100;
|
|---|
| 25 | double b[n][m];
|
|---|
| 26 | #pragma omp parallel for private(j)
|
|---|
| 27 | for (i=0;i<n;i++)
|
|---|
| 28 | for (j=0;j<m;j++) // Note there will be out of bound access
|
|---|
| 29 | b[i][j]=b[i][j-1];
|
|---|
| 30 |
|
|---|
| 31 | printf ("b[50][50]=%f\n",b[50][50]);
|
|---|
| 32 |
|
|---|
| 33 | return 0;
|
|---|
| 34 | }
|
|---|
| 35 |
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.