source: doc/theses/mike_brooks_MMath/programs/hello-accordion.cfa @ feb999f

Last change on this file since feb999f was 5546f50b, checked in by Peter A. Buhr <pabuhr@…>, 8 months ago

more switch to tabs

  • Property mode set to 100644
File size: 1.1 KB
Line 
1#include <fstream.hfa>
2#include <stdlib.hfa>
3#include <array.hfa>
4
5
6
7
8
9
10
11forall( T, [Nclients], [Ncosts] )
12struct request {
13        unsigned int requestor_id;
14        array( T, Nclients ) impacted_client_ids; // nested VLA
15        array( float, Ncosts ) cost_contribs; // nested VLA
16        float total_cost;
17};
18
19
20// TODO: understand (fix?) why these are needed (autogen seems to be failing ... is typeof as struct member nayok?)
21
22forall( T, [Nclients], [Ncosts] )
23        void ?{}( T &, request( T, Nclients, Ncosts ) & this ) {}
24
25forall( T &, [Nclients], [Ncosts] )
26        void ^?{}( request( T, Nclients, Ncosts ) & this ) {}
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41forall( T, [Nclients], [Ncosts] )
42void summarize( request( T, Nclients, Ncosts ) & r ) {
43        r.total_cost = 0;
44        for( i; Ncosts )
45                r.total_cost += r.cost_contribs[i];
46        // say the cost is per-client, to make output vary
47        r.total_cost *= Nclients;
48}
49
50
51
52
53
54
55
56
57
58
59
60
61int main( int argc, char * argv[] ) {
62        const int ncl = ato( argv[1] );
63        const int nco = 2;
64
65        request( int, ncl, nco ) r;
66        r.cost_contribs[0] = 100;
67        r.cost_contribs[1] = 0.1;
68
69        summarize(r);
70        sout | "Total cost:" | r.total_cost;
71}
72/*
73$\$$ ./a.out 5
74Total cost: 500.5
75$\$$ ./a.out 6
76Total cost: 600.6
77*/
Note: See TracBrowser for help on using the repository browser.