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

Last change on this file since b28ce93 was d923fca, checked in by Andrew Beach <ajbeach@…>, 7 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
Line 
1#include <actor.hfa>
2#include <fstream.hfa>
3#include <stdlib.hfa>
4#include <string.h>
5#include <stdio.h>
6
7ssize_t xr = 500, xc = 500, yc = 500, Processors = 1; // default values, must be signed
8
9struct derived_actor { inline actor; };
10
11struct derived_msg {
12 inline message;
13 int * Z;
14 int * X;
15 int ** Y;
16};
17
18void ?{}( derived_msg & this ) {}
19void ?{}( derived_msg & this, int * Z, int * X, int ** Y ) {
20 set_allocation( this, Nodelete );
21 this.Z = Z;
22 this.X = X;
23 this.Y = Y;
24}
25
26allocation receive( derived_actor &, derived_msg & msg ) {
27 for ( i; yc ) { // multiply X_row by Y_col and sum products
28 msg.Z[i] = 0;
29 for ( j; xc ) {
30 msg.Z[i] += msg.X[j] * msg.Y[j][i];
31 } // for
32 } // for
33 return Finished;
34}
35
36int main( int argc, char * argv[] ) {
37 switch ( argc ) {
38 case 5:
39 if ( strcmp( argv[4], "d" ) != 0 ) { // default ?
40 Processors = ato( argv[4] );
41 if ( Processors < 1 ) fallthrough default;
42 } // if
43 fallthrough;
44 case 4:
45 if ( strcmp( argv[3], "d" ) != 0 ) { // default ?
46 xr = ato( argv[3] );
47 if ( xr < 1 ) fallthrough default;
48 } // if
49 fallthrough;
50 case 3:
51 if ( strcmp( argv[2], "d" ) != 0 ) { // default ?
52 xc = ato( argv[2] );
53 if ( xc < 1 ) fallthrough default;
54 } // if
55 fallthrough;
56 case 2:
57 if ( strcmp( argv[1], "d" ) != 0 ) { // default ?
58 yc = ato( argv[1] );
59 if ( yc < 1 ) fallthrough default;
60 } // if
61 fallthrough;
62 case 1: // use defaults
63 break;
64 default:
65 exit | "Usage: " | argv[0]
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
75 for ( r; xr ) { // create/initialize X matrix
76 X[r] = aalloc( xc );
77 for ( c; xc ) {
78 X[r][c] = r * c % 37; // for timing
79 } // for
80 } // for
81 for ( r; xc ) { // create/initialize Y matrix
82 Y[r] = aalloc( yc );
83 for ( c; yc ) {
84 Y[r][c] = r * c % 37; // for timing
85 } // for
86 } // for
87 for ( r; xr ) { // create Z matrix
88 Z[r] = aalloc( yc );
89 } // for
90
91 executor e{ Processors, Processors, Processors == 1 ? 1 : Processors * 16, true };
92
93 sout | "starting";
94 actor_start( e );
95 sout | "started";
96 derived_msg messages[xr];
97 derived_actor actors[xr];
98
99 for ( r; xr ) {
100 messages[r]{ Z[r], X[r], Y };
101 } // for
102 for ( r; xr ) {
103 actors[r] | messages[r];
104 } // for
105
106 sout | "stopping";
107 actor_stop();
108 sout | "stopped";
109
110 for ( r; xr ) { // deallocate X and Z matrices
111 free( X[r] );
112 free( Z[r] );
113 } // for
114 for ( r; xc ) { // deallocate Y matrix
115 free( Y[r] );
116 } // for
117}
Note: See TracBrowser for help on using the repository browser.