OpenFPM_pdata  1.1.0
Project that contain the implementation of distributed structures
 All Data Structures Namespaces Functions Variables Typedefs Enumerations Friends Pages
vector_dist_performance_util.hpp
1 /*
2  * vector_dist_performance_util.hpp
3  *
4  * Created on: Jun 17, 2016
5  * Author: Yaroslav Zaluzhnyi
6  */
7 
8 #ifndef SRC_VECTOR_VECTOR_DIST_PERFORMANCE_UTIL_HPP_
9 #define SRC_VECTOR_VECTOR_DIST_PERFORMANCE_UTIL_HPP_
10 
11 #include "Plot/GoogleChart.hpp"
12 #include "vector_dist_performance_common.hpp"
13 
14 // Number of tests
15 #define N_VERLET_TEST 3
16 #define N_STAT_TEST 30
17 
18 static inline void warning_set(int & warning_level, double mean, double mean_ref, double sigma)
19 {
20  int warning_level_candidate;
21 
22  if (mean - mean_ref < -2.0*sigma )
23  warning_level_candidate = -1;
24  else if (mean - mean_ref < 2.0*sigma)
25  warning_level_candidate = 0;
26  else if (mean - mean_ref < 3.0*sigma)
27  warning_level_candidate = 1;
28  else
29  warning_level_candidate = 2;
30 
31  if (warning_level_candidate > warning_level)
32  warning_level = warning_level_candidate;
33 }
34 
35 static inline void addchartarea(std::string & chart_area, int lvl)
36 {
37  std::string color;
38 
39  if (lvl == -1)
40  {
41  chart_area = std::string(",chartArea: {\
42  backgroundColor: {\
43  stroke: '#00FF00',\
44  strokeWidth: 6\
45  }\
46  }");
47  }
48  else if (lvl == 0)
49  {
50  // NOTHING TO DO
51  }
52  else if (lvl == 1)
53  {
54  chart_area = std::string(",chartArea: {\
55  backgroundColor: {\
56  stroke: '#FFFF00',\
57  strokeWidth: 6\
58  }\
59  }");
60  }
61  else if (lvl == 2)
62  {
63  chart_area = std::string(",chartArea: {\
64  backgroundColor: {\
65  stroke: '#FF0000',\
66  strokeWidth: 6\
67  }\
68  }");
69  }
70 
71 }
72 
73 void addUpdtateTime(GoogleChart & cg);
74 
83 static inline void standard_deviation(openfpm::vector<double> measures, double & mean, double & dev)
84 {
85  for (size_t i = 0 ; i < measures.size() ; i++)
86  mean += measures.get(i);
87  mean /= measures.size();
88 
89  dev = 0;
90  for (size_t i = 0 ; i < measures.size() ; i++)
91  dev += (measures.get(i) - mean)*(measures.get(i) - mean);
92 
93  dev = sqrt(dev / (measures.size() - 1));
94 }
95 
96 
97 
106 template<unsigned int dim, size_t prp = 0, typename T, typename V> double benchmark_calc_forces(T & NN, V & vd, float r_cut)
107 {
108  //Timer
109  timer t;
110  t.start();
111 
112  calc_forces<dim,prp>(NN,vd,r_cut);
113 
114  t.stop();
115 
116  return t.getwct();
117 }
118 
126 template<typename V> double benchmark_reorder(V & vd, size_t m)
127 {
128  //Timer
129  timer t;
130  t.start();
131 
132  //Reorder
133  vd.reorder(m);
134 
135  t.stop();
136 
137  return t.getwct();
138 }
139 
148 template<typename T, typename V> double benchmark_get_celllist(T & NN, V & vd, float r_cut)
149 {
150  // Cell list timer
151  timer t;
152  t.start();
153 
154  //get cell list
155  NN = vd.getCellList(r_cut);
156 
157  t.stop();
158 
159  return t.getwct();
160 }
161 
169 template<typename V> double benchmark_get_verlet(V & vd, float r_cut)
170 {
172  //Timer
173  timer t;
174  t.start();
175 
176  //get verlet
177  auto vr = vd.getVerlet(r_cut);
178 
179  t.stop();
180 
181  return t.getwct();
182 }
183 
184 
185 
194 template<unsigned int dim, size_t prp = 0, typename T, typename V> double benchmark_calc_forces_hilb(T & NN, V & vd, float r_cut)
195 {
196  //Forces timer
197  timer t;
198  t.start();
199 
200  calc_forces_hilb<dim,prp>(NN,vd,r_cut);
201 
202  t.stop();
203 
204  return t.getwct();
205 }
206 
215 template<typename T, typename V> double benchmark_get_celllist_hilb(T & NN, V & vd, float r_cut)
216 {
217  // Cell list timer
218  timer t;
219  t.start();
220 
221  //get cell list
222  NN = vd.getCellList_hilb(r_cut);
223 
224  t.stop();
225 
226  return t.getwct();
227 }
228 
235 template<unsigned int dim, typename v_dist> void move_particles(v_dist & vd, double dist)
236 {
237  double phi;
238  double theta;
239  const double pi = 3.14159;
240 
241  auto it = vd.getDomainIterator();
242 
243  while (it.isNext())
244  {
245  phi = rand()/double(RAND_MAX);
246  theta = rand()/double(RAND_MAX);
247  phi *= 2.0*pi;
248  theta *= pi;
249 
250  auto key = it.get();
251 
252  if(dim == 1)
253  vd.getPos(key)[0] += dist*sin(theta)*cos(phi);
254  else if(dim == 2)
255  {
256  vd.getPos(key)[0] += dist*sin(theta)*cos(phi);
257  vd.getPos(key)[1] += dist*sin(theta)*sin(phi);
258  }
259  else if(dim == 3)
260  {
261  vd.getPos(key)[0] += dist*sin(theta)*cos(phi);
262  vd.getPos(key)[1] += dist*sin(theta)*sin(phi);
263  vd.getPos(key)[2] += dist*cos(phi);
264  }
265 
266  ++it;
267  }
268 }
269 
271 
278 extern void StandardPerformanceGraph(std::string file_mean,
279  std::string file_var,
280  std::string file_mean_save,
281  std::string file_var_save,
282  GoogleChart & cg,
288  std::string x_string,
289  std::string y_string,
290  bool use_log);
291 
292 
293 #endif /* SRC_VECTOR_VECTOR_DIST_PERFORMANCE_UTIL_HPP_ */
size_t size()
Stub size.
Definition: map_vector.hpp:70
double getwct()
Return the elapsed real time.
Definition: timer.hpp:108
Small class to produce graph with Google chart in HTML.
void start()
Start the timer.
Definition: timer.hpp:73
This class is a trick to indicate the compiler a specific specialization pattern. ...
Definition: memory_c.hpp:201
Implementation of 1-D std::vector like structure.
Definition: map_vector.hpp:61
Class for cpu time benchmarking.
Definition: timer.hpp:25
void stop()
Stop the timer.
Definition: timer.hpp:97