-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
114 lines (101 loc) · 4.3 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
108
109
110
111
112
113
#include "detail/rwt_omp.h"
#include <random>
constexpr double f = 15.0;
constexpr double rate = 95000;
std::array<detail::rwt::transform_result_type, static_cast<size_t>(rate)> transform_uni_result, transform_omp_result, transform_tw_result, transform_honest_omp_result;
using namespace detail;
using namespace detail::rwt;
struct compare_repeat_strategy{
compare_repeat_strategy(size_t iter_cnt, size_t iterations, ricker_filter const & filter, signal_sequence_type const & ss) :
iter_cnt_(iter_cnt), iterations_(iterations), filter_(filter), ss_(ss) {}
void process()
{
while (iter_cnt_--)
{
if (iter_cnt_ % 2) {
times_sums[0] += measure_it("transform-tw: ", transform_tw, ss_,
std::addressof(transform_tw_result[0]), filter_);
times_sums[1] += measure_it("transform-honest-omp: ", transform_honest_omp, ss_,
std::addressof(transform_honest_omp_result[0]), filter_);
} else {
times_sums[1] += measure_it("transform-honest-omp: ", transform_honest_omp, ss_,
std::addressof(transform_honest_omp_result[0]), filter_);
times_sums[0] += measure_it("transform-tw: ", transform_tw, ss_,
std::addressof(transform_tw_result[0]), filter_);
}
}
std::cout << "Average:\n";
std::cout << "tw: " << times_sums[0] / iterations_ << '\n';
std::cout << "honest_omp: " << times_sums[1] / iterations_ << '\n';
}
private:
size_t iter_cnt_;
size_t iterations_;
signal_sequence_type const & ss_;
ricker_filter const & filter_;
std::array<decltype(std::chrono::duration_cast<std::chrono::milliseconds>
(std::chrono::high_resolution_clock::now() - std::chrono::high_resolution_clock::now()).count()), 2> times_sums {};
};
struct vacation_tw_repeat_strategy {
vacation_tw_repeat_strategy (size_t iter_cnt, ricker_filter const & filter, signal_sequence_type const & ss) :
iter_cnt_(iter_cnt), filter_(filter), ss_(ss) {}
void process()
{
while (iter_cnt_--)
{
if (iter_cnt_ % 2) {
auto const newtime = measure_it("transform-tw: ", transform_tw, ss_, std::addressof(transform_tw_result[0]), filter_);
if (newtime < 1000)
std::this_thread::sleep_for(std::chrono::milliseconds(1000-newtime));
} else {
auto const newtime = measure_it("transform-tw: ", transform_tw, ss_, std::addressof(transform_tw_result[0]), filter_);
if (newtime < 1000)
std::this_thread::sleep_for(std::chrono::milliseconds(1000-newtime));
}
}
}
private:
size_t iter_cnt_;
signal_sequence_type const & ss_;
ricker_filter const & filter_;
};
int main(int argc, char* argv[])
{
if (argc != 2)
{
std::cout << argv[0] << " <number>\n";
exit(1);
}
size_t iter_cnt, iterations;
try {
iter_cnt = iterations = std::stoi(std::string(argv[1]));
} catch (std::invalid_argument const & e)
{
std::cout << e.what() << '\n';
exit(1);
}
ricker_filter filter{};
try {
filter = create_filter (make_odd(align_by_ten(ricker_filter_size(f, rate))));
} catch (std::exception const & e)
{
std::cout << e.what() << '\n';
return 1;
}
signal_sequence_type ss (static_cast<size_t>(rate) + filter.actual_sz);
std::mt19937 rng;
std::generate_n(std::begin(ss), std::distance(std::begin(ss), std::end(ss)), rng);
#if 1
measure_it("transform-uni: ", transform_uni, ss, std::addressof(transform_uni_result[0]), filter);
#endif
#if 0
measure_it("transform-omp: ", transform_omp, ss, std::addressof(transform_omp_result[0]), filter);
measure_it("transform-tw: ", transform_tw, ss, std::addressof(transform_tw_result[0]), filter);
measure_it("transform-honest-omp: ", transform_honest_omp, ss, std::addressof(transform_honest_omp_result[0]), filter);
#else
compare_repeat_strategy rs (iter_cnt, iterations, filter, ss);
//vacation_tw_repeat_strategy rs (iter_cnt, filter, ss);
rs.process();
#endif
return 0;
}