source: doc/theses/mike_brooks_MMath/benchmarks/list/observation.c@ d2e6f84

Last change on this file since d2e6f84 was 6c58850, checked in by Michael Brooks <mlbrooks@…>, 6 weeks ago

Revise data in linked-list plots with streamlined harness and data from runs on swift.

No change to text discussing the plots, so some of that discussion is now stale.

Harness changes allow more ifdef feature disabling and eliminate side-array usage, keeping all per-node harness state inside the list nodes.

Completely disable the interleaving experiment, which was not giving discernable data.

  • Property mode set to 100644
File size: 3.5 KB
Line 
1#include <assert.h>
2
3#ifdef __needExternC
4#error Only compile observation.c (once) in plain C
5#endif
6
7#include <stdio.h>
8#include <stddef.h>
9#include <sys/param.h>
10
11#include "observation.h"
12
13static size_t NumNodes;
14
15void bobs_init(size_t NumNodes_) {
16 // printf("at bobs_init; bobs_ops_completed = %zd\n", bobs_ops_completed);
17
18 // todo: register a signal handler that prints progress info
19 // note function bobs_XXX in driver.c are untested until that's working
20 // to be driven as:
21 // ./a.out & # then, very quickly
22 // kill -s USR2 $!
23
24 NumNodes = NumNodes_;
25}
26
27#ifdef BOBS_SHOW_ADDRESSES
28#define SNAP \
29 void * userAddr = bobs_getCurrentLoc(); \
30 size_t userValue = bobs_getCurrentVal();
31#define SHOW(pfx, sfx) \
32 printf(" " pfx "%d@%p" sfx, userValue, userAddr);
33#else
34#define SNAP \
35 size_t userValue = bobs_getCurrentVal();
36#define SHOW(pfx, sfx) \
37 printf(" " pfx "%zd" sfx, userValue);
38#endif
39
40static void printPreds(size_t leash) {
41 if (leash==0)
42 return;
43 if (!bobs_hasCurrent()) {
44 printf(" |");
45 return;
46 }
47 SNAP
48 bobs_movePrev();
49 printPreds(leash - 1);
50 SHOW("", "")
51}
52static void printSuccs(size_t leash) {
53 if (leash==0)
54 return;
55 if (!bobs_hasCurrent()) {
56 printf(" |");
57 return;
58 }
59 SNAP
60 SHOW("", "")
61 bobs_moveNext();
62 printSuccs(leash - 1);
63}
64static void explore(size_t here, size_t leash) {
65 bobs_seek(here);
66 if (!bobs_hasCurrent()) {
67 printf(" <X>");
68 return;
69 }
70 bobs_movePrev();
71 printPreds(leash);
72
73 bobs_seek(here);
74 SNAP
75 SHOW("<", ">")
76
77 bobs_moveNext();
78 printSuccs(leash);
79}
80static void exploreRange(size_t validFrom, size_t validTo) {
81 size_t gapsize = validTo - validFrom;
82 size_t midpoint = (validTo + validFrom) / 2;
83
84 size_t listFirstmost, listLastmost;
85 switch(bobs_op_polarity) {
86 case insfirst:
87 listFirstmost = validTo;
88 listLastmost = validFrom;
89 break;
90 case inslast:
91 listFirstmost = validFrom;
92 listLastmost = validTo;
93 break;
94 default:
95 assert(0 && "unsupported bobs_op_movement value");
96 }
97
98 printf(" v%zd..%zd ", listFirstmost, listLastmost);
99
100 explore(listFirstmost, 6);
101 printf(" ...");
102 // if (gapsize > 5) {
103 // explore(midpoint);
104 // printf(" ...");
105 // }
106 explore(listLastmost, 6);
107}
108
109void bobs_report(void) {
110 if (bobs_prog_rollover_flag) {
111 printf("%8zd + ? (rolling over)\n", bobs_ops_completed);
112 } else {
113 printf("%8zd + %6zd/2 + %6zd/2, %6zd@e %6zd_u", bobs_ops_completed, bobs_prog_inserting, bobs_prog_removing, bobs_prog_removing_end, *bobs_prog_rem_pos);
114
115 // signed arithmetic allows representating empty range as from=0, to=-1
116 ptrdiff_t validFrom, validTo;
117 switch(bobs_op_movement) {
118 case stack:
119 validFrom = 0;
120 validTo = MIN( (ptrdiff_t)bobs_prog_inserting -1, (ptrdiff_t)NumNodes - (ptrdiff_t)*bobs_prog_rem_pos - 1 );
121 break;
122 case queue:
123 validFrom = (ptrdiff_t)*bobs_prog_rem_pos;
124 validTo = (ptrdiff_t)bobs_prog_inserting-1;
125 break;
126 default:
127 assert(0 && "unsupported bobs_op_movement value");
128 }
129
130 printf(" ");
131
132 if (validTo < validFrom) {
133 printf(" (list is empty)");
134 } else {
135 exploreRange(validFrom, validTo);
136 }
137
138 printf("\n");
139 }
140}
Note: See TracBrowser for help on using the repository browser.