source: doc/theses/mike_brooks_MMath/content/array/features/hello-accordion.cfa @ 8e819a9

ADTast-experimentalenumpthread-emulationqualifiedEnum
Last change on this file since 8e819a9 was 8e819a9, checked in by Michael Brooks <mlbrooks@…>, 2 years ago

Mike MMath initial

  • Property mode set to 100644
File size: 1.2 KB
Line 
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
20forall( ztype(Nclients), ztype(Ncosts) )
21struct 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
31forall( ztype(Nclients), ztype(Ncosts) )
32void ?{}( request(Nclients, Ncosts) & this ) {}
33
34forall( ztype(Nclients), ztype(Ncosts) )
35void ^?{}( request(Nclients, Ncosts) & this ) {}
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50forall( ztype(Nclients), ztype(Ncosts) )
51void 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
96int main( int argc, char ** argv ) {
97
98
99
100const int ncl = atoi(argv[1]);
101const int nco = 2;
102
103request( Z(ncl), Z(nco) ) r;
104r.cost_contribs[0] = 100;
105r.cost_contribs[1] = 0.1;
106
107summarize(r);
108printf("Total cost: %.1f\n", r.total_cost);
109
110/*
111./a.out 5
112Total cost: 500.5
113./a.out 6
114Total cost: 600.6
115*/
116
117
118
119
120}
Note: See TracBrowser for help on using the repository browser.