OpenFPM_pdata  4.1.0
Project that contain the implementation of distributed structures
verlet_performance_tests.hpp
1 /*
2  * vector_dist_verlet_performance_tests.hpp
3  *
4  * Created on: Mar 9, 2016
5  * Author: Yaroslav Zaluzhnyi
6  */
7 
8 #ifndef SRC_VECTOR_VECTOR_DIST_VERLET_PERFORMANCE_TESTS_HPP_
9 #define SRC_VECTOR_VECTOR_DIST_VERLET_PERFORMANCE_TESTS_HPP_
10 
11 #include "util/stat/common_statistics.hpp"
12 
13 // Property tree
15 {
16  boost::property_tree::ptree graphs;
17 };
18 
19 report_verlet_tests report_vl;
20 
27 void print_test_v(std::string test, size_t sz)
28 {
29  if (create_vcluster().getProcessUnitID() == 0)
30  std::cout << test << " " << sz << "\n";
31 }
32 
33 BOOST_AUTO_TEST_SUITE( verletlist_performance_test )
34 
35 
37 // Cut-off radiuses. Can be put different number of values
38 openfpm::vector<float> r_cutoff {0.004, 0.007, 0.01};
39 // Orders of a curve. Can be put different number of values
40 // The starting amount of particles (remember that this number is multiplied by number of processors you use for testing)
41 size_t k_start = 100000;
42 // The minimal amount of particles
43 size_t k_min = 15000;
44 // Ghost part of distributed vector
45 
47 
48 // Numbers of particles vector
49 openfpm::vector<size_t> n_particles;
50 
54 template<unsigned int dim> void vd_verlet_random_benchmark(size_t k_start,
55  size_t k_min,
56  openfpm::vector<float> & r_cutoff,
57  openfpm::vector<size_t> & n_particles)
58 {
59  std::string str("Testing " + std::to_string(dim) + "D vector no-order, Verlet-list");
60  print_test_v(str,0);
61 
62  {
63  //For different r_cut
64  for (size_t r = 0; r < r_cutoff.size(); r++ )
65  {
66  Vcluster<> & v_cl = create_vcluster();
67 
68  //Cut-off radius
69  float r_cut = r_cutoff.get(r);
70 
71  report_vl.graphs.put("performance.verletlist.getVerletList" + std::to_string(dim) + "D(" + std::to_string(r) + ").rcut",r_cut);
72 
73  //Number of particles
74  size_t k = k_start * v_cl.getProcessingUnits();
75 
76  //Counter number for amounts of particles
77  size_t k_count = 1 + log2(k/k_min);
78 
79  int c = 0;
80 
81  for (size_t k_int = k ; k_int >= k_min ; k_int/=2 )
82  {
83  BOOST_TEST_CHECKPOINT( "Testing " << dim << "D vector without an Hilbert curve reordering k=" << k_int );
84 
85  report_vl.graphs.put("performance.verletlist.getVerletList" + std::to_string(dim) + "D(" + std::to_string(r) + ").npart(" + std::to_string(c) + ").n",k_int);
86  report_vl.graphs.put("performance.verletlist.calc_forces" + std::to_string(dim) + "D(" + std::to_string(r) + ").npart(" + std::to_string(c) + ").n",k_int);
87 
88  if (n_particles.size() < k_count)
89  n_particles.add(k_int);
90 
91  Box<dim,float> box;
92 
93  for (size_t i = 0; i < dim; i++)
94  {
95  box.setLow(i,0.0);
96  box.setHigh(i,1.0);
97  }
98 
99  // Boundary conditions
100  size_t bc[dim];
101  for (size_t i = 0; i < dim; i++)
102  bc[i] = PERIODIC;
103 
105 
106  // Initialize a dist vector
107  vd_initialize<dim>(vd, v_cl);
108 
109  vd.template ghost_get<0>();
110 
111  //Get verlet list
112 
113  openfpm::vector<double> measures;
114  double sum_verlet_mean = 0;
115  double sum_verlet_dev = 0;
116  for (size_t n = 0 ; n < N_STAT_TEST; n++)
117  {measures.add(benchmark_get_verlet(vd,r_cut));}
118  standard_deviation(measures,sum_verlet_mean,sum_verlet_dev);
119 
120  report_vl.graphs.put("performance.verletlist.getVerletList" + std::to_string(dim) + "D(" + std::to_string(r) + ").npart(" + std::to_string(c) + ").mean",sum_verlet_mean);
121  report_vl.graphs.put("performance.verletlist.getVerletList" + std::to_string(dim) + "D(" + std::to_string(r) + ").npart(" + std::to_string(c) + ").dev",sum_verlet_dev);
122 
123  //Calculate forces
124 
125  auto NN = vd.getCellList(r_cut);
126  double sum_fr_mean = 0;
127  double sum_fr_dev = 0;
128 
129  measures.clear();
130  for (size_t l = 0 ; l < N_STAT_TEST ; l++)
131  {measures.add(benchmark_calc_forces<dim>(NN,vd,r_cut));}
132  standard_deviation(measures,sum_fr_mean,sum_fr_dev);
133 
134  report_vl.graphs.put("performance.verletlist.calc_forces" + std::to_string(dim) + "D(" + std::to_string(r) + ").npart(" + std::to_string(c) + ").mean",sum_fr_mean);
135  report_vl.graphs.put("performance.verletlist.calc_forces" + std::to_string(dim) + "D(" + std::to_string(r) + ").npart(" + std::to_string(c) + ").dev",sum_fr_dev);
136 
137  if (v_cl.getProcessUnitID() == 0)
138  {std::cout << "Particles: " << k_int << "," << "cut-off: " << r_cut << " time to construct a Verlet list = " << sum_verlet_mean << " dev: " << sum_verlet_dev << " calculate force = " << sum_fr_mean << " dev: " << sum_fr_dev << std::endl;}
139 
140  c++;
141  }
142  }
143  }
144 }
145 
146 
147 BOOST_AUTO_TEST_CASE( vector_dist_verlet_test )
148 {
149  //Benchmark test for 2D and 3D
150  vd_verlet_random_benchmark<3>(k_start,k_min,r_cutoff,n_particles);
151  vd_verlet_random_benchmark<2>(k_start,k_min,r_cutoff,n_particles);
152 }
153 
154 BOOST_AUTO_TEST_CASE(vector_dist_verlet_performance_write_report)
155 {
156  //For different r_cut
157  for (size_t r = 0; r < r_cutoff.size(); r++ )
158  {
159  report_vl.graphs.put("graphs.graph(" + std::to_string(r) + ").type","line");
160  report_vl.graphs.add("graphs.graph(" + std::to_string(r) + ").title","getVerletList 3D performance r_cut=" + std::to_string(r_cutoff.get(r)));
161  report_vl.graphs.add("graphs.graph(" + std::to_string(r) + ").x.title","number of particles");
162  report_vl.graphs.add("graphs.graph(" + std::to_string(r) + ").y.title","Time seconds");
163  report_vl.graphs.add("graphs.graph(" + std::to_string(r) + ").y.data(0).source","performance.verletlist.getVerletList3D(" + std::to_string(r) + ").npart(#).mean");
164  report_vl.graphs.add("graphs.graph(" + std::to_string(r) + ").x.data(0).source","performance.verletlist.getVerletList3D(" + std::to_string(r) + ").npart(#).n");
165  report_vl.graphs.add("graphs.graph(" + std::to_string(r) + ").y.data(0).title","Verlet-list");
166  report_vl.graphs.add("graphs.graph(" + std::to_string(r) + ").options.log_y","true");
167  }
168 
169  //For different r_cut
170  for (size_t r = 0; r < r_cutoff.size(); r++ )
171  {
172  report_vl.graphs.put("graphs.graph(" + std::to_string(r_cutoff.size() + r) + ").type","line");
173  report_vl.graphs.add("graphs.graph(" + std::to_string(r_cutoff.size() + r) + ").title","calc_force 3D performance r_cut=" + std::to_string(r_cutoff.get(r)));
174  report_vl.graphs.add("graphs.graph(" + std::to_string(r_cutoff.size() + r) + ").x.title","number of particles");
175  report_vl.graphs.add("graphs.graph(" + std::to_string(r_cutoff.size() + r) + ").y.title","Time seconds");
176  report_vl.graphs.add("graphs.graph(" + std::to_string(r_cutoff.size() + r) + ").y.data(0).source","performance.verletlist.calc_forces3D(" + std::to_string(r) + ").npart(#).mean");
177  report_vl.graphs.add("graphs.graph(" + std::to_string(r_cutoff.size() + r) + ").x.data(0).source","performance.verletlist.calc_forces3D(" + std::to_string(r) + ").npart(#).n");
178  report_vl.graphs.add("graphs.graph(" + std::to_string(r_cutoff.size() + r) + ").y.data(0).title","Verlet-list");
179  report_vl.graphs.add("graphs.graph(" + std::to_string(r_cutoff.size() + r) + ").options.log_y","true");
180  }
181 
182  //For different r_cut
183  for (size_t r = 0; r < r_cutoff.size(); r++ )
184  {
185  report_vl.graphs.put("graphs.graph(" + std::to_string(2*r_cutoff.size() + r) + ").type","line");
186  report_vl.graphs.add("graphs.graph(" + std::to_string(2*r_cutoff.size() + r) + ").title","getVerletList 2D performance r_cut=" + std::to_string(r_cutoff.get(r)));
187  report_vl.graphs.add("graphs.graph(" + std::to_string(2*r_cutoff.size() + r) + ").x.title","number of particles");
188  report_vl.graphs.add("graphs.graph(" + std::to_string(2*r_cutoff.size() + r) + ").y.title","Time seconds");
189  report_vl.graphs.add("graphs.graph(" + std::to_string(2*r_cutoff.size() + r) + ").y.data(0).source","performance.verletlist.getVerletList2D(" + std::to_string(r) + ").npart(#).mean");
190  report_vl.graphs.add("graphs.graph(" + std::to_string(2*r_cutoff.size() + r) + ").x.data(0).source","performance.verletlist.getVerletList2D(" + std::to_string(r) + ").npart(#).n");
191  report_vl.graphs.add("graphs.graph(" + std::to_string(2*r_cutoff.size() + r) + ").y.data(0).title","Verlet-list");
192  report_vl.graphs.add("graphs.graph(" + std::to_string(2*r_cutoff.size() + r) + ").options.log_y","true");
193  }
194 
195  //For different r_cut
196  for (size_t r = 0; r < r_cutoff.size(); r++ )
197  {
198  report_vl.graphs.put("graphs.graph(" + std::to_string(3*r_cutoff.size() + r) + ").type","line");
199  report_vl.graphs.add("graphs.graph(" + std::to_string(3*r_cutoff.size() + r) + ").title","calc_force 2D performance r_cut=" + std::to_string(r_cutoff.get(r)));
200  report_vl.graphs.add("graphs.graph(" + std::to_string(3*r_cutoff.size() + r) + ").x.title","number of particles");
201  report_vl.graphs.add("graphs.graph(" + std::to_string(3*r_cutoff.size() + r) + ").y.title","Time seconds");
202  report_vl.graphs.add("graphs.graph(" + std::to_string(3*r_cutoff.size() + r) + ").y.data(0).source","performance.verletlist.calc_forces2D(" + std::to_string(r) + ").npart(#).mean");
203  report_vl.graphs.add("graphs.graph(" + std::to_string(3*r_cutoff.size() + r) + ").x.data(0).source","performance.verletlist.calc_forces2D(" + std::to_string(r) + ").npart(#).n");
204  report_vl.graphs.add("graphs.graph(" + std::to_string(3*r_cutoff.size() + r) + ").y.data(0).title","Verlet-list");
205  report_vl.graphs.add("graphs.graph(" + std::to_string(3*r_cutoff.size() + r) + ").options.log_y","true");
206  }
207 
208  if (create_vcluster().rank() == 0)
209  {
210  boost::property_tree::xml_writer_settings<std::string> settings(' ', 4);
211  boost::property_tree::write_xml("verletlist_performance.xml", report_vl.graphs,std::locale(),settings);
212 
213  std::string file_xml_ref(test_dir);
214  file_xml_ref += std::string("/openfpm_pdata/verletlist_performance_ref.xml");
215 
216  GoogleChart cg;
217 
218  StandardXMLPerformanceGraph("verletlist_performance.xml",file_xml_ref,cg);
219 
220  addUpdateTime(cg,create_vcluster().size(),"pdata","verletlist_performance");
221 
222  if (create_vcluster().getProcessUnitID() == 0)
223  {cg.write("verletlist_performance.html");}
224  }
225 }
226 
227 BOOST_AUTO_TEST_SUITE_END()
228 
229 #endif /* SRC_VECTOR_VECTOR_DIST_VERLET_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