source: CIVL/examples/concurrency/adderBad.cvl@ ac5660f

1.23 2.0 acw/focus-triggers main test-branch
Last change on this file since ac5660f was 6aaa7a2, checked in by Manchun Zheng <zmanchun@…>, 13 years ago

create benchmarks as a new source folder /bench.

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

  • Property mode set to 100644
File size: 767 bytes
Line 
1/*
2 * civl verify -inputB=5 adderBad.cvl
3 * */
4#include <civlc.h>
5
6$input int B; // upper bound on array length
7$input int N; // length of array
8$assume 0<=N && N<=B;
9$input double a[N];
10
11double adderSeq(double *p, int n) {
12 double s = 0.0;
13
14 for (int i = 0; i < n; i++) {
15 s += p[i];
16 }
17 return s;
18}
19
20double adderPar(double *p, int n) {
21 double s = 0.0; // sum shared by workers
22 $proc workers[n]; // one worker for each element!
23
24 void worker(int i) {
25 double t;
26
27 t = s;
28 t += p[i];
29 s = t;
30 }
31
32 for (int j = 0; j < n; j++)
33 workers[j] = $spawn worker(j);
34 for (int j = 0; j < n; j++)
35 $wait workers[j];
36 return s;
37}
38
39void main() {
40 double seq = adderSeq(&a[0], N);
41 double par = adderPar(&a[0], N);
42
43 $assert seq == par;
44}
Note: See TracBrowser for help on using the repository browser.