source: doc/theses/colby_parsons_MMAth/benchmarks/actors/cfa/balance.cfa @ 4eebbcc

ADTast-experimental
Last change on this file since 4eebbcc was cec2551, checked in by caparson <caparson@…>, 20 months ago

added cfa benchmarks

  • Property mode set to 100644
File size: 5.0 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
8// int Actors = 40000, Set = 100, Rounds = 100, Processors = 1, Batch = 1, BufSize = 10; // default values
9int ActorsPerQueue = 32, Set = 32, Rounds = 100, Processors = 1, Batch = 100, BufSize = 10; // other defaults for test to run in reasonable time
10
11struct filler {
12    inline actor;
13};
14void ?{}( filler & this ) with(this) { ((actor &)this){}; }
15
16static int ids = 0;
17struct d_actor {
18    inline actor;
19    int gstart, id, rounds, recs, sends;
20};
21void ?{}( d_actor & this, int idx ) with(this) {
22    ((actor &)this){};
23    id = idx;
24    gstart = id / Set * Set; // remember group-start index
25    rounds = Set * Rounds;      // send at least one message to each group member
26    recs = 0;
27    sends = 0;
28}
29struct d_msg { inline message; } shared_msg;
30struct start_msg { inline message; } start_send;
31
32d_actor ** actor_arr;
33Allocation receive( d_actor & this, start_msg & msg ) with( this ) {
34    for ( i; Set ) {
35        *actor_arr[i + gstart] << shared_msg;
36    }
37    return Nodelete;
38}
39
40Allocation receive( d_actor & this, d_msg & msg ) with( this ) {
41    if ( recs == rounds ) return Delete;
42    if ( recs % Batch == 0 ) {
43        for ( i; Batch ) {
44            *actor_arr[gstart + sends % Set] << shared_msg;
45            sends += 1;
46        }
47    }
48    recs += 1;
49    return Nodelete;
50}
51
52Allocation receive( filler & this, d_msg & msg ) { return Delete; }
53
54int main( int argc, char * argv[] ) {
55    switch ( argc ) {
56          case 7:
57                if ( strcmp( argv[6], "d" ) != 0 ) {                    // default ?
58                        BufSize = atoi( argv[6] );
59                        if ( BufSize < 0 ) goto Usage;
60                } // if
61          case 6:
62                if ( strcmp( argv[5], "d" ) != 0 ) {                    // default ?
63                        Batch = atoi( argv[5] );
64                        if ( Batch < 1 ) goto Usage;
65                } // if
66          case 5:
67                if ( strcmp( argv[4], "d" ) != 0 ) {                    // default ?
68                        Processors = atoi( argv[4] );
69                        if ( Processors < 1 ) goto Usage;
70                } // if
71          case 4:
72                if ( strcmp( argv[3], "d" ) != 0 ) {                    // default ?
73                        Rounds = atoi( argv[3] );
74                        if ( Rounds < 1 ) goto Usage;
75                } // if
76          case 3:
77                if ( strcmp( argv[2], "d" ) != 0 ) {                    // default ?
78                        Set = atoi( argv[2] );
79                        if ( Set < 1 ) goto Usage;
80                } // if
81          case 2:
82                if ( strcmp( argv[1], "d" ) != 0 ) {                    // default ?
83                        ActorsPerQueue = atoi( argv[1] );
84                        if ( ActorsPerQueue < 1 ) goto Usage;
85                } // if
86          case 1:                                                                                       // use defaults
87                break;
88          default:
89          Usage:
90                sout | "Usage: " | argv[0]
91             | " [ ActorsPerQueue (> 0) | 'd' (default " | ActorsPerQueue
92                         | ") ] [ set (> 0) | 'd' (default " | Set
93                         | ") ] [ rounds (> 0) | 'd' (default " | Rounds
94                         | ") ] [ processors (> 0) | 'd' (default " | Processors
95                         | ") ] [ batch (> 0) | 'd' (default " | Batch
96                         | ") ] [ buffer size (>= 0) | 'd' (default " | BufSize
97                         | ") ]" ;
98                exit( EXIT_FAILURE );
99        } // switch
100
101    //C_TODO: make this an arg
102    unsigned int qpw = 512; // queues per worker
103
104    executor e{ Processors, Processors, Processors == 1 ? 1 : Processors * qpw, true };
105
106    // printf("starting\n");
107
108    start_actor_system( e );
109
110    // printf("started\n");
111
112    #ifndef MULTI
113    int Actors = ActorsPerQueue * qpw;
114    int FillActors = ActorsPerQueue * qpw * (Processors - 1);
115    #else
116    int extra = Processors % 2;
117    int ActorProcs = (Processors / 2 + extra);
118    int Actors = ActorsPerQueue * qpw * ActorProcs;
119    int FillActors = ActorsPerQueue * qpw * (Processors/2);
120    #endif
121    int fill_offset = (Processors - 1) * qpw;
122
123    int AllocFill = FillActors;
124    if ( FillActors == 0 ) AllocFill = 1;
125
126    d_actor ** actors; // array needs to be on the heap since it can be very large
127    actors = aalloc( Actors );
128
129    actor_arr = actors;
130
131    filler ** filler_actors; // array needs to be on the heap since it can be very large
132    filler_actors = aalloc( AllocFill );
133
134    int actor_count = 0;
135    int fill_count = 0;
136
137    int idx;
138    for ( i; ActorsPerQueue ) {
139        for ( j; Processors ) {
140            for ( k; qpw ) {
141                #ifndef MULTI
142                if ( j == 0 )
143                #else
144                if ( j % 2 == 0 )
145                #endif
146                {
147                    #ifndef MULTI
148                    idx = k * ActorsPerQueue + i;
149                    #else
150                    idx = (j / 2) * qpw * ActorsPerQueue + k * ActorsPerQueue + i; // set all on one queue
151                    #endif
152                    (*(actors[ idx ] = alloc())){ idx };
153                } else {
154                    (*(filler_actors[ fill_count ] = alloc())){};
155                    fill_count++;
156                }
157            }
158        }
159    }
160
161    uint64_t start_time = bench_time();
162
163    #ifndef MULTI
164        for ( i; qpw )
165                *actors[i * ActorsPerQueue] << start_send;
166    #else
167    for ( i; qpw * ActorProcs ) {
168                *actors[i * ActorsPerQueue] << start_send;
169    }
170    #endif
171   
172    for ( i; FillActors )
173        *filler_actors[i] << shared_msg;
174
175    stop_actor_system();
176   
177    uint64_t end_time = bench_time();
178
179    printf("%.2f\n", ((double)(end_time - start_time))*((double)1e-9) );
180
181    adelete( filler_actors );
182    adelete( actors );
183
184    return 0;
185}
Note: See TracBrowser for help on using the repository browser.