- Timestamp:
- Dec 11, 2023, 1:46:50 PM (8 months ago)
- Branches:
- master
- Children:
- 40ab446
- Parents:
- 2554f24
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
doc/theses/mike_brooks_MMath/programs/hello-accordion.cfa
r2554f24 rdab9fb93 1 #include "stdlib.hfa" 2 #include "array.hfa" 1 #include <fstream.hfa> 2 #include <stdlib.hfa> 3 #include <array.hfa> 4 5 6 7 8 9 10 11 forall( T, [Nclients], [Ncosts] ) 12 struct 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 22 forall( T, [Nclients], [Ncosts] ) 23 void ?{}( T &, request( T, Nclients, Ncosts ) & this ) {} 24 25 forall( T &, [Nclients], [Ncosts] ) 26 void ^?{}( request( T, Nclients, Ncosts ) & this ) {} 3 27 4 28 … … 15 39 16 40 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 ) { 41 forall( T, [Nclients], [Ncosts] ) 42 void summarize( request( T, Nclients, Ncosts ) & r ) { 52 43 r.total_cost = 0; 53 for( i; z(Ncosts))44 for( i; Ncosts ) 54 45 r.total_cost += r.cost_contribs[i]; 55 46 // say the cost is per-client, to make output vary 56 r.total_cost *= z(Nclients);47 r.total_cost *= Nclients; 57 48 } 58 49 … … 68 59 69 60 61 int main( int argc, char * argv[] ) { 62 const int ncl = ato( argv[1] ); 63 const int nco = 2; 70 64 65 request( int, ncl, nco ) r; 66 r.cost_contribs[0] = 100; 67 r.cost_contribs[1] = 0.1; 71 68 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 69 summarize(r); 70 sout | "Total cost:" | r.total_cost; 71 } 110 72 /* 111 ./a.out 573 $\$$ ./a.out 5 112 74 Total cost: 500.5 113 ./a.out 675 $\$$ ./a.out 6 114 76 Total cost: 600.6 115 77 */ 116 117 118 119 120 }
Note: See TracChangeset
for help on using the changeset viewer.