Changeset 6e1e2d0 for doc/theses/mike_brooks_MMath/benchmarks/list/driver.c
- Timestamp:
- May 1, 2023, 4:19:09 PM (20 months ago)
- 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. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
doc/theses/mike_brooks_MMath/benchmarks/list/driver.c
ra50fdfb r6e1e2d0 17 17 18 18 #if defined(NDEBUG) || (defined(__cforall) && !defined(__CFA_DEBUG__)) 19 enum { DefaultNumNodes = 1000, DefaultExperimentDurSec = 1, DefaultCheck ClockFreq = 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, DefaultCheck ClockFreq = 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]; … … 72 75 ) 73 76 77 unsigned int uDefaultPreemption() { 78 return 0; 79 } 80 74 81 int main(int argc, const char *argv[]) { 75 82 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; 79 85 80 86 unsigned int ExperimentDurSec = DefaultExperimentDurSec; 81 unsigned int Check ClockFreq = DefaultCheckClockFreq;87 unsigned int CheckDonePeriod = DefaultCheckDonePeriod; 82 88 unsigned int NumNodes = DefaultNumNodes; 83 89 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 ) { 93 101 printf("usage: %s %s\n", argv[0], usage_args); 94 102 return -1; 95 103 } 96 104 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) 103 122 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)]; 105 157 curUI->userdata[17] = i; 106 158 } … … 110 162 bobs_init(NumNodes); 111 163 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 115 171 // Logical insert number 0 and remove number n-1 are given with a distinguished hook. 116 172 // Logical insert numbers [1,n) and remove numbers [0,n-1) are pumped by the basic SUT hooks. 117 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.) 118 176 119 177 // Default init/teardown is insert/remove 120 178 // Cartridges whose SUT insert/remove actions work on empty lists need not provide special-case ones. 121 179 #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) 123 181 #endif 124 182 #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) 126 184 #endif 127 185 … … 129 187 clock_t start = clock(); 130 188 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 ) { 133 193 TRACE('a') 134 194 listedItems[0] = 135 BOP_INIT(lst, ui, listedItems, 0);195 BOP_INIT(lst, listedItems, 0, ui[INSERTPOS(0)]); 136 196 TRACE('b') 137 197 for ( int privateCurInsert = 1; … … 141 201 TRACE('-') 142 202 listedItems[privateCurInsert] = 143 BOP_INSERT( lst, ui, listedItems, privateCurInsert);203 BOP_INSERT( lst, listedItems, privateCurInsert, ui[INSERTPOS(privateCurInsert)] ); 144 204 TRACE('+') 145 205 } … … 150 210 ) { 151 211 TRACE('-') 152 BOP_REMOVE( lst, ui,listedItems, privateCurRemove-1 );212 BOP_REMOVE( lst, listedItems, privateCurRemove-1 ); 153 213 TRACE('+') 154 214 } 155 215 TRACE('D') 156 BOP_TEARDOWN(lst, ui,listedItems, NumNodes-1);216 BOP_TEARDOWN(lst, listedItems, NumNodes-1); 157 217 TRACE('d') 218 219 privateOpsCompleted += NumNodes; 158 220 159 221 bobs_prog_rollover_flag = 1; … … 161 223 bobs_prog_inserting = 0; 162 224 bobs_prog_removing = 0; 163 bobs_ops_completed += NumNodes;225 bobs_ops_completed = privateOpsCompleted; 164 226 TRACE('f') 165 227 bobs_prog_rollover_flag = 0; 166 228 TRACE('g') 167 229 } 230 #ifndef DISABLE_CLOCK_RECHECK 168 231 clock_t end = clock(); 169 232 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 171 241 172 242 double mean_op_dur_ns = elapsed_sec / ((double)bobs_ops_completed) * 1000 * 1000 * 1000; … … 175 245 free(ui); 176 246 free(listedItems); 247 free(insertOrdShuf); 177 248 }
Note: See TracChangeset
for help on using the changeset viewer.