1.23
2.0
acw/focus-triggers
main
test-branch
| Line | |
|---|
| 1 | // x: not live-in, yes live-out
|
|---|
| 2 | // outer scope
|
|---|
| 3 | // loop-carried output-dependence: x=... : accept values based on loop variable; or not.
|
|---|
| 4 | //Solution: Can be parallelized using lastprivate(x)
|
|---|
| 5 | //
|
|---|
| 6 | // Semantics of lastprivate (x)
|
|---|
| 7 | // causes the corresponding original list item to be updated after the end of the region.
|
|---|
| 8 | // The compiler/runtime copies the local value back to the shared one within the last iteration.
|
|---|
| 9 | // Without lastprivate(x), there will be race condition for x.
|
|---|
| 10 | #include <stdio.h>
|
|---|
| 11 | #include <stdlib.h>
|
|---|
| 12 | int main(int argc, char* argv[])
|
|---|
| 13 | {
|
|---|
| 14 | int i,x;
|
|---|
| 15 | int len = 10000;
|
|---|
| 16 |
|
|---|
| 17 | if (argc>1)
|
|---|
| 18 | len = atoi(argv[1]);
|
|---|
| 19 |
|
|---|
| 20 | #pragma omp parallel for private (i)
|
|---|
| 21 | for (i=0;i<len;i++)
|
|---|
| 22 | x=i;
|
|---|
| 23 | printf("x=%d",x);
|
|---|
| 24 | return 0;
|
|---|
| 25 | }
|
|---|
| 26 |
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.