source: CIVL/examples/concurrency/threadprivate.cvl@ a465feb

1.23 2.0 acw/focus-triggers main test-branch
Last change on this file since a465feb was 551b7d9, checked in by Manchun Zheng <zmanchun@…>, 12 years ago

remove $atomic.

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

  • Property mode set to 100644
File size: 1.1 KB
Line 
1#include<civlc.h>
2#include<stdio.h>
3#define OWNS(numIters, threadId, index) ((index)%NTHREADS==threadId)
4$heap h;
5int NTHREADS = 10;
6$proc threads[NTHREADS];
7
8int calculate_sum(int length, int *_pglobal) {
9 int sum = 0;
10
11 for (int j=0; j<length; j++) sum += _pglobal[j];
12 return(sum);
13}
14
15
16void main() {
17 int i, j, sum, TID, n=20;
18 int length[n], check[n];
19
20 for (i=0; i<n; i++) {
21 length[i] = 10*(i+1);
22 check[i] = length[i]*(length[i]+1)/2;
23 }
24
25 void __par_1(int _TID) { // every thread runs this
26 int *_pglobal;
27
28 void __for_loop_1 (int _i) {
29 int _j, _sum;
30
31 _pglobal = (int*)$malloc(&h, length[_i]*sizeof(int));
32 _sum = 0;
33 for (_j=0; _j<length[_i]; _j++) _pglobal[_j]=_j+1;
34 _sum = calculate_sum(length[_i], _pglobal);
35 printf("TID %d: value of sum for i = %d is %8d (check = %8d)\n",
36 _TID, _i, _sum, check[_i]);
37 $assert(_sum == check[_i]);
38 $free(&h, _pglobal);
39 }
40
41 for (int _i=0; _i<n; _i++)
42 if (OWNS(n, _TID, _i)) __for_loop_1(_i);
43 }
44
45 for (int t=0; t<NTHREADS; t++) threads[t] = $spawn __par_1(t);
46 for (int t=0; t<NTHREADS; t++) $wait threads[t];
47
48}
Note: See TracBrowser for help on using the repository browser.