OpenFPM_pdata  4.1.0
Project that contain the implementation of distributed structures
vector_dist_gg_map_performance.hpp
1 #ifndef VECTOR_DIST_GG_MAP_PERFORMANCE_HPP_
2 
3 #include "Vector/vector_dist.hpp"
4 #include "data_type/aggregate.hpp"
5 #include "Plot/GoogleChart.hpp"
6 #include <functional>
7 
8 // Property tree
10 {
11  boost::property_tree::ptree graphs;
12 };
13 
15 
17 
18 // The starting amount of particles (remember that this number is multiplied by number of processors you use for testing)
19 size_t k_start = 100000;
20 // The minimal amount of particles
21 size_t k_min = 15000;
22 
24 
25 BOOST_AUTO_TEST_SUITE( vector_gg_map_performance_test )
26 
27 
28 // Numbers of particles vector
29 openfpm::vector<size_t> n_particles;
30 
31 template<unsigned int dim>
32 double benchmark_map(size_t k_int, Vcluster<HeapMemory> & v_cl)
33 {
34  Box<dim,float> box;
35 
36  for (size_t i = 0; i < dim; i++)
37  {
38  box.setLow(i,0.0);
39  box.setHigh(i,1.0);
40  }
41 
42  // Boundary conditions
43  size_t bc[dim];
44 
45  for (size_t i = 0; i < dim; i++)
46  {bc[i] = PERIODIC;}
47 
48  vector_dist<dim,float, aggregate<float[dim]> > vd(v_cl.size()*v_cl.size()*k_int,box,bc,Ghost<dim,float>(0.1));
49 
50  auto & dec = vd.getDecomposition();
51 
52  int start = 0;
53  int stop = k_int;
54 
55  for (size_t i = 0 ; i < v_cl.size() ; i++)
56  {
57  if (i == v_cl.rank())
58  {continue;}
59 
60  auto & nn_box = dec.getNearSubdomains(i);
61 
62  if (nn_box.size() != 0)
63  {
64  // generate all particles in the near processor
65 
66  vd_initialize_box_nomap<dim>(vd,nn_box.get(0),v_cl,start,stop);
67 
68  start += k_int;
69  stop += k_int;
70  }
71  }
72 
73  //Timer
74  timer t;
75  t.start();
76 
77  // benckmark map
78  vd.map();
79 
80  t.stop();
81 
82  return t.getwct();
83 }
84 
85 
89 template<unsigned int dim>
90 void vector_gg_map_benchmark(size_t cl_k_start,
91  size_t cl_k_min,
92  openfpm::vector<size_t> & cl_n_particles)
93 {
94  std::string str("Testing " + std::to_string(dim) + "D vector, no-order, map ghost_get");
95  print_test_v(str,0);
96 
97  {
98 
99  Vcluster<> & v_cl = create_vcluster();
100 
101  if (v_cl.size() != 3)
102  {return;}
103 
104  //Number of particles
105  size_t k = cl_k_start * v_cl.getProcessingUnits();
106 
107  //Counter number for amounts of particles
108  size_t k_count = 1 + log2(k/cl_k_min);
109 
110  int c = 0;
111 
112  //For different number of particles
113  for (size_t k_int = k ; k_int >= cl_k_min ; k_int/=2 )
114  {
115  BOOST_TEST_CHECKPOINT( "Testing " << dim << "D vector without an Hilbert curve reordering k=" << k_int );
116 
117  report_ggm.graphs.put("performance.map_" + std::to_string(dim) + "D.npart(" + std::to_string(c) + ").n",k_int);
118 
119  if (cl_n_particles.size() < k_count)
120  {cl_n_particles.add(k_int);}
121 
122  openfpm::vector<double> measures;
123  double sum_map_mean = 0.0;
124  double sum_map_dev = 0.0;
125  for (size_t h = 0 ; h < N_STAT_TEST; h++)
126  {measures.add(benchmark_map<dim>(k_int,v_cl));}
127  standard_deviation(measures,sum_map_mean,sum_map_dev);
128 
129  report_ggm.graphs.put("performance.map_" + std::to_string(dim) + "D.npart(" + std::to_string(c) + ").mean",sum_map_mean);
130  report_ggm.graphs.put("performance.map_" + std::to_string(dim) + "D.npart(" + std::to_string(c) + ").dev",sum_map_dev);
131 
132  c++;
133  }
134  }
135 }
136 
137 
138 
139 BOOST_AUTO_TEST_CASE( vector_dist_map_test )
140 {
141  //Benchmark test for 2D and 3D
142  vector_gg_map_benchmark<3>(k_start,k_min,n_particles);
143  vector_gg_map_benchmark<2>(k_start,k_min,n_particles);
144 }
145 
146 
147 BOOST_AUTO_TEST_CASE(vector_dist_gg_map_performance_write_report)
148 {
149  // Create a graphs
150 
151  report_ggm.graphs.put("graphs.graph.type","line");
152  report_ggm.graphs.add("graphs.graph.title","Map performance");
153  report_ggm.graphs.add("graphs.graph.x.title","number of particles");
154  report_ggm.graphs.add("graphs.graph.y.title","Time seconds");
155  report_ggm.graphs.add("graphs.graph.y.data(0).source","performance.map_3D.npart(#).mean");
156  report_ggm.graphs.add("graphs.graph.x.data(0).source","performance.map_3D.npart(#).n");
157  report_ggm.graphs.add("graphs.graph.y.data(0).title","Map function");
158  report_ggm.graphs.add("graphs.graph.options.log_y","false");
159 
160  if (create_vcluster().rank() == 0)
161  {
162  boost::property_tree::xml_writer_settings<std::string> settings(' ', 4);
163  boost::property_tree::write_xml("particles_map_performance.xml", report_ggm.graphs,std::locale(),settings);
164 
165  std::string file_xml_ref(test_dir);
166  file_xml_ref += std::string("/openfpm_pdata/particles_map_performance_ref.xml");
167 
168  GoogleChart cg;
169 
170  StandardXMLPerformanceGraph("particles_map_performance.xml",file_xml_ref,cg);
171 
172  addUpdateTime(cg,create_vcluster().size(),"pdata","particles_map_performance");
173 
174  if (create_vcluster().getProcessUnitID() == 0)
175  {cg.write("particles_map_performance.html");}
176  }
177 }
178 
179 BOOST_AUTO_TEST_SUITE_END()
180 
181 #endif
182 
Decomposition & getDecomposition()
Get the decomposition.
size_t size()
Stub size.
Definition: map_vector.hpp:211
double getwct()
Return the elapsed real time.
Definition: timer.hpp:130
Definition: Ghost.hpp:39
__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.
size_t rank()
Get the process unit id.
__device__ __host__ void setLow(int i, T val)
set the low interval of the box
Definition: Box.hpp:533
void start()
Start the timer.
Definition: timer.hpp:90
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.
size_t size()
Get the total number of processors.
Class for cpu time benchmarking.
Definition: timer.hpp:27
void stop()
Stop the timer.
Definition: timer.hpp:119