Ignore:
Timestamp:
Apr 10, 2023, 12:03:17 PM (20 months ago)
Author:
Mike Brooks <mlbrooks@…>
Branches:
ADT, ast-experimental, master
Children:
a085470
Parents:
e9ed2a1
Message:

Adjust LL perf to use a random layout of nodes in memory

File:
1 edited

Legend:

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

    re9ed2a1 r2b01f8e  
    1717
    1818#if defined(NDEBUG) || (defined(__cforall) && !defined(__CFA_DEBUG__))
    19     enum { DefaultNumNodes = 1000, DefaultExperimentDurSec = 1, DefaultCheckDonePeriod = 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, DefaultCheckDonePeriod = 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];
     
    7881int main(int argc, const char *argv[]) {
    7982
    80 
    81     const char * usage_args = "[ExperimentDurSec [CheckDonePeriod [NumNodes [ExperimentDurOpCount]]]]";
    82     const int static_arg_posns = 4;
     83    const char * usage_args = "[ExperimentDurSec [CheckDonePeriod [NumNodes [ExperimentDurOpCount [Seed]]]]]";
     84    const int static_arg_posns = 5;
    8385
    8486    unsigned int ExperimentDurSec     = DefaultExperimentDurSec;
     
    8688    unsigned int NumNodes             = DefaultNumNodes;
    8789    size_t       ExperimentDurOpCount = DefaultExperimentDurOpCount;
     90    unsigned int Seed                 = DefaultSeed;
    8891
    8992    switch (((argc - 1) < static_arg_posns) ? (argc - 1) : static_arg_posns) {
     93      case 5: Seed = atoi(argv[5]);
    9094      case 4: ExperimentDurOpCount = atol(argv[4]);
    9195      case 3: NumNodes = atoi(argv[3]);
     
    9498    }
    9599
    96     if (ExperimentDurSec == 0 || CheckDonePeriod == 0 || NumNodes == 0 || ExperimentDurOpCount == 0 ) {
     100    if (ExperimentDurSec == 0 || CheckDonePeriod == 0 || NumNodes == 0 || ExperimentDurOpCount == 0 || Seed == 0 ) {
    97101        printf("usage: %s %s\n", argv[0], usage_args);
    98102        return -1;
     
    106110  #endif
    107111
    108     ui = (B_UserItem*) malloc( NumNodes * sizeof(B_UserItem) );
    109     memset(ui, 0, NumNodes * sizeof(B_UserItem));
    110 
    111     listedItems = (BFX_LISTED_ELEM_T(B_UserItem)*)malloc( NumNodes * sizeof(BFX_LISTED_ELEM_T(B_UserItem)) );
    112     memset(listedItems, 0, NumNodes * sizeof(BFX_LISTED_ELEM_T(B_UserItem)));
    113 
     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)
    114122    for (int i = 0; i < NumNodes; i++) {
    115         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)];
    116157        curUI->userdata[17] = i;
    117158    }
     
    121162    bobs_init(NumNodes);
    122163
    123     // BOP Convention:
    124     // Action-number arguments are for the BOP cartridge to interpret.
    125     // 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
    126171    // Logical insert number 0 and remove number n-1 are given with a distinguished hook.
    127172    // Logical insert numbers [1,n) and remove numbers [0,n-1) are pumped by the basic SUT hooks.
    128173    // 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.)
    129176
    130177    // Default init/teardown is insert/remove
    131178    // Cartridges whose SUT insert/remove actions work on empty lists need not provide special-case ones.
    132179    #ifndef BOP_INIT
    133     #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)
    134181    #endif
    135182    #ifndef BOP_TEARDOWN
    136     #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)
    137184    #endif
    138185
     
    146193            TRACE('a')
    147194            listedItems[0] =
    148                 BOP_INIT(lst, ui, listedItems, 0);
     195                BOP_INIT(lst, listedItems, 0, ui[INSERTPOS(0)]);
    149196            TRACE('b')
    150197            for ( int privateCurInsert = 1;
     
    154201                TRACE('-')
    155202                listedItems[privateCurInsert] =
    156                     BOP_INSERT( lst, ui, listedItems, privateCurInsert );
     203                    BOP_INSERT( lst, listedItems, privateCurInsert, ui[INSERTPOS(privateCurInsert)] );
    157204                TRACE('+')
    158205            }
     
    163210                ) {
    164211                TRACE('-')
    165                 BOP_REMOVE( lst, ui, listedItems, privateCurRemove-1 );
     212                BOP_REMOVE( lst, listedItems, privateCurRemove-1 );
    166213                TRACE('+')
    167214            }
    168215            TRACE('D')
    169             BOP_TEARDOWN(lst, ui, listedItems, NumNodes-1);
     216            BOP_TEARDOWN(lst, listedItems, NumNodes-1);
    170217            TRACE('d')
    171218
     
    198245    free(ui);
    199246    free(listedItems);
     247    free(insertOrdShuf);
    200248}
Note: See TracChangeset for help on using the changeset viewer.