1.23
2.0
acw/focus-triggers
main
test-branch
| Line | |
|---|
| 1 | // Some threads may finish the for loop early and execute errors = dt[9]+1
|
|---|
| 2 | // while another thread may still be simultaneously executing
|
|---|
| 3 | // the for worksharing region by writing to d[9],
|
|---|
| 4 | // which may cause a data race.
|
|---|
| 5 | // This is a good test for dynamic tools since the data race does not always happen at runtime.
|
|---|
| 6 | //
|
|---|
| 7 | // Liao, source paper: Ma Symbolic Analysis of Concurrency Errors in OpenMP Programs, ICPP 2013
|
|---|
| 8 | #include <stdio.h>
|
|---|
| 9 | #include <assert.h>
|
|---|
| 10 |
|
|---|
| 11 | int main()
|
|---|
| 12 | {
|
|---|
| 13 | int i,error;
|
|---|
| 14 | int len = 1000;
|
|---|
| 15 | int a[1000], b=5;
|
|---|
| 16 |
|
|---|
| 17 | for (i=0; i<len; i++)
|
|---|
| 18 | a[i]= i;
|
|---|
| 19 |
|
|---|
| 20 | #pragma omp parallel shared(b, error)
|
|---|
| 21 | {
|
|---|
| 22 | #pragma omp for nowait
|
|---|
| 23 | for(i = 0; i < len; i++)
|
|---|
| 24 | a[i] = b + a[i]*5;
|
|---|
| 25 |
|
|---|
| 26 | #pragma omp single
|
|---|
| 27 | error = a[9] + 1;
|
|---|
| 28 | }
|
|---|
| 29 |
|
|---|
| 30 | printf ("error = %d\n", error);
|
|---|
| 31 | // assert (error==51);
|
|---|
| 32 | return 0;
|
|---|
| 33 | }
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.