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:
825 bytes
|
| Line | |
|---|
| 1 | /* Commandline execution:
|
|---|
| 2 | * civl verify -inputB=5 adder.cvl
|
|---|
| 3 | * */
|
|---|
| 4 | #include <civlc.cvh>
|
|---|
| 5 |
|
|---|
| 6 | $input int B = 5; // upper bound on array length
|
|---|
| 7 | $input int N; // length of array
|
|---|
| 8 | $assume(1<=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 | int mutex = 0; // mutex shared by workers
|
|---|
| 23 | $proc workers[n]; // one worker for each element! UNUSED
|
|---|
| 24 |
|
|---|
| 25 | void worker(int i) {
|
|---|
| 26 | double t;
|
|---|
| 27 |
|
|---|
| 28 | $when (mutex == 0) mutex = 1;
|
|---|
| 29 | t = s;
|
|---|
| 30 | t += p[i];
|
|---|
| 31 | s = t;
|
|---|
| 32 | mutex = 0;
|
|---|
| 33 | }
|
|---|
| 34 |
|
|---|
| 35 | $parfor (int j : 0 .. n-1)
|
|---|
| 36 | worker(j);
|
|---|
| 37 | return s;
|
|---|
| 38 | }
|
|---|
| 39 |
|
|---|
| 40 | void main() {
|
|---|
| 41 | double seq = adderSeq(&a[0], N);
|
|---|
| 42 | double par = adderPar(&a[0], N);
|
|---|
| 43 |
|
|---|
| 44 | $assert(seq == par);
|
|---|
| 45 | }
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.