source: CIVL/examples/concurrency/adderBad.cvl

main
Last change on this file was ea777aa, checked in by Alex Wilton <awilton@…>, 3 years ago

Moved examples, include, build_default.properties, common.xml, and README out from dev.civl.com into the root of the repo.

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

  • Property mode set to 100644
File size: 830 bytes
Line 
1/* Commandline execution:
2 * civl verify -inputB=5 adderBad.cvl
3 * or (if you want to find the minimal counterexample)
4 * civl verify -inputB=5 adderBad.cvl -min
5 * */
6#include <civlc.cvh>
7
8$input int B = 5; // upper bound on array length
9$input int N; // length of array
10$assume(0<=N && N<=B);
11$input double a[N];
12
13double adderSeq(double *p, int n) {
14 double s = 0.0;
15
16 for (int i = 0; i < n; i++) {
17 s += p[i];
18 }
19 return s;
20}
21
22double adderPar(double *p, int n) {
23 double s = 0.0; // sum shared by workers
24 $proc workers[n]; // one worker for each element!
25
26 void worker(int i) {
27 double t;
28
29 t = s;
30 t += p[i];
31 s = t;
32 }
33
34 $parfor(int i : 0 .. n-1)
35 worker(i);
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.