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_dlb_test.hpp
1 /*
2  * vector_dist_dlb_test.hpp
3  *
4  * Created on: Feb 21, 2017
5  * Author: i-bird
6  */
7 
8 #ifndef SRC_VECTOR_VECTOR_DIST_DLB_TEST_HPP_
9 #define SRC_VECTOR_VECTOR_DIST_DLB_TEST_HPP_
10 
11 #include "DLB/LB_Model.hpp"
12 #include "vector_dist.hpp"
13 
14 BOOST_AUTO_TEST_SUITE( vector_dist_dlb_test )
15 
16 template<typename vector_type>
17 void mp_test_template(vector_type & vd0, vector_type & vd1, vector_type & vd2, vector_type & vd3)
18 {
19  Vcluster & v_cl = create_vcluster();
20 
21  // Only processor 0 initialy add particles on a corner of a domain
22 
23  if (v_cl.getProcessUnitID() == 0)
24  {
25  for(size_t i = 0 ; i < 50000 ; i++)
26  {
27  vd0.add();
28  vd1.add();
29  vd2.add();
30  vd3.add();
31 
32  vd0.getLastPos()[0] = ((float)rand())/RAND_MAX * 0.3;
33  vd0.getLastPos()[1] = ((float)rand())/RAND_MAX * 0.3;
34  vd0.getLastPos()[2] = ((float)rand())/RAND_MAX * 0.3;
35 
36  vd1.getLastPos()[0] = ((float)rand())/RAND_MAX * 0.3 + 0.1;
37  vd1.getLastPos()[1] = ((float)rand())/RAND_MAX * 0.3 + 0.1;
38  vd1.getLastPos()[2] = ((float)rand())/RAND_MAX * 0.3 + 0.1;
39 
40  vd2.getLastPos()[0] = ((float)rand())/RAND_MAX * 0.3 + 0.2;
41  vd2.getLastPos()[1] = ((float)rand())/RAND_MAX * 0.3 + 0.2;
42  vd2.getLastPos()[2] = ((float)rand())/RAND_MAX * 0.3 + 0.2;
43 
44  vd3.getLastPos()[0] = ((float)rand())/RAND_MAX * 0.3 + 0.3;
45  vd3.getLastPos()[1] = ((float)rand())/RAND_MAX * 0.3 + 0.3;
46  vd3.getLastPos()[2] = ((float)rand())/RAND_MAX * 0.3 + 0.3;
47  }
48  }
49 
50  vd0.map();
51  vd0.template ghost_get<>();
52  vd1.map();
53  vd1.template ghost_get<>();
54  vd2.map();
55  vd2.template ghost_get<>();
56  vd3.map();
57  vd3.template ghost_get<>();
58 
59  ModelSquare md;
60  md.factor = 1;
61  vd0.initializeComputationCosts();
62  vd0.addComputationCosts(vd0,md);
63  vd0.addComputationCosts(vd1,md);
64  vd0.addComputationCosts(vd2,md);
65  vd0.addComputationCosts(vd3,md);
66  vd0.finalizeComputationCosts();
67 
68  vd0.getDecomposition().decompose();
69 
70  // Copy the decomposition back to the other
71  vd1.getDecomposition() = vd0.getDecomposition();
72  vd2.getDecomposition() = vd0.getDecomposition();
73  vd3.getDecomposition() = vd0.getDecomposition();
74 
75  vd0.map();
76  vd1.map();
77  vd2.map();
78  vd3.map();
79 
80  vd0.initializeComputationCosts();
81  vd0.addComputationCosts(vd0,md);
82  vd0.addComputationCosts(vd1,md);
83  vd0.addComputationCosts(vd2,md);
84  vd0.addComputationCosts(vd3,md);
85  vd0.finalizeComputationCosts();
86 
88  size_t load = vd0.getDecomposition().getDistribution().getProcessorLoad();
89  v_cl.allGather(load,loads);
90  v_cl.execute();
91 
92  for (size_t i = 0 ; i < loads.size() ; i++)
93  {
94  float load_f = load;
95  float load_fc = loads.get(i);
96 
97  BOOST_REQUIRE_CLOSE(load_f,load_fc,7.0);
98  }
99 
100  Point<3,float> v({1.0,1.0,1.0});
101 
102  for (size_t i = 0 ; i < 25 ; i++)
103  {
104  // move the particles by 0.1
105 
106  {
107  auto it = vd0.getDomainIterator();
108 
109  while (it.isNext())
110  {
111  auto p = it.get();
112 
113  vd0.getPos(p)[0] += v.get(0) * 0.09;
114  vd0.getPos(p)[1] += v.get(1) * 0.09;
115  vd0.getPos(p)[2] += v.get(2) * 0.09;
116 
117  ++it;
118  }
119  }
120 
121  {
122  auto it = vd1.getDomainIterator();
123  while (it.isNext())
124  {
125  auto p = it.get();
126 
127  vd1.getPos(p)[0] += v.get(0) * 0.06;
128  vd1.getPos(p)[1] += v.get(1) * 0.06;
129  vd1.getPos(p)[2] += v.get(2) * 0.06;
130 
131  ++it;
132  }
133  }
134 
135  {
136  auto it = vd2.getDomainIterator();
137  while (it.isNext())
138  {
139  auto p = it.get();
140 
141  vd2.getPos(p)[0] += v.get(0) * 0.06;
142  vd2.getPos(p)[1] += v.get(1) * 0.06;
143  vd2.getPos(p)[2] += v.get(2) * 0.06;
144 
145  ++it;
146  }
147  }
148 
149  {
150  auto it = vd3.getDomainIterator();
151  while (it.isNext())
152  {
153  auto p = it.get();
154 
155  vd3.getPos(p)[0] += v.get(0) * 0.06;
156  vd3.getPos(p)[1] += v.get(1) * 0.06;
157  vd3.getPos(p)[2] += v.get(2) * 0.06;
158 
159  ++it;
160  }
161  }
162 
163  vd0.map();
164  vd1.map();
165  vd2.map();
166  vd3.map();
167 
168  ModelSquare md;
169  vd0.initializeComputationCosts();
170  vd0.addComputationCosts(vd0,md);
171  vd0.addComputationCosts(vd1,md);
172  vd0.addComputationCosts(vd2,md);
173  vd0.addComputationCosts(vd3,md);
174  vd0.finalizeComputationCosts();
175 
176  vd0.getDecomposition().redecompose(200);
177 
178  // Copy the decomposition back to the other
179  vd1.getDecomposition() = vd0.getDecomposition();
180  vd2.getDecomposition() = vd0.getDecomposition();
181  vd3.getDecomposition() = vd0.getDecomposition();
182  vd0.map();
183  vd1.map();
184  vd2.map();
185  vd3.map();
186 
187  vd0.template ghost_get<>();
188  vd1.template ghost_get<>();
189  vd2.template ghost_get<>();
190  vd3.template ghost_get<>();
191 
192  vd0.initializeComputationCosts();
193  vd0.addComputationCosts(vd0,md);
194  vd0.addComputationCosts(vd1,md);
195  vd0.addComputationCosts(vd2,md);
196  vd0.addComputationCosts(vd3,md);
197  vd0.finalizeComputationCosts();
198 
200  size_t load = vd0.getDecomposition().getDistribution().getProcessorLoad();
201  v_cl.allGather(load,loads);
202  v_cl.execute();
203 
204  for (size_t i = 0 ; i < loads.size() ; i++)
205  {
206  float load_f = load;
207  float load_fc = loads.get(i);
208 
209  BOOST_REQUIRE_CLOSE(load_f,load_fc,10.0);
210  }
211  }
212 }
213 
214 template<typename vector_type> void test_dlb_vector()
215 {
216  Vcluster & v_cl = create_vcluster();
217 
218  if (v_cl.getProcessingUnits() > 8)
219  return;
220 
221  Box<3,float> domain({0.0,0.0,0.0},{1.0,1.0,1.0});
222  Ghost<3,float> g(0.1);
223  size_t bc[3] = {PERIODIC,PERIODIC,PERIODIC};
224 
225  vector_type vd(0,domain,bc,g,DEC_GRAN(2048));
226 
227  // Only processor 0 initialy add particles on a corner of a domain
228 
229  if (v_cl.getProcessUnitID() == 0)
230  {
231  for(size_t i = 0 ; i < 50000 ; i++)
232  {
233  vd.add();
234 
235  vd.getLastPos()[0] = ((float)rand())/RAND_MAX * 0.3;
236  vd.getLastPos()[1] = ((float)rand())/RAND_MAX * 0.3;
237  vd.getLastPos()[2] = ((float)rand())/RAND_MAX * 0.3;
238  }
239  }
240 
241  vd.map();
242  vd.template ghost_get<>();
243 
244  ModelSquare md;
245  md.factor = 10;
246  vd.addComputationCosts(md);
247  vd.getDecomposition().decompose();
248  vd.map();
249 
250 
251  vd.addComputationCosts(md);
252 
254  size_t load = vd.getDecomposition().getDistribution().getProcessorLoad();
255  v_cl.allGather(load,loads);
256  v_cl.execute();
257 
258  for (size_t i = 0 ; i < loads.size() ; i++)
259  {
260  float load_f = load;
261  float load_fc = loads.get(i);
262 
263  BOOST_REQUIRE_CLOSE(load_f,load_fc,7.0);
264  }
265 
266  BOOST_REQUIRE(vd.size_local() != 0);
267 
268  Point<3,float> v({1.0,1.0,1.0});
269 
270  for (size_t i = 0 ; i < 25 ; i++)
271  {
272  // move the particles by 0.1
273 
274  auto it = vd.getDomainIterator();
275 
276  while (it.isNext())
277  {
278  auto p = it.get();
279 
280  vd.getPos(p)[0] += v.get(0) * 0.09;
281  vd.getPos(p)[1] += v.get(1) * 0.09;
282  vd.getPos(p)[2] += v.get(2) * 0.09;
283 
284  ++it;
285  }
286  vd.map();
287 
288  ModelSquare md;
289  vd.addComputationCosts(md);
290  vd.getDecomposition().redecompose(200);
291  vd.map();
292 
293  BOOST_REQUIRE(vd.size_local() != 0);
294 
295  vd.template ghost_get<>();
296 
297  vd.addComputationCosts(md);
298 
300  size_t load = vd.getDecomposition().getDistribution().getProcessorLoad();
301  v_cl.allGather(load,loads);
302  v_cl.execute();
303 
304  for (size_t i = 0 ; i < loads.size() ; i++)
305  {
306  float load_f = load;
307  float load_fc = loads.get(i);
308 
309  BOOST_REQUIRE_CLOSE(load_f,load_fc,10.0);
310  }
311  }
312 }
313 
314 
315 template<typename vector_type> void test_dlb_multi_phase_vector()
316 {
317  Vcluster & v_cl = create_vcluster();
318 
319  if (v_cl.getProcessingUnits() > 8)
320  return;
321 
322  Box<3,float> domain({0.0,0.0,0.0},{1.0,1.0,1.0});
323  Ghost<3,float> g(0.1);
324  size_t bc[3] = {PERIODIC,PERIODIC,PERIODIC};
325 
326  vector_type vd0(0,domain,bc,g,DEC_GRAN(2048));
327  vector_type vd1(0,domain,bc,g,DEC_GRAN(2048));
328  vector_type vd2(0,domain,bc,g,DEC_GRAN(2048));
329  vector_type vd3(0,domain,bc,g,DEC_GRAN(2048));
330 
331  mp_test_template(vd0,vd1,vd2,vd3);
332 }
333 
334 
335 
336 template<typename vector_type> void test_dlb_multi_phase_v_vector()
337 {
338  Vcluster & v_cl = create_vcluster();
339 
340  if (v_cl.getProcessingUnits() > 8)
341  return;
342 
343  Box<3,float> domain({0.0,0.0,0.0},{1.0,1.0,1.0});
344  Ghost<3,float> g(0.1);
345  size_t bc[3] = {PERIODIC,PERIODIC,PERIODIC};
346 
348  {
349  vector_type vd0(0,domain,bc,g,DEC_GRAN(2048));
350  v_phases.add(vd0);
351  v_phases.add(vector_type(vd0.getDecomposition(),0));
352  v_phases.add(vector_type(vd0.getDecomposition(),0));
353  v_phases.add(vector_type(vd0.getDecomposition(),0));
354  }
355 
356  auto & vd0 = v_phases.get(0);
357  auto & vd1 = v_phases.get(1);
358  auto & vd2 = v_phases.get(2);
359  auto & vd3 = v_phases.get(3);
360 
361  mp_test_template(vd0,vd1,vd2,vd3);
362 }
363 
364 BOOST_AUTO_TEST_CASE( vector_dist_dlb_test_part )
365 {
366  test_dlb_vector<vector_dist<3,float,aggregate<float>>>();
367 }
368 
369 BOOST_AUTO_TEST_CASE( vector_dist_dlb_multi_phase_test_part )
370 {
371  test_dlb_multi_phase_vector<vector_dist<3,float,aggregate<float>>>();
372 }
373 
374 BOOST_AUTO_TEST_CASE( vector_dist_dlb_multi_phase_v_test_part )
375 {
376  test_dlb_multi_phase_v_vector<vector_dist<3,float,aggregate<float>>>();
377 }
378 
379 BOOST_AUTO_TEST_CASE( vector_dist_dlb_metis_test_part )
380 {
381  test_dlb_vector<vector_dist<3,
382  float,
387 }
388 
389 BOOST_AUTO_TEST_SUITE_END()
390 
391 #endif /* SRC_VECTOR_VECTOR_DIST_DLB_TEST_HPP_ */
Transform the boost::fusion::vector into memory specification (memory_traits)
Definition: memory_conf.hpp:93
size_t getProcessUnitID()
Get the process unit id.
void execute()
Execute all the requests.
size_t size()
Stub size.
Definition: map_vector.hpp:70
This class implement the point shape in an N-dimensional space.
Definition: Point.hpp:22
Definition: Ghost.hpp:39
Implementation of VCluster class.
Definition: VCluster.hpp:36
This class decompose a space into sub-sub-domains and distribute them across processors.
Linear model.
Definition: LB_Model.hpp:47
Distributed vector.
aggregate of properties, from a list of object if create a struct that follow the OPENFPM native stru...
Definition: aggregate.hpp:81
size_t getProcessingUnits()
Get the total number of processors.
bool allGather(T &send, openfpm::vector< T, Mem, gr > &v)
Gather the data from all processors.