| 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
|
|---|
| 9 | int ActorsPerQueue = 32, Set = 32, Rounds = 100, Processors = 1, Batch = 100, BufSize = 10; // other defaults for test to run in reasonable time
|
|---|
| 10 |
|
|---|
| 11 | struct filler {
|
|---|
| 12 | inline actor;
|
|---|
| 13 | };
|
|---|
| 14 | void ?{}( filler & this ) with(this) { ((actor &)this){}; }
|
|---|
| 15 |
|
|---|
| 16 | static int ids = 0;
|
|---|
| 17 | struct d_actor {
|
|---|
| 18 | inline actor;
|
|---|
| 19 | int gstart, id, rounds, recs, sends;
|
|---|
| 20 | };
|
|---|
| 21 | void ?{}( 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 | }
|
|---|
| 29 | struct d_msg { inline message; } shared_msg;
|
|---|
| 30 | struct start_msg { inline message; } start_send;
|
|---|
| 31 |
|
|---|
| 32 | d_actor ** actor_arr;
|
|---|
| 33 | allocation 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 |
|
|---|
| 40 | allocation 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 |
|
|---|
| 52 | allocation receive( filler & this, d_msg & msg ) { return Delete; }
|
|---|
| 53 |
|
|---|
| 54 | int 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 | unsigned int qpw = 512; // queues per worker
|
|---|
| 102 |
|
|---|
| 103 | executor e{ Processors, Processors, Processors == 1 ? 1 : Processors * qpw, true };
|
|---|
| 104 |
|
|---|
| 105 | // printf("starting\n");
|
|---|
| 106 |
|
|---|
| 107 | start_actor_system( e );
|
|---|
| 108 |
|
|---|
| 109 | // printf("started\n");
|
|---|
| 110 |
|
|---|
| 111 | #ifndef MULTI
|
|---|
| 112 | int Actors = ActorsPerQueue * qpw;
|
|---|
| 113 | int FillActors = ActorsPerQueue * qpw * (Processors - 1);
|
|---|
| 114 | #else
|
|---|
| 115 | int extra = Processors % 2;
|
|---|
| 116 | int ActorProcs = (Processors / 2 + extra);
|
|---|
| 117 | int Actors = ActorsPerQueue * qpw * ActorProcs;
|
|---|
| 118 | int FillActors = ActorsPerQueue * qpw * (Processors/2);
|
|---|
| 119 | #endif
|
|---|
| 120 | int fill_offset = (Processors - 1) * qpw;
|
|---|
| 121 |
|
|---|
| 122 | int AllocFill = FillActors;
|
|---|
| 123 | if ( FillActors == 0 ) AllocFill = 1;
|
|---|
| 124 |
|
|---|
| 125 | d_actor ** actors; // array needs to be on the heap since it can be very large
|
|---|
| 126 | actors = aalloc( Actors );
|
|---|
| 127 |
|
|---|
| 128 | actor_arr = actors;
|
|---|
| 129 |
|
|---|
| 130 | filler ** filler_actors; // array needs to be on the heap since it can be very large
|
|---|
| 131 | filler_actors = aalloc( AllocFill );
|
|---|
| 132 |
|
|---|
| 133 | int actor_count = 0;
|
|---|
| 134 | int fill_count = 0;
|
|---|
| 135 |
|
|---|
| 136 | int idx;
|
|---|
| 137 | for ( i; ActorsPerQueue ) {
|
|---|
| 138 | for ( j; Processors ) {
|
|---|
| 139 | for ( k; qpw ) {
|
|---|
| 140 | #ifndef MULTI
|
|---|
| 141 | if ( j == 0 )
|
|---|
| 142 | #else
|
|---|
| 143 | if ( j % 2 == 0 )
|
|---|
| 144 | #endif
|
|---|
| 145 | {
|
|---|
| 146 | #ifndef MULTI
|
|---|
| 147 | idx = k * ActorsPerQueue + i;
|
|---|
| 148 | #else
|
|---|
| 149 | idx = (j / 2) * qpw * ActorsPerQueue + k * ActorsPerQueue + i; // set all on one queue
|
|---|
| 150 | #endif
|
|---|
| 151 | (*(actors[ idx ] = alloc())){ idx };
|
|---|
| 152 | } else {
|
|---|
| 153 | (*(filler_actors[ fill_count ] = alloc())){};
|
|---|
| 154 | fill_count++;
|
|---|
| 155 | }
|
|---|
| 156 | }
|
|---|
| 157 | }
|
|---|
| 158 | }
|
|---|
| 159 |
|
|---|
| 160 | uint64_t start_time = bench_time();
|
|---|
| 161 |
|
|---|
| 162 | #ifndef MULTI
|
|---|
| 163 | for ( i; qpw )
|
|---|
| 164 | *actors[i * ActorsPerQueue] | start_send;
|
|---|
| 165 | #else
|
|---|
| 166 | for ( i; qpw * ActorProcs ) {
|
|---|
| 167 | *actors[i * ActorsPerQueue] | start_send;
|
|---|
| 168 | }
|
|---|
| 169 | #endif
|
|---|
| 170 |
|
|---|
| 171 | for ( i; FillActors )
|
|---|
| 172 | *filler_actors[i] | shared_msg;
|
|---|
| 173 |
|
|---|
| 174 | stop_actor_system();
|
|---|
| 175 |
|
|---|
| 176 | uint64_t end_time = bench_time();
|
|---|
| 177 |
|
|---|
| 178 | printf("%.2f\n", ((double)(end_time - start_time))*((double)1e-9) );
|
|---|
| 179 |
|
|---|
| 180 | adelete( filler_actors );
|
|---|
| 181 | adelete( actors );
|
|---|
| 182 |
|
|---|
| 183 | return 0;
|
|---|
| 184 | }
|
|---|