-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
50 lines (40 loc) · 1.52 KB
/
main.cpp
File metadata and controls
50 lines (40 loc) · 1.52 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
#include "inc/quad_tree.cuh"
#include <random>
#include <memory>
#include <chrono>
#include "inc/node.cuh"
std::unique_ptr<float[]> generate_random_floats(size_t N, float min, float max)
{
std::unique_ptr<float[]> data(new float[N]);
std::random_device rd;
std::mt19937 gen(rd());
std::uniform_real_distribution<float> dist(min, max);
for (size_t i = 0; i < N; ++i)
{
data[i] = dist(gen);
}
return data;
}
constexpr size_t N = 1000000;
int main(void)
{
// thrust::device_vector<float> x = {0.0f, 0.1f, 0.9f, 1.0f, 0.9999f};
// thrust::device_vector<float> y = {0.0f, 0.1f, 0.9f, 1.0f, 0.9999f};
// thrust::device_vector<float> m = {1.0f, 1.0f, 1.0f};
{
auto host_buffer_x = generate_random_floats(N, 0.0f, 1.0f);
auto host_buffer_y = generate_random_floats(N, 0.0f, 1.0f);
auto host_buffer_z = generate_random_floats(N, 0.0f, 1.0f);
thrust::device_vector<float> x(host_buffer_x.get(), host_buffer_x.get() + N);
thrust::device_vector<float> y(host_buffer_y.get(), host_buffer_y.get() + N);
thrust::device_vector<float> m(host_buffer_z.get(), host_buffer_z.get() + N);
ParallelQuadtree p(std::move(x), std::move(y), std::move(m));
auto clock = std::chrono::high_resolution_clock();
auto beg = clock.now();
p.build_tree();
std::cout << std::chrono::duration_cast<std::chrono::milliseconds>(clock.now() - beg).count() << "\n";
cudaDeviceSynchronize();
cudaDeviceReset();
}
return 0;
}