OpenFPM_pdata  4.1.0
Project that contain the implementation of distributed structures
cell_list_comp_reorder.hpp
1 /*
2  * vector_dist_cl_hilb_performance_tests.hpp
3  *
4  * Created on: May 24, 2016
5  * Author: Yaroslav Zaluzhnyi
6  */
7 
8 #ifndef SRC_VECTOR_VECTOR_DIST_CL_HILB_PERFORMANCE_TESTS_HPP_
9 #define SRC_VECTOR_VECTOR_DIST_CL_HILB_PERFORMANCE_TESTS_HPP_
10 
11 #include "Vector/vector_dist.hpp"
12 #include "data_type/aggregate.hpp"
13 #include "Plot/GoogleChart.hpp"
14 #include "vector_dist_performance_util.hpp"
15 
16 // Property tree
18 {
19  boost::property_tree::ptree graphs;
20 };
21 
22 report_cell_list_func_tests report_cl_funcs;
23 
24 BOOST_AUTO_TEST_SUITE( celllist_getCellList_calc_forces_performance_test )
25 
26 
27 
29 // Cut-off radiuses. Can be put different number of values
30 openfpm::vector<float> r_cutoff {0.004, 0.007, 0.01};
31 // The starting amount of particles (remember that this number is multiplied by number of processors you use for testing)
32 size_t k_start = 100000;
33 // The lower threshold for number of particles
34 size_t k_min = 15000;
35 
37 
38 // Numbers of particles vector
39 openfpm::vector<size_t> n_particles;
40 
44 template<unsigned int dim> void cell_list_getCellList_calc_force_benchmark(size_t cl_k_start,
45  size_t cl_k_min,
46  openfpm::vector<float> & cl_r_cutoff,
47  openfpm::vector<size_t> & cl_n_particles)
48 {
49  std::string str("Testing " + std::to_string(dim) + "D vector, no order, cell-list");
50  print_test_v(str,0);
51 
52  {
53  //For different r_cut
54  for (size_t r = 0; r < cl_r_cutoff.size(); r++ )
55  {
56  Vcluster<> & v_cl = create_vcluster();
57 
58  //Cut-off radius
59  float r_cut = cl_r_cutoff.get(r);
60 
61  //Number of particles
62  size_t k = cl_k_start * v_cl.getProcessingUnits();
63 
64  //Counter number for amounts of particles
65  size_t k_count = 1 + log2(k/cl_k_min);
66 
67  report_cl_funcs.graphs.put("performance.celllist.getCellList" + std::to_string(dim) + "D(" + std::to_string(r) + ").rcut",r_cut);
68 
69  int c = 0;
70 
71  //For different number of particles
72  for (size_t k_int = k ; k_int >= cl_k_min ; k_int/=2 )
73  {
74  BOOST_TEST_CHECKPOINT( "Testing " << dim << "D vector with a random cell list k=" << k_int );
75 
76  report_cl_funcs.graphs.put("performance.celllist.getCellList" + std::to_string(dim) + "D(" + std::to_string(r) + ").npart(" + std::to_string(c) + ").n",k_int);
77  report_cl_funcs.graphs.put("performance.celllist.calc_forces" + std::to_string(dim) + "D(" + std::to_string(r) + ").npart(" + std::to_string(c) + ").n",k_int);
78 
79 
80  if (cl_n_particles.size() < k_count)
81  cl_n_particles.add(k_int);
82 
83  Box<dim,float> box;
84 
85  for (size_t i = 0; i < dim; i++)
86  {
87  box.setLow(i,0.0);
88  box.setHigh(i,1.0);
89  }
90 
91  // Boundary conditions
92  size_t bc[dim];
93 
94  for (size_t i = 0; i < dim; i++)
95  {bc[i] = PERIODIC;}
96 
98 
99  // Initialize a dist vector
100  vd_initialize<dim>(vd, v_cl);
101 
102  vd.template ghost_get<0>();
103 
104  //Get a cell list
105 
106  auto NN = vd.getCellList(r_cut);
107  double sum_cl_mean = 0;
108  double sum_cl_dev = 0;
109 
110  openfpm::vector<double> measures;
111  for (size_t n = 0 ; n < N_STAT_TEST; n++)
112  {
113  measures.add(benchmark_get_celllist(NN,vd,r_cut));
114  }
115  standard_deviation(measures,sum_cl_mean,sum_cl_dev);
116  //Average total time
117 
118  report_cl_funcs.graphs.put("performance.celllist.getCellList" + std::to_string(dim) + "D(" + std::to_string(r) + ").npart(" + std::to_string(c) + ").mean",sum_cl_mean);
119  report_cl_funcs.graphs.put("performance.celllist.getCellList" + std::to_string(dim) + "D(" + std::to_string(r) + ").npart(" + std::to_string(c) + ").dev",sum_cl_dev);
120 
121  //Calculate forces
122 
123  double sum_fr_mean = 0;
124  double sum_fr_dev = 0;
125 
126  measures.clear();
127  for (size_t l = 0 ; l < N_STAT_TEST; l++)
128  {measures.add(benchmark_calc_forces<dim>(NN,vd,r_cut));}
129  standard_deviation(measures,sum_fr_mean,sum_fr_dev);
130 
131  report_cl_funcs.graphs.put("performance.celllist.calc_forces" + std::to_string(dim) + "D(" + std::to_string(r) + ").npart(" + std::to_string(c) + ").mean",sum_fr_mean);
132  report_cl_funcs.graphs.put("performance.celllist.calc_forces" + std::to_string(dim) + "D(" + std::to_string(r) + ").npart(" + std::to_string(c) + ").dev",sum_fr_dev);
133 
134  if (v_cl.getProcessUnitID() == 0)
135  std::cout << "Cut-off = " << r_cut << ", Particles = " << k_int << ". Time to create a cell-list: " << sum_cl_mean << " dev: " << sum_cl_dev << " time to calculate forces: " << sum_fr_mean << " dev: " << sum_fr_dev << std::endl;
136 
137  c++;
138  }
139  }
140  }
141 }
142 
146 template<unsigned int dim> void cell_list_getCellList_hilb_calc_force_benchmark(size_t cl_k_start,
147  size_t cl_k_min,
148  openfpm::vector<float> & cl_r_cutoff,
149  openfpm::vector<size_t> & cl_n_particles)
150 {
151  report_cl_funcs.graphs.put("performance.celllist.dim",std::to_string(dim));
152 
153  std::string str("Testing " + std::to_string(dim) + "D vector, Hilbert comp reorder, cell list");
154  print_test_v(str,0);
155 
156  {
157  //For different r_cut
158  for (size_t r = 0; r < cl_r_cutoff.size(); r++ )
159  {
160  Vcluster<> & v_cl = create_vcluster();
161 
162  //Cut-off radius
163  float r_cut = cl_r_cutoff.get(r);
164 
165  report_cl_funcs.graphs.put("performance.celllist.getCellList_hilb" + std::to_string(dim) + "D(" + std::to_string(r) + ").rcut",r_cut);
166 
167  //Number of particles
168  size_t k = cl_k_start * v_cl.getProcessingUnits();
169 
170  //Counter number for amounts of particles
171  size_t k_count = 1 + log2(k/cl_k_min);
172 
173  int c = 0;
174 
175  //For different number of particles
176  for (size_t k_int = k ; k_int >= cl_k_min ; k_int/=2 )
177  {
178  BOOST_TEST_CHECKPOINT( "Testing " << dim << "D vector with an Hilbert cell list k=" << k_int );
179 
180  report_cl_funcs.graphs.put("performance.celllist.getCellList_hilb" + std::to_string(dim) + "D(" + std::to_string(r) + ").npart(" + std::to_string(c) + ").n",k_int);
181  report_cl_funcs.graphs.put("performance.celllist.calc_forces_hilb" + std::to_string(dim) + "D(" + std::to_string(r) + ").npart(" + std::to_string(c) + ").n",k_int);
182 
183  if (cl_n_particles.size() < k_count)
184  cl_n_particles.add(k_int);
185 
186  Box<dim,float> box;
187 
188  for (size_t i = 0; i < dim; i++)
189  {
190  box.setLow(i,0.0);
191  box.setHigh(i,1.0);
192  }
193 
194  // Boundary conditions
195  size_t bc[dim];
196 
197  for (size_t i = 0; i < dim; i++)
198  bc[i] = PERIODIC;
199 
201 
202  // Initialize a dist vector
203  vd_initialize<dim>(vd, v_cl);
204 
205  vd.template ghost_get<0>();
206 
207  //Get a cell list hilb
208 
209  auto NN = vd.getCellList_hilb(r_cut);
210 
211  openfpm::vector<double> measures;
212 
213  double sum_cl_mean = 0;
214  double sum_cl_dev = 0;
215  for (size_t n = 0 ; n < N_STAT_TEST; n++)
216  {measures.add(benchmark_get_celllist_hilb(NN,vd,r_cut));}
217  standard_deviation(measures,sum_cl_mean,sum_cl_dev);
218  //Average total time
219 
220  report_cl_funcs.graphs.put("performance.celllist.getCellList_hilb" + std::to_string(dim) + "D(" + std::to_string(r) + ").npart(" + std::to_string(c) + ").mean",sum_cl_mean);
221  report_cl_funcs.graphs.put("performance.celllist.getCellList_hilb" + std::to_string(dim) + "D(" + std::to_string(r) + ").npart(" + std::to_string(c) + ").dev",sum_cl_dev);
222 
223  //Calculate forces
224 
225  double sum_fr_mean = 0;
226  double sum_fr_dev = 0;
227 
228  // Initialize SFC (we are only interested in force calculation)
229  NN.init_SFC();
230 
231  measures.clear();
232  for (size_t l = 0 ; l < N_STAT_TEST; l++)
233  {measures.add(benchmark_calc_forces_hilb<dim>(NN,vd,r_cut));}
234  standard_deviation(measures,sum_fr_mean,sum_fr_dev);
235 
236  report_cl_funcs.graphs.put("performance.celllist.calc_forces_hilb" + std::to_string(dim) + "D(" + std::to_string(r) + ").npart(" + std::to_string(c) + ").mean",sum_fr_mean);
237  report_cl_funcs.graphs.put("performance.celllist.calc_forces_hilb" + std::to_string(dim) + "D(" + std::to_string(r) + ").npart(" + std::to_string(c) + ").dev",sum_fr_dev);
238 
239 
240  if (v_cl.getProcessUnitID() == 0)
241  {std::cout << "Cut-off = " << r_cut << ", Particles = " << k_int << ". Time to create: " << sum_cl_mean << " dev: " << sum_cl_dev << " time to calculate force: " << sum_fr_mean << " dev: " << sum_fr_dev << std::endl;}
242 
243  c++;
244  }
245  }
246  }
247 }
248 
249 
250 BOOST_AUTO_TEST_CASE( vector_dist_celllist_random_test )
251 {
252  //Benchmark test for 2D and 3D
253  cell_list_getCellList_calc_force_benchmark<3>(k_start,
254  k_min,
255  r_cutoff,
256  n_particles);
257 
258 
259  cell_list_getCellList_calc_force_benchmark<2>(k_start,
260  k_min,
261  r_cutoff,
262  n_particles);
263 }
264 
265 BOOST_AUTO_TEST_CASE( vector_dist_celllist_hilbert_test )
266 {
267  //Benchmark test for 2D and 3D
268  cell_list_getCellList_hilb_calc_force_benchmark<3>(k_start,
269  k_min,
270  r_cutoff,
271  n_particles);
272 
273  cell_list_getCellList_hilb_calc_force_benchmark<2>(k_start,
274  k_min,
275  r_cutoff,
276  n_particles);
277 }
278 
279 
280 BOOST_AUTO_TEST_CASE(vector_dist_cl_performance_write_report)
281 {
282  // Create a graphs
283 
284  //For different r_cut
285  for (size_t r = 0; r < r_cutoff.size(); r++ )
286  {
287  report_cl_funcs.graphs.put("graphs.graph(" + std::to_string(r) + ").type","line");
288  report_cl_funcs.graphs.add("graphs.graph(" + std::to_string(r) + ").title","getCellList 3D performance r_cut=" + std::to_string(r_cutoff.get(r)));
289  report_cl_funcs.graphs.add("graphs.graph(" + std::to_string(r) + ").x.title","number of particles");
290  report_cl_funcs.graphs.add("graphs.graph(" + std::to_string(r) + ").y.title","Time seconds");
291  report_cl_funcs.graphs.add("graphs.graph(" + std::to_string(r) + ").y.data(0).source","performance.celllist.getCellList_hilb3D(" + std::to_string(r) + ").npart(#).mean");
292  report_cl_funcs.graphs.add("graphs.graph(" + std::to_string(r) + ").x.data(0).source","performance.celllist.getCellList_hilb3D(" + std::to_string(r) + ").npart(#).n");
293  report_cl_funcs.graphs.add("graphs.graph(" + std::to_string(r) + ").y.data(0).title","Cell-list hilbert");
294  report_cl_funcs.graphs.add("graphs.graph(" + std::to_string(r) + ").y.data(1).source","performance.celllist.getCellList3D(" + std::to_string(r) + ").npart(#).mean");
295  report_cl_funcs.graphs.add("graphs.graph(" + std::to_string(r) + ").x.data(1).source","performance.celllist.getCellList3D(" + std::to_string(r) + ").npart(#).n");
296  report_cl_funcs.graphs.add("graphs.graph(" + std::to_string(r) + ").y.data(1).title","Cell-list normal");
297  report_cl_funcs.graphs.add("graphs.graph(" + std::to_string(r) + ").options.log_y","true");
298  }
299 
300  //For different r_cut
301  for (size_t r = 0; r < r_cutoff.size(); r++ )
302  {
303  report_cl_funcs.graphs.put("graphs.graph(" + std::to_string(r_cutoff.size() + r) + ").type","line");
304  report_cl_funcs.graphs.add("graphs.graph(" + std::to_string(r_cutoff.size() + r) + ").title","calc_force 3D performance (Note hilbert require space filling curve pre-calculation) r_cut=" + std::to_string(r_cutoff.get(r)));
305  report_cl_funcs.graphs.add("graphs.graph(" + std::to_string(r_cutoff.size() + r) + ").x.title","number of particles");
306  report_cl_funcs.graphs.add("graphs.graph(" + std::to_string(r_cutoff.size() + r) + ").y.title","Time seconds");
307  report_cl_funcs.graphs.add("graphs.graph(" + std::to_string(r_cutoff.size() + r) + ").y.data(0).source","performance.celllist.calc_forces_hilb3D(" + std::to_string(r) + ").npart(#).mean");
308  report_cl_funcs.graphs.add("graphs.graph(" + std::to_string(r_cutoff.size() + r) + ").x.data(0).source","performance.celllist.calc_forces_hilb3D(" + std::to_string(r) + ").npart(#).n");
309  report_cl_funcs.graphs.add("graphs.graph(" + std::to_string(r_cutoff.size() + r) + ").y.data(0).title","Cell-list hilbert");
310  report_cl_funcs.graphs.add("graphs.graph(" + std::to_string(r_cutoff.size() + r) + ").y.data(1).source","performance.celllist.calc_forces3D(" + std::to_string(r) + ").npart(#).mean");
311  report_cl_funcs.graphs.add("graphs.graph(" + std::to_string(r_cutoff.size() + r) + ").x.data(1).source","performance.celllist.calc_forces3D(" + std::to_string(r) + ").npart(#).n");
312  report_cl_funcs.graphs.add("graphs.graph(" + std::to_string(r_cutoff.size() + r) + ").y.data(1).title","Cell-list normal");
313  report_cl_funcs.graphs.add("graphs.graph(" + std::to_string(r_cutoff.size() + r) + ").options.log_y","true");
314  }
315 
316  //For different r_cut
317  for (size_t r = 0; r < r_cutoff.size(); r++ )
318  {
319  report_cl_funcs.graphs.put("graphs.graph(" + std::to_string(2*r_cutoff.size() + r) + ").type","line");
320  report_cl_funcs.graphs.add("graphs.graph(" + std::to_string(2*r_cutoff.size() + r) + ").title","getCellList 2D performance r_cut=" + std::to_string(r_cutoff.get(r)));
321  report_cl_funcs.graphs.add("graphs.graph(" + std::to_string(2*r_cutoff.size() + r) + ").x.title","number of particles");
322  report_cl_funcs.graphs.add("graphs.graph(" + std::to_string(2*r_cutoff.size() + r) + ").y.title","Time seconds");
323  report_cl_funcs.graphs.add("graphs.graph(" + std::to_string(2*r_cutoff.size() + r) + ").y.data(0).source","performance.celllist.getCellList_hilb2D(" + std::to_string(r) + ").npart(#).mean");
324  report_cl_funcs.graphs.add("graphs.graph(" + std::to_string(2*r_cutoff.size() + r) + ").x.data(0).source","performance.celllist.getCellList_hilb2D(" + std::to_string(r) + ").npart(#).n");
325  report_cl_funcs.graphs.add("graphs.graph(" + std::to_string(2*r_cutoff.size() + r) + ").y.data(0).title","Cell-list hilbert");
326  report_cl_funcs.graphs.add("graphs.graph(" + std::to_string(2*r_cutoff.size() + r) + ").y.data(1).source","performance.celllist.getCellList2D(" + std::to_string(r) + ").npart(#).mean");
327  report_cl_funcs.graphs.add("graphs.graph(" + std::to_string(2*r_cutoff.size() + r) + ").x.data(1).source","performance.celllist.getCellList2D(" + std::to_string(r) + ").npart(#).n");
328  report_cl_funcs.graphs.add("graphs.graph(" + std::to_string(2*r_cutoff.size() + r) + ").y.data(1).title","Cell-list normal");
329  report_cl_funcs.graphs.add("graphs.graph(" + std::to_string(2*r_cutoff.size() + r) + ").options.log_y","true");
330  }
331 
332  //For different r_cut
333  for (size_t r = 0; r < r_cutoff.size(); r++ )
334  {
335  report_cl_funcs.graphs.put("graphs.graph(" + std::to_string(3*r_cutoff.size() + r) + ").type","line");
336  report_cl_funcs.graphs.add("graphs.graph(" + std::to_string(3*r_cutoff.size() + r) + ").title","calc_force 2D performance (Note hilbert require space filling curve pre-calculation) r_cut=" + std::to_string(r_cutoff.get(r)));
337  report_cl_funcs.graphs.add("graphs.graph(" + std::to_string(3*r_cutoff.size() + r) + ").x.title","number of particles");
338  report_cl_funcs.graphs.add("graphs.graph(" + std::to_string(3*r_cutoff.size() + r) + ").y.title","Time seconds");
339  report_cl_funcs.graphs.add("graphs.graph(" + std::to_string(3*r_cutoff.size() + r) + ").y.data(0).source","performance.celllist.calc_forces_hilb2D(" + std::to_string(r) + ").npart(#).mean");
340  report_cl_funcs.graphs.add("graphs.graph(" + std::to_string(3*r_cutoff.size() + r) + ").x.data(0).source","performance.celllist.calc_forces_hilb2D(" + std::to_string(r) + ").npart(#).n");
341  report_cl_funcs.graphs.add("graphs.graph(" + std::to_string(3*r_cutoff.size() + r) + ").y.data(0).title","Cell-list hilbert");
342  report_cl_funcs.graphs.add("graphs.graph(" + std::to_string(3*r_cutoff.size() + r) + ").y.data(1).source","performance.celllist.calc_forces2D(" + std::to_string(r) + ").npart(#).mean");
343  report_cl_funcs.graphs.add("graphs.graph(" + std::to_string(3*r_cutoff.size() + r) + ").x.data(1).source","performance.celllist.calc_forces2D(" + std::to_string(r) + ").npart(#).n");
344  report_cl_funcs.graphs.add("graphs.graph(" + std::to_string(3*r_cutoff.size() + r) + ").y.data(1).title","Cell-list normal");
345  report_cl_funcs.graphs.add("graphs.graph(" + std::to_string(3*r_cutoff.size() + r) + ").options.log_y","true");
346  }
347 
348  if (create_vcluster().rank() == 0)
349  {
350  boost::property_tree::xml_writer_settings<std::string> settings(' ', 4);
351  boost::property_tree::write_xml("celllist_performance.xml", report_cl_funcs.graphs,std::locale(),settings);
352 
353  GoogleChart cg;
354 
355  std::string file_xml_ref(test_dir);
356  file_xml_ref += std::string("/openfpm_pdata/celllist_performance_ref.xml");
357 
358  StandardXMLPerformanceGraph("celllist_performance.xml",file_xml_ref,cg);
359 
360  addUpdateTime(cg,create_vcluster().size(),"pdata","celllist_performance");
361 
362  createCommitFile("pdata");
363 
364  cg.write("celllist_performance.html");
365  }
366 }
367 
368 
369 
370 BOOST_AUTO_TEST_SUITE_END()
371 
372 #endif /* SRC_VECTOR_VECTOR_DIST_CL_HILB_PERFORMANCE_TESTS_HPP_ */
size_t getProcessUnitID()
Get the process unit id.
size_t size()
Stub size.
Definition: map_vector.hpp:211
Definition: Ghost.hpp:39
Implementation of VCluster class.
Definition: VCluster.hpp:58
__device__ __host__ void setHigh(int i, T val)
set the high interval of the box
Definition: Box.hpp:544
Small class to produce graph with Google chart in HTML.
__device__ __host__ void setLow(int i, T val)
set the low interval of the box
Definition: Box.hpp:533
size_t getProcessingUnits()
Get the total number of processors.
This class represent an N-dimensional box.
Definition: Box.hpp:60
void write(std::string file)
It write the graphs on file in html format using Google charts.
Distributed vector.
Implementation of 1-D std::vector like structure.
Definition: map_vector.hpp:202