OpenFPM_pdata  1.1.0
Project that contain the implementation of distributed structures
 All Data Structures Namespaces Functions Variables Typedefs Enumerations Friends Pages
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 #include "cl_comp_performance_graph.hpp"
16 
17 BOOST_AUTO_TEST_SUITE( celllist_comp_reorder_performance_test )
18 
19 
21 // Cut-off radiuses. Can be put different number of values
22 openfpm::vector<float> r_cutoff {0.004, 0.007, 0.01};
23 // The starting amount of particles (remember that this number is multiplied by number of processors you use for testing)
24 size_t k_start = 100000;
25 // The lower threshold for number of particles
26 size_t k_min = 15000;
27 
29 
30 // Numbers of particles vector
31 openfpm::vector<size_t> n_particles;
32 // Vectors to store the data for 2D
37 openfpm::vector<openfpm::vector<double>> time_create_rand_mean;
38 openfpm::vector<openfpm::vector<double>> time_create_hilb_mean;
39 openfpm::vector<openfpm::vector<double>> time_create_rand_dev;
40 openfpm::vector<openfpm::vector<double>> time_create_hilb_dev;
41 // Vectors to store the data for 3D
46 openfpm::vector<openfpm::vector<double>> time_create_rand_2_mean;
47 openfpm::vector<openfpm::vector<double>> time_create_hilb_2_mean;
48 openfpm::vector<openfpm::vector<double>> time_create_rand_2_dev;
49 openfpm::vector<openfpm::vector<double>> time_create_hilb_2_dev;
50 
54 template<unsigned int dim> void cell_list_comp_reorder_random_benchmark(size_t cl_k_start,
55  size_t cl_k_min,
56  openfpm::vector<float> & cl_r_cutoff,
57  openfpm::vector<size_t> & cl_n_particles,
58  openfpm::vector<openfpm::vector<double>> & cl_time_rand_mean,
59  openfpm::vector<openfpm::vector<double>> & cl_time_rand_dev,
60  openfpm::vector<openfpm::vector<double>> & cl_time_create_rand_mean,
61  openfpm::vector<openfpm::vector<double>> & cl_time_create_rand_dev)
62 {
63  cl_time_rand_mean.resize(cl_r_cutoff.size());
64  cl_time_create_rand_mean.resize(cl_r_cutoff.size());
65  cl_time_rand_dev.resize(cl_r_cutoff.size());
66  cl_time_create_rand_dev.resize(cl_r_cutoff.size());
67 
68  std::string str("Testing " + std::to_string(dim) + "D vector, no order, cell-list");
69  print_test_v(str,0);
70 
71  {
72  //For different r_cut
73  for (size_t r = 0; r < cl_r_cutoff.size(); r++ )
74  {
75  Vcluster & v_cl = create_vcluster();
76 
77  //Cut-off radius
78  float r_cut = cl_r_cutoff.get(r);
79 
80  //Number of particles
81  size_t k = cl_k_start * v_cl.getProcessingUnits();
82 
83  //Counter number for amounts of particles
84  size_t k_count = 1 + log2(k/cl_k_min);
85 
86  //For different number of particles
87  for (size_t k_int = k ; k_int >= cl_k_min ; k_int/=2 )
88  {
89  BOOST_TEST_CHECKPOINT( "Testing " << dim << "D vector with a random cell list k=" << k_int );
90 
91  if (cl_n_particles.size() < k_count)
92  cl_n_particles.add(k_int);
93 
94  Box<dim,float> box;
95 
96  for (size_t i = 0; i < dim; i++)
97  {
98  box.setLow(i,0.0);
99  box.setHigh(i,1.0);
100  }
101 
102  // Boundary conditions
103  size_t bc[dim];
104 
105  for (size_t i = 0; i < dim; i++)
106  bc[i] = PERIODIC;
107 
109 
110  // Initialize a dist vector
111  vd_initialize<dim>(vd, v_cl, k_int);
112 
113  vd.template ghost_get<0>();
114 
115  //Get a cell list
116 
117  auto NN = vd.getCellList(r_cut);
118  double sum_cl_mean = 0;
119  double sum_cl_dev = 0;
120 
121  openfpm::vector<double> measures;
122  for (size_t n = 0 ; n < N_STAT_TEST; n++)
123  measures.add(benchmark_get_celllist(NN,vd,r_cut));
124  standard_deviation(measures,sum_cl_mean,sum_cl_dev);
125  //Average total time
126 
127  cl_time_create_rand_mean.get(r).add(sum_cl_mean);
128  cl_time_create_rand_dev.get(r).add(sum_cl_dev);
129 
130  //Calculate forces
131 
132  double sum_fr_mean = 0;
133  double sum_fr_dev = 0;
134 
135  measures.clear();
136  for (size_t l = 0 ; l < N_STAT_TEST; l++)
137  measures.add(benchmark_calc_forces<dim>(NN,vd,r_cut));
138  standard_deviation(measures,sum_fr_mean,sum_fr_dev);
139 
140  cl_time_rand_mean.get(r).add(sum_fr_mean);
141  cl_time_rand_dev.get(r).add(sum_fr_dev);
142 
143  if (v_cl.getProcessUnitID() == 0)
144  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;
145  }
146  }
147  }
148 }
149 
153 template<unsigned int dim> void cell_list_comp_reorder_hilbert_benchmark(size_t cl_k_start,
154  size_t cl_k_min,
155  openfpm::vector<float> & cl_r_cutoff,
156  openfpm::vector<size_t> & cl_n_particles,
157  openfpm::vector<openfpm::vector<double>> & cl_time_force_mean,
158  openfpm::vector<openfpm::vector<double>> & cl_time_force_dev,
159  openfpm::vector<openfpm::vector<double>> & cl_time_create_mean,
160  openfpm::vector<openfpm::vector<double>> & cl_time_create_dev)
161 {
162  cl_time_force_mean.resize(cl_r_cutoff.size());
163  cl_time_create_mean.resize(cl_r_cutoff.size());
164  cl_time_force_dev.resize(cl_r_cutoff.size());
165  cl_time_create_dev.resize(cl_r_cutoff.size());
166 
167  std::string str("Testing " + std::to_string(dim) + "D vector, Hilbert comp reorder, cell list");
168  print_test_v(str,0);
169 
170  {
171  //For different r_cut
172  for (size_t r = 0; r < cl_r_cutoff.size(); r++ )
173  {
174  Vcluster & v_cl = create_vcluster();
175 
176  //Cut-off radius
177  float r_cut = cl_r_cutoff.get(r);
178 
179  //Number of particles
180  size_t k = cl_k_start * v_cl.getProcessingUnits();
181 
182  //Counter number for amounts of particles
183  size_t k_count = 1 + log2(k/cl_k_min);
184 
185  //For different number of particles
186  for (size_t k_int = k ; k_int >= cl_k_min ; k_int/=2 )
187  {
188  BOOST_TEST_CHECKPOINT( "Testing " << dim << "D vector with an Hilbert cell list k=" << k_int );
189 
190  if (cl_n_particles.size() < k_count)
191  cl_n_particles.add(k_int);
192 
193  Box<dim,float> box;
194 
195  for (size_t i = 0; i < dim; i++)
196  {
197  box.setLow(i,0.0);
198  box.setHigh(i,1.0);
199  }
200 
201  // Boundary conditions
202  size_t bc[dim];
203 
204  for (size_t i = 0; i < dim; i++)
205  bc[i] = PERIODIC;
206 
208 
209  // Initialize a dist vector
210  vd_initialize<dim>(vd, v_cl, k_int);
211 
212  vd.template ghost_get<0>();
213 
214  //Get a cell list hilb
215 
216  auto NN = vd.getCellList_hilb(r_cut);
217 
218  openfpm::vector<double> measures;
219 
220  double sum_cl_mean = 0;
221  double sum_cl_dev = 0;
222  for (size_t n = 0 ; n < N_VERLET_TEST; n++)
223  {measures.add(benchmark_get_celllist_hilb(NN,vd,r_cut));}
224  standard_deviation(measures,sum_cl_mean,sum_cl_dev);
225  //Average total time
226  cl_time_create_mean.get(r).add(sum_cl_mean);
227  cl_time_create_dev.get(r).add(sum_cl_dev);
228 
229  //Calculate forces
230 
231  double sum_fr_mean = 0;
232  double sum_fr_dev = 0;
233 
234  // Initialize SFC (we are only interested in force calculation)
235  NN.init_SFC();
236 
237  measures.clear();
238  for (size_t l = 0 ; l < N_VERLET_TEST; l++)
239  {measures.add(benchmark_calc_forces_hilb<dim>(NN,vd,r_cut));}
240  standard_deviation(measures,sum_fr_mean,sum_fr_dev);
241 
242  cl_time_force_mean.get(r).add(sum_fr_mean);
243  cl_time_force_dev.get(r).add(sum_fr_dev);
244 
245  if (v_cl.getProcessUnitID() == 0)
246  {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;}
247  }
248  }
249  }
250 }
251 
252 
253 BOOST_AUTO_TEST_CASE( vector_dist_celllist_random_test )
254 {
255  //Benchmark test for 2D and 3D
256  cell_list_comp_reorder_random_benchmark<3>(k_start,
257  k_min,
258  r_cutoff,
259  n_particles,
260  time_rand_mean,
261  time_rand_dev,
262  time_create_rand_mean,
263  time_create_rand_dev);
264 
265 
266  cell_list_comp_reorder_random_benchmark<2>(k_start,
267  k_min,
268  r_cutoff,
269  n_particles,
270  time_rand_2_mean,
271  time_rand_2_dev,
272  time_create_rand_2_mean,
273  time_create_rand_2_dev);
274 }
275 
276 BOOST_AUTO_TEST_CASE( vector_dist_celllist_hilbert_test )
277 {
278  //Benchmark test for 2D and 3D
279  cell_list_comp_reorder_hilbert_benchmark<3>(k_start,
280  k_min,
281  r_cutoff,
282  n_particles,
283  time_hilb_mean,
284  time_hilb_dev,
285  time_create_hilb_mean,
286  time_create_hilb_dev);
287 
288  cell_list_comp_reorder_hilbert_benchmark<2>(k_start,
289  k_min,
290  r_cutoff,
291  n_particles,
292  time_hilb_2_mean,
293  time_hilb_2_dev,
294  time_create_hilb_2_mean,
295  time_create_hilb_2_dev);
296 }
297 
301 template<unsigned int dim> void cell_list_comp_reorder_report(GoogleChart & cg,
302  openfpm::vector<float> & cl_r_cutoff,
303  openfpm::vector<size_t> & cl_n_particles,
304  openfpm::vector<openfpm::vector<double>> & cl_time_hilb_mean,
305  openfpm::vector<openfpm::vector<double>> & cl_time_rand_mean,
306  openfpm::vector<openfpm::vector<double>> & cl_time_hilb_dev,
307  openfpm::vector<openfpm::vector<double>> & cl_time_rand_dev,
308  openfpm::vector<openfpm::vector<double>> & cl_time_create_hilb_mean,
309  openfpm::vector<openfpm::vector<double>> & cl_time_create_rand_mean,
310  openfpm::vector<openfpm::vector<double>> & cl_time_create_hilb_dev,
311  openfpm::vector<openfpm::vector<double>> & cl_time_create_rand_dev,
312  double & warning_level,
313  double & norm)
314 {
315  cl_comp_normal_vs_hilbert_force_time<dim>(cg,
316  cl_n_particles,
317  cl_r_cutoff,
318  cl_time_hilb_mean,
319  cl_time_rand_mean,
320  cl_time_hilb_dev,
321  cl_time_rand_dev,
322  warning_level,
323  norm);
324 
325  cl_comp_normal_vs_hilbert_create_time<dim>(cg,
326  cl_n_particles,
327  cl_r_cutoff,
328  cl_time_create_hilb_mean,
329  cl_time_create_rand_mean,
330  cl_time_create_hilb_dev,
331  cl_time_create_rand_dev,
332  warning_level,
333  norm);
334 }
335 
336 BOOST_AUTO_TEST_CASE(vector_dist_cl_performance_write_report)
337 {
338  GoogleChart cg;
339 
340  double warning_level = 0;
341  double norm = 0;
342 
343  //Write report for 2D and 3D
344  cell_list_comp_reorder_report<3>(cg,
345  r_cutoff,
346  n_particles,
347  time_hilb_mean,
348  time_rand_mean,
349  time_hilb_dev,
350  time_rand_dev,
351  time_create_hilb_mean,
352  time_create_rand_mean,
353  time_create_hilb_dev,
354  time_create_rand_dev,
355  warning_level,
356  norm);
357 
358  cell_list_comp_reorder_report<2>(cg,
359  r_cutoff,
360  n_particles,
361  time_hilb_2_mean,
362  time_rand_2_mean,
363  time_rand_2_dev,
364  time_hilb_2_dev,
365  time_create_hilb_2_mean,
366  time_create_rand_2_mean,
367  time_create_hilb_2_dev,
368  time_create_rand_2_dev,
369  warning_level,
370  norm);
371 
372  addUpdtateTime(cg);
373 
374  if (create_vcluster().getProcessUnitID() == 0)
375  {
376  // write the xml report
377  pt.put("celllist.comp.warning",warning_level);
378 
379  cg.write("Celllist_comp_ord.html");
380  }
381 }
382 
383 
384 
385 BOOST_AUTO_TEST_SUITE_END()
386 
387 #endif /* SRC_VECTOR_VECTOR_DIST_CL_HILB_PERFORMANCE_TESTS_HPP_ */
void setHigh(int i, T val)
set the high interval of the box
Definition: Box.hpp:467
size_t size()
Stub size.
Definition: map_vector.hpp:70
Definition: Ghost.hpp:39
Implementation of VCluster class.
Definition: VCluster.hpp:36
Small class to produce graph with Google chart in HTML.
void setLow(int i, T val)
set the low interval of the box
Definition: Box.hpp:456
This class represent an N-dimensional box.
Definition: Box.hpp:56
Distributed vector.
size_t getProcessingUnits()
Get the total number of processors.