#include #include #include #include #include ssize_t xr = 500, xc = 500, yc = 500, Processors = 1; // default values, must be signed struct derived_actor { inline actor; }; struct derived_msg { inline message; int * Z; int * X; int ** Y; }; void ?{}( derived_msg & this ) {} void ?{}( derived_msg & this, int * Z, int * X, int ** Y ) { set_allocation( this, Nodelete ); this.Z = Z; this.X = X; this.Y = Y; } allocation receive( derived_actor & receiver, derived_msg & msg ) { for ( i; yc ) { // multiply X_row by Y_col and sum products msg.Z[i] = 0; for ( j; xc ) { msg.Z[i] += msg.X[j] * msg.Y[j][i]; } // for } // for return Finished; } int main( int argc, char * argv[] ) { switch ( argc ) { 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 ? xr = ato( argv[3] ); if ( xr < 1 ) fallthru default; } // if case 3: if ( strcmp( argv[2], "d" ) != 0 ) { // default ? xc = ato( argv[2] ); if ( xc < 1 ) fallthru default; } // if case 2: if ( strcmp( argv[1], "d" ) != 0 ) { // default ? yc = ato( argv[1] ); if ( yc < 1 ) fallthru default; } // if case 1: // use defaults break; default: exit | "Usage: " | argv[0] | " [ yc (> 0) | 'd' (default " | yc | ") ] [ xc (> 0) | 'd' (default " | xc | ") ] [ xr (> 0) | 'd' (default " | xr | ") ] [ processors (> 0) | 'd' (default " | Processors | ") ]" ; } // switch int * Z[xr], * X[xr], * Y[xc]; for ( r; xr ) { // create/initialize X matrix X[r] = aalloc( xc ); for ( c; xc ) { X[r][c] = r * c % 37; // for timing } // for } // for for ( r; xc ) { // create/initialize Y matrix Y[r] = aalloc( yc ); for ( c; yc ) { Y[r][c] = r * c % 37; // for timing } // for } // for for ( r; xr ) { // create Z matrix Z[r] = aalloc( yc ); } // for executor e{ Processors, Processors, Processors == 1 ? 1 : Processors * 16, true }; sout | "starting"; start_actor_system( e ); sout | "started"; derived_msg messages[xr]; derived_actor actors[xr]; for ( r; xr ) { messages[r]{ Z[r], X[r], Y }; } // for for ( r; xr ) { actors[r] | messages[r]; } // for sout | "stopping"; stop_actor_system(); sout | "stopped"; for ( r; xr ) { // deallocate X and Z matrices free( X[r] ); free( Z[r] ); } // for for ( r; xc ) { // deallocate Y matrix free( Y[r] ); } // for }