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
performance.hpp
1 /*
2  * performance.hpp
3  *
4  * Created on: Jan 11, 2016
5  * Author: i-bird
6  */
7 
8 #ifndef OPENFPM_DATA_SRC_PERFORMANCE_HPP_
9 #define OPENFPM_DATA_SRC_PERFORMANCE_HPP_
10 
11 #include "Plot/GoogleChart.hpp"
12 #include "timer.hpp"
13 
14 //#define N_STAT 256
15 //#define N_STAT_SMALL 32
16 //#define N_TRY 8
17 
18 #define N_STAT 1
19 #define N_STAT_SMALL 1
20 #define N_TRY 1
21 
22 #ifdef PERFORMANCE_TEST
23 
24 GoogleChart cg;
25 const char * test_dir;
26 
27 // Declaration of functions
28 
29 
30 void load_and_combine(std::string file, openfpm::vector<openfpm::vector<float>> & y, openfpm::vector<float> & per_times, size_t nc);
32 
33 BOOST_AUTO_TEST_SUITE( performance )
34 
35 
37 #include "Grid/grid_performance_tests.hpp"
38 #include "Vector/vector_performance_test.hpp"
39 
40 BOOST_AUTO_TEST_SUITE_END()
41 
42 #define MEASURE_SET 5
43 
52 std::string exec(const char* cmd)
53 {
54  std::shared_ptr<FILE> pipe(popen(cmd, "r"), pclose);
55  if (!pipe)
56  return "ERROR";
57 
58  char buffer[128];
59  std::string result = "";
60  while (!feof(pipe.get()))
61  {
62  if (fgets(buffer, 128, pipe.get()) != NULL)
63  result += buffer;
64  }
65  return result;
66 }
67 
72 struct configuration
73 {
74  char data_commit[41];
75  char pdata_commit[41];
76  char devices_commit[41];
77  char io_commit[41];
78  char vcluster_commit[41];
79  char numeric_commit[41];
80 
86  std::string toHTML(size_t i)
87  {
88  std::stringstream html;
89 
90  html << "<div style=\" border-radius: 25px; padding: 20px 20px 20px 20px ;\" >\n\
91  <div style=\"background-color:white; border-radius: 25px;border: 2px solid #000000; padding: 20px;\" >\n\
92  <h4>config " << i << "</h4>\n";
93  html << "<strong>OpenFPM numeric:</strong> " << numeric_commit << "<br>\n";
94  html << "<strong>OpenFPM pdata:</strong> " << pdata_commit << "<br>\n";
95  html << "<strong>OpenFPM vcluster:</strong> " << vcluster_commit << "<br>\n";
96  html << "<strong>OpenFPM io:</strong> " << io_commit << "<br>\n";
97  html << "<strong>OpenFPM pdata:</strong> " << pdata_commit << "<br>\n";
98  html << "<strong>OpenFPM data:</strong> " << data_commit << "<br>\n";
99  html << "<strong>OpenFPM devices:</strong> " << devices_commit << "<br>\n";
100  html << "</div>\n";
101  html << "</div>\n";
102 
103  return html.str();
104  }
105 };
106 
112 void getConfig(configuration & conf)
113 {
114  // take the head of the actual version of data
115  std::string out = exec("git rev-parse HEAD");
116 
117  // copy the actual commit version
118  for (size_t i = 0 ; i < 40 ; i++)
119  conf.data_commit[i] = out[i];
120  out[40] = 0;
121 
122  // take the head of the actual version of devices
123  std::string out2 = exec("cd ../../openfpm_devices ; git rev-parse HEAD");
124 
125  // copy the actual commit version
126  for (size_t i = 0 ; i < 40 ; i++)
127  conf.devices_commit[i] = out2[i];
128  out2[40] = 0;
129 
130  // take the head of the actual version of io
131  std::string out3 = exec("cd ../../openfpm_io ; git rev-parse HEAD");
132 
133  // copy the actual commit version
134  for (size_t i = 0 ; i < 40 ; i++)
135  conf.io_commit[i] = out3[i];
136  out[40] = 0;
137 
138  // take the head of the actual version of vcluster
139  std::string out4 = exec("cd ../../openfpm_vcluster ; git rev-parse HEAD");
140 
141  // copy the actual commit version
142  for (size_t i = 0 ; i < 40 ; i++)
143  conf.vcluster_commit[i] = out4[i];
144  out[40] = 0;
145 
146  // take the head of the actual version of pdata
147  std::string out5 = exec("cd ../../ ; git rev-parse HEAD");
148 
149  // copy the actual commit version
150  for (size_t i = 0 ; i < 40 ; i++)
151  conf.pdata_commit[i] = out5[i];
152  out[40] = 0;
153 
154  // take the head of the actual version of numerics
155  std::string out6 = exec("cd ../../openfpm_numerics ; git rev-parse HEAD");
156 
157  // copy the actual commit version
158  for (size_t i = 0 ; i < 40 ; i++)
159  conf.numeric_commit[i] = out6[i];
160  out[40] = 0;
161 }
162 
169 void load_and_combine_commit(std::string file, openfpm::vector<configuration> & commits)
170 {
171  // Load the previous measure and combine the previous measure with the actual measure
172  commits.clear();
173  commits.load(file);
174 
175  // remove the oldest commit
176  if (commits.size() >= MEASURE_SET)
177  commits.remove(0);
178 
179  commits.add();
180 
181  getConfig(commits.last());
182 
183  bool saved = commits.save(file);
184  if (saved == false)
185  std::cerr << __FILE__ << ":" << __LINE__ << " error saving previous commit \n";
186 }
187 
198 void load_and_combine(std::string file, openfpm::vector<openfpm::vector<float>> & y, openfpm::vector<float> & per_times, size_t nc)
199 {
200  // Load the previous measure and combine the previous measure with the actual measure
201  y.clear();
202 
203  y.load(file);
204  if (y.size() == 0)
205  y.resize(nc);
206 
207  if (nc == 0)
208  return;
209 
210  for(size_t i = 0 ; i < y.size() ; i++)
211  {
212  if (y.get(i).size() >= MEASURE_SET)
213  y.get(i).remove(0);
214  y.get(i).add(per_times.get(i));
215  }
216 
217  y.save(file);
218 }
219 
232 {
233  yn.clear();
234 
235  for (size_t i = 0 ; i < y_ref.size() ; i++)
236  {
237  // Get the minimum and maximum of the reference time
238  float min = 100.0;
239  float max = 0.0;
240  float average = 0.0;
241 
242  for (size_t j = 0 ; j < y_ref.get(i).size() ; j++)
243  {
244  if (y_ref.get(i).get(j) < min)
245  min = y_ref.get(i).get(j);
246 
247  if (y_ref.get(i).get(j) > max)
248  max = y_ref.get(i).get(j);
249 
250  average += y_ref.get(i).get(j);
251  }
252  average /= y_ref.get(i).size();
253 
254  // calculate speedup percentage
255 
256  y_ref_sup.add();
257 
258  for (size_t j = 0 ; j < y.get(i).size() ; j++)
259  {
260  y_ref_sup.last().add((average/y.get(i).get(j) - 1.0) * 100.0);
261  yn.add("config " + std::to_string(j));
262  }
263 
264  y_ref_sup.last().add((average/min - 1.0) * 100.0);
265  yn.add("interval");
266  y_ref_sup.last().add((average/max - 1.0) * 100.0);
267  yn.add("interval");
268  }
269 }
270 
271 void write_performance_report()
272 {
273 
275 
276  // Get the directory of the performance test files
277  std::string per_dir(test_dir);
278 
279  // Load the previous git commit SHA1 of the previous tests
280  load_and_combine_commit(per_dir + std::string("/prev_commit"),pcommit);
281 
282  std::string config_list;
283 
284  config_list += std::string("<h3>Highest configuration number is the latest version</h3>\n");
285 
286  for (size_t i = 0 ; i < pcommit.size() ; i++)
287  config_list += pcommit.get(i).toHTML(i);
288 
289  cg.addHTML(config_list);
290  cg.write(test_dir + std::string("/gc_out.html"));
291 }
292 
293 #endif
294 
295 #endif /* OPENFPM_DATA_SRC_PERFORMANCE_HPP_ */
Implementation of 1-D std::vector like structure.
Definition: map_grid.hpp:94