-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.cpp
107 lines (93 loc) · 2.98 KB
/
main.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
#include <sys/mman.h>
#include <chrono>
#include <iostream>
#include <random>
#include "HammerSlide.hpp"
#include "utils/AggregationFunctions.hpp"
#include "utils/SystemConf.h"
#include "utils/utils.h"
static volatile size_t result = 0;
int main(int argc, const char** argv) {
parseCLArgs(argc, argv);
// bind the process to one core
const int core_id = 1;
set_cpu_manually(core_id);
// initialize Hammerslide
HammerSlide<Sum<int, int, int>, SUM> hammerslide(WINDOW_SIZE, WINDOW_SLIDE);
// use a cache-aligned input vector
std::vector<int, tbb::cache_aligned_allocator<int>> input(INPUT_SIZE);
// generate random ints
std::random_device rd;
std::mt19937 mt(rd());
std::uniform_int_distribution<int> dist(1, INPUT_SIZE * 2);
for (auto& i : input) {
i = dist(mt);
}
// measure simple operations
bool first = true;
unsigned int idx = 0;
size_t tuples = 0;
auto t1 = std::chrono::high_resolution_clock::now();
auto t2 = t1;
auto time_span = std::chrono::duration_cast<std::chrono::duration<double>>(t2 - t1);
while (true) {
if (first) {
for (; idx < WINDOW_SIZE && idx < input.size(); ++idx) {
hammerslide.insert(input[idx]);
}
first = false;
}
for (; idx < input.size();) {
result += hammerslide.query(false);
hammerslide.evict(WINDOW_SLIDE);
int i = 0;
for (; i < WINDOW_SLIDE && idx < input.size(); ++idx) {
hammerslide.insert(input[idx]);
i++;
}
}
idx = 0; // start from the beginning
tuples += input.size();
t2 = std::chrono::high_resolution_clock::now();
time_span = std::chrono::duration_cast<std::chrono::duration<double>>(t2 - t1);
if (time_span.count() >= (double)DURATION / 1000) {
break;
}
}
std::cout << "Throughput: " << tuples / time_span.count() << " tuples/sec ("
<< result << ")" << std::endl;
// reset hammerslide
hammerslide.reset();
// measure simd operations
first = true;
result = 0;
idx = 0;
tuples = 0;
t1 = std::chrono::high_resolution_clock::now();
t2 = t1;
time_span = std::chrono::duration_cast<std::chrono::duration<double>>(t2 - t1);
while (true) {
if (first) {
idx = std::min(WINDOW_SIZE, (unsigned int)input.size());
hammerslide.insert(input.data(), 0, idx);
first = false;
}
for (; idx < input.size();) {
result += hammerslide.query();
hammerslide.evict(WINDOW_SLIDE);
auto next_idx = std::min(idx + WINDOW_SLIDE, (unsigned int)input.size());
hammerslide.insert(input.data(), idx, next_idx);
idx = next_idx;
}
idx = 0; // start from the beginning
tuples += input.size();
t2 = std::chrono::high_resolution_clock::now();
time_span = std::chrono::duration_cast<std::chrono::duration<double>>(t2 - t1);
if (time_span.count() >= (double)DURATION / 1000) {
break;
}
}
std::cout << "Throughput with SIMD: " << tuples / time_span.count()
<< " tuples/sec (" << result << ")" << std::endl;
return 0;
}