-
Notifications
You must be signed in to change notification settings - Fork 0
/
ACA2-2013.cpp
104 lines (78 loc) · 2.9 KB
/
ACA2-2013.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
//============================================================================
// Author : George Rokos
// Description : 2nd Assessed Coursework for ACA 2013
//============================================================================
#include <cstdlib>
#include <iostream>
#include <sys/time.h>
#include "Mesh.hpp"
#include "Smooth.hpp"
#include "Color.hpp"
double get_wtime(){
struct timeval tic;
long seconds, useconds;
gettimeofday(&tic, NULL);
seconds = tic.tv_sec;
useconds = tic.tv_usec;
return seconds + useconds*1e-06;
}
void colourSetsToArray(const std::vector<std::vector<size_t> > & colour_sets,
size_t** colourIndex,
size_t** colourArray,
size_t* num_coloured_nodes
)
{
std::vector<std::vector<size_t> >::const_iterator vec_it;
std::vector<size_t>::const_iterator vector_it;
cudaHostAlloc((void**)colourIndex, colour_sets.size()+1, cudaHostAllocPortable);
*num_coloured_nodes = 0;
for(vec_it = colour_sets.begin(); vec_it != colour_sets.end(); ++vec_it) {
*num_coloured_nodes += vec_it->size();
}
cudaHostAlloc((void **) colourArray, *num_coloured_nodes, cudaHostAllocPortable);
size_t offset = 0;
size_t colorSetIndex = 0;
for(vec_it = colour_sets.begin(); vec_it != colour_sets.end(); vec_it++, colorSetIndex++)
{
(*colourIndex)[colorSetIndex] = offset;
for(vector_it = vec_it->begin();
vector_it != vec_it->end();
vector_it++, offset++) {
(*colourArray)[offset] = *vector_it;
}
}
(*colourIndex)[colour_sets.size()] = offset;
}
int main(int argc, char **argv){
if(argc!=2){
std::cerr << "Usage: " << argv[0] << " mesh_file" << std::endl;
}
Mesh *mesh = new Mesh(argv[1]);
std::vector<std::vector<size_t> > colorings = Color::color(mesh, false);
/* Pin mesh nd color data */
mesh->pin_data();
size_t* colourIndex;
size_t* colourArray;
size_t num_coloured_nodes;
colourSetsToArray(colorings, &colourIndex, &colourArray, &num_coloured_nodes);
Quality q = mesh->get_mesh_quality();
std::cout << "Initial quality:\n"
<< "Quality mean: " << q.mean << std::endl
<< "Quality min: " << q.min << std::endl;
double time = get_wtime();
Smooth::smooth(mesh, 200, colorings.size(), num_coloured_nodes, colourIndex, colourArray);
double time_smooth = get_wtime() - time;
q = mesh->get_mesh_quality();
std::cout<<"After smoothing:\n"
<< "Quality mean: " << q.mean << std::endl
<< "Quality min: " << q.min << std::endl;
if((q.mean>0.90)&&(q.min>0.55))
std::cout << "Test passed"<< std::endl;
else
std::cout << "Test failed"<< std::endl;
std::cout<<"BENCHMARK: " << time_smooth << "s" << std::endl;
delete mesh;
cudaFreeHost(colourIndex);
cudaFreeHost(colourArray);
return EXIT_SUCCESS;
}