-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathmain.cpp
More file actions
85 lines (65 loc) · 1.83 KB
/
main.cpp
File metadata and controls
85 lines (65 loc) · 1.83 KB
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
#include "vp-tree.h"
#include <cmath>
#include <iostream>
#include <numeric>
#include <cassert>
#include <omp.h>
struct Vector {
Vector(double x, double y) : x(x), y(y) {
}
inline
double length() const {
return std::sqrt(length_squared());
}
inline
double length_squared() const {
return x*x + y*y;
}
double x, y;
};
inline
Vector operator -(const Vector &v1, const Vector &v2) {
return Vector(v1.x - v2.x, v1.y - v2.y);
}
struct Particle {
Particle(double x, double y) : pos(x, y) {
}
Particle(const Vector &pos) : pos(pos) {
}
Vector pos;
};
inline
double dist(const Particle &p1, const Particle &p2) {
return (p1.pos - p2.pos).length();
}
int main() {
assert(Vector(1.0, 0.0).length() == 1.0);
assert((Vector(1.0, 0.0) - Vector(2.0, 0.0)).length() == 1.0);
VpTree<Particle, dist> tree;
std::vector<Particle> particles;
double dx = 0.1;
double dy = 0.1;
double start = omp_get_wtime();
for (int x = 0; x < 1000; x++) {
for (int y = 0; y < 1000; y++) {
particles.push_back(Particle(x*dx, y*dy));
}
}
double end = omp_get_wtime();
std::cout << "creating particles took: " << end - start << " seconds" << std::endl;
start = omp_get_wtime();
tree.create(particles);
end = omp_get_wtime();
std::cout << "creating tree took: " << end - start << " seconds" << std::endl;
int k = 10;
start = omp_get_wtime();
#pragma omp parallel for
for (size_t i = 0; i < particles.size(); i++) {
std::vector<double> distances;
std::vector<Particle> neighbors;
tree.search(particles[i], k, &neighbors, &distances);
}
end = omp_get_wtime();
std::cout << "searching neighbors for all particles took: " << end - start << " seconds" << std::endl;
return 0;
}