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