1.23
2.0
acw/focus-triggers
main
test-branch
| 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 |
|
|---|
| 11 | double 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 |
|
|---|
| 20 | double 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 |
|
|---|
| 39 | void 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.