source: tests/concurrency/actors/matrixMultiply.cfa@ 0497b6ba

Last change on this file since 0497b6ba was 41882628, checked in by Peter A. Buhr <pabuhr@…>, 10 months ago

update test programs with actor name change

  • Property mode set to 100644
File size: 2.6 KB
RevLine 
[418882af]1#include <actor.hfa>
2#include <fstream.hfa>
3#include <stdlib.hfa>
4#include <string.h>
5#include <stdio.h>
6
[b244fa8]7ssize_t xr = 500, xc = 500, yc = 500, Processors = 1; // default values, must be signed
[418882af]8
[4933f18]9struct derived_actor { inline actor; };
[418882af]10
11struct derived_msg {
[7edf912]12 inline message;
13 int * Z;
[418882af]14 int * X;
[7edf912]15 int ** Y;
[418882af]16};
17
18void ?{}( derived_msg & this ) {}
19void ?{}( derived_msg & this, int * Z, int * X, int ** Y ) {
[7edf912]20 set_allocation( this, Nodelete );
21 this.Z = Z;
22 this.X = X;
23 this.Y = Y;
[418882af]24}
25
[c880a7b]26allocation receive( derived_actor & receiver, derived_msg & msg ) {
[b244fa8]27 for ( i; yc ) { // multiply X_row by Y_col and sum products
[7edf912]28 msg.Z[i] = 0;
[b244fa8]29 for ( j; xc ) {
[7edf912]30 msg.Z[i] += msg.X[j] * msg.Y[j][i];
31 } // for
32 } // for
33 return Finished;
[418882af]34}
35
36int main( int argc, char * argv[] ) {
[7edf912]37 switch ( argc ) {
[418882af]38 case 5:
39 if ( strcmp( argv[4], "d" ) != 0 ) { // default ?
[50be8af5]40 Processors = ato( argv[4] );
41 if ( Processors < 1 ) fallthru default;
[418882af]42 } // if
43 case 4:
44 if ( strcmp( argv[3], "d" ) != 0 ) { // default ?
[50be8af5]45 xr = ato( argv[3] );
46 if ( xr < 1 ) fallthru default;
[418882af]47 } // if
48 case 3:
49 if ( strcmp( argv[2], "d" ) != 0 ) { // default ?
[50be8af5]50 xc = ato( argv[2] );
51 if ( xc < 1 ) fallthru default;
[418882af]52 } // if
53 case 2:
54 if ( strcmp( argv[1], "d" ) != 0 ) { // default ?
[50be8af5]55 yc = ato( argv[1] );
56 if ( yc < 1 ) fallthru default;
[418882af]57 } // if
58 case 1: // use defaults
59 break;
60 default:
[50be8af5]61 exit | "Usage: " | argv[0]
[418882af]62 | " [ yc (> 0) | 'd' (default " | yc
63 | ") ] [ xc (> 0) | 'd' (default " | xc
64 | ") ] [ xr (> 0) | 'd' (default " | xr
65 | ") ] [ processors (> 0) | 'd' (default " | Processors
66 | ") ]" ;
67 } // switch
68
69 int * Z[xr], * X[xr], * Y[xc];
70
[b244fa8]71 for ( r; xr ) { // create/initialize X matrix
[418882af]72 X[r] = aalloc( xc );
[b244fa8]73 for ( c; xc ) {
[418882af]74 X[r][c] = r * c % 37; // for timing
75 } // for
76 } // for
[b244fa8]77 for ( r; xc ) { // create/initialize Y matrix
[418882af]78 Y[r] = aalloc( yc );
[b244fa8]79 for ( c; yc ) {
[418882af]80 Y[r][c] = r * c % 37; // for timing
81 } // for
82 } // for
[b244fa8]83 for ( r; xr ) { // create Z matrix
[418882af]84 Z[r] = aalloc( yc );
85 } // for
86
[7edf912]87 executor e{ Processors, Processors, Processors == 1 ? 1 : Processors * 16, true };
[418882af]88
[7edf912]89 sout | "starting";
[41882628]90 actor_start( e );
[7edf912]91 sout | "started";
92 derived_msg messages[xr];
93 derived_actor actors[xr];
[418882af]94
[b244fa8]95 for ( r; xr ) {
[418882af]96 messages[r]{ Z[r], X[r], Y };
97 } // for
[b244fa8]98 for ( r; xr ) {
[77fd9fe2]99 actors[r] | messages[r];
[418882af]100 } // for
101
[7edf912]102 sout | "stopping";
[41882628]103 actor_stop();
[7edf912]104 sout | "stopped";
[418882af]105
[b244fa8]106 for ( r; xr ) { // deallocate X and Z matrices
[418882af]107 free( X[r] );
[7edf912]108 free( Z[r] );
[418882af]109 } // for
[b244fa8]110 for ( r; xc ) { // deallocate Y matrix
[7edf912]111 free( Y[r] );
[418882af]112 } // for
[50be8af5]113}
Note: See TracBrowser for help on using the repository browser.