OpenFPM_data  0.1.0
Project that contain the implementation and interfaces for basic structure like vectors, grids, graph ... .
 All Data Structures Namespaces Functions Variables Typedefs Friends
grid_performance_tests.hpp
1 /*
2  * grid_performance_tests.hpp
3  *
4  * Created on: Nov 1, 2015
5  * Author: i-bird
6  */
7 
8 #ifndef OPENFPM_DATA_SRC_GRID_GRID_PERFORMANCE_TESTS_HPP_
9 #define OPENFPM_DATA_SRC_GRID_GRID_PERFORMANCE_TESTS_HPP_
10 
11 #include "grid_util_test.hpp"
12 
14 openfpm::vector<float> per_timesg;
15 
16 BOOST_AUTO_TEST_CASE(grid_performance_set_obj)
17 {
18  size_t sz[] = {128,128,128};
19 
21  c3.setMemory();
22 
23  fill_grid<3>(c3);
24 
26  f.fill();
27 
28  std::vector<double> times(N_STAT + 1);
29  times[0] = 1000;
30 
31  for (size_t j = 0 ; j < 8 ; j++)
32  {
33  for (size_t i = 1 ; i < N_STAT+1 ; i++)
34  {
35  timer t;
36  t.start();
37 
38  auto it = c3.getIterator();
39 
40  while (it.isNext())
41  {
42  c3.set(it.get(),f);
43 
44  ++it;
45  }
46 
47  t.stop();
48 
49  times[i] = t.getcputime();
50  }
51  std::sort(times.begin(),times.end());
52  sleep(5);
53  }
54 
55  testsg.add("Grid so");
56  per_timesg.add(times[0]);
57 
58 }
59 
60 BOOST_AUTO_TEST_CASE(grid_performance_set_other_grid)
61 {
62  size_t sz[] = {128,128,128};
63 
65  c3.setMemory();
66 
67  fill_grid<3>(c3);
69 
70  std::vector<double> times(N_STAT + 1);
71  times[0] = 1000;
72 
73  for (size_t j = 0 ; j < 8 ; j++)
74  {
75  for (size_t i = 1 ; i < N_STAT+1 ; i++)
76  {
77  timer t;
78  t.start();
79 
80  auto it = c3.getIterator();
81 
82  while (it.isNext())
83  {
84  c3.set(it.get(),c1,it.get());
85 
86  ++it;
87  }
88 
89  t.stop();
90 
91  times[i] = t.getcputime();
92  }
93  std::sort(times.begin(),times.end());
94  sleep(5);
95  }
96 
97  testsg.add("Grid sog");
98  per_timesg.add(times[0]);
99 
100 }
101 
102 BOOST_AUTO_TEST_CASE(grid_performance_set_other_grid_encap)
103 {
104  size_t sz[] = {128,128,128};
105 
107  c3.setMemory();
108 
109  fill_grid<3>(c3);
111 
112  std::vector<double> times(N_STAT + 1);
113  times[0] = 1000;
114 
115  for (size_t j = 0 ; j < 8 ; j++)
116  {
117  for (size_t i = 1 ; i < N_STAT+1 ; i++)
118  {
119  timer t;
120  t.start();
121 
122  auto it = c3.getIterator();
123 
124  while (it.isNext())
125  {
126  c3.set(it.get(),c1.get_o(it.get()));
127 
128  ++it;
129  }
130 
131  t.stop();
132 
133  times[i] = t.getcputime();
134  }
135  std::sort(times.begin(),times.end());
136  sleep(5);
137  }
138 
139  testsg.add("Grid soge");
140  per_timesg.add(times[0]);
141 }
142 
143 BOOST_AUTO_TEST_CASE(grid_performance_duplicate)
144 {
145  size_t sz[] = {128,128,128};
146 
148  c3.setMemory();
149 
150  fill_grid<3>(c3);
152 
153  std::vector<double> times(N_STAT_SMALL + 1);
154  times[0] = 1000;
155 
156  for (size_t j = 0 ; j < 8 ; j++)
157  {
158  for (size_t i = 1 ; i < N_STAT_SMALL+1 ; i++)
159  {
160  timer t;
161  t.start();
162 
163  c1 = c3.duplicate();
164 
165  t.stop();
166 
167  times[i] = t.getcputime();
168  }
169  std::sort(times.begin(),times.end());
170  sleep(5);
171  }
172 
173  testsg.add("Grid dup");
174  per_timesg.add(times[0]);
175 }
176 
178 
179 BOOST_AUTO_TEST_CASE(grid_performance_write_report)
180 {
183 
184  // Get the directory of the performance test files
185  std::string per_dir(test_dir);
186 
187  // Reference time
189  y_ref.load(per_dir + std::string("/ref_timesg"));
190 
191  load_and_combine(per_dir + std::string("/previous_measureg"),y,per_timesg,testsg.size());
192 
193  // Adding the dataset names
194  if (y.size() != 0)
195  {
196  for (size_t j = 0; j < y.get(0).size(); j++)
197  yn.add("config " + std::to_string(j));
198  }
199 
200  // Google charts options
201  GCoptions options;
202 
203  options.title = std::string("Grid Performances");
204  options.yAxis = std::string("Time (seconds)");
205  options.xAxis = std::string("Benchmark");
206  options.stype = std::string("bars");
207 
208  std::stringstream g_test_desc;
209  g_test_desc << "<h2>Grid performance test</h2>\n";
210  g_test_desc << "<strong>128x128x128 Grid containing a Point_test<float></strong><br>";
211  g_test_desc << "<strong>Grid so:</strong> Initialize each element of the grid<br>";
212  g_test_desc << "<strong>Grid sog:</strong> Manual copy of two grids<br>";
213  g_test_desc << "<strong>Grid soge:</strong> Manual copy of two grids in a different way<br>";
214  g_test_desc << "<strong>Grid dup:</strong> Duplication of the grid<br>";
215 
216 
217  cg.addHTML(g_test_desc.str());
218  cg.AddColumsGraph(testsg,y,yn,options);
219 
220  // compare the reference times with the actual times
221 
222  // calculate speed-up
224 
225  speedup_calculate(y_ref_sup,y,y_ref,yn);
226 
227  std::stringstream g_test_spdesc;
228  g_test_spdesc << "<h2>Grid speedup</h2>\n";
229  g_test_spdesc << "The previous tests are compared with the best performances ever registered, ";
230  g_test_spdesc << "the banded area indicate the upper and lower bounds of the best registrered performances.<br>";
231  g_test_spdesc << "The lines are the latest 5 test<br>";
232  g_test_spdesc << "<strong>Line inside the area</strong>: The tested configuration has improvement or degradation in performance<br>";
233  g_test_spdesc << "<strong>Line break the upper bound</strong>: The tested configuration has improvement in performance<br>";
234  g_test_spdesc << "<strong>Line break the lower bound</strong>: The tested configuration has degradation in performance<br>";
235 
236  cg.addHTML(g_test_spdesc.str());
237  cg.AddPointsGraph(testsg,y_ref_sup,yn,options);
238 }
239 
240 #endif /* OPENFPM_DATA_SRC_GRID_GRID_PERFORMANCE_TESTS_HPP_ */
double getcputime()
Return the cpu time.
Definition: timer.hpp:114
void fill()
fill
Definition: Point_test.hpp:227
void start()
Start the timer.
Definition: timer.hpp:67
grid_cpu< dim, T, S, Mem > duplicate() const THROW
create a duplicated version of the grid
Definition: map_grid.hpp:619
Test structure used for several test.
Definition: Point_test.hpp:72
Implementation of 1-D std::vector like structure.
Definition: map_grid.hpp:94
Class for cpu time benchmarking.
Definition: timer.hpp:25
void stop()
Stop the timer.
Definition: timer.hpp:91