forked from matalek/eth-dphpc-project
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tester.cc
113 lines (94 loc) · 3.21 KB
/
tester.cc
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 <vector>
#include <memory>
#include <cassert>
#include <stdio.h>
#include <chrono>
#include <string>
#include <iostream>
#include <fstream>
#include "geometric_helpers.hh"
#include "merge_hull.hh"
#include "algorithm_interfaces/convex_hull_sequential_algorithm.hh"
#include "algorithm_interfaces/convex_hull_parallel_algorithm.hh"
#include "data_structures/convex_hull_representation.hh"
#include "data_structures/vector_convex_hull_representation.hh"
#include "sequential/andrew_algorithm.hh"
#include "simple_parallel/simple_parallel_algorithm.hh"
#include "naive_parallel/naive_parallel_algorithm.hh"
#include "algorithm_interfaces/convex_hull_parallel_tree_algorithm.hh"
#include "hull_tree/hull_tree_algorithm.hh"
using namespace std;
using namespace std::chrono;
// high_resolution_clock::time_point ConvexHullAlgorithm::middle_time;
LL ConvexHullAlgorithm::sequential_time;
// In order to add a new algorithm:
// - create a class subtyping ConveHullAlgorithm providing implementation
// of the new algorithm,
// - include its header file in this file,
// - add an apropriate 'if' statement in the 'load_algorithm' function.
bool is_sequential;
// Loads an appropriate algorithm based on command line params.
ConvexHullAlgorithm* load_algorithm(char* argv[]) {
ConvexHullAlgorithm* algorithm;
string arg = (string) argv[1];
int threads = 1;
string name;
size_t split_point = arg.find(':');
if (split_point != string::npos) {
name = arg.substr(0, split_point);
threads = stoi(arg.substr(split_point + 1));
} else {
name = arg;
}
if (name == "Sequential") {
is_sequential = true;
algorithm = new AndrewAlgorithm();
} else if (name == "NaiveParallel") {
assert(threads > 0);
algorithm = new NaiveParallelAlgorithm(threads);
} else if (name == "SimpleParallel") {
assert(threads > 0);
algorithm = new SimpleParallelAlgorithm(threads);
} else if (name == "HullTree") {
assert(threads > 0);
algorithm = new HullTreeAlgorithm(threads);
} else {
assert(false && "No algorithm found with this name");
}
return algorithm;
}
int main(int argc, char* argv[]) {
std::ios_base::sync_with_stdio(false);
// Number of points.
int n;
cin >> n;
// Reading points.
vector<POINT> points(n);
vector<POINT*> points_pointers(n);
for (int i = 0; i < n; i++) {
LL x, y;
cin >> x >> y;
points[i] = POINT(x, y);
points_pointers[i] = &points[i];
}
ConvexHullAlgorithm* algorithm;
algorithm = load_algorithm(argv);
//computing exec time (could find better way)
high_resolution_clock::time_point t1 = high_resolution_clock::now();
shared_ptr<HullWrapper> convex_hull_points = shared_ptr<HullWrapper>(algorithm->convex_hull(points_pointers));
high_resolution_clock::time_point t2 = high_resolution_clock::now();
cout << "TIME: ";
if (is_sequential) {
cout << duration_cast<microseconds>( t2 - t1 ).count() << " " << 0 << "\n";
} else {
cout << ConvexHullAlgorithm::sequential_time << " "
<< duration_cast<microseconds>( t2 - t1 ).count() - ConvexHullAlgorithm::sequential_time << "\n";
}
shared_ptr<vector<POINT*>> result = convex_hull_points->get_points();
cout << result->size() << "\n";
for (POINT* point : (*result)) {
point->print();
}
delete(algorithm);
return 0;
}