Changeset 2b01f8e for doc/theses/mike_brooks_MMath/benchmarks/list/driver.c
- Timestamp:
- Apr 10, 2023, 12:03:17 PM (20 months ago)
- Branches:
- ADT, ast-experimental, master
- Children:
- a085470
- Parents:
- e9ed2a1
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
doc/theses/mike_brooks_MMath/benchmarks/list/driver.c
re9ed2a1 r2b01f8e 17 17 18 18 #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 }; 20 20 #define TRACE(tp) 21 21 #else 22 enum { DefaultNumNodes = 10, DefaultExperimentDurSec = 1, DefaultCheckDonePeriod = 2, DefaultExperimentDurOpCount = 20 };22 enum { DefaultNumNodes = 10, DefaultExperimentDurSec = 1, DefaultCheckDonePeriod = 2, DefaultExperimentDurOpCount = 20, DefaultSeed = 5 }; 23 23 static const char * tp_filter 24 24 // = ""; … … 63 63 } 64 64 65 int bobs_getCurrent() { 65 void * bobs_getCurrentLoc() { 66 return BFX_DEREF_POS(B_UserItem, lst, observedItem); 67 } 68 int bobs_getCurrentVal() { 66 69 B_UserItem * curUI = BFX_DEREF_POS(B_UserItem, lst, observedItem); 67 70 return curUI->userdata[17]; … … 78 81 int main(int argc, const char *argv[]) { 79 82 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; 83 85 84 86 unsigned int ExperimentDurSec = DefaultExperimentDurSec; … … 86 88 unsigned int NumNodes = DefaultNumNodes; 87 89 size_t ExperimentDurOpCount = DefaultExperimentDurOpCount; 90 unsigned int Seed = DefaultSeed; 88 91 89 92 switch (((argc - 1) < static_arg_posns) ? (argc - 1) : static_arg_posns) { 93 case 5: Seed = atoi(argv[5]); 90 94 case 4: ExperimentDurOpCount = atol(argv[4]); 91 95 case 3: NumNodes = atoi(argv[3]); … … 94 98 } 95 99 96 if (ExperimentDurSec == 0 || CheckDonePeriod == 0 || NumNodes == 0 || ExperimentDurOpCount == 0 ) {100 if (ExperimentDurSec == 0 || CheckDonePeriod == 0 || NumNodes == 0 || ExperimentDurOpCount == 0 || Seed == 0 ) { 97 101 printf("usage: %s %s\n", argv[0], usage_args); 98 102 return -1; … … 106 110 #endif 107 111 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) 114 122 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)]; 116 157 curUI->userdata[17] = i; 117 158 } … … 121 162 bobs_init(NumNodes); 122 163 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 126 171 // Logical insert number 0 and remove number n-1 are given with a distinguished hook. 127 172 // Logical insert numbers [1,n) and remove numbers [0,n-1) are pumped by the basic SUT hooks. 128 173 // 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.) 129 176 130 177 // Default init/teardown is insert/remove 131 178 // Cartridges whose SUT insert/remove actions work on empty lists need not provide special-case ones. 132 179 #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) 134 181 #endif 135 182 #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) 137 184 #endif 138 185 … … 146 193 TRACE('a') 147 194 listedItems[0] = 148 BOP_INIT(lst, ui, listedItems, 0);195 BOP_INIT(lst, listedItems, 0, ui[INSERTPOS(0)]); 149 196 TRACE('b') 150 197 for ( int privateCurInsert = 1; … … 154 201 TRACE('-') 155 202 listedItems[privateCurInsert] = 156 BOP_INSERT( lst, ui, listedItems, privateCurInsert);203 BOP_INSERT( lst, listedItems, privateCurInsert, ui[INSERTPOS(privateCurInsert)] ); 157 204 TRACE('+') 158 205 } … … 163 210 ) { 164 211 TRACE('-') 165 BOP_REMOVE( lst, ui,listedItems, privateCurRemove-1 );212 BOP_REMOVE( lst, listedItems, privateCurRemove-1 ); 166 213 TRACE('+') 167 214 } 168 215 TRACE('D') 169 BOP_TEARDOWN(lst, ui,listedItems, NumNodes-1);216 BOP_TEARDOWN(lst, listedItems, NumNodes-1); 170 217 TRACE('d') 171 218 … … 198 245 free(ui); 199 246 free(listedItems); 247 free(insertOrdShuf); 200 248 }
Note: See TracChangeset
for help on using the changeset viewer.