#include #include #include #include #include // int Actors = 40000, Set = 100, Rounds = 100, Processors = 1, Batch = 1, BufSize = 10; // default values int Actors = 1000, Set = 20, Rounds = 10, Processors = 1, Batch = 1, BufSize = 10; // other defaults for test to run in reasonable time static int ids = 0; struct d_actor { inline actor; d_actor * gstart; int id, rounds, recs, sends; }; void ?{}( d_actor & this ) with(this) { id = ids++; gstart = (&this + (id / Set * Set - id)); // remember group-start array-element rounds = Set * Rounds; // send at least one message to each group member recs = 0; sends = 0; } struct d_msg { inline message; } shared_msg; allocation receive( d_actor & this, d_msg & msg ) with( this ) { if ( recs == rounds ) return Finished; if ( recs % Batch == 0 ) { for ( i; Batch ) { gstart[sends % Set] | shared_msg; sends += 1; } } recs += 1; return Nodelete; } int main( int argc, char * argv[] ) { switch ( argc ) { case 7: if ( strcmp( argv[6], "d" ) != 0 ) { // default ? BufSize = ato( argv[6] ); if ( BufSize < 0 ) fallthru default; } // if case 6: if ( strcmp( argv[5], "d" ) != 0 ) { // default ? Batch = ato( argv[5] ); if ( Batch < 1 ) fallthru default; } // if case 5: if ( strcmp( argv[4], "d" ) != 0 ) { // default ? Processors = ato( argv[4] ); if ( Processors < 1 ) fallthru default; } // if case 4: if ( strcmp( argv[3], "d" ) != 0 ) { // default ? Rounds = ato( argv[3] ); if ( Rounds < 1 ) fallthru default; } // if case 3: if ( strcmp( argv[2], "d" ) != 0 ) { // default ? Set = ato( argv[2] ); if ( Set < 1 ) fallthru default; } // if case 2: if ( strcmp( argv[1], "d" ) != 0 ) { // default ? Actors = ato( argv[1] ); if ( Actors < 1 || Actors <= Set || Actors % Set != 0 ) fallthru default; } // if case 1: // use defaults break; default: exit | "Usage: " | argv[0] | " [ actors (> 0 && > set && actors % set == 0 ) | 'd' (default " | Actors | ") ] [ set (> 0) | 'd' (default " | Set | ") ] [ rounds (> 0) | 'd' (default " | Rounds | ") ] [ processors (> 0) | 'd' (default " | Processors | ") ] [ batch (> 0) | 'd' (default " | Batch | ") ] [ buffer size (>= 0) | 'd' (default " | BufSize | ") ]" ; } // switch executor e{ Processors, Processors, Processors == 1 ? 1 : Processors * 512, true }; sout | "starting"; actor_start( e ); sout | "started"; d_actor actors[ Actors ]; for ( i; Actors ) { actors[i] | shared_msg; } // for sout | "stopping"; actor_stop(); sout | "stopped"; }