ADTast-experimental
Last change
on this file since 9d84a88 was
bbf6a180,
checked in by Peter A. Buhr <pabuhr@…>, 2 years ago
|
change to uw-ethesis and restructure source
|
-
Property mode set to
100644
|
File size:
1.2 KB
|
Rev | Line | |
---|
[bbf6a180] | 1 | #include "stdlib.hfa" |
---|
| 2 | #include "array.hfa" |
---|
| 3 | |
---|
| 4 | |
---|
| 5 | |
---|
| 6 | |
---|
| 7 | |
---|
| 8 | |
---|
| 9 | |
---|
| 10 | |
---|
| 11 | |
---|
| 12 | |
---|
| 13 | |
---|
| 14 | |
---|
| 15 | |
---|
| 16 | |
---|
| 17 | |
---|
| 18 | |
---|
| 19 | |
---|
| 20 | forall( ztype(Nclients), ztype(Ncosts) ) |
---|
| 21 | struct request { |
---|
| 22 | unsigned int requestor_id; |
---|
| 23 | array( unsigned int, Nclients ) impacted_client_ids; |
---|
| 24 | array( float, Ncosts ) cost_contribs; |
---|
| 25 | float total_cost; |
---|
| 26 | }; |
---|
| 27 | |
---|
| 28 | |
---|
| 29 | // TODO: understand (fix?) why these are needed (autogen seems to be failing ... is typeof as struct member nayok?) |
---|
| 30 | |
---|
| 31 | forall( ztype(Nclients), ztype(Ncosts) ) |
---|
| 32 | void ?{}( request(Nclients, Ncosts) & this ) {} |
---|
| 33 | |
---|
| 34 | forall( ztype(Nclients), ztype(Ncosts) ) |
---|
| 35 | void ^?{}( request(Nclients, Ncosts) & this ) {} |
---|
| 36 | |
---|
| 37 | |
---|
| 38 | |
---|
| 39 | |
---|
| 40 | |
---|
| 41 | |
---|
| 42 | |
---|
| 43 | |
---|
| 44 | |
---|
| 45 | |
---|
| 46 | |
---|
| 47 | |
---|
| 48 | |
---|
| 49 | |
---|
| 50 | forall( ztype(Nclients), ztype(Ncosts) ) |
---|
| 51 | void summarize( request(Nclients, Ncosts) & r ) { |
---|
| 52 | r.total_cost = 0; |
---|
| 53 | for( i; z(Ncosts) ) |
---|
| 54 | r.total_cost += r.cost_contribs[i]; |
---|
| 55 | // say the cost is per-client, to make output vary |
---|
| 56 | r.total_cost *= z(Nclients); |
---|
| 57 | } |
---|
| 58 | |
---|
| 59 | |
---|
| 60 | |
---|
| 61 | |
---|
| 62 | |
---|
| 63 | |
---|
| 64 | |
---|
| 65 | |
---|
| 66 | |
---|
| 67 | |
---|
| 68 | |
---|
| 69 | |
---|
| 70 | |
---|
| 71 | |
---|
| 72 | |
---|
| 73 | |
---|
| 74 | |
---|
| 75 | |
---|
| 76 | |
---|
| 77 | |
---|
| 78 | |
---|
| 79 | |
---|
| 80 | |
---|
| 81 | |
---|
| 82 | |
---|
| 83 | |
---|
| 84 | |
---|
| 85 | |
---|
| 86 | |
---|
| 87 | |
---|
| 88 | |
---|
| 89 | |
---|
| 90 | |
---|
| 91 | |
---|
| 92 | |
---|
| 93 | |
---|
| 94 | |
---|
| 95 | |
---|
| 96 | int main( int argc, char ** argv ) { |
---|
| 97 | |
---|
| 98 | |
---|
| 99 | |
---|
| 100 | const int ncl = atoi(argv[1]); |
---|
| 101 | const int nco = 2; |
---|
| 102 | |
---|
| 103 | request( Z(ncl), Z(nco) ) r; |
---|
| 104 | r.cost_contribs[0] = 100; |
---|
| 105 | r.cost_contribs[1] = 0.1; |
---|
| 106 | |
---|
| 107 | summarize(r); |
---|
| 108 | printf("Total cost: %.1f\n", r.total_cost); |
---|
| 109 | |
---|
| 110 | /* |
---|
| 111 | ./a.out 5 |
---|
| 112 | Total cost: 500.5 |
---|
| 113 | ./a.out 6 |
---|
| 114 | Total cost: 600.6 |
---|
| 115 | */ |
---|
| 116 | |
---|
| 117 | |
---|
| 118 | |
---|
| 119 | |
---|
| 120 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.