source: CIVL/examples/omp/DataRaceBench/micro-benchmarks/outofbounds-var-yes.c@ e5cec5ae

1.23 2.0 acw/focus-triggers main test-branch
Last change on this file since e5cec5ae was 36a61f3, checked in by Ziqing Luo <ziqing@…>, 9 years ago

Commit DataRaceBench into CIVL examples

git-svn-id: svn://vsl.cis.udel.edu/civl/trunk@4225 fb995dde-84ed-4084-dfe6-e5aef3e2452c

  • Property mode set to 100644
File size: 883 bytes
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>
22int 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.