Ignore:
Timestamp:
Sep 18, 2023, 10:21:29 AM (10 months ago)
Author:
caparsons <caparson@…>
Branches:
master
Children:
e4c3819
Parents:
e3784a50 (diff), 7edf912 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge branch 'master' of plg.uwaterloo.ca:software/cfa/cfa-cc

File:
1 edited

Legend:

Unmodified
Added
Removed
  • tests/concurrency/actors/matrix.cfa

    re3784a50 ra2c2363  
    55#include <stdio.h>
    66
    7 unsigned int xr = 500, xc = 500, yc = 500, Processors = 1; // default values
     7int xr = 500, xc = 500, yc = 500, Processors = 1; // default values, must be signed
    88
    99struct derived_actor { inline actor; };
    1010
    1111struct derived_msg {
    12     inline message;
    13     int * Z;
     12        inline message;
     13        int * Z;
    1414        int * X;
    15     int ** Y;
     15        int ** Y;
    1616};
    1717
    1818void ?{}( derived_msg & this ) {}
    1919void ?{}( 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;
     20        set_allocation( this, Nodelete );
     21        this.Z = Z;
     22        this.X = X;
     23        this.Y = Y;
    2424}
    2525
    2626allocation 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;
     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;
    3434}
    3535
    3636int main( int argc, char * argv[] ) {
    37     switch ( argc ) {
     37        switch ( argc ) {
    3838          case 5:
    3939                if ( strcmp( argv[4], "d" ) != 0 ) {                    // default ?
    40                         Processors = atoi( argv[4] );
    41                         if ( Processors < 1 ) goto Usage;
     40                        Processors = ato( argv[4] );
     41                        if ( Processors < 1 ) fallthru default;
    4242                } // if
    4343          case 4:
    4444                if ( strcmp( argv[3], "d" ) != 0 ) {                    // default ?
    45                         xr = atoi( argv[3] );
    46                         if ( xr < 1 ) goto Usage;
     45                        xr = ato( argv[3] );
     46                        if ( xr < 1 ) fallthru default;
    4747                } // if
    4848          case 3:
    4949                if ( strcmp( argv[2], "d" ) != 0 ) {                    // default ?
    50                         xc = atoi( argv[2] );
    51                         if ( xc < 1 ) goto Usage;
     50                        xc = ato( argv[2] );
     51                        if ( xc < 1 ) fallthru default;
    5252                } // if
    5353          case 2:
    5454                if ( strcmp( argv[1], "d" ) != 0 ) {                    // default ?
    55                         yc = atoi( argv[1] );
    56                         if ( yc < 1 ) goto Usage;
     55                        yc = ato( argv[1] );
     56                        if ( yc < 1 ) fallthru default;
    5757                } // if
    5858          case 1:                                                                                       // use defaults
    5959                break;
    6060          default:
    61           Usage:
    62                 sout | "Usage: " | argv[0]
     61                exit | "Usage: " | argv[0]
    6362                         | " [ yc (> 0) | 'd' (default " | yc
    6463                         | ") ] [ xc (> 0) | 'd' (default " | xc
     
    6665                         | ") ] [ processors (> 0) | 'd' (default " | Processors
    6766                         | ") ]" ;
    68                 exit( EXIT_FAILURE );
    6967        } // switch
    7068
    71     unsigned int r, c;
     69        unsigned int r, c;
    7270        int * Z[xr], * X[xr], * Y[xc];
    7371
     
    8886        } // for
    8987
    90     executor e{ Processors, Processors, Processors == 1 ? 1 : Processors * 16, true };
     88        executor e{ Processors, Processors, Processors == 1 ? 1 : Processors * 16, true };
    9189
    92     printf("starting\n");
     90        sout | "starting";
    9391
    94     start_actor_system( e );
     92        start_actor_system( e );
    9593
    96     printf("started\n");
     94        sout | "started";
    9795
    98     derived_msg messages[xr];
     96        derived_msg messages[xr];
    9997
    100     derived_actor actors[xr];
     98        derived_actor actors[xr];
    10199
    102100        for ( unsigned int r = 0; r < xr; r += 1 ) {
     
    108106        } // for
    109107
    110     printf("stopping\n");
     108        sout | "stopping";
    111109
    112     stop_actor_system();
     110        stop_actor_system();
    113111
    114     printf("stopped\n");
     112        sout | "stopped";
    115113
    116     for ( r = 0; r < xr; r += 1 ) {                                             // deallocate X and Z matrices
     114        for ( r = 0; r < xr; r += 1 ) {                                         // deallocate X and Z matrices
    117115                free( X[r] );
    118         free( Z[r] );
     116                free( Z[r] );
    119117        } // for
    120118        for ( r = 0; r < xc; r += 1 ) {                                         // deallocate Y matrix
    121         free( Y[r] );
     119                free( Y[r] );
    122120        } // for
    123 
    124     return 0;
    125121}
Note: See TracChangeset for help on using the changeset viewer.