Ignore:
Timestamp:
May 1, 2023, 4:19:09 PM (20 months ago)
Author:
caparsons <caparson@…>
Branches:
ADT, ast-experimental, master
Children:
c083c3d
Parents:
a50fdfb (diff), 985b624 (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:

resolved merge conflicts

File:
1 edited

Legend:

Unmodified
Added
Removed
  • doc/theses/mike_brooks_MMath/benchmarks/list/driver.c

    ra50fdfb r6e1e2d0  
    1717
    1818#if defined(NDEBUG) || (defined(__cforall) && !defined(__CFA_DEBUG__))
    19     enum { DefaultNumNodes = 1000, DefaultExperimentDurSec = 1, DefaultCheckClockFreq = 1000, DefaultExperimentDurOpCount = -1 };
     19    enum { DefaultNumNodes = 1000, DefaultExperimentDurSec = 1, DefaultCheckDonePeriod = 1000, DefaultExperimentDurOpCount = -1, DefaultSeed = 5 };
    2020    #define TRACE(tp)
    2121#else
    22     enum { DefaultNumNodes = 10, DefaultExperimentDurSec = 1, DefaultCheckClockFreq = 2, DefaultExperimentDurOpCount = 20 };
     22    enum { DefaultNumNodes = 10, DefaultExperimentDurSec = 1, DefaultCheckDonePeriod = 2, DefaultExperimentDurOpCount = 20, DefaultSeed = 5 };
    2323    static const char * tp_filter
    2424    // = "";
     
    6363    }
    6464
    65     int bobs_getCurrent() {
     65    void * bobs_getCurrentLoc() {
     66        return BFX_DEREF_POS(B_UserItem, lst, observedItem);
     67    }
     68    int bobs_getCurrentVal() {
    6669        B_UserItem * curUI = BFX_DEREF_POS(B_UserItem, lst, observedItem);
    6770        return curUI->userdata[17];
     
    7275)
    7376
     77unsigned int uDefaultPreemption() {
     78        return 0;
     79}
     80
    7481int main(int argc, const char *argv[]) {
    7582
    76 
    77     const char * usage_args = "[ExperimentDurSec [CheckClockFreq [NumNodes [ExperimentDurOpCount]]]]";
    78     const int static_arg_posns = 4;
     83    const char * usage_args = "[ExperimentDurSec [CheckDonePeriod [NumNodes [ExperimentDurOpCount [Seed]]]]]";
     84    const int static_arg_posns = 5;
    7985
    8086    unsigned int ExperimentDurSec     = DefaultExperimentDurSec;
    81     unsigned int CheckClockFreq       = DefaultCheckClockFreq;
     87    unsigned int CheckDonePeriod      = DefaultCheckDonePeriod;
    8288    unsigned int NumNodes             = DefaultNumNodes;
    8389    size_t       ExperimentDurOpCount = DefaultExperimentDurOpCount;
    84 
    85     switch ((argc < static_arg_posns) ? argc : static_arg_posns) {
    86       case 5: ExperimentDurOpCount = atoi(argv[4]);
    87       case 4: NumNodes = atoi(argv[3]);
    88       case 3: CheckClockFreq = atoi(argv[2]);
    89       case 2: ExperimentDurSec = atoi(argv[1]);
    90     }
    91 
    92     if (ExperimentDurSec == 0 || CheckClockFreq == 0 || NumNodes == 0 || ExperimentDurOpCount == 0 ) {
     90    unsigned int Seed                 = DefaultSeed;
     91
     92    switch (((argc - 1) < static_arg_posns) ? (argc - 1) : static_arg_posns) {
     93      case 5: Seed = atoi(argv[5]);
     94      case 4: ExperimentDurOpCount = atol(argv[4]);
     95      case 3: NumNodes = atoi(argv[3]);
     96      case 2: CheckDonePeriod = atoi(argv[2]);
     97      case 1: ExperimentDurSec = atoi(argv[1]);
     98    }
     99
     100    if (ExperimentDurSec == 0 || CheckDonePeriod == 0 || NumNodes == 0 || ExperimentDurOpCount == 0 || Seed == 0 ) {
    93101        printf("usage: %s %s\n", argv[0], usage_args);
    94102        return -1;
    95103    }
    96104
    97     ui = (B_UserItem*) malloc( NumNodes * sizeof(B_UserItem) );
    98     memset(ui, 0, NumNodes * sizeof(B_UserItem));
    99 
    100     listedItems = (BFX_LISTED_ELEM_T(B_UserItem)*)malloc( NumNodes * sizeof(BFX_LISTED_ELEM_T(B_UserItem)) );
    101     memset(listedItems, 0, NumNodes * sizeof(BFX_LISTED_ELEM_T(B_UserItem)));
    102 
     105  #ifdef DISABLE_CLOCK_RECHECK
     106    if (ExperimentDurSec != -1) {
     107        printf("Error: experiment compiled as fixed-work only.  ExperimentDurSec (currently %d) must be set to -1.\nUsage: %s %s\n", ExperimentDurSec, argv[0], usage_args);
     108        return -1;
     109    }
     110  #endif
     111
     112  #ifdef DISABLE_SHUFFLING_INDIRECTION
     113    #define INSERTPOS(insertNum) insertNum
     114  #else
     115    // To ensure random memory order of nodes being inserted, do so according to a shuffled ordering of them.
     116    unsigned int * insertOrdShuf = (unsigned int *) malloc( (size_t)NumNodes * sizeof(unsigned int) );
     117    if (!insertOrdShuf) {
     118        printf("malloc request for %zd bytes for insertOrdShuf refused\n", (size_t)NumNodes * (size_t)sizeof(unsigned int));
     119        return 1;
     120    }
     121    // Fill with the ordinals (iota)
    103122    for (int i = 0; i < NumNodes; i++) {
    104         B_UserItem * curUI = & ui[i];
     123        insertOrdShuf[i] = i;
     124    }
     125    // Dummy "Seed" of -1 means skip the shuffle: measure overhead of insertOrdShuf indirection
     126    if (Seed != -1) {
     127        // Shuffle
     128        srand(Seed);
     129        for (unsigned int i = 0; i < NumNodes; i++) {
     130            unsigned int nodesRemaining = NumNodes - i;
     131            unsigned int swapWith = i + rand() % nodesRemaining;
     132            unsigned int tempValue = insertOrdShuf[swapWith];
     133            insertOrdShuf[swapWith] = insertOrdShuf[i];
     134            insertOrdShuf[i] = tempValue;
     135        }
     136    }
     137    #define INSERTPOS(insertNum) insertOrdShuf[insertNum]
     138  #endif
     139
     140    ui = (B_UserItem*) malloc( (size_t)NumNodes * (size_t)sizeof(B_UserItem) );
     141    if (!ui) {
     142        printf("malloc request for %zd bytes for ui refused\n", (size_t)NumNodes * (size_t)sizeof(B_UserItem));
     143        return 1;
     144    }
     145    memset(ui, 0, (size_t)NumNodes * (size_t)sizeof(B_UserItem));
     146
     147    listedItems = (BFX_LISTED_ELEM_T(B_UserItem)*)malloc( (size_t)NumNodes * (size_t)sizeof(BFX_LISTED_ELEM_T(B_UserItem)) );
     148    if (!listedItems) {
     149        printf("malloc request for %zd bytes for listedItems refused\n", (size_t)NumNodes * (size_t)sizeof(BFX_LISTED_ELEM_T(B_UserItem)));
     150        return 1;
     151    }
     152    memset(listedItems, 0, (size_t)NumNodes * (size_t)sizeof(BFX_LISTED_ELEM_T(B_UserItem)));
     153
     154    // Fill with demo data
     155    for (unsigned int i = 0; i < NumNodes; i++) {
     156        B_UserItem * curUI = & ui[INSERTPOS(i)];
    105157        curUI->userdata[17] = i;
    106158    }
     
    110162    bobs_init(NumNodes);
    111163
    112     // BOP Convention:
    113     // Action-number arguments are for the BOP cartridge to interpret.
    114     // I.e. the driver assumes no relationship between BOP_INSERT(_,_,xx) and ui[xx].
     164    // BOP_ADDFOO(lst, iters, insNo, item)
     165    // BOP_REMFOO(lst, iters, remNo)
     166    //   lst    lvalue of the list head being added to / removed from
     167    //   iters  array of ADD return values, in logical-insert order; on ADD, is valid at [0..insNo)
     168    //   insNo  counter of the ADD calls (logical insert number)
     169    //   remNo  counter of the REM calls (logical remove number)
     170    //   item   lvalue of the item being added
    115171    // Logical insert number 0 and remove number n-1 are given with a distinguished hook.
    116172    // Logical insert numbers [1,n) and remove numbers [0,n-1) are pumped by the basic SUT hooks.
    117173    // This pattern lets BOP cartridges that measure element-level operations know statically when there is a reference element in the list.
     174    // The driver owns the relationship between a logical insert number and the location of the `item` argument within `ui`.  (Scattered for randomness.)
     175    // The BOP cartridge owns the relationship between logical remove number and any choice of an item in iters.  (Defines stack vs queue.)
    118176
    119177    // Default init/teardown is insert/remove
    120178    // Cartridges whose SUT insert/remove actions work on empty lists need not provide special-case ones.
    121179    #ifndef BOP_INIT
    122     #define BOP_INIT(lst, ui, iters, i) BOP_INSERT(lst, ui, iters, i)
     180    #define BOP_INIT(lst, iters, insNo, item) BOP_INSERT(lst, iters, insNo, item)
    123181    #endif
    124182    #ifndef BOP_TEARDOWN
    125     #define BOP_TEARDOWN(lst, ui, iters, i) BOP_REMOVE(lst, ui, iters, i)
     183    #define BOP_TEARDOWN(lst, iters, remNo) BOP_REMOVE(lst, iters, remNo)
    126184    #endif
    127185
     
    129187    clock_t start = clock();
    130188
    131     while (elapsed_sec <= (double) ExperimentDurSec && bobs_ops_completed < ExperimentDurOpCount) {
    132         for ( int t = 0; t < CheckClockFreq; t += 1 ) {
     189    size_t privateOpsCompleted = 0;
     190
     191    while (elapsed_sec <= (double) ExperimentDurSec && privateOpsCompleted < ExperimentDurOpCount) {
     192        for ( int t = 0; t < CheckDonePeriod; t += 1 ) {
    133193            TRACE('a')
    134194            listedItems[0] =
    135                 BOP_INIT(lst, ui, listedItems, 0);
     195                BOP_INIT(lst, listedItems, 0, ui[INSERTPOS(0)]);
    136196            TRACE('b')
    137197            for ( int privateCurInsert = 1;
     
    141201                TRACE('-')
    142202                listedItems[privateCurInsert] =
    143                     BOP_INSERT( lst, ui, listedItems, privateCurInsert );
     203                    BOP_INSERT( lst, listedItems, privateCurInsert, ui[INSERTPOS(privateCurInsert)] );
    144204                TRACE('+')
    145205            }
     
    150210                ) {
    151211                TRACE('-')
    152                 BOP_REMOVE( lst, ui, listedItems, privateCurRemove-1 );
     212                BOP_REMOVE( lst, listedItems, privateCurRemove-1 );
    153213                TRACE('+')
    154214            }
    155215            TRACE('D')
    156             BOP_TEARDOWN(lst, ui, listedItems, NumNodes-1);
     216            BOP_TEARDOWN(lst, listedItems, NumNodes-1);
    157217            TRACE('d')
     218
     219            privateOpsCompleted += NumNodes;
    158220
    159221            bobs_prog_rollover_flag = 1;
     
    161223            bobs_prog_inserting = 0;
    162224            bobs_prog_removing = 0;           
    163             bobs_ops_completed += NumNodes;
     225            bobs_ops_completed = privateOpsCompleted;
    164226            TRACE('f')
    165227            bobs_prog_rollover_flag = 0;
    166228            TRACE('g')
    167229        }
     230      #ifndef DISABLE_CLOCK_RECHECK
    168231        clock_t end = clock();
    169232        elapsed_sec = ((double)(end - start)) / ((double)CLOCKS_PER_SEC);
    170     }
     233      #endif
     234    }
     235    #ifdef DISABLE_CLOCK_RECHECK
     236    {
     237        clock_t end = clock();
     238        elapsed_sec = ((double)(end - start)) / ((double)CLOCKS_PER_SEC);
     239    }
     240    #endif
    171241
    172242    double mean_op_dur_ns = elapsed_sec / ((double)bobs_ops_completed) * 1000 * 1000 * 1000;
     
    175245    free(ui);
    176246    free(listedItems);
     247    free(insertOrdShuf);
    177248}
Note: See TracChangeset for help on using the changeset viewer.