OpenFPM_pdata  4.1.0
Project that contain the implementation of distributed structures
 
Loading...
Searching...
No Matches
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/vector_dist.hpp"
13
14BOOST_AUTO_TEST_SUITE( vector_dist_dlb_test )
15
16template<typename vector_type>
17void 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 // coverty[dont_call]
33 vd0.getLastPos()[0] = ((float)rand())/RAND_MAX * 0.3;
34 // coverty[dont_call]
35 vd0.getLastPos()[1] = ((float)rand())/RAND_MAX * 0.3;
36 // coverty[dont_call]
37 vd0.getLastPos()[2] = ((float)rand())/RAND_MAX * 0.3;
38
39 // coverty[dont_call]
40 vd1.getLastPos()[0] = ((float)rand())/RAND_MAX * 0.3 + 0.1;
41 // coverty[dont_call]
42 vd1.getLastPos()[1] = ((float)rand())/RAND_MAX * 0.3 + 0.1;
43 // coverty[dont_call]
44 vd1.getLastPos()[2] = ((float)rand())/RAND_MAX * 0.3 + 0.1;
45
46 // coverty[dont_call]
47 vd2.getLastPos()[0] = ((float)rand())/RAND_MAX * 0.3 + 0.2;
48 // coverty[dont_call]
49 vd2.getLastPos()[1] = ((float)rand())/RAND_MAX * 0.3 + 0.2;
50 // coverty[dont_call]
51 vd2.getLastPos()[2] = ((float)rand())/RAND_MAX * 0.3 + 0.2;
52
53 // coverty[dont_call]
54 vd3.getLastPos()[0] = ((float)rand())/RAND_MAX * 0.3 + 0.3;
55 // coverty[dont_call]
56 vd3.getLastPos()[1] = ((float)rand())/RAND_MAX * 0.3 + 0.3;
57 // coverty[dont_call]
58 vd3.getLastPos()[2] = ((float)rand())/RAND_MAX * 0.3 + 0.3;
59 }
60 }
61
62 vd0.map();
63 vd0.template ghost_get<>();
64 vd1.map();
65 vd1.template ghost_get<>();
66 vd2.map();
67 vd2.template ghost_get<>();
68 vd3.map();
69 vd3.template ghost_get<>();
70
71 ModelSquare md;
72 md.factor = 1;
74 vd0.addComputationCosts(vd0,md);
75 vd0.addComputationCosts(vd1,md);
76 vd0.addComputationCosts(vd2,md);
77 vd0.addComputationCosts(vd3,md);
79
80 vd0.getDecomposition().decompose();
81
82 // Copy the decomposition back to the other
86
87 vd0.map();
88 vd1.map();
89 vd2.map();
90 vd3.map();
91
93 vd0.addComputationCosts(vd0,md);
94 vd0.addComputationCosts(vd1,md);
95 vd0.addComputationCosts(vd2,md);
96 vd0.addComputationCosts(vd3,md);
98
100 size_t load = vd0.getDecomposition().getDistribution().getProcessorLoad();
101 v_cl.allGather(load,loads);
102 v_cl.execute();
103
104 for (size_t i = 0 ; i < loads.size() ; i++)
105 {
106 float load_f = load;
107 float load_fc = loads.get(i);
108
109 BOOST_REQUIRE_CLOSE(load_f,load_fc,7.0);
110 }
111
112 Point<3,float> v({1.0,1.0,1.0});
113
114 for (size_t i = 0 ; i < 25 ; i++)
115 {
116 // move the particles by 0.1
117
118 {
119 auto it = vd0.getDomainIterator();
120
121 while (it.isNext())
122 {
123 auto p = it.get();
124
125 vd0.getPos(p)[0] += v.get(0) * 0.09;
126 vd0.getPos(p)[1] += v.get(1) * 0.09;
127 vd0.getPos(p)[2] += v.get(2) * 0.09;
128
129 ++it;
130 }
131 }
132
133 {
134 auto it = vd1.getDomainIterator();
135 while (it.isNext())
136 {
137 auto p = it.get();
138
139 vd1.getPos(p)[0] += v.get(0) * 0.06;
140 vd1.getPos(p)[1] += v.get(1) * 0.06;
141 vd1.getPos(p)[2] += v.get(2) * 0.06;
142
143 ++it;
144 }
145 }
146
147 {
148 auto it = vd2.getDomainIterator();
149 while (it.isNext())
150 {
151 auto p = it.get();
152
153 vd2.getPos(p)[0] += v.get(0) * 0.06;
154 vd2.getPos(p)[1] += v.get(1) * 0.06;
155 vd2.getPos(p)[2] += v.get(2) * 0.06;
156
157 ++it;
158 }
159 }
160
161 {
162 auto it = vd3.getDomainIterator();
163 while (it.isNext())
164 {
165 auto p = it.get();
166
167 vd3.getPos(p)[0] += v.get(0) * 0.06;
168 vd3.getPos(p)[1] += v.get(1) * 0.06;
169 vd3.getPos(p)[2] += v.get(2) * 0.06;
170
171 ++it;
172 }
173 }
174
175 vd0.map();
176 vd1.map();
177 vd2.map();
178 vd3.map();
179
180 ModelSquare md;
182 vd0.addComputationCosts(vd0,md);
183 vd0.addComputationCosts(vd1,md);
184 vd0.addComputationCosts(vd2,md);
185 vd0.addComputationCosts(vd3,md);
187
188 vd0.getDecomposition().redecompose(200);
189
190 // Copy the decomposition back to the other
194 vd0.map();
195 vd1.map();
196 vd2.map();
197 vd3.map();
198
199 vd0.template ghost_get<>();
200 vd1.template ghost_get<>();
201 vd2.template ghost_get<>();
202 vd3.template ghost_get<>();
203
205 vd0.addComputationCosts(vd0,md);
206 vd0.addComputationCosts(vd1,md);
207 vd0.addComputationCosts(vd2,md);
208 vd0.addComputationCosts(vd3,md);
210
212 size_t load = vd0.getDecomposition().getDistribution().getProcessorLoad();
213 v_cl.allGather(load,loads);
214 v_cl.execute();
215
216 for (size_t i = 0 ; i < loads.size() ; i++)
217 {
218 float load_f = load;
219 float load_fc = loads.get(i);
220
221 BOOST_REQUIRE_CLOSE(load_f,load_fc,10.0);
222 }
223 }
224}
225
226template<typename vector_type> void test_dlb_vector()
227{
228 Vcluster<> & v_cl = create_vcluster();
229
230 if (v_cl.getProcessingUnits() > 8)
231 return;
232
233 Box<3,double> domain({0.0,0.0,0.0},{1.0,1.0,1.0});
234 Ghost<3,double> g(0.1);
235 size_t bc[3] = {PERIODIC,PERIODIC,PERIODIC};
236
237 vector_type vd(0,domain,bc,g,DEC_GRAN(2048));
238
239 // Only processor 0 initialy add particles on a corner of a domain
240
241 if (v_cl.getProcessUnitID() == 0)
242 {
243 for(size_t i = 0 ; i < 50000 ; i++)
244 {
245 vd.add();
246
247 vd.getLastPos()[0] = ((double)rand())/RAND_MAX * 0.3;
248 vd.getLastPos()[1] = ((double)rand())/RAND_MAX * 0.3;
249 vd.getLastPos()[2] = ((double)rand())/RAND_MAX * 0.3;
250 }
251 }
252
253 vd.map();
254 vd.template ghost_get<>();
255
256 // Get the neighborhood of each particles
257
258 auto VV = vd.getVerlet(0.01);
259
260 // store the number of neighborhood for each particles
261
262 auto it = vd.getDomainIterator();
263
264 while (it.isNext())
265 {
266 auto p = it.get();
267
268 vd.template getProp<0>(p) = VV.getNNPart(p.getKey());
269
270 ++it;
271 }
272
273 ModelSquare md;
274 md.factor = 10;
275 vd.map();
276
277 vd.addComputationCosts(md);
278 vd.getDecomposition().decompose();
279 vd.map();
280
281 vd.addComputationCosts(md);
282
284 size_t load = vd.getDecomposition().getDistribution().getProcessorLoad();
285 v_cl.allGather(load,loads);
286 v_cl.execute();
287
288 for (size_t i = 0 ; i < loads.size() ; i++)
289 {
290 double load_f = load;
291 double load_fc = loads.get(i);
292
293 BOOST_REQUIRE_CLOSE(load_f,load_fc,7.0);
294 }
295
296 BOOST_REQUIRE(vd.size_local() != 0);
297
298 Point<3,double> v({1.0,1.0,1.0});
299
300 for (size_t i = 0 ; i < 25 ; i++)
301 {
302 // move the particles by 0.1
303
304 auto it = vd.getDomainIterator();
305
306 while (it.isNext())
307 {
308 auto p = it.get();
309
310 vd.getPos(p)[0] += v.get(0) * 0.09;
311 vd.getPos(p)[1] += v.get(1) * 0.09;
312 vd.getPos(p)[2] += v.get(2) * 0.09;
313
314 ++it;
315 }
316
317 vd.map();
318
319 vd.template ghost_get<>();
320
321 auto VV2 = vd.getVerlet(0.01);
322
323 auto it2 = vd.getDomainIterator();
324
325 bool match = true;
326 while (it2.isNext())
327 {
328 auto p = it2.get();
329
330 match &= vd.template getProp<0>(p) == VV2.getNNPart(p.getKey());
331
332 ++it2;
333 }
334
335 BOOST_REQUIRE_EQUAL(match,true);
336
337 ModelSquare md;
338 vd.addComputationCosts(md);
339 vd.getDecomposition().redecompose(200);
340 vd.map();
341
342 BOOST_REQUIRE(vd.size_local() != 0);
343
344 vd.template ghost_get<>();
345
346 vd.addComputationCosts(md);
347
349 size_t load = vd.getDecomposition().getDistribution().getProcessorLoad();
350 v_cl.allGather(load,loads);
351 v_cl.execute();
352
353 for (size_t i = 0 ; i < loads.size() ; i++)
354 {
355 double load_f = load;
356 double load_fc = loads.get(i);
357
358 BOOST_REQUIRE_CLOSE(load_f,load_fc,10.0);
359 }
360 }
361}
362
363
364template<typename vector_type> void test_dlb_multi_phase_vector()
365{
366 Vcluster<> & v_cl = create_vcluster();
367
368 if (v_cl.getProcessingUnits() > 8)
369 return;
370
371 Box<3,float> domain({0.0,0.0,0.0},{1.0,1.0,1.0});
372 Ghost<3,float> g(0.1);
373 size_t bc[3] = {PERIODIC,PERIODIC,PERIODIC};
374
375 vector_type vd0(0,domain,bc,g,DEC_GRAN(2048));
376 vector_type vd1(0,domain,bc,g,DEC_GRAN(2048));
377 vector_type vd2(0,domain,bc,g,DEC_GRAN(2048));
378 vector_type vd3(0,domain,bc,g,DEC_GRAN(2048));
379
380 mp_test_template(vd0,vd1,vd2,vd3);
381}
382
383
384
385template<typename vector_type> void test_dlb_multi_phase_v_vector()
386{
387 Vcluster<> & v_cl = create_vcluster();
388
389 if (v_cl.getProcessingUnits() > 8)
390 return;
391
392 Box<3,float> domain({0.0,0.0,0.0},{1.0,1.0,1.0});
393 Ghost<3,float> g(0.1);
394 size_t bc[3] = {PERIODIC,PERIODIC,PERIODIC};
395
397 {
398 vector_type vd0(0,domain,bc,g,DEC_GRAN(2048));
399 v_phases.add(vd0);
400 v_phases.add(vector_type(vd0.getDecomposition(),0));
401 v_phases.add(vector_type(vd0.getDecomposition(),0));
402 v_phases.add(vector_type(vd0.getDecomposition(),0));
403 }
404
405 auto & vd0 = v_phases.get(0);
406 auto & vd1 = v_phases.get(1);
407 auto & vd2 = v_phases.get(2);
408 auto & vd3 = v_phases.get(3);
409
410 mp_test_template(vd0,vd1,vd2,vd3);
411}
412
413BOOST_AUTO_TEST_CASE( vector_dist_dlb )
414{
415 test_dlb_vector<vector_dist<3,double,aggregate<double>>>();
416}
417
418BOOST_AUTO_TEST_CASE( vector_dist_dlb_multi_phase_test_part )
419{
420 test_dlb_multi_phase_vector<vector_dist<3,float,aggregate<float>>>();
421}
422
423BOOST_AUTO_TEST_CASE( vector_dist_dlb_multi_phase_v_test_part )
424{
425 test_dlb_multi_phase_v_vector<vector_dist<3,float,aggregate<float>>>();
426}
427
428BOOST_AUTO_TEST_CASE( vector_dist_dlb_metis_test_part )
429{
430 test_dlb_vector<vector_dist<3,
431 double,
434}
435
436BOOST_AUTO_TEST_SUITE_END()
437
438#endif /* SRC_VECTOR_VECTOR_DIST_DLB_TEST_HPP_ */
This class represent an N-dimensional box.
Definition Box.hpp:61
This class decompose a space into sub-sub-domains and distribute them across processors.
This class implement the point shape in an N-dimensional space.
Definition Point.hpp:28
void execute()
Execute all the requests.
size_t getProcessUnitID()
Get the process unit id.
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.
Implementation of VCluster class.
Definition VCluster.hpp:59
Implementation of 1-D std::vector like structure.
size_t size()
Stub size.
vect_dist_key_dx get()
Get the actual key.
Distributed vector.
auto getPos(vect_dist_key_dx vec_key) -> decltype(v_pos.template get< 0 >(vec_key.getKey()))
Get the position of an element.
vector_dist_iterator getDomainIterator() const
Get an iterator that traverse the particles in the domain.
void finalizeComputationCosts(Model md=Model(), size_t ts=1)
Add the computation cost on the decomposition coming from the particles.
void map(size_t opt=NONE)
It move all the particles that does not belong to the local processor to the respective processor.
void initializeComputationCosts()
Initialize the computational cost.
auto getLastPos() -> decltype(v_pos.template get< 0 >(0))
Get the position of the last element.
void add()
Add local particle.
void addComputationCosts(const self &vd, Model md=Model())
Add the computation cost on the decomposition coming from the particles.
Decomposition & getDecomposition()
Get the decomposition.
Linear model.
Definition LB_Model.hpp:48
aggregate of properties, from a list of object if create a struct that follow the OPENFPM native stru...