-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathxeon_tester.cc
127 lines (107 loc) · 4.31 KB
/
xeon_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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
#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 "./generator/generator_loader.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;
string algorithms[3] = {"SimpleParallel", "NaiveParallel", "HullTree"};
string threads_count[6] = {"2", "4", "8", "16", "32", "64"};
string points_dimension[4] = {"10000", "100000", "1000000", "10000000"};
string shape = "circle";
string destination_file_path = "/mnt/hostfs/team08/log_files/";
// Loads an appropriate algorithm based on command line params.
ConvexHullAlgorithm* load_algorithm(string arg) {
ConvexHullAlgorithm* algorithm;
int threads;
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[]) {
cout << "START\n";
ConvexHullAlgorithm* algorithm;
Generator* generator = load_generator(shape);
for (auto num_of_points : points_dimension){
for (int rep = 0; rep < 4; rep++){
//generate input points of size num_of_points
int n = stoi(num_of_points);
// Reading points.
vector<POINT> points;
points = generator->generate_points(n);
vector<POINT*> points_pointers(n);
for (int i = 0; i < n; i++) {
points_pointers[i] = &points[i];
}
for (auto algorithm_name : algorithms){
for (auto n_threads : threads_count){
algorithm = load_algorithm(algorithm_name + ":" + n_threads);
ofstream output_file;
output_file.open (destination_file_path + algorithm_name + "_" + n_threads + ".log", ios::app);
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();
output_file << "POINTS: " << num_of_points << "\nREP: " << (rep + 1) << "\nTIME: ";
output_file << ConvexHullAlgorithm::sequential_time << " "
<< duration_cast<microseconds>( t2 - t1 ).count() - ConvexHullAlgorithm::sequential_time << "\n";
output_file.close();
}
}
algorithm = load_algorithm("Sequential:1");
ofstream output_file;
output_file.open (destination_file_path + "Sequential_1.log", ios::app);
//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();
output_file << "POINTS: " << num_of_points << "\nREP: " << (rep + 1) << "\nTIME: ";
output_file << duration_cast<microseconds>( t2 - t1 ).count() << " " << 0 << "\n";
output_file.close();
}
}
return 0;
}