1.23
2.0
main
test-branch
|
Last change
on this file since 9179b4f was f28d814, checked in by Tim Zirkel <zirkeltk@…>, 13 years ago |
|
Updated Makefile. Changed examples to use civlc.h and $ instead of \ at beginning of CIVL keywords.
git-svn-id: svn://vsl.cis.udel.edu/civl/trunk@59 fb995dde-84ed-4084-dfe6-e5aef3e2452c
|
-
Property mode
set to
100644
|
|
File size:
622 bytes
|
| Line | |
|---|
| 1 | #include <civlc.h>
|
|---|
| 2 | $input double a[3];
|
|---|
| 3 |
|
|---|
| 4 | double adderSeq(int n) {
|
|---|
| 5 | double s = 0.0;
|
|---|
| 6 |
|
|---|
| 7 | for (int i = 0; i < n; i++) {
|
|---|
| 8 | s += a[i];
|
|---|
| 9 | }
|
|---|
| 10 | return s;
|
|---|
| 11 | }
|
|---|
| 12 |
|
|---|
| 13 | double adderPar(int m) {
|
|---|
| 14 | double s = 0.0;
|
|---|
| 15 | int mutex = 0;
|
|---|
| 16 | $proc workers[m];
|
|---|
| 17 |
|
|---|
| 18 | void worker(int i) {
|
|---|
| 19 | double t;
|
|---|
| 20 |
|
|---|
| 21 | $when (mutex == 0) mutex = 1;
|
|---|
| 22 | t = s;
|
|---|
| 23 | t += a[i];
|
|---|
| 24 | s = t;
|
|---|
| 25 | mutex = 0;
|
|---|
| 26 | }
|
|---|
| 27 |
|
|---|
| 28 | for (int j = 0; j < m; j++) {
|
|---|
| 29 | workers[j] = $spawn worker(j);
|
|---|
| 30 | }
|
|---|
| 31 | for (int k = 0; k < m; k++) {
|
|---|
| 32 | $wait workers[k];
|
|---|
| 33 | }
|
|---|
| 34 | return s;
|
|---|
| 35 | }
|
|---|
| 36 |
|
|---|
| 37 | void main() {
|
|---|
| 38 | double seq;
|
|---|
| 39 | double par;
|
|---|
| 40 |
|
|---|
| 41 | seq = adderSeq(3);
|
|---|
| 42 | par = adderPar(3);
|
|---|
| 43 | $assert seq == par;
|
|---|
| 44 | }
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.