#include #include #include #include #include #include "bench.hfa" size_t Messages = 100000, Processors = 4, QScale = 256, Times = 100; struct Server { inline actor; }; struct IntMsg { inline message; int val; }; struct CharMsg { inline message; char val; }; struct StateMsg { inline message; } stateMsg; struct Client { inline actor; Server * servers; IntMsg * intmsg; CharMsg * charmsg; size_t results, times; }; void ?{}( Client & this ) with(this) { ((actor &)this){}; results = 0; times = 0; servers = aalloc( Messages ); intmsg = aalloc( Messages ); charmsg = aalloc( Messages ); for ( i; Messages ) { servers[i]{}; intmsg[i]{}; charmsg[i]{}; } } void ^?{}( Client & this ) with(this) { adelete( servers ); adelete( intmsg ); adelete( charmsg ); } Client * cl; Allocation receive( Server & this, IntMsg & msg ) { msg.val = 7; *cl << msg; return Nodelete; } Allocation receive( Server & this, CharMsg & msg ) { msg.val = 'x'; *cl << msg; return Nodelete; } Allocation receive( Server & this, StateMsg & msg ) { return Finished; } void terminateServers( Client & this ) with(this) { for ( i; Messages ) { servers[i] << stateMsg; } // for } Allocation reset( Client & this ) with(this) { times += 1; if ( times == Times ) { terminateServers( this ); return Finished; } results = 0; this << stateMsg; return Nodelete; } Allocation process( Client & this ) with(this) { this.results++; if ( results == 2 * Messages ) { return reset( this ); } return Nodelete; } Allocation receive( Client & this, IntMsg & msg ) { return process( this ); } Allocation receive( Client & this, CharMsg & msg ) { return process( this ); } Allocation receive( Client & this, StateMsg & msg ) with(this) { for ( i; Messages ) { servers[i] << intmsg[i]; servers[i] << charmsg[i]; } return Nodelete; } int main( int argc, char * argv[] ) { switch ( argc ) { case 5: if ( strcmp( argv[4], "d" ) != 0 ) { // default ? QScale = atoi( argv[4] ); if ( QScale < 1 ) goto Usage; } // if case 4: if ( strcmp( argv[3], "d" ) != 0 ) { // default ? Times = atoi( argv[3] ); if ( Times < 1 ) goto Usage; } // if case 3: if ( strcmp( argv[2], "d" ) != 0 ) { // default ? Processors = atoi( argv[2] ); if ( Processors < 1 ) goto Usage; } // if case 2: if ( strcmp( argv[1], "d" ) != 0 ) { // default ? Messages = atoi( argv[1] ); if ( Messages < 1 ) goto Usage; } // if case 1: // use defaults break; default: Usage: sout | "Usage: " | argv[0] | ") ] [ messages (> 0) | 'd' (default " | Messages | ") ] [ processors (> 0) | 'd' (default " | Processors | ") ] [ Times (> 0) | 'd' (default " | Times | ") ] [ qscale (> 0) | 'd' (default " | QScale | ") ]" ; exit( EXIT_FAILURE ); } // switch executor e{ Processors, Processors, Processors == 1 ? 1 : Processors * QScale, true, 1 }; uint64_t start_time = bench_time(); start_actor_system( e ); Client client; cl = &client; client << stateMsg; stop_actor_system(); uint64_t end_time = bench_time(); printf("%.2f\n", ((double)(end_time - start_time))*((double)1e-9) ); return 0; }