Ignore:
Timestamp:
Jun 7, 2023, 1:34:08 PM (13 months ago)
Author:
caparson <caparson@…>
Branches:
master
Children:
fa5e1aa5
Parents:
ded6c2a6
Message:

refactored waituntil future benchmarks and updated runscript

File:
1 edited

Legend:

Unmodified
Added
Removed
  • doc/theses/colby_parsons_MMAth/benchmarks/waituntil/ucpp/future.cc

    rded6c2a6 rb5e3a80  
    33#include <uFuture.h>
    44
    5 size_t Clients = 2, Time = 10;
     5// #define ANDOR
    66
     7size_t Processors = 2, Time = 10;
    78size_t globalTotal = 0;
    8 Future_ISM<size_t> A, B, C;
    9 volatile bool server_done_loop = false;
    10 volatile bool client_done_loop = false;
     9volatile bool done_loop = false;
    1110volatile bool client_done = false;
    1211volatile bool server_done = false;
    1312
    14 volatile size_t client_count = 0;
    15 volatile size_t client_loop_count = 0;
     13Future_ISM<size_t> A, B, C;
     14
     15static inline void wait() {
     16    #ifdef OR
     17    _Select( A ) { A(); }
     18    or _Select( B ) { B(); }
     19    or _Select( C ) { C(); }
     20    #endif
     21    #ifdef AND
     22    _Select( A ) { A(); }
     23    and _Select( B ) { B(); }
     24    #endif
     25    #ifdef AND3
     26    _Select( A ) { A(); }
     27    and _Select( B ) { B(); }
     28    and _Select( C ) { C(); }
     29    #endif
     30    #ifdef ANDOR
     31    _Select( A ) { A(); }
     32    and _Select( B ) { B(); }
     33    or _Select( C ) { C(); }
     34    #endif
     35    #ifdef ORAND
     36    (_Select( A ) { A(); }
     37    or _Select( B ) { B(); })
     38    and _Select( C ) { C(); }
     39    #endif
     40    #ifdef BASIC
     41    A();
     42    #endif
     43}
     44
     45static inline void fulfill( size_t i ) {
     46    #ifdef OR
     47    if ( i % 3 == 0 ) {
     48        A.delivery(i);
     49    } else if ( i % 3 == 1 ) {
     50        B.delivery(i);
     51    } else {
     52        C.delivery(i);
     53    }
     54    #endif
     55    #ifdef AND
     56    if ( i % 2 == 0 ) {
     57        A.delivery(i);
     58        B.delivery(i);
     59    } else {
     60        B.delivery(i);
     61        A.delivery(i);
     62    }
     63    #endif
     64    #ifdef AND3
     65    if ( i % 6 == 0 ) {
     66        A.delivery(i);
     67        B.delivery(i);
     68        C.delivery(i);
     69    } else if ( i % 6 == 1 ) {
     70        A.delivery(i);
     71        C.delivery(i);
     72        B.delivery(i);
     73    } else if ( i % 6 == 2 ) {
     74        B.delivery(i);
     75        A.delivery(i);
     76        C.delivery(i);
     77    } else if ( i % 6 == 3 ) {
     78        B.delivery(i);
     79        C.delivery(i);
     80        A.delivery(i);
     81    } else if ( i % 6 == 4 ) {
     82        C.delivery(i);
     83        A.delivery(i);
     84        B.delivery(i);
     85    } else if ( i % 6 == 5 ) {
     86        C.delivery(i);
     87        B.delivery(i);
     88        A.delivery(i);
     89    }
     90    #endif
     91    #ifdef ANDOR
     92    if ( i % 4 == 0 ) {
     93        A.delivery(i);
     94        B.delivery(i);
     95    } else if ( i % 4 == 1 ) {
     96        A.delivery(i);
     97        C.delivery(i);
     98    } else if ( i % 4 == 2 ) {
     99        B.delivery(i);
     100        C.delivery(i);
     101    } else {
     102        C.delivery(i);
     103    }
     104    #endif
     105    #ifdef ORAND
     106    if ( i % 4 == 0 ) {
     107        A.delivery(i);
     108        C.delivery(i);
     109    } else if ( i % 4 == 1 ) {
     110        C.delivery(i);
     111        A.delivery(i);
     112    } else if ( i % 4 == 2 ) {
     113        B.delivery(i);
     114        C.delivery(i);
     115    } else {
     116        C.delivery(i);
     117        B.delivery(i);
     118    }
     119    #endif
     120    #ifdef BASIC
     121    A.delivery(i);
     122    #endif
     123}
     124
    16125_Task Client {
    17126        void main() {
    18127                size_t i = 0;
    19         for(;; i++ ) {
    20             _Select( A ) { A(); }
    21             and _Select( B ) { B(); }
    22             or _Select( C ) { C(); }
    23 
    24             // needs to check after waituntil for termination synchronization
    25             if ( client_done ) break;
    26            
    27             // Barrier-like synch needed to reset futures safely
    28             if ( __atomic_add_fetch(&client_count, 1, __ATOMIC_SEQ_CST) == Clients ) {
    29                 client_count = 0;
    30                 A.reset();
    31                 B.reset();
    32                 C.reset();
    33                 client_done_loop = true;
    34             }
    35             while( !client_done_loop ) {} // client barrier
    36             if ( __atomic_add_fetch( &client_loop_count, 1, __ATOMIC_SEQ_CST ) == Clients ) {
    37                 client_done_loop = false; // reset barrier before clients can proceed past waituntil
    38                 server_done_loop = true; // unblock server to restart iteration
    39                 client_loop_count = 0;
    40             }
     128        for(; !client_done; i++ ) {
     129            wait();
     130            A.reset();
     131            B.reset();
     132            C.reset();
     133            done_loop = true;
    41134        }
    42135        __atomic_fetch_add( &globalTotal, i, __ATOMIC_SEQ_CST );
     
    47140        void main() {
    48141                for( size_t i = 0; !server_done; i++ ) {
    49             if ( i % 4 == 0 ) {
    50                 A.delivery(i);
    51                 B.delivery(i);
    52             } else if ( i % 4 == 1 ) {
    53                 A.delivery(i);
    54                 C.delivery(i);
    55             } else if ( i % 4 == 2 ) {
    56                 B.delivery(i);
    57                 C.delivery(i);
    58             } else {
    59                 C.delivery(i);
    60             }
    61             while( !server_done_loop && !server_done ) {} // server barrier
    62             server_done_loop = false; // reset server barrier
     142            fulfill( i );
     143            while( !done_loop ) {}
     144            done_loop = false;
    63145        }
    64146        }
     
    67149int main( int argc, char * argv[] ) {
    68150        switch ( argc ) {
    69           case 3:
    70                 if ( strcmp( argv[2], "d" ) != 0 ) {                    // default ?
    71                         Time = atoi( argv[2] );
    72                 } // if
    73151          case 2:
    74152                if ( strcmp( argv[1], "d" ) != 0 ) {                    // default ?
    75                         Clients = atoi( argv[1] );
    76                         if ( Clients < 1 ) goto Usage;
     153                        Time = atoi( argv[1] );
     154                        if ( Time < 0 ) goto Usage;
    77155                } // if
    78156          case 1:                                                                                       // use defaults
     
    81159          Usage:
    82160                cerr << "Usage: " << argv[0]
    83              << " [ clients (> 0) | 'd' (default " << Clients
    84                          << ") ] [ time (>= 0) | 'd' (default " << Time
     161             << "[ time (>= 0) | 'd' (default " << Time
    85162                         << ") ]" ;
    86163                exit( EXIT_FAILURE );
    87164        } // switch
    88     uProcessor p[Clients];
     165    uProcessor p[Processors - 1];
    89166
    90167    {
    91         Client c[Clients];
     168        Server s;
    92169        {
    93             Server s;
     170            Client c;
    94171
    95172            uBaseTask::sleep( uDuration( Time ) );
    96173
    97             server_done = true;
     174            client_done = true;
    98175        }
    99         while( A.available() || B.available() || C.available() ) {}
    100         client_done = true;
    101         C.delivery(1); // can't deliver 0 since it causes ambiguity
     176        server_done = true;
     177        done_loop = true;
    102178    }
    103179    cout << globalTotal << endl;
Note: See TracChangeset for help on using the changeset viewer.