source: doc/theses/mike_brooks_MMath/benchmarks/list/driver.c @ 1dfc3d0

ADTast-experimental
Last change on this file since 1dfc3d0 was 1dfc3d0, checked in by Mike Brooks <mlbrooks@…>, 15 months ago

Tweak LL perf compilation--CLI to support a fixed-work mode that does not re-check clock() during the run.

  • Property mode set to 100644
File size: 6.5 KB
Line 
1#include <time.h>
2#include <stdio.h>
3#include <stdlib.h>
4#include <string.h>
5
6#include "observation.h"
7
8typedef struct B_UserItem
9    BFX_EXTRUSION_DECL(B_UserItem)
10{
11    BFX_INTRUSION(B_UserItem)
12    int userdata[64];
13}
14B_UserItem;
15
16BFX_EXTRUSION_FOLLOWUP(B_UserItem)
17
18#if defined(NDEBUG) || (defined(__cforall) && !defined(__CFA_DEBUG__))
19    enum { DefaultNumNodes = 1000, DefaultExperimentDurSec = 1, DefaultCheckDoneFreq = 1000, DefaultExperimentDurOpCount = -1 };
20    #define TRACE(tp)
21#else
22    enum { DefaultNumNodes = 10, DefaultExperimentDurSec = 1, DefaultCheckDoneFreq = 2, DefaultExperimentDurOpCount = 20 };
23    static const char * tp_filter
24    // = "";
25    // = "+ea";
26        = "*";
27    #define TRACE(tp) \
28        if (strcmp("*", tp_filter) == 0 || strchr(tp_filter, tp)) { \
29            printf("%c", tp); \
30            bobs_report(); \
31        }
32#endif
33
34static B_UserItem *ui = NULL;
35
36static BFX_LISTED_ELEM_T(B_UserItem) *listedItems = NULL;
37static BFX_LISTED_ELEM_T(B_UserItem) observedItem;
38
39static BFX_LIST_HEAD_T(B_UserItem) lst;
40
41
42MAYBE_EXTERN_C (
43
44    volatile size_t       bobs_ops_completed      = 0;
45    volatile unsigned int bobs_prog_inserting     = 0;
46    volatile unsigned int bobs_prog_removing      = 0;
47    volatile unsigned int bobs_prog_rollover_flag = 0;
48
49    void bobs_seek(unsigned int i) {
50        observedItem = listedItems[i];
51    }
52
53    void bobs_moveNext() {
54        observedItem = BFX_GET_AFTER(B_UserItem, lst, observedItem);
55    }
56
57    void bobs_movePrev() {
58        observedItem = BFX_GET_BEFORE(B_UserItem, lst, observedItem);
59    }
60
61    int bobs_hasCurrent() {
62        return BFX_IS_VALID_POS(B_UserItem, lst, observedItem);
63    }
64
65    int bobs_getCurrent() {
66        B_UserItem * curUI = BFX_DEREF_POS(B_UserItem, lst, observedItem);
67        return curUI->userdata[17];
68    }
69
70    enum bobs_op_movement_t bobs_op_movement = OP_MOVEMENT;
71    enum bobs_op_polarity_t bobs_op_polarity = OP_POLARITY;
72)
73
74unsigned int uDefaultPreemption() {
75        return 0;
76}
77
78int main(int argc, const char *argv[]) {
79
80
81    const char * usage_args = "[ExperimentDurSec [CheckDoneFreq [NumNodes [ExperimentDurOpCount]]]]";
82    const int static_arg_posns = 4;
83
84    unsigned int ExperimentDurSec     = DefaultExperimentDurSec;
85    unsigned int CheckDoneFreq       = DefaultCheckDoneFreq;
86    unsigned int NumNodes             = DefaultNumNodes;
87    size_t       ExperimentDurOpCount = DefaultExperimentDurOpCount;
88
89    switch (((argc - 1) < static_arg_posns) ? (argc - 1) : static_arg_posns) {
90      case 4: ExperimentDurOpCount = atol(argv[4]);
91      case 3: NumNodes = atoi(argv[3]);
92      case 2: CheckDoneFreq = atoi(argv[2]);
93      case 1: ExperimentDurSec = atoi(argv[1]);
94    }
95
96    if (ExperimentDurSec == 0 || CheckDoneFreq == 0 || NumNodes == 0 || ExperimentDurOpCount == 0 ) {
97        printf("usage: %s %s\n", argv[0], usage_args);
98        return -1;
99    }
100
101  #ifdef DISABLE_CLOCK_RECHECK
102    if (ExperimentDurSec != -1) {
103        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);
104        return -1;
105    }
106  #endif
107
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
114    printf("ui @ %p\nlistedItems @ %p\n\n", ui, listedItems);
115
116    for (int i = 0; i < NumNodes; i++) {
117        B_UserItem * curUI = & ui[i];
118        curUI->userdata[17] = i;
119    }
120
121    BFX_INIT(B_UserItem, lst);
122
123    bobs_init(NumNodes);
124
125    // BOP Convention:
126    // Action-number arguments are for the BOP cartridge to interpret.
127    // I.e. the driver assumes no relationship between BOP_INSERT(_,_,xx) and ui[xx].
128    // Logical insert number 0 and remove number n-1 are given with a distinguished hook.
129    // Logical insert numbers [1,n) and remove numbers [0,n-1) are pumped by the basic SUT hooks.
130    // This pattern lets BOP cartridges that measure element-level operations know statically when there is a reference element in the list.
131
132    // Default init/teardown is insert/remove
133    // Cartridges whose SUT insert/remove actions work on empty lists need not provide special-case ones.
134    #ifndef BOP_INIT
135    #define BOP_INIT(lst, ui, iters, i) BOP_INSERT(lst, ui, iters, i)
136    #endif
137    #ifndef BOP_TEARDOWN
138    #define BOP_TEARDOWN(lst, ui, iters, i) BOP_REMOVE(lst, ui, iters, i)
139    #endif
140
141    double elapsed_sec = 0;
142    clock_t start = clock();
143
144    while (elapsed_sec <= (double) ExperimentDurSec && bobs_ops_completed < ExperimentDurOpCount) {
145        for ( int t = 0; t < CheckDoneFreq; t += 1 ) {
146            TRACE('a')
147            listedItems[0] =
148                BOP_INIT(lst, ui, listedItems, 0);
149            TRACE('b')
150            for ( int privateCurInsert = 1;
151                  (bobs_prog_inserting = privateCurInsert, privateCurInsert < NumNodes);
152                  privateCurInsert += 1
153                ) {
154                TRACE('-')
155                listedItems[privateCurInsert] =
156                    BOP_INSERT( lst, ui, listedItems, privateCurInsert );
157                TRACE('+')
158            }
159            TRACE('c')
160            for ( int privateCurRemove = 1;
161                  (bobs_prog_removing = privateCurRemove, privateCurRemove < NumNodes);
162                  privateCurRemove += 1
163                ) {
164                TRACE('-')
165                BOP_REMOVE( lst, ui, listedItems, privateCurRemove-1 );
166                TRACE('+')
167            }
168            TRACE('D')
169            BOP_TEARDOWN(lst, ui, listedItems, NumNodes-1);
170            TRACE('d')
171
172            bobs_prog_rollover_flag = 1;
173            TRACE('e')
174            bobs_prog_inserting = 0;
175            bobs_prog_removing = 0;           
176            bobs_ops_completed += NumNodes;
177            TRACE('f')
178            bobs_prog_rollover_flag = 0;
179            TRACE('g')
180        }
181      #ifndef DISABLE_CLOCK_RECHECK
182        clock_t end = clock();
183        elapsed_sec = ((double)(end - start)) / ((double)CLOCKS_PER_SEC);
184      #endif
185    }
186    #ifdef DISABLE_CLOCK_RECHECK
187    {
188        clock_t end = clock();
189        elapsed_sec = ((double)(end - start)) / ((double)CLOCKS_PER_SEC);
190    }
191    #endif
192
193    double mean_op_dur_ns = elapsed_sec / ((double)bobs_ops_completed) * 1000 * 1000 * 1000;
194    printf("%s,%zd,%f,%f\n", argv[0], bobs_ops_completed, elapsed_sec, mean_op_dur_ns);
195
196    free(ui);
197    free(listedItems);
198}
Note: See TracBrowser for help on using the repository browser.