source: doc/theses/colby_parsons_MMAth/benchmarks/actors/cfa/repeat.cfa @ 8cb2ff6

Last change on this file since 8cb2ff6 was 05956d21, checked in by caparsons <caparson@…>, 17 months ago

refactored benchmarks to use actor bar operator

  • Property mode set to 100644
File size: 3.3 KB
Line 
1#include <actor.hfa>
2#include <fstream.hfa>
3#include <stdlib.hfa>
4#include <string.h>
5#include <stdio.h>
6#include "bench.hfa"
7
8size_t Messages = 100000, Processors = 4, QScale = 256, Times = 100;
9
10struct Server { inline actor; };
11struct IntMsg {
12    inline message;
13    int val;
14};
15struct CharMsg {
16    inline message;
17    char val;
18};
19struct StateMsg { inline message; } stateMsg;
20
21struct Client {
22    inline actor;
23    Server * servers;
24        IntMsg * intmsg;
25        CharMsg * charmsg;
26        size_t results, times;
27};
28void ?{}( Client & this ) with(this) {
29    ((actor &)this){};
30    results = 0;
31    times = 0;
32    servers = aalloc( Messages );
33    intmsg = aalloc( Messages );
34    charmsg = aalloc( Messages );
35    for ( i; Messages ) {
36        servers[i]{};
37        intmsg[i]{};
38        charmsg[i]{};
39    }
40}
41void ^?{}( Client & this ) with(this) {
42    adelete( servers );
43    adelete( intmsg );
44    adelete( charmsg );
45}
46
47Client * cl;
48allocation receive( Server & this, IntMsg & msg ) { msg.val = 7; *cl | msg; return Nodelete; }
49allocation receive( Server & this, CharMsg & msg ) { msg.val = 'x'; *cl | msg; return Nodelete; }
50allocation receive( Server & this, StateMsg & msg ) { return Finished; }
51
52void terminateServers( Client & this ) with(this) {
53    for ( i; Messages ) {
54        servers[i] | stateMsg;
55    } // for
56}
57
58allocation reset( Client & this ) with(this) {
59    times += 1;
60    if ( times == Times ) { terminateServers( this ); return Finished; }
61    results = 0;
62    this | stateMsg;
63    return Nodelete;
64}
65
66allocation process( Client & this ) with(this) {
67    this.results++;
68    if ( results == 2 * Messages ) { return reset( this ); }
69    return Nodelete;
70}
71
72allocation receive( Client & this, IntMsg & msg ) { return process( this ); }
73allocation receive( Client & this, CharMsg & msg ) { return process( this ); }
74allocation receive( Client & this, StateMsg & msg ) with(this) {
75    for ( i; Messages ) {
76        servers[i] | intmsg[i];
77        servers[i] | charmsg[i];
78    }
79    return Nodelete;
80}
81
82int main( int argc, char * argv[] ) {
83    switch ( argc ) {
84      case 5:
85                if ( strcmp( argv[4], "d" ) != 0 ) {                    // default ?
86                        QScale = atoi( argv[4] );
87                        if ( QScale < 1 ) goto Usage;
88                } // if
89          case 4:
90                if ( strcmp( argv[3], "d" ) != 0 ) {                    // default ?
91                        Times = atoi( argv[3] );
92                        if ( Times < 1 ) goto Usage;
93                } // if
94          case 3:
95                if ( strcmp( argv[2], "d" ) != 0 ) {                    // default ?
96                        Processors = atoi( argv[2] );
97                        if ( Processors < 1 ) goto Usage;
98                } // if
99          case 2:
100                if ( strcmp( argv[1], "d" ) != 0 ) {                    // default ?
101                        Messages = atoi( argv[1] );
102                        if ( Messages < 1 ) goto Usage;
103                } // if
104          case 1:                                                                                       // use defaults
105                break;
106          default:
107          Usage:
108                sout | "Usage: " | argv[0]
109             | ") ] [ messages (> 0) | 'd' (default " | Messages
110                         | ") ] [ processors (> 0) | 'd' (default " | Processors
111             | ") ] [ Times (> 0) | 'd' (default " | Times
112                         | ") ] [ qscale (> 0) | 'd' (default " | QScale
113                         | ") ]" ;
114                exit( EXIT_FAILURE );
115        } // switch
116
117   
118    executor e{ Processors, Processors, Processors == 1 ? 1 : Processors * QScale, true, 1 };
119
120    uint64_t start_time = bench_time();
121
122    start_actor_system( e );
123
124    Client client;
125    cl = &client;
126    client | stateMsg;
127
128    stop_actor_system();
129
130    uint64_t end_time = bench_time();
131
132    printf("%.2f\n", ((double)(end_time - start_time))*((double)1e-9) );
133
134    return 0;
135}
Note: See TracBrowser for help on using the repository browser.