Changeset 50be8af


Ignore:
Timestamp:
Sep 17, 2023, 11:19:08 AM (7 months ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
master
Children:
7edf912
Parents:
697c957
Message:

clean up command-line handling and I/O

Location:
tests/concurrency
Files:
18 edited

Legend:

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

    r697c957 r50be8af  
    3636          case 2:
    3737                if ( strcmp( argv[1], "d" ) != 0 ) {                    // default ?
    38                         Times = atoi( argv[1] );
    39                         if ( Times < 1 ) goto Usage;
     38                        Times = ato( argv[1] );
     39                        if ( Times < 1 ) fallthru default;
    4040                } // if
    4141          case 1:                                                                                       // use defaults
    4242                break;
    4343          default:
    44           Usage:
    45                 sout | "Usage: " | argv[0] | " [ times (> 0) ]";
    46                 exit( EXIT_FAILURE );
     44                exit | "Usage: " | argv[0] | " [ times (> 0) ]";
    4745        } // switch
    4846
    49     printf("starting\n");
     47    sout | "starting";
    5048
    5149    executor e{ 0, 1, 1, false };
    5250    start_actor_system( e );
    5351
    54     printf("started\n");
     52    sout | "started";
    5553
    5654    derived_msg * d_msg = alloc();
     
    6058    *d_actor | *d_msg;
    6159
    62     printf("stopping\n");
     60    sout | "stopping";
    6361
    6462    stop_actor_system();
    6563
    66     printf("stopped\n");
     64    sout | "stopped";
    6765
    6866    return 0;
  • tests/concurrency/actors/executor.cfa

    r697c957 r50be8af  
    4040          case 7:
    4141                if ( strcmp( argv[6], "d" ) != 0 ) {                    // default ?
    42                         BufSize = atoi( argv[6] );
    43                         if ( BufSize < 0 ) goto Usage;
     42                        BufSize = ato( argv[6] );
     43                        if ( BufSize < 0 ) fallthru default;
    4444                } // if
    4545          case 6:
    4646                if ( strcmp( argv[5], "d" ) != 0 ) {                    // default ?
    47                         Batch = atoi( argv[5] );
    48                         if ( Batch < 1 ) goto Usage;
     47                        Batch = ato( argv[5] );
     48                        if ( Batch < 1 ) fallthru default;
    4949                } // if
    5050          case 5:
    5151                if ( strcmp( argv[4], "d" ) != 0 ) {                    // default ?
    52                         Processors = atoi( argv[4] );
    53                         if ( Processors < 1 ) goto Usage;
     52                        Processors = ato( argv[4] );
     53                        if ( Processors < 1 ) fallthru default;
    5454                } // if
    5555          case 4:
    5656                if ( strcmp( argv[3], "d" ) != 0 ) {                    // default ?
    57                         Rounds = atoi( argv[3] );
    58                         if ( Rounds < 1 ) goto Usage;
     57                        Rounds = ato( argv[3] );
     58                        if ( Rounds < 1 ) fallthru default;
    5959                } // if
    6060          case 3:
    6161                if ( strcmp( argv[2], "d" ) != 0 ) {                    // default ?
    62                         Set = atoi( argv[2] );
    63                         if ( Set < 1 ) goto Usage;
     62                        Set = ato( argv[2] );
     63                        if ( Set < 1 ) fallthru default;
    6464                } // if
    6565          case 2:
    6666                if ( strcmp( argv[1], "d" ) != 0 ) {                    // default ?
    67                         Actors = atoi( argv[1] );
    68                         if ( Actors < 1 || Actors <= Set || Actors % Set != 0 ) goto Usage;
     67                        Actors = ato( argv[1] );
     68                        if ( Actors < 1 || Actors <= Set || Actors % Set != 0 ) fallthru default;
    6969                } // if
    7070          case 1:                                                                                       // use defaults
    7171                break;
    7272          default:
    73           Usage:
    74                 sout | "Usage: " | argv[0]
     73                exit | "Usage: " | argv[0]
    7574             | " [ actors (> 0 && > set && actors % set == 0 ) | 'd' (default " | Actors
    7675                         | ") ] [ set (> 0) | 'd' (default " | Set
     
    8079                         | ") ] [ buffer size (>= 0) | 'd' (default " | BufSize
    8180                         | ") ]" ;
    82                 exit( EXIT_FAILURE );
    8381        } // switch
    8482
    8583    executor e{ Processors, Processors, Processors == 1 ? 1 : Processors * 512, true };
    8684
    87     printf("starting\n");
     85    sout | "starting";
    8886
    8987    start_actor_system( e );
    9088
    91     printf("started\n");
     89    sout | "started";
    9290
    9391    d_actor actors[ Actors ];
     
    9795        } // for
    9896
    99     printf("stopping\n");
     97    sout | "stopping";
    10098
    10199    stop_actor_system();
    102100
    103     printf("stopped\n");
     101    sout | "stopped";
    104102
    105103    return 0;
  • tests/concurrency/actors/matrix.cfa

    r697c957 r50be8af  
    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; };
     
    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
     
    9088    executor e{ Processors, Processors, Processors == 1 ? 1 : Processors * 16, true };
    9189
    92     printf("starting\n");
     90    sout | "starting";
    9391
    9492    start_actor_system( e );
    9593
    96     printf("started\n");
     94    sout | "started";
    9795
    9896    derived_msg messages[xr];
     
    108106        } // for
    109107
    110     printf("stopping\n");
     108    sout | "stopping";
    111109
    112110    stop_actor_system();
    113111
    114     printf("stopped\n");
     112    sout | "stopped";
    115113
    116114    for ( r = 0; r < xr; r += 1 ) {                                             // deallocate X and Z matrices
     
    121119        free( Y[r] );
    122120        } // for
    123 
    124     return 0;
    125121}
  • tests/concurrency/actors/pingpong.cfa

    r697c957 r50be8af  
    4242
    4343int main( int argc, char * argv[] ) {
    44     printf("start\n");
     44    sout | "start";
    4545
    4646    processor p[Processors - 1];
     
    5656    stop_actor_system();
    5757
    58     printf("end\n");
    59     return 0;
     58    sout | "end";
    6059}
  • tests/concurrency/actors/static.cfa

    r697c957 r50be8af  
    3333          case 2:
    3434                if ( strcmp( argv[1], "d" ) != 0 ) {                    // default ?
    35                         Times = atoi( argv[1] );
    36                         if ( Times < 1 ) goto Usage;
     35                        Times = ato( argv[1] );
     36                        if ( Times < 1 ) fallthru default;
    3737                } // if
    3838          case 1:                                                                                       // use defaults
    3939                break;
    4040          default:
    41           Usage:
    42                 sout | "Usage: " | argv[0] | " [ times (> 0) ]";
    43                 exit( EXIT_FAILURE );
     41                exit | "Usage: " | argv[0] | " [ times (> 0) ]";
    4442        } // switch
    4543
    46     printf("starting\n");
     44    sout | "starting";
    4745
    4846    executor e{ 0, 1, 1, false };
    4947    start_actor_system( e );
    5048
    51     printf("started\n");
     49    sout | "started";
    5250
    5351    derived_msg msg;
     
    5755    actor | msg;
    5856
    59     printf("stopping\n");
     57    sout | "stopping";
    6058
    6159    stop_actor_system();
    6260
    63     printf("stopped\n");
     61    sout | "stopped";
    6462
    6563    return 0;
  • tests/concurrency/actors/types.cfa

    r697c957 r50be8af  
    6262
    6363int main( int argc, char * argv[] ) {
    64     printf("start\n");
     64    sout | "start";
    6565
    6666    processor p[Processors - 1];
    6767
    68     printf("basic test\n");
     68    sout | "basic test";
    6969    start_actor_system( Processors ); // test passing number of processors
    7070    derived_actor a;
     
    7575    stop_actor_system();
    7676
    77     printf("same message and different actors test\n");
     77    sout | "same message and different actors test";
    7878    start_actor_system(); // let system detect # of processors
    7979    derived_actor2 d_ac2_0, d_ac2_1;
     
    8686   
    8787    {
    88         printf("same message and different actor types test\n");
     88        sout | "same message and different actor types test";
    8989        executor e{ 0, Processors, Processors == 1 ? 1 : Processors * 4, false };
    9090        start_actor_system( e ); // pass an explicit executor
     
    9999
    100100    {
    101         printf("different message types, one actor test\n");
     101        sout | "different message types, one actor test";
    102102        executor e{ 1, Processors, Processors == 1 ? 1 : Processors * 4, true };
    103103        start_actor_system( Processors );
     
    112112
    113113    {
    114         printf("nested inheritance actor test\n");
     114        sout | "nested inheritance actor test";
    115115        executor e{ 1, Processors, Processors == 1 ? 1 : Processors * 4, true };
    116116        start_actor_system( Processors );
     
    124124    } // RAII to clean up executor
    125125
    126     printf("end\n");
    127     return 0;
     126    sout | "end";
    128127}
  • tests/concurrency/channels/barrier.cfa

    r697c957 r50be8af  
    88
    99size_t total_operations = 0;
    10 int Processors = 1, Tasks = 5, BarrierSize = 2;
     10ssize_t Processors = 1, Tasks = 5, BarrierSize = 2;             // must be signed
    1111
    1212typedef channel( int ) Channel;
     
    6565          case 3:
    6666                if ( strcmp( argv[2], "d" ) != 0 ) {                    // default ?
    67                         BarrierSize = atoi( argv[2] );
    68             if ( Processors < 1 ) goto Usage;
     67                        BarrierSize = ato( argv[2] );
     68            if ( Processors < 1 ) fallthru default;
    6969                } // if
    7070          case 2:
    7171                if ( strcmp( argv[1], "d" ) != 0 ) {                    // default ?
    72                         Processors = atoi( argv[1] );
    73                         if ( Processors < 1 ) goto Usage;
     72                        Processors = ato( argv[1] );
     73                        if ( Processors < 1 ) fallthru default;
    7474                } // if
    7575          case 1:                                                                                       // use defaults
    7676                break;
    7777          default:
    78           Usage:
    79                 sout | "Usage: " | argv[0]
     78                exit | "Usage: " | argv[0]
    8079             | " [ processors (> 0) | 'd' (default " | Processors
    8180                         | ") ] [ BarrierSize (> 0) | 'd' (default " | BarrierSize
    8281                         | ") ]" ;
    83                 exit( EXIT_FAILURE );
    8482        } // switch
    8583    if ( Tasks < BarrierSize )
  • tests/concurrency/channels/big_elems.cfa

    r697c957 r50be8af  
    22#include "parallel_harness.hfa"
    33
    4 size_t Processors = 10, Channels = 10, Producers = 40, Consumers = 40, ChannelSize = 128;
     4ssize_t Processors = 10, Channels = 10, Producers = 40, Consumers = 40, ChannelSize = 128;
    55
    66int main() {
  • tests/concurrency/channels/churn.cfa

    r697c957 r50be8af  
    77#include <time.hfa>
    88
    9 size_t Processors = 1, Channels = 4, Producers = 2, Consumers = 2, ChannelSize = 128;
     9ssize_t Processors = 1, Channels = 4, Producers = 2, Consumers = 2, ChannelSize = 128;
    1010
    1111owner_lock o;
     
    9090      case 4:
    9191                if ( strcmp( argv[3], "d" ) != 0 ) {                    // default ?
    92                         if ( atoi( argv[3] ) < 1 ) goto Usage;
    93                         ChannelSize = atoi( argv[3] );
     92                        ChannelSize = ato( argv[3] );
     93                        if ( ChannelSize < 1 ) fallthru default;
    9494                } // if
    9595      case 3:
    9696                if ( strcmp( argv[2], "d" ) != 0 ) {                    // default ?
    97                         if ( atoi( argv[2] ) < 1 ) goto Usage;
    98                         Channels = atoi( argv[2] );
     97                        Channels = ato( argv[2] );
     98                        if ( Channels < 1 ) fallthru default;
    9999                } // if
    100100      case 2:
    101101                if ( strcmp( argv[1], "d" ) != 0 ) {                    // default ?
    102                         if ( atoi( argv[1] ) < 1 ) goto Usage;
    103                         Processors = atoi( argv[1] );
     102                        Processors = ato( argv[1] );
     103                        if ( Processors < 1 ) fallthru default;
    104104                } // if
    105105          case 1:                                                                                       // use defaults
    106106                break;
    107107          default:
    108           Usage:
    109                 sout | "Usage: " | argv[0]
     108                exit | "Usage: " | argv[0]
    110109             | " [ processors > 0 | d ]"
    111110             | " [ producers > 0 | d ]"
    112111             | " [ consumers > 0 | d ]"
    113112             | " [ channels > 0 | d ]";
    114                 exit( EXIT_FAILURE );
    115113    }
    116114    processor p[Processors - 1];
  • tests/concurrency/channels/contend.cfa

    r697c957 r50be8af  
    127127          case 3:
    128128                if ( strcmp( argv[2], "d" ) != 0 ) {                    // default ?
    129                         ChannelSize = atoi( argv[2] );
     129                        ChannelSize = ato( argv[2] );
     130                        if ( ChannelSize < 1 ) fallthru default;
    130131                } // if
    131132          case 2:
    132133                if ( strcmp( argv[1], "d" ) != 0 ) {                    // default ?
    133                         Processors = atoi( argv[1] );
    134                         if ( Processors < 1 ) goto Usage;
     134                        Processors = ato( argv[1] );
     135                        if ( Processors < 1 ) fallthru default;
    135136                } // if
    136137          case 1:                                                                                       // use defaults
    137138                break;
    138139          default:
    139           Usage:
    140                 sout | "Usage: " | argv[0]
     140                exit | "Usage: " | argv[0]
    141141             | " [ processors (> 0) | 'd' (default " | Processors
    142142                         | ") ] [ channel size (>= 0) | 'd' (default " | ChannelSize
    143143                         | ") ]" ;
    144                 exit( EXIT_FAILURE );
    145144        } // switch
     145
    146146    test(Processors, Channels, Producers, Consumers, ChannelSize);
    147147}
  • tests/concurrency/channels/daisy_chain.cfa

    r697c957 r50be8af  
    88
    99size_t total_operations = 0;
    10 size_t Processors = 1, Tasks = 4;
     10ssize_t Processors = 1, Tasks = 4;                                              // must be signed
    1111
    1212owner_lock o;
     
    3737          case 3:
    3838                if ( strcmp( argv[2], "d" ) != 0 ) {                    // default ?
    39                         Tasks = atoi( argv[2] );
    40             if ( Tasks < 1 ) goto Usage;
     39                        Tasks = ato( argv[2] );
     40            if ( Tasks < 1 ) fallthru default;
    4141                } // if
    4242          case 2:
    4343                if ( strcmp( argv[1], "d" ) != 0 ) {                    // default ?
    44                         Processors = atoi( argv[1] );
    45                         if ( Processors < 1 ) goto Usage;
     44                        Processors = ato( argv[1] );
     45                        if ( Processors < 1 ) fallthru default;
    4646                } // if
    4747          case 1:                                                                                       // use defaults
    4848                break;
    4949          default:
    50           Usage:
    51                 sout | "Usage: " | argv[0]
     50                exit | "Usage: " | argv[0]
    5251             | " [ processors (> 0) | 'd' (default " | Processors
    5352                         | ") ] [ channel size (>= 0) | 'd' (default " | Tasks
    5453                         | ") ]" ;
    55                 exit( EXIT_FAILURE );
    5654        } // switch
    5755    processor proc[Processors - 1];
     
    7169    // sout | total_operations;
    7270    sout | "done";
    73 
    74     return 0;
    7571}
  • tests/concurrency/channels/hot_potato.cfa

    r697c957 r50be8af  
    88
    99size_t total_operations = 0;
    10 size_t Processors = 1, Tasks = 4;
     10ssize_t Processors = 1, Tasks = 4;                                              // must be signed
    1111
    1212owner_lock o;
     
    3838}
    3939
    40 
    4140int main( int argc, char * argv[] ) {
    4241    switch ( argc ) {
    4342          case 3:
    4443                if ( strcmp( argv[2], "d" ) != 0 ) {                    // default ?
    45                         Tasks = atoi( argv[2] );
    46             if ( Tasks < 1 ) goto Usage;
     44                        Tasks = ato( argv[2] );
     45            if ( Tasks < 1 ) fallthru default;
    4746                } // if
    4847          case 2:
    4948                if ( strcmp( argv[1], "d" ) != 0 ) {                    // default ?
    50                         Processors = atoi( argv[1] );
    51                         if ( Processors < 1 ) goto Usage;
     49                        Processors = ato( argv[1] );
     50                        if ( Processors < 1 ) fallthru default;
    5251                } // if
    5352          case 1:                                                                                       // use defaults
    5453                break;
    5554          default:
    56           Usage:
    57                 sout | "Usage: " | argv[0]
     55                exit | "Usage: " | argv[0]
    5856             | " [ processors (> 0) | 'd' (default " | Processors
    5957                         | ") ] [ channel size (>= 0) | 'd' (default " | Tasks
    6058                         | ") ]" ;
    61                 exit( EXIT_FAILURE );
    6259        } // switch
     60
    6361    processor proc[Processors - 1];
    6462
  • tests/concurrency/channels/pub_sub.cfa

    r697c957 r50be8af  
    8787          case 3:
    8888                if ( strcmp( argv[2], "d" ) != 0 ) {                    // default ?
    89                         Tasks = atoi( argv[2] );
    90             if ( Tasks < 1 ) goto Usage;
     89                        Tasks = ato( argv[2] );
     90            if ( Tasks < 1 ) fallthru default;
    9191                } // if
    9292          case 2:
    9393                if ( strcmp( argv[1], "d" ) != 0 ) {                    // default ?
    94                         Processors = atoi( argv[1] );
    95                         if ( Processors < 1 ) goto Usage;
     94                        Processors = ato( argv[1] );
     95                        if ( Processors < 1 ) fallthru default;
    9696                } // if
    9797          case 1:                                                                                       // use defaults
    9898                break;
    9999          default:
    100           Usage:
    101                 sout | "Usage: " | argv[0]
     100                exit | "Usage: " | argv[0]
    102101             | " [ processors (> 0) | 'd' (default " | Processors
    103102                         | ") ] [ Tasks (> 0) | 'd' (default " | Tasks
    104103                         | ") ]" ;
    105                 exit( EXIT_FAILURE );
    106104        } // switch
    107105    BarrierSize = Tasks;
  • tests/concurrency/examples/matrixSum.cfa

    r697c957 r50be8af  
    1010// Created On       : Mon Oct  9 08:29:28 2017
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Wed Feb 20 08:37:53 2019
    13 // Update Count     : 16
     12// Last Modified On : Fri Sep  8 19:05:34 2023
     13// Update Count     : 19
    1414//
    1515
    1616#include <fstream.hfa>
    17 #include <kernel.hfa>
    1817#include <thread.hfa>
    1918
     
    3534
    3635int main() {
    37         /* const */ int rows = 10, cols = 1000;
     36        const int rows = 10, cols = 1000;
    3837        int matrix[rows][cols], subtotals[rows], total = 0;
    3938        processor p;                                                                            // add kernel thread
    4039
    41         for ( r; rows ) {
     40        for ( r; rows ) {                                                                       // initialize
    4241                for ( c; cols ) {
    4342                        matrix[r][c] = 1;
    4443                } // for
    4544        } // for
     45
    4646        Adder * adders[rows];
    4747        for ( r; rows ) {                                                                       // start threads to sum rows
    4848                adders[r] = &(*malloc()){ matrix[r], cols, subtotals[r] };
    49 //              adders[r] = new( matrix[r], cols, &subtotals[r] );
     49                // adders[r] = new( matrix[r], cols, subtotals[r] );
    5050        } // for
     51
    5152        for ( r; rows ) {                                                                       // wait for threads to finish
    5253                delete( adders[r] );
     
    5758
    5859// Local Variables: //
    59 // tab-width: 4 //
    6060// compile-command: "cfa matrixSum.cfa" //
    6161// End: //
  • tests/concurrency/unified_locking/locks.cfa

    r697c957 r50be8af  
    11#include <stdio.h>
    2 #include "locks.hfa"
     2#include <locks.hfa>
    33#include <stdlib.hfa>
    44#include <thread.hfa>
  • tests/concurrency/unified_locking/pthread_locks.cfa

    r697c957 r50be8af  
    11#include <stdio.h>
    2 #include "locks.hfa"
     2#include <locks.hfa>
    33#include <stdlib.hfa>
    44#include <thread.hfa>
  • tests/concurrency/unified_locking/test_debug.cfa

    r697c957 r50be8af  
    1 #include "locks.hfa"
     1#include <locks.hfa>
    22
    33fast_block_lock f;
  • tests/concurrency/unified_locking/thread_test.cfa

    r697c957 r50be8af  
    11#include <stdio.h>
    2 #include "locks.hfa"
     2#include <locks.hfa>
    33#include <stdlib.hfa>
    44#include <thread.hfa>
Note: See TracChangeset for help on using the changeset viewer.