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

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

fixed the bug for message passing programs. (that used bundle type to look for a communicator); added ring3.cvl for a simple mpi example modeled in CIVL.

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

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