source: doc/theses/colby_parsons_MMAth/benchmarks/actors/cfa/matrix.cfa @ cec2551

ADTast-experimental
Last change on this file since cec2551 was cec2551, checked in by caparson <caparson@…>, 15 months ago

added cfa benchmarks

  • Property mode set to 100644
File size: 3.1 KB
Line 
1#include <actor.hfa>
2#include <fstream.hfa>
3#include <stdlib.hfa>
4#include <string.h>
5#include <stdio.h>
6#include "bench.hfa"
7
8unsigned int xr = 500, xc = 500, yc = 500, Processors = 1; // default values
9
10struct derived_actor { inline actor; };
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    ((message &) this){ Nodelete };
21    this.Z = Z;
22    this.X = X;
23    this.Y = Y;
24}
25
26Allocation receive( derived_actor & receiver, derived_msg & msg ) {
27    for ( unsigned int i = 0; i < yc; i += 1 ) { // multiply X_row by Y_col and sum products
28        msg.Z[i] = 0;
29        for ( unsigned int j = 0; j < xc; j += 1 ) {
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 = atoi( argv[4] );
41                        if ( Processors < 1 ) goto Usage;
42                } // if
43          case 4:
44                if ( strcmp( argv[3], "d" ) != 0 ) {                    // default ?
45                        xr = atoi( argv[3] );
46                        if ( xr < 1 ) goto Usage;
47                } // if
48          case 3:
49                if ( strcmp( argv[2], "d" ) != 0 ) {                    // default ?
50                        xc = atoi( argv[2] );
51                        if ( xc < 1 ) goto Usage;
52                } // if
53          case 2:
54                if ( strcmp( argv[1], "d" ) != 0 ) {                    // default ?
55                        yc = atoi( argv[1] );
56                        if ( yc < 1 ) goto Usage;
57                } // if
58          case 1:                                                                                       // use defaults
59                break;
60          default:
61          Usage:
62                sout | "Usage: " | argv[0]
63                         | " [ yc (> 0) | 'd' (default " | yc
64                         | ") ] [ xc (> 0) | 'd' (default " | xc
65                         | ") ] [ xr (> 0) | 'd' (default " | xr
66                         | ") ] [ processors (> 0) | 'd' (default " | Processors
67                         | ") ]" ;
68                exit( EXIT_FAILURE );
69        } // switch
70
71    unsigned int r, c;
72        int * Z[xr], * X[xr], * Y[xc];
73
74        for ( r = 0; r < xr; r += 1 ) {                                         // create/initialize X matrix
75                X[r] = aalloc( xc );
76                for ( c = 0; c < xc; c += 1 ) {
77                        X[r][c] = r * c % 37;                                           // for timing
78                } // for
79        } // for
80        for ( r = 0; r < xc; r += 1 ) {                                         // create/initialize Y matrix
81                Y[r] = aalloc( yc );
82                for ( c = 0; c < yc; c += 1 ) {
83                        Y[r][c] = r * c % 37;                                           // for timing
84                } // for
85        } // for
86        for ( r = 0; r < xr; r += 1 ) {                                         // create Z matrix
87                Z[r] = aalloc( yc );
88        } // for
89
90    executor e{ Processors, Processors, Processors == 1 ? 1 : Processors * 32, true };
91
92    // printf("starting\n");
93
94    uint64_t start_time = bench_time();
95
96    start_actor_system( e );
97
98    // printf("started\n");
99
100    derived_msg messages[xr];
101
102    derived_actor actors[xr];
103
104        for ( unsigned int r = 0; r < xr; r += 1 ) {
105                messages[r]{ Z[r], X[r], Y };
106        } // for
107
108        for ( unsigned int r = 0; r < xr; r += 1 ) {
109                actors[r] << messages[r];
110        } // for
111
112    // printf("stopping\n");
113
114    stop_actor_system();
115   
116    uint64_t end_time = bench_time();
117
118    printf("%.2f\n", ((double)(end_time - start_time))*((double)1e-9) );
119
120    // printf("stopped\n");
121
122    for ( r = 0; r < xr; r += 1 ) {                                             // deallocate X and Z matrices
123                free( X[r] );
124        free( Z[r] );
125        } // for
126        for ( r = 0; r < xc; r += 1 ) {                                         // deallocate Y matrix
127        free( Y[r] );
128        } // for
129
130    return 0;
131}
Note: See TracBrowser for help on using the repository browser.