Ignore:
Timestamp:
Sep 17, 2023, 11:19:08 AM (17 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/channels
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • tests/concurrency/channels/barrier.cfa

    r697c957 r50be8af5  
    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 r50be8af5  
    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 r50be8af5  
    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 r50be8af5  
    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 r50be8af5  
    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 r50be8af5  
    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 r50be8af5  
    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;
Note: See TracChangeset for help on using the changeset viewer.