1.23
2.0
main
test-branch
| Line | |
|---|
| 1 | // Data race on outLen due to ++ operation.
|
|---|
| 2 | // Adding private (outLen) can avoid race condition. But it is wrong semantically.
|
|---|
| 3 | #include <stdlib.h>
|
|---|
| 4 | #include <stdio.h>
|
|---|
| 5 | int input[1000];
|
|---|
| 6 | int output[1000];
|
|---|
| 7 |
|
|---|
| 8 | int main()
|
|---|
| 9 | {
|
|---|
| 10 | int i ;
|
|---|
| 11 | int inLen=1000 ;
|
|---|
| 12 | int outLen = 0;
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 | for (i=0; i<inLen; ++i)
|
|---|
| 16 | input[i]= i;
|
|---|
| 17 |
|
|---|
| 18 | #pragma omp parallel for
|
|---|
| 19 | for (i=0; i<inLen; ++i)
|
|---|
| 20 | {
|
|---|
| 21 | output[outLen++] = input[i] ;
|
|---|
| 22 | }
|
|---|
| 23 |
|
|---|
| 24 |
|
|---|
| 25 | printf("output[500]=%d\n",output[500]);
|
|---|
| 26 |
|
|---|
| 27 | return 0;
|
|---|
| 28 | }
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.