-
Notifications
You must be signed in to change notification settings - Fork 2
/
chearch.chpl
181 lines (150 loc) · 4.25 KB
/
chearch.chpl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
use Logging, SearchIndex, SyntheticDataIndexer, Time;
config const peformAR = true;
/**
This is server-less mode of Chearch that should eventually have a repl
*/
proc main() {
// simple class to escape the const intents of forall
class Counter {
var count: atomic uint;
}
writeln("using ", Locales.size, " locales");
writeln("initializing index");
initPartitions();
indexSyntheticDocuments();
var t: Timer;
writeln("---querying 2 on each locale");
{
for loc in Locales {
on loc {
var counts = new Counter();
var t: Timer;
local {
var buffer = new InstructionBuffer(32);
var writer = new InstructionWriter(buffer);
buffer.clear();
writer.write_push();
writer.write_term(2);
t.start();
for result in localQuery(new Query(buffer)) {
if (result.term != 2) {
halt("term not 2 ", result);
}
counts.count.add(1);
}
t.stop();
delete buffer;
}
writeln("AL-", here.id, ",", Locales.size, ", ", t.elapsed(TimeUnits.microseconds), ",", counts.count.read());
}
}
}
var counts = new Counter();
// this will hold the query instruction
var buffer = new InstructionBuffer(32);
// perform sample queries
var writer = new InstructionWriter(buffer);
if (peformAR) {
writeln("---querying 2 on remote locales");
for loc in Locales {
if (loc.id == here.id) {
continue;
}
var baselocaleKnownTermId = ((loc.id * 2048) + 1024 * 1024) : Term;
var queryTimes: [1..1024] real;
for termIdStep in queryTimes.domain {
counts.count.write(0);
var localeKnownTermId = (baselocaleKnownTermId + termIdStep - 1): Term;
buffer.clear();
writer.write_push_term(localeKnownTermId);
t.clear();
t.start();
for result in query(new Query(buffer)) {
if (result.term != localeKnownTermId) {
halt("term not ", localeKnownTermId, " got ", result);
}
counts.count.add(1);
}
t.stop();
queryTimes[termIdStep] = t.elapsed(TimeUnits.microseconds);
}
writeln("AR-", here.id, ",", Locales.size, ", ", queryTimes);
}
}
writeln("---querying for 3");
{
counts.count.write(0);
buffer.clear();
writer.write_push();
writer.write_term(3);
t.clear();
t.start();
forall result in query(new Query(buffer)) {
if (result.term != 3) {
halt("term not 3 ", result);
}
counts.count.add(1);
}
t.stop();
writeln("B,", Locales.size, ", ", t.elapsed(TimeUnits.microseconds), ",", counts.count.read());
}
writeln("---querying for 3 AND 2");
{
counts.count.write(0);
buffer.clear();
writer.write_push();
writer.write_term(3);
writer.write_push();
writer.write_term(2);
writer.write_and();
t.clear();
t.start();
forall result in query(new Query(buffer)) {
if ((result.term != 3) && (result.term != 2)) {
halt("term not 3 or 2 ", result);
}
counts.count.add(1);
}
t.stop();
writeln("C,", Locales.size, ", ", t.elapsed(TimeUnits.microseconds), ",", counts.count.read());
}
writeln("---querying for 3 OR 2");
{
counts.count.write(0);
buffer.clear();
writer.write_push();
writer.write_term(3);
writer.write_push();
writer.write_term(2);
writer.write_or();
t.clear();
t.start();
forall result in query(new Query(buffer)) {
if ((result.term != 3) && (result.term != 2)) {
halt("term not 3 or 2 ", result);
}
counts.count.add(1);
}
t.stop();
writeln("D,", Locales.size, ", ", t.elapsed(TimeUnits.microseconds), ",", counts.count.read());
}
writeln("---querying for missing term");
{
counts.count.write(0);
buffer.clear();
writer.write_push();
writer.write_term(1024*1024 * 8);
t.clear();
t.start();
forall result in query(new Query(buffer)) {
writeln(result);
counts.count.add(1);
}
t.stop();
if (counts.count.read() > 0) {
halt("counts > 0!");
}
writeln("E,", Locales.size, ", ", t.elapsed(TimeUnits.microseconds), ",", counts.count.read());
}
delete buffer;
}