forked from fast-pack/FastPFOR
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcodecs.cpp
424 lines (415 loc) · 20 KB
/
codecs.cpp
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
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
/**
* This code is released under the
* Apache License Version 2.0 http://www.apache.org/licenses/.
*
* (c) Daniel Lemire, http://lemire.me/en/
*/
#include <getopt.h>
#include <string.h>
#include <time.h>
#include <cstdlib>
#include <ctype.h>
#include <memory>
#include <iomanip>
#include "codecfactory.h"
#include "ztimer.h"
#include "synthetic.h"
#include "cpubenchmark.h"
#include "stringutil.h"
#include "entropy.h"
#include "memutil.h"
#include "deltautil.h"
using namespace std;
using namespace FastPForLib;
static struct option long_options[] = { { "uniformsparseclassic", no_argument,
0, 0 }, { "displayhistogram", no_argument, 0, 'H' }, {
"uniformdenseclassic", no_argument, 0, 0 }, { "clustersparseclassic",
no_argument, 0, 0 }, { "clusterdenseclassic", no_argument, 0, 0 }, {
"uniformsparse", no_argument, 0, 0 }, { "uniformdense", no_argument, 0,
0 }, { "clustersparse", no_argument, 0, 0 }, { "clusterdense",
no_argument, 0, 0 }, { "zipfian1", no_argument, 0, 0 }, { "zipfian2",
no_argument, 0, 0 }, { "vclusterdynamic", no_argument, 0, 0 }, {
"crazyclusterdynamic", no_argument, 0, 0 }, { "clusterdynamicsmall",
no_argument, 0, 0 }, { "uniformdynamicsmall", no_argument, 0, 0 }, {
"clusterdynamic", no_argument, 0, 0 }, { "uniformdynamic", no_argument,
0, 0 }, { "clusterdynamicpredelta", no_argument, 0, 0 }, {
"uniformdynamicpredelta", no_argument, 0, 0 }, { "sillyuniformdynamic",
no_argument, 0, 0 }, { "codecs", required_argument, 0, 'c' }, {
"splitlongarrays", no_argument, 0, 'S' }, { "short", no_argument, 0,
's' }, { 0, 0, 0, 0 } };
void message() {
int c = 0;
cout << "You must select one of these options:" << endl;
while (long_options[c].name != 0) {
if ((strcmp(long_options[c].name, "codecs") == 0) || ((strcmp(
long_options[c].name, "short") == 0)))
++c;
else
cout << "--" << long_options[c++].name << endl;
}
cout << "the --codecs flag takes as an argument"
" a comma-separated list of schemes chosen among those:" << endl;
vector < string > all = CODECFactory::allNames();
for (auto i = all.begin(); i != all.end(); ++i) {
cout << *i;
if (i + 1 == all.end())
cout << endl;
else
cout << ",";
}
cout << "(or give NONE instead of a list)" << endl;
cout << "The --displayhistogram flag must appear before the other flags."
<< endl;
cout << "Note that the --codecs flag must appear before the other flags."
<< endl;
cout << "You can get a more concise output by using the --short flag."
<< endl;
}
int main(int argc, char **argv) {
srand(10);//time(NULL));
bool fulldisplay = true;
bool displayhistogram = false;
bool computeentropy = false;
bool splitlongarrays = true;
vector < shared_ptr<IntegerCODEC> > tmp = CODECFactory::allSchemes();// the default
vector<algostats> myalgos;
for (auto & i : tmp) {
myalgos.push_back(algostats(i));
myalgos.push_back(algostats(i,true));// by default?
}
int c;
while (1) {
int option_index = 0;
c = getopt_long(argc, argv, "Sfec:", long_options, &option_index);
if (c == -1)
break;
switch (c) {
case 'S':
cout<<"#\n# disabling partition of big arrays. Performance may suffer.#\n"<<endl;
splitlongarrays = false;
break;
case 'c': {
myalgos.clear();
string codecsstr(optarg);
if (codecsstr.compare("NONE") != 0) {
vector < string > codecslst = split(codecsstr, ",:;");
for (auto i = codecslst.begin(); i != codecslst.end(); ++i) {
cout << "# pretty name = " << *i << endl;
if (i->at(0) == '@') {// SIMD
myalgos.push_back(
algostats(
CODECFactory::getFromName(
i->substr(1, i->size() - 1)),
true));
} else {
myalgos.push_back(
algostats(CODECFactory::getFromName(*i)));
}
cout << "# added '" << myalgos.back().name() << "'" << endl;
}
}
}
break;
case 'e':
computeentropy = true;
break;
case 'H':
displayhistogram = true;
break;
case 's':
fulldisplay = false;
break;
case 'f':
fulldisplay = true;
break;
case 0: {
if (optind < argc) {
cout << "There are some trailing flags...?" << endl;
message();
return 0;
}
const char * parameter = long_options[option_index].name;
cout << "# found " << parameter << endl;
if (strcmp(parameter, "zipfian1") == 0) {
const uint32_t N = 4194304 * 16;
vector < vector<uint32_t, cacheallocator> > datas;
cout << "# zipfian 1 data generation..." << endl;
for (uint32_t k = 0; k < (1U << 1); ++k)
datas.push_back(generateZipfianArray32(N, 1.0, 1U << 20));
if (splitlongarrays)
splitLongArrays( datas);
processparameters pp(false, fulldisplay, displayhistogram,
computeentropy, false);
Delta::process(myalgos, datas, pp);
summarize(myalgos, "#");
return 0;
} else if (strcmp(parameter, "zipfian2") == 0) {
const uint32_t N = 4194304 * 16;
vector < vector<uint32_t, cacheallocator> > datas;
for (uint32_t k = 0; k < (1U << 1); ++k)
cout << "# zipfian 2 data generation..." << endl;
datas.push_back(generateZipfianArray32(N, 2.0, 1U << 20));
if (splitlongarrays)
splitLongArrays( datas);
processparameters pp(false, fulldisplay, displayhistogram,
computeentropy, false);
Delta::process(myalgos, datas, pp);
summarize(myalgos, "#");
return 0;
} else if (strcmp(parameter, "uniformdenseclassic") == 0) {
cout << "# dense uniform data generation..." << endl;
vector < vector<uint32_t, cacheallocator> > datas;
UniformDataGenerator clu;
for (uint32_t k = 0; k < (1U << 5); ++k)
datas.push_back(clu.generateUniform((1U << 18), 1U << 27));
cout << "# generated " << datas.size() << " arrays" << endl;
if (splitlongarrays)
splitLongArrays( datas);
processparameters pp(true, fulldisplay, displayhistogram,
computeentropy, false);
Delta::process(myalgos, datas, pp);
summarize(myalgos, "#");
return 0;
} else if (strcmp(parameter, "uniformsparseclassic") == 0) {
cout << "# sparse uniform data generation..." << endl;
vector < vector<uint32_t, cacheallocator> > datas;
UniformDataGenerator clu;
for (uint32_t k = 0; k < (1U << 14); ++k)// by original paper should be 1U<<19
datas.push_back(clu.generateUniform((1U << 9), 1U << 27));
cout << "# generated " << datas.size() << " arrays" << endl;
if (splitlongarrays)
splitLongArrays( datas);
processparameters pp(true, fulldisplay, displayhistogram,
computeentropy, false);
Delta::process(myalgos, datas, pp);
summarize(myalgos, "#");
return 0;
} else if (strcmp(parameter, "clusterdenseclassic") == 0) {
cout << "# dense cluster data generation..." << endl;
vector < vector<uint32_t, cacheallocator> > datas;
ClusteredDataGenerator clu;
for (uint32_t k = 0; k < (1U << 5); ++k)// by original paper should be 1U<<10
datas.push_back(clu.generateClustered((1U << 18), 1U << 27));
cout << "# generated " << datas.size() << " arrays" << endl;
if (splitlongarrays)
splitLongArrays( datas);
processparameters pp(true, fulldisplay, displayhistogram,
computeentropy, false);
Delta::process(myalgos, datas, pp);
summarize(myalgos, "#");
return 0;
} else if (strcmp(parameter, "clustersparseclassic") == 0) {
cout << "# sparse cluster data generation..." << endl;
vector < vector<uint32_t, cacheallocator> > datas;
ClusteredDataGenerator clu;
for (uint32_t k = 0; k < (1U << 14); ++k)// by original paper should be 1U<<19
datas.push_back(clu.generateClustered((1U << 9), 1U << 27));
cout << "# generated " << datas.size() << " arrays" << endl;
if (splitlongarrays)
splitLongArrays( datas);
processparameters pp(true, fulldisplay, displayhistogram,
computeentropy, false);
Delta::process(myalgos, datas, pp);
summarize(myalgos, "#");
return 0;
} else if (strcmp(parameter, "uniformdense") == 0) {
cout << "# dense uniform data generation..." << endl;
vector < vector<uint32_t, cacheallocator> > datas;
UniformDataGenerator clu;
for (uint32_t k = 0; k < (1U << 3); ++k)// by original paper should be 1U<<10
datas.push_back(clu.generateUniform((1U << 22), 1U << 29));
cout << "# generated " << datas.size() << " arrays" << endl;
if (splitlongarrays)
splitLongArrays( datas);
processparameters pp(true, fulldisplay, displayhistogram,
computeentropy, false);
Delta::process(myalgos, datas, pp);
summarize(myalgos, "#");
return 0;
} else if (strcmp(parameter, "uniformsparse") == 0) {
cout << "# sparse uniform data generation..." << endl;
vector < vector<uint32_t, cacheallocator> > datas;
UniformDataGenerator clu;
for (uint32_t k = 0; k < (1U << 13); ++k)
datas.push_back(clu.generateUniform((1U << 12), 1U << 29));
cout << "# generated " << datas.size() << " arrays" << endl;
if (splitlongarrays)
splitLongArrays( datas);
processparameters pp(true, fulldisplay, displayhistogram,
computeentropy, false);
Delta::process(myalgos, datas, pp);
summarize(myalgos, "#");
return 0;
} else if (strcmp(parameter, "clusterdense") == 0) {
cout << "# dense cluster data generation..." << endl;
vector < vector<uint32_t, cacheallocator> > datas;
ClusteredDataGenerator clu;
for (uint32_t k = 0; k < 1; ++k)
datas.push_back(clu.generateClustered((1U << 23), 1U << 26));
cout << "# generated " << datas.size() << " arrays" << endl;
if (splitlongarrays)
splitLongArrays( datas);
processparameters pp(true, fulldisplay, displayhistogram,
computeentropy, false);
Delta::process(myalgos, datas, pp);
summarize(myalgos, "#");
return 0;
} else if (strcmp(parameter, "clustersparse") == 0) {
cout << "# sparse cluster data generation..." << endl;
vector < vector<uint32_t, cacheallocator> > datas;
ClusteredDataGenerator clu;
for (uint32_t k = 0; k < (1U << 13); ++k)
datas.push_back(clu.generateClustered((1U << 12), 1U << 26));
cout << "# generated " << datas.size() << " arrays" << endl;
if (splitlongarrays)
splitLongArrays( datas);
processparameters pp(true, fulldisplay, displayhistogram,
computeentropy, false);
Delta::process(myalgos, datas, pp);
summarize(myalgos, "#");
return 0;
} else if (strcmp(parameter, "clusterdynamic") == 0) {
cout << "# dynamic clustered data generation..." << endl;
ClusteredDataGenerator clu;
for (uint32_t K = 15; K <= 25; K += 5) {
vector < vector<uint32_t, cacheallocator> > datas;
for (uint32_t k = 0; k < (1U << (25 - K)); ++k)
datas.push_back(
clu.generateClustered((1U << K), 1U << 29));
cout << "# generated " << datas.size() << " arrays" << endl;
cout << "# their size is " << (1U << K) << endl;
const uint32_t p = 29 - K;
ostringstream convert;
convert << p;
if (splitlongarrays)
splitLongArrays( datas);
processparameters pp(true, fulldisplay, displayhistogram,
computeentropy, false);
Delta::process(myalgos, datas, pp, convert.str());
}
summarize(myalgos, "#");
return 0;
} else if (strcmp(parameter, "uniformdynamic") == 0) {
cout << "# sparse uniform data generation..." << endl;
UniformDataGenerator clu;
for (uint32_t K = 15; K <= 25; K += 5) {
vector < vector<uint32_t, cacheallocator> > datas;
for (uint32_t k = 0; k < (1U << (25 - K)); ++k)
datas.push_back(
clu.generateUniform((1U << K), 1U << 29));
cout << "# generated " << datas.size() << " arrays" << endl;
cout << "# their size is " << (1U << K) << endl;
const uint32_t p = 29 - K;
ostringstream convert;
convert << p;
if (splitlongarrays)
splitLongArrays( datas);
processparameters pp(true, fulldisplay, displayhistogram,
computeentropy, false);
Delta::process(myalgos, datas, pp, convert.str());
}
summarize(myalgos, "#");
return 0;
} else if (strcmp(parameter, "clusterdynamicsmall") == 0) {
cout << "# dynamic clustered data generation..." << endl;
ClusteredDataGenerator clu;
for (uint32_t K = 15; K <= 20; K += 5) {
vector < vector<uint32_t, cacheallocator> > datas;
for (size_t k = 0; k < static_cast<size_t>(1U << (20 - K)); ++k)
datas.push_back(
clu.generateClustered((1U << K), 1U << 29));
cout << "# generated " << datas.size() << " arrays" << endl;
cout << "# their size is " << (1U << K) << endl;
const uint32_t p = 29 - K;
ostringstream convert;
convert << p;
if (splitlongarrays)
splitLongArrays( datas);
processparameters pp(true, fulldisplay, displayhistogram,
computeentropy, false);
Delta::process(myalgos, datas, pp, convert.str());
}
summarize(myalgos, "#");
return 0;
} else if (strcmp(parameter, "uniformdynamicsmall") == 0) {
cout << "# sparse uniform data generation..." << endl;
UniformDataGenerator clu;
for (uint32_t K = 15; K <= 20; K += 5) {
vector < vector<uint32_t, cacheallocator> > datas;
for (size_t k = 0; k < static_cast<size_t>(1U << (20 - K)); ++k)
datas.push_back(
clu.generateUniform((1U << K), 1U << 29));
cout << "# generated " << datas.size() << " arrays" << endl;
cout << "# their size is " << (1U << K) << endl;
const uint32_t p = 29 - K;
ostringstream convert;
convert << p;
if (splitlongarrays)
splitLongArrays( datas);
processparameters pp(true, fulldisplay, displayhistogram,
computeentropy, false);
Delta::process(myalgos, datas, pp, convert.str());
}
summarize(myalgos, "#");
return 0;
} else if (strcmp(parameter, "clusterdynamicpredelta") == 0) {
cout << "# dynamic clustered data generation..." << endl;
ClusteredDataGenerator clu;
for (uint32_t K = 15; K <= 25; K += 5) {
vector < vector<uint32_t, cacheallocator> > datas;
for (size_t k = 0; k < static_cast<size_t>(1U << (25 - K)); ++k)
datas.push_back(
diffs(
clu.generateClustered((1U << K),
1U << 29), false));
cout << "# generated " << datas.size()
<< " arrays and applied delta coding" << endl;
cout << "# their size is " << (1U << K) << endl;
const uint32_t p = 29 - K;
ostringstream convert;
convert << p;
if (splitlongarrays)
splitLongArrays( datas);
processparameters pp(false, fulldisplay, displayhistogram,
computeentropy, false);
Delta::process(myalgos, datas, pp, convert.str());
}
summarize(myalgos, "#");
return 0;
} else if (strcmp(parameter, "uniformdynamicpredelta") == 0) {
cout << "# sparse uniform data generation..." << endl;
UniformDataGenerator clu;
for (uint32_t K = 15; K <= 25; K += 5) {
vector < vector<uint32_t, cacheallocator> > datas;
for (size_t k = 0; k < static_cast<size_t>(1U << (25 - K)); ++k)
datas.push_back(
diffs(clu.generateUniform((1U << K), 1U << 29),
false));
cout << "# generated " << datas.size()
<< " arrays and applied delta coding" << endl;
cout << "# their size is " << (1U << K) << endl;
const uint32_t p = 29 - K;
ostringstream convert;
convert << p;
if (splitlongarrays)
splitLongArrays( datas);
processparameters pp(false, fulldisplay, displayhistogram,
computeentropy, false);
Delta::process(myalgos, datas, pp, convert.str());
}
summarize(myalgos, "#");
return 0;
} else {
cerr << "Support for " << parameter << " was not found."
<< endl;
}
break;
}
default:
/* You won't actually get here. */
break;
}
}
message();
return 0;
}