source: tests/concurrency/actors/matrixMultiply.cfa@ d2e6f84

Last change on this file since d2e6f84 was d923fca, checked in by Andrew Beach <ajbeach@…>, 8 months ago

Clean-up the warnings of the concurrency tests. A lot of little test level fixes, the most interesting repeated one is some formally redundent fallthough statements. pthread_attr_test had to be rewritten because of library restrictions. Changed some types so they would always be pointer sized. There was a library change, there was a function that could not be implemented; I trust that it is included for a reason so I just put it in a comment. There is a change to the compiler, wait-until now uses goto. The labelled breaks were code generated as unlabelled breaks and although it worked out slipped through some checks. Finally, there is one warning that I cannot solve at this time so tests that produce it have been put in their own lax group.

  • 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
[d923fca]26allocation receive( derived_actor &, 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] );
[d96f7c4]41 if ( Processors < 1 ) fallthrough default;
[418882af]42 } // if
[d923fca]43 fallthrough;
[418882af]44 case 4:
45 if ( strcmp( argv[3], "d" ) != 0 ) { // default ?
[50be8af5]46 xr = ato( argv[3] );
[d96f7c4]47 if ( xr < 1 ) fallthrough default;
[418882af]48 } // if
[d923fca]49 fallthrough;
[418882af]50 case 3:
51 if ( strcmp( argv[2], "d" ) != 0 ) { // default ?
[50be8af5]52 xc = ato( argv[2] );
[d96f7c4]53 if ( xc < 1 ) fallthrough default;
[418882af]54 } // if
[d923fca]55 fallthrough;
[418882af]56 case 2:
57 if ( strcmp( argv[1], "d" ) != 0 ) { // default ?
[50be8af5]58 yc = ato( argv[1] );
[d96f7c4]59 if ( yc < 1 ) fallthrough default;
[418882af]60 } // if
[d923fca]61 fallthrough;
[418882af]62 case 1: // use defaults
63 break;
64 default:
[50be8af5]65 exit | "Usage: " | argv[0]
[418882af]66 | " [ yc (> 0) | 'd' (default " | yc
67 | ") ] [ xc (> 0) | 'd' (default " | xc
68 | ") ] [ xr (> 0) | 'd' (default " | xr
69 | ") ] [ processors (> 0) | 'd' (default " | Processors
70 | ") ]" ;
71 } // switch
72
73 int * Z[xr], * X[xr], * Y[xc];
74
[b244fa8]75 for ( r; xr ) { // create/initialize X matrix
[418882af]76 X[r] = aalloc( xc );
[b244fa8]77 for ( c; xc ) {
[418882af]78 X[r][c] = r * c % 37; // for timing
79 } // for
80 } // for
[b244fa8]81 for ( r; xc ) { // create/initialize Y matrix
[418882af]82 Y[r] = aalloc( yc );
[b244fa8]83 for ( c; yc ) {
[418882af]84 Y[r][c] = r * c % 37; // for timing
85 } // for
86 } // for
[b244fa8]87 for ( r; xr ) { // create Z matrix
[418882af]88 Z[r] = aalloc( yc );
89 } // for
90
[7edf912]91 executor e{ Processors, Processors, Processors == 1 ? 1 : Processors * 16, true };
[418882af]92
[7edf912]93 sout | "starting";
[41882628]94 actor_start( e );
[7edf912]95 sout | "started";
96 derived_msg messages[xr];
97 derived_actor actors[xr];
[418882af]98
[b244fa8]99 for ( r; xr ) {
[418882af]100 messages[r]{ Z[r], X[r], Y };
101 } // for
[b244fa8]102 for ( r; xr ) {
[77fd9fe2]103 actors[r] | messages[r];
[418882af]104 } // for
105
[7edf912]106 sout | "stopping";
[41882628]107 actor_stop();
[7edf912]108 sout | "stopped";
[418882af]109
[b244fa8]110 for ( r; xr ) { // deallocate X and Z matrices
[418882af]111 free( X[r] );
[7edf912]112 free( Z[r] );
[418882af]113 } // for
[b244fa8]114 for ( r; xc ) { // deallocate Y matrix
[7edf912]115 free( Y[r] );
[418882af]116 } // for
[50be8af5]117}
Note: See TracBrowser for help on using the repository browser.