OpenFPM_pdata  1.1.0
Project that contain the implementation of distributed structures
 All Data Structures Namespaces Functions Variables Typedefs Enumerations Friends Pages
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 #include "Memleak_check.hpp"
14 
15 #define N_STAT 256
16 #define N_STAT_SMALL 32
17 #define N_TRY 8
18 
19 #ifdef PERFORMANCE_TEST
20 
21 GoogleChart cg;
22 const char * test_dir;
23 
24 // Declaration of functions
25 
26 
27 void load_and_combine(std::string file, openfpm::vector<openfpm::vector<float>> & y, openfpm::vector<float> & per_times);
29 
30 BOOST_AUTO_TEST_SUITE( performance )
31 
32 
34 #include "Grid/grid_performance_tests.hpp"
35 #include "Vector/vector_performance_test.hpp"
36 
37 BOOST_AUTO_TEST_SUITE_END()
38 
39 #define MEASURE_SET 5
40 
41 
46 struct configuration
47 {
48  char data_commit[41];
49  char pdata_commit[41];
50  char devices_commit[41];
51  char io_commit[41];
52  char vcluster_commit[41];
53  char numeric_commit[41];
54 
60  std::string toHTML(size_t i)
61  {
62  std::stringstream html;
63 
64  html << "<div style=\" border-radius: 25px; padding: 20px 20px 20px 20px ;\" >\n\
65  <div style=\"background-color:white; border-radius: 25px;border: 2px solid #000000; padding: 20px;\" >\n\
66  <h4>config " << i << "</h4>\n";
67  html << "<strong>OpenFPM numeric:</strong> " << numeric_commit << "<br>\n";
68  html << "<strong>OpenFPM pdata:</strong> " << pdata_commit << "<br>\n";
69  html << "<strong>OpenFPM vcluster:</strong> " << vcluster_commit << "<br>\n";
70  html << "<strong>OpenFPM io:</strong> " << io_commit << "<br>\n";
71  html << "<strong>OpenFPM pdata:</strong> " << pdata_commit << "<br>\n";
72  html << "<strong>OpenFPM data:</strong> " << data_commit << "<br>\n";
73  html << "<strong>OpenFPM devices:</strong> " << devices_commit << "<br>\n";
74  html << "</div>\n";
75  html << "</div>\n";
76 
77  return html.str();
78  }
79 };
80 
86 void getConfig(configuration & conf)
87 {
88  // take the head of the actual version of data
89  std::string out = exec("git rev-parse HEAD");
90 
91  // copy the actual commit version
92  for (size_t i = 0 ; i < 40 ; i++)
93  conf.data_commit[i] = out[i];
94  out[40] = 0;
95 
96  // take the head of the actual version of devices
97  std::string out2 = exec("cd ../../openfpm_devices ; git rev-parse HEAD");
98 
99  // copy the actual commit version
100  for (size_t i = 0 ; i < 40 ; i++)
101  conf.devices_commit[i] = out2[i];
102  out2[40] = 0;
103 
104  // take the head of the actual version of io
105  std::string out3 = exec("cd ../../openfpm_io ; git rev-parse HEAD");
106 
107  // copy the actual commit version
108  for (size_t i = 0 ; i < 40 ; i++)
109  conf.io_commit[i] = out3[i];
110  out[40] = 0;
111 
112  // take the head of the actual version of vcluster
113  std::string out4 = exec("cd ../../openfpm_vcluster ; git rev-parse HEAD");
114 
115  // copy the actual commit version
116  for (size_t i = 0 ; i < 40 ; i++)
117  conf.vcluster_commit[i] = out4[i];
118  out[40] = 0;
119 
120  // take the head of the actual version of pdata
121  std::string out5 = exec("cd ../../ ; git rev-parse HEAD");
122 
123  // copy the actual commit version
124  for (size_t i = 0 ; i < 40 ; i++)
125  conf.pdata_commit[i] = out5[i];
126  out[40] = 0;
127 
128  // take the head of the actual version of numerics
129  std::string out6 = exec("cd ../../openfpm_numerics ; git rev-parse HEAD");
130 
131  // copy the actual commit version
132  for (size_t i = 0 ; i < 40 ; i++)
133  conf.numeric_commit[i] = out6[i];
134  out[40] = 0;
135 }
136 
143 void load_and_combine_commit(std::string file, openfpm::vector<configuration> & commits)
144 {
145  // Load the previous measure and combine the previous measure with the actual measure
146  commits.clear();
147  commits.load(file);
148 
149  // remove the oldest commit
150  if (commits.size() >= MEASURE_SET)
151  commits.remove(0);
152 
153  commits.add();
154 
155  getConfig(commits.last());
156 
157  bool saved = commits.save(file);
158  if (saved == false)
159  std::cerr << __FILE__ << ":" << __LINE__ << " error saving previous commit \n";
160 }
161 
172 void load_and_combine(std::string file, openfpm::vector<openfpm::vector<float>> & y, openfpm::vector<float> & per_times)
173 {
174  // Load the previous measure and combine the previous measure with the actual measure
175  y.clear();
176 
177  y.load(file);
178 
179  if (per_times.size() == 0)
180  return;
181 
182  if (y.size() == 0)
183  y.resize(per_times.size());
184 
185  for(size_t i = 0 ; i < y.size() ; i++)
186  {
187  if (y.get(i).size() >= MEASURE_SET)
188  y.get(i).remove(0);
189  y.get(i).add(per_times.get(i));
190  }
191 
192  y.save(file);
193 }
194 
207 {
208  yn.clear();
209 
210  for (size_t i = 0 ; i < y_ref.size() ; i++)
211  {
212  // Get the minimum and maximum of the reference time
213  float min = 100.0;
214  float max = 0.0;
215  float average = 0.0;
216 
217  for (size_t j = 0 ; j < y_ref.get(i).size() ; j++)
218  {
219  if (y_ref.get(i).get(j) < min)
220  min = y_ref.get(i).get(j);
221 
222  if (y_ref.get(i).get(j) > max)
223  max = y_ref.get(i).get(j);
224 
225  average += y_ref.get(i).get(j);
226  }
227  average /= y_ref.get(i).size();
228 
229  // calculate speedup percentage
230 
231  y_ref_sup.add();
232 
233  for (size_t j = 0 ; j < y.get(i).size() ; j++)
234  {
235  y_ref_sup.last().add((average/y.get(i).get(j) - 1.0) * 100.0);
236  yn.add("config " + std::to_string(j));
237  }
238 
239  y_ref_sup.last().add((average/min - 1.0) * 100.0);
240  yn.add("interval");
241  y_ref_sup.last().add((average/max - 1.0) * 100.0);
242  yn.add("interval");
243  }
244 }
245 
246 void write_performance_report()
247 {
248 
250 
251  // Get the directory of the performance test files
252  std::string per_dir(test_dir);
253 
254  // Load the previous git commit SHA1 of the previous tests
255  load_and_combine_commit(per_dir + std::string("/openfpm_data/prev_commit"),pcommit);
256 
257  std::string config_list;
258 
259  config_list += std::string("<h3>Highest configuration number is the latest version</h3>\n");
260 
261  for (size_t i = 0 ; i < pcommit.size() ; i++)
262  config_list += pcommit.get(i).toHTML(i);
263 
264  cg.addHTML(config_list);
265  cg.write(test_dir + std::string("/openfpm_data/openfpm_data_performance.html"));
266 }
267 
268 #endif
269 
270 #endif /* OPENFPM_DATA_SRC_PERFORMANCE_HPP_ */
void addHTML(const std::string &html)
Add HTML text.
size_t size()
Stub size.
Definition: map_vector.hpp:70
Small class to produce graph with Google chart in HTML.
void write(std::string file)
It write the graphs on file in html format using Google charts.
Implementation of 1-D std::vector like structure.
Definition: map_vector.hpp:61