source: CIVL/examples/omp/DataRaceBench/micro-benchmarks/lastprivatemissing-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: 730 bytes
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>
12int 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.