OpenFPM_pdata  4.1.0
Project that contain the implementation of distributed structures
vector_dist_gpu_MP_tests.cu
1 #define BOOST_TEST_DYN_LINK
2 #include <boost/test/unit_test.hpp>
3 
4 #include "Vector/vector_dist_multiphase_functions.hpp"
5 #include "VCluster/VCluster.hpp"
6 #include "Vector/vector_dist.hpp"
7 
8 BOOST_AUTO_TEST_SUITE( vector_dist_multiphase_gpu_test )
9 
10 BOOST_AUTO_TEST_CASE( vector_dist_multiphase_gpu_cell_list_test )
11 {
12  if (create_vcluster().getProcessingUnits() > 24)
13  return;
14 
15  size_t sz[3] = {60,60,40};
16 
17  // The domain
18  Box<3,float> box({-1000.0,-1000.0,-1000.0},{2000.0,2000.0,1000.0});
19 
20  // Boundary conditions
21  size_t bc[3]={PERIODIC,PERIODIC,PERIODIC};
22 
23  float r_cut = 51.0;
24 
25  // ghost, big enough to contain the interaction radius
26  Ghost<3,float> ghost(r_cut);
27 
29 
30  // first phase
31  phases.add( vector_dist_gpu<3,float, aggregate<double,double>>(0,box,bc,ghost) );
32 
33  // The other 3 phases
34  phases.add( vector_dist_gpu<3,float, aggregate<double,double>>(phases.get(0).getDecomposition(),0) );
35  phases.add( vector_dist_gpu<3,float, aggregate<double,double>>(phases.get(0).getDecomposition(),0) );
36  phases.add( vector_dist_gpu<3,float, aggregate<double,double>>(phases.get(0).getDecomposition(),0) );
37 
38  // Fill the phases with particles
39 
40  auto g_it = phases.get(0).getGridIterator(sz);
41 
42  while (g_it.isNext())
43  {
44  auto key = g_it.get();
45 
46  // Add a particle to all the phases
47  phases.get(0).add();
48  phases.get(1).add();
49  phases.get(2).add();
50  phases.get(3).add();
51 
52  phases.get(0).getLastPos()[0] = key.get(0) * g_it.getSpacing(0) + box.getLow(0);
53  phases.get(0).getLastPos()[1] = key.get(1) * g_it.getSpacing(1) + box.getLow(1);
54  phases.get(0).getLastPos()[2] = key.get(2) * g_it.getSpacing(2) + box.getLow(2);
55 
56  phases.get(1).getLastPos()[0] = key.get(0) * g_it.getSpacing(0) + box.getLow(0);
57  phases.get(1).getLastPos()[1] = key.get(1) * g_it.getSpacing(1) + box.getLow(1);
58  phases.get(1).getLastPos()[2] = key.get(2) * g_it.getSpacing(2) + box.getLow(2);
59 
60  phases.get(2).getLastPos()[0] = key.get(0) * g_it.getSpacing(0) + box.getLow(0);
61  phases.get(2).getLastPos()[1] = key.get(1) * g_it.getSpacing(1) + box.getLow(1);
62  phases.get(2).getLastPos()[2] = key.get(2) * g_it.getSpacing(2) + box.getLow(2);
63 
64  phases.get(3).getLastPos()[0] = key.get(0) * g_it.getSpacing(0) + box.getLow(0);
65  phases.get(3).getLastPos()[1] = key.get(1) * g_it.getSpacing(1) + box.getLow(1);
66  phases.get(3).getLastPos()[2] = key.get(2) * g_it.getSpacing(2) + box.getLow(2);
67 
68  ++g_it;
69  }
70 
71  // Sync all phases
72  for (size_t i = 0 ; i < 4 ; i++)
73  {
74  phases.get(i).map();
75  }
76 
77  // randomize a little the particles
78 
79  for (size_t p = 0 ; p < phases.size() ; p++)
80  {
82 
83  for (size_t j = 0 ; j < phases.get(p).size_local() ; j++)
84  {
85  vt.add(phases.get(p).getPos((j + p*133) % phases.get(p).size_local()));
86  }
87  phases.get(p).getPosVector().swap(vt);
88  }
89 
90  // Sync all phases
91  for (size_t i = 0 ; i < 4 ; i++)
92  {
93  phases.get(i).ghost_get<>();
94  }
95 
96  // Get the cell list of the phase 0 and 1
97  auto CL_phase0 = phases.get(0).getCellList(r_cut);
98  auto CL_phase1 = phases.get(1).getCellList(r_cut);
99 
100  // This function create a Verlet-list between phases 0 and 1
101  auto NN_ver01 = createVerlet(phases.get(0),phases.get(1),CL_phase1,r_cut);
102 
103  // Check NNver0_1
104 
105  bool ret = true;
106  auto it = phases.get(0).getDomainIterator();
107 
108  while (it.isNext())
109  {
110  auto p = it.get();
111  auto Np = NN_ver01.getNNIterator<NO_CHECK>(p.getKey());
112 
113  size_t nn_count = 0;
114 
115  // For each neighborhood of the particle p
116  while (Np.isNext())
117  {
118  // Count the number of particles
119  nn_count++;
120 
121  ++Np;
122  }
123 
124  ret &= nn_count == 7ul;
125 
126  ++it;
127  }
128 
129  BOOST_REQUIRE_EQUAL(ret,true);
130 
131  // Sync all phases
132  for (size_t i = 0 ; i < 4 ; i++)
133  {
134  phases.get(i).map();
135  phases.get(i).ghost_get<>();
136  }
137 
138  // NN_ver0_all
139 
140  // This function create an "Empty" Multiphase Cell List
141  auto CL_all = createCellListM<2>(phases,r_cut);
142 
143  // This create a Verlet-list between phase 0 and all the other phases
144  auto NNver0_all = createVerletM<2>(0,phases.get(0),phases,CL_all,r_cut);
145 
146  it = phases.get(0).getDomainIterator();
147 
148  while (it.isNext())
149  {
150  auto p = it.get();
151  auto Np = NNver0_all.getNNIterator<NO_CHECK>(p.getKey());
152 
153  size_t nn_cout[4] = {0,0,0,0};
154 
155  // For each neighborhood of the particle p
156  while (Np.isNext())
157  {
158  // Get from which phase it come from
159  auto ph_q = Np.getV();
160 
161  nn_cout[ph_q]++;
162 
163  ++Np;
164  }
165 
166  ret &= nn_cout[0] == 7;
167  ret &= nn_cout[1] == 7;
168  ret &= nn_cout[2] == 7;
169  ret &= nn_cout[3] == 7;
170 
171  ++it;
172  }
173 
174  BOOST_REQUIRE_EQUAL(ret,true);
175 }
176 
177 
178 BOOST_AUTO_TEST_CASE( vector_dist_multiphase_cell_list_sym_test )
179 {
180  if (create_vcluster().getProcessingUnits() > 24)
181  return;
182 
183  size_t sz[3] = {60,60,40};
184 
185  // The domain
186  Box<3,float> box({-1000.0,-1000.0,-1000.0},{2000.0,2000.0,1000.0});
187 
188  // Boundary conditions
189  size_t bc[3]={PERIODIC,PERIODIC,PERIODIC};
190 
191  float r_cut = 51.0;
192 
193  // ghost, big enough to contain the interaction radius
194  Ghost<3,float> ghost(r_cut);
195 
197 
198  // first phase
199  phases.add( vector_dist_gpu<3,float, aggregate<size_t>>(0,box,bc,ghost) );
200 
201  // The other 3 phases
202  phases.add( vector_dist_gpu<3,float, aggregate<size_t>>(phases.get(0).getDecomposition(),0) );
203  phases.add( vector_dist_gpu<3,float, aggregate<size_t>>(phases.get(0).getDecomposition(),0) );
204  phases.add( vector_dist_gpu<3,float, aggregate<size_t>>(phases.get(0).getDecomposition(),0) );
205 
206  // Fill the phases with particles
207 
208  auto g_it = phases.get(0).getGridIterator(sz);
209 
210  while (g_it.isNext())
211  {
212  auto key = g_it.get();
213 
214  // Add a particle to all the phases
215  phases.get(0).add();
216  phases.get(1).add();
217  phases.get(2).add();
218  phases.get(3).add();
219 
220  phases.get(0).getLastPosWrite()[0] = key.get(0) * g_it.getSpacing(0) + box.getLow(0);
221  phases.get(0).getLastPosWrite()[1] = key.get(1) * g_it.getSpacing(1) + box.getLow(1);
222  phases.get(0).getLastPosWrite()[2] = key.get(2) * g_it.getSpacing(2) + box.getLow(2);
223  phases.get(0).getLastPropWrite<0>() = 0;
224 
225  phases.get(1).getLastPosWrite()[0] = key.get(0) * g_it.getSpacing(0) + box.getLow(0);
226  phases.get(1).getLastPosWrite()[1] = key.get(1) * g_it.getSpacing(1) + box.getLow(1);
227  phases.get(1).getLastPosWrite()[2] = key.get(2) * g_it.getSpacing(2) + box.getLow(2);
228  phases.get(1).getLastPropWrite<0>() = 0;
229 
230  phases.get(2).getLastPosWrite()[0] = key.get(0) * g_it.getSpacing(0) + box.getLow(0);
231  phases.get(2).getLastPosWrite()[1] = key.get(1) * g_it.getSpacing(1) + box.getLow(1);
232  phases.get(2).getLastPosWrite()[2] = key.get(2) * g_it.getSpacing(2) + box.getLow(2);
233  phases.get(2).getLastPropWrite<0>() = 0;
234 
235  phases.get(3).getLastPosWrite()[0] = key.get(0) * g_it.getSpacing(0) + box.getLow(0);
236  phases.get(3).getLastPosWrite()[1] = key.get(1) * g_it.getSpacing(1) + box.getLow(1);
237  phases.get(3).getLastPosWrite()[2] = key.get(2) * g_it.getSpacing(2) + box.getLow(2);
238  phases.get(3).getLastPropWrite<0>() = 0;
239 
240  ++g_it;
241  }
242 
243  // Sync all phases
244  for (size_t i = 0 ; i < 4 ; i++)
245  {
246  phases.get(i).map();
247  }
248 
249  // randomize a little the particles
250 
251  for (size_t p = 0 ; p < phases.size() ; p++)
252  {
254 
255  for (size_t j = 0 ; j < phases.get(p).size_local() ; j++)
256  {
257  vt.add(phases.get(p).getPos((j + p*133) % phases.get(p).size_local()));
258  }
259  phases.get(p).getPosVector().swap(vt);
260  }
261 
262  // Sync all phases
263  for (size_t i = 0 ; i < 4 ; i++)
264  {
265  phases.get(i).ghost_get<0>();
266  }
267 
268  // Get the cell list of the phase 0 and 1
269  auto CL_phase0 = phases.get(0).getCellListSym(r_cut);
270  auto CL_phase1 = phases.get(1).getCellListSym(r_cut);
271 
272  // This function create a Verlet-list between phases 0 and 1
273  auto NN_ver01 = createVerletSym(phases.get(0),phases.get(1),CL_phase1,r_cut);
274 
275  // Check NNver0_1
276 
277  bool ret = true;
278  auto it = phases.get(0).getDomainIterator();
279 
280  while (it.isNext())
281  {
282  auto p = it.get();
283  auto Np = NN_ver01.getNNIterator<NO_CHECK>(p.getKey());
284 
285  // For each neighborhood of the particle p
286  while (Np.isNext())
287  {
288  // Neighborhood particle q
289  auto q = Np.get();
290 
291  phases.get(0).getPropWrite<0>(p)++;
292  phases.get(1).getPropWrite<0>(q)++;
293 
294  ++Np;
295  }
296 
297  ++it;
298  }
299 
300  phases.get(0).ghost_put<add_,0>();
301  phases.get(1).ghost_put<add_,0>();
302 
303 #ifdef SE_CLASS3
304 
305  phases.get(1).getDomainIterator();
306 
307 #endif
308 
309  it = phases.get(0).getDomainIterator();
310  while (it.isNext())
311  {
312  auto p = it.get();
313 
314  ret &= phases.get(0).getPropRead<0>(p) == 7;
315  ret &= phases.get(1).getPropRead<0>(p) == 7;
316 
317  ++it;
318  }
319 
320  BOOST_REQUIRE_EQUAL(ret,true);
321 
322  // Sync all phases
323  for (size_t i = 0 ; i < 4 ; i++)
324  {
325  phases.get(i).map();
326  phases.get(i).ghost_get<>();
327  }
328 
329  // Reset counter on all phases
330 
331  for (size_t i = 0 ; i < phases.size() ; i++)
332  {
333  it = phases.get(i).getDomainAndGhostIterator();
334  while (it.isNext())
335  {
336  auto p = it.get();
337 
338  phases.get(i).getPropWrite<0>(p) = 0;
339 
340  ++it;
341  }
342  }
343 
344  // NN_ver0_all
345 
346  // This function create an "Empty" Multiphase Cell List
347  auto CL_all = createCellListSymM<2>(phases,r_cut);
348 
349  typedef decltype(createVerletSymM<2>(0,phases.get(0),phases,CL_all,r_cut)) verlet_type;
350 
351  verlet_type NNver_all[4];
352 
353  // This create a Verlet-list between each phase to all the other phases
354  NNver_all[0] = createVerletSymM<2>(0,phases.get(0),phases,CL_all,r_cut);
355  NNver_all[1] = createVerletSymM<2>(1,phases.get(1),phases,CL_all,r_cut);
356  NNver_all[2] = createVerletSymM<2>(2,phases.get(2),phases,CL_all,r_cut);
357  NNver_all[3] = createVerletSymM<2>(3,phases.get(3),phases,CL_all,r_cut);
358 
359  // all phases to all phases
360 
361  for (size_t i = 0 ; i < phases.size() ; i++)
362  {
363  it = phases.get(i).getDomainIterator();
364 
365  while (it.isNext())
366  {
367  auto p = it.get();
368  auto Np = NNver_all[i].getNNIterator<NO_CHECK>(p.getKey());
369 
370  // For each neighborhood of the particle p
371  while (Np.isNext())
372  {
373  // Get the particle q near to p
374  auto q = Np.getP();
375 
376  // Get from which phase it come from
377  auto ph_q = Np.getV();
378 
379  phases.get(i).getPropWrite<0>(p)++;
380  phases.get(ph_q).getPropWrite<0>(q)++;
381 
382  ++Np;
383  }
384 
385  ++it;
386  }
387  }
388 
389  phases.get(0).ghost_put<add_,0>();
390  phases.get(1).ghost_put<add_,0>();
391  phases.get(2).ghost_put<add_,0>();
392  phases.get(3).ghost_put<add_,0>();
393 
394 #ifdef SE_CLASS3
395 
396  it = phases.get(1).getDomainIterator();
397  it = phases.get(2).getDomainIterator();
398  it = phases.get(3).getDomainIterator();
399 
400 #endif
401 
402  it = phases.get(0).getDomainIterator();
403  while (it.isNext())
404  {
405  auto p = it.get();
406 
407  ret &= phases.get(0).getPropRead<0>(p) == 32;
408  ret &= phases.get(1).getPropRead<0>(p) == 32;
409  ret &= phases.get(2).getPropRead<0>(p) == 32;
410  ret &= phases.get(3).getPropRead<0>(p) == 32;
411 
412  if (ret == false)
413  {
414  std::cout << phases.get(0).getPropRead<0>(p) << std::endl;
415  std::cout << phases.get(1).getPropRead<0>(p) << std::endl;
416  std::cout << phases.get(2).getPropRead<0>(p) << std::endl;
417  std::cout << phases.get(3).getPropRead<0>(p) << std::endl;
418  }
419 
420  ++it;
421  }
422 
423  BOOST_REQUIRE_EQUAL(ret,true);
424 }
425 
426 template<typename mp_vector_type, typename output_type>
427 __global__ void vdmkt(mp_vector_type mp_v, output_type ot)
428 {
429  int k = 0;
430  for (int i = 0 ; i < mp_v.size() ; i++)
431  {
432  for (int j = 0 ; j < mp_v.template get<0>(i).size() ; j++)
433  {
434  ot.template get<0>(k) = mp_v.template get<0>(i). template getProp<0>(j);
435  k++;
436  }
437  }
438 }
439 
440 template<typename mp_vector_type, typename output_type>
441 __global__ void vdmkt_simple(mp_vector_type mp_v, output_type ot)
442 {
443  int k = 0;
444 
445  for (int i = 0 ; i < mp_v.size() ; i++)
446  {
447  for (int j = 0 ; j < mp_v.get(i).size_local() ; j++)
448  {
449  ot.template get<0>(k) = mp_v.get(i).template getProp<0>(j);
450  k++;
451  }
452  }
453 }
454 
455 template<typename mp_vector_type, typename output_type, typename cl_type>
456 __global__ void vdmkt_simple_cl(mp_vector_type mp_v, output_type ot, cl_type cl, output_type ot2)
457 {
458  int k = 0;
459 
460  for (int i = 0 ; i < mp_v.size() ; i++)
461  {
462  for (int j = 0 ; j < mp_v.get(i).size_local() ; j++)
463  {
464  ot.template get<0>(k) = mp_v.get(i).template getProp<0>(j);
465  k++;
466  }
467  }
468 
469  k = 0;
470  for (int i = 0 ; i < cl.size() ; i++)
471  {
472  for (int j = 0 ; j < cl.get(i).getNCells() ; j++)
473  {
474  for (int k = 0 ; k < cl.get(i).getNelements(j) ; k++)
475  {
476  auto s = cl.get(i).get(j,k);
477 
478  ot2.template get<0>(k) = s;
479 
480  k++;
481  }
482  }
483  }
484 
485  //auto & cl_ph = cl.template get(0).getNNIterator();
486 }
487 
488 BOOST_AUTO_TEST_CASE( vector_dist_multiphase_kernel_test )
489 {
490  if (create_vcluster().getProcessingUnits() > 24)
491  {return;}
492 
493  // The domain
494  Box<3,float> box({-1000.0,-1000.0,-1000.0},{2000.0,2000.0,1000.0});
495 
496  // Boundary conditions
497  size_t bc[3]={PERIODIC,PERIODIC,PERIODIC};
498 
499  float r_cut = 51.0;
500 
501  // ghost, big enough to contain the interaction radius
502  Ghost<3,float> ghost(r_cut);
503 
505 
506  // first phase
507  phases.add_no_device();
508  phases.template get<0>(0) = vector_dist_gpu<3,float, aggregate<float>>(0,box,bc,ghost);
509 
510  // The other 3 phases
511  phases.add_no_device();
512  phases.template get<0>(1) = vector_dist_gpu<3,float, aggregate<float>>(phases.template get<0>(0).getDecomposition(),0);
513  phases.add_no_device();
514  phases.template get<0>(2) = vector_dist_gpu<3,float, aggregate<float>>(phases.template get<0>(0).getDecomposition(),0);
515  phases.add_no_device();
516  phases.template get<0>(3) = vector_dist_gpu<3,float, aggregate<float>>(phases.template get<0>(0).getDecomposition(),0);
517 
518  for (size_t i = 0 ; i < 100 ; i++)
519  {
520  // Add a particle to all the phases
521  phases.template get<0>(0).add();
522  phases.template get<0>(1).add();
523  phases.template get<0>(2).add();
524  phases.template get<0>(3).add();
525 
526  phases.template get<0>(0).getLastPosWrite()[0] = (float)rand() / (float)RAND_MAX;
527  phases.template get<0>(0).getLastPosWrite()[1] = (float)rand() / (float)RAND_MAX;
528  phases.template get<0>(0).getLastPosWrite()[2] = (float)rand() / (float)RAND_MAX;
529  phases.template get<0>(0).getLastPropWrite<0>() = (float)rand() / (float)RAND_MAX;
530 
531  phases.template get<0>(1).getLastPosWrite()[0] = (float)rand() / (float)RAND_MAX;
532  phases.template get<0>(1).getLastPosWrite()[1] = (float)rand() / (float)RAND_MAX;
533  phases.template get<0>(1).getLastPosWrite()[2] = (float)rand() / (float)RAND_MAX;
534  phases.template get<0>(1).getLastPropWrite<0>() = (float)rand() / (float)RAND_MAX;
535 
536  phases.template get<0>(2).getLastPosWrite()[0] = (float)rand() / (float)RAND_MAX;
537  phases.template get<0>(2).getLastPosWrite()[1] = (float)rand() / (float)RAND_MAX;
538  phases.template get<0>(2).getLastPosWrite()[2] = (float)rand() / (float)RAND_MAX;
539  phases.template get<0>(2).getLastPropWrite<0>() = (float)rand() / (float)RAND_MAX;
540 
541  phases.template get<0>(3).getLastPosWrite()[0] = (float)rand() / (float)RAND_MAX;
542  phases.template get<0>(3).getLastPosWrite()[1] = (float)rand() / (float)RAND_MAX;
543  phases.template get<0>(3).getLastPosWrite()[2] = (float)rand() / (float)RAND_MAX;
544  phases.template get<0>(3).getLastPropWrite<0>() = (float)rand() / (float)RAND_MAX;
545  }
546 
547  phases.template get<0>(0).hostToDevicePos();
548  phases.template get<0>(1).hostToDevicePos();
549  phases.template get<0>(2).hostToDevicePos();
550  phases.template get<0>(3).hostToDevicePos();
551 
552  phases.template get<0>(0).template hostToDeviceProp<0>();
553  phases.template get<0>(1).template hostToDeviceProp<0>();
554  phases.template get<0>(2).template hostToDeviceProp<0>();
555  phases.template get<0>(3).template hostToDeviceProp<0>();
556 
557  phases.template hostToDevice<0>();
558 
560  output.resize(100 * phases.size());
561 
562  CUDA_LAUNCH_DIM3(vdmkt,1,1,phases.toKernel(),output.toKernel());
563 
564  output.template deviceToHost<0>();
565 
566  bool match = true;
567  int k = 0;
568  for (int i = 0 ; i < phases.size() ; i++)
569  {
570  for (int j = 0 ; j < phases.template get<0>(i).size_local() ; j++)
571  {
572  match = output.template get<0>(k) == phases.template get<0>(i). template getProp<0>(j);
573  k++;
574  }
575  }
576 
577  BOOST_REQUIRE_EQUAL(match,true);
578 }
579 
580 BOOST_AUTO_TEST_CASE( vector_dist_multiphase_kernel_test_simplified )
581 {
582  if (create_vcluster().getProcessingUnits() > 24)
583  {return;}
584 
585  // The domain
586  Box<3,float> box({-1000.0,-1000.0,-1000.0},{2000.0,2000.0,1000.0});
587 
588  // Boundary conditions
589  size_t bc[3]={PERIODIC,PERIODIC,PERIODIC};
590 
591  float r_cut = 51.0;
592 
593  // ghost, big enough to contain the interaction radius
594  Ghost<3,float> ghost(r_cut);
595 
597 
598  // first phase
599  phases.add();
600  phases.get(0) = vector_dist_gpu<3,float, aggregate<float>>(0,box,bc,ghost);
601 
602  // The other 3 phases
603  phases.add();
604  phases.get(1) = vector_dist_gpu<3,float, aggregate<float>>(phases.get(0).getDecomposition(),0);
605  phases.add();
606  phases.get(2) = vector_dist_gpu<3,float, aggregate<float>>(phases.get(0).getDecomposition(),0);
607  phases.add();
608  phases.get(3) = vector_dist_gpu<3,float, aggregate<float>>(phases.get(0).getDecomposition(),0);
609 
610  for (size_t i = 0 ; i < 100 ; i++)
611  {
612  // Add a particle to all the phases
613  phases.get(0).add();
614  phases.get(1).add();
615  phases.get(2).add();
616  phases.get(3).add();
617 
618  phases.get(0).getLastPosWrite()[0] = (float)rand() / (float)RAND_MAX;
619  phases.get(0).getLastPosWrite()[1] = (float)rand() / (float)RAND_MAX;
620  phases.get(0).getLastPosWrite()[2] = (float)rand() / (float)RAND_MAX;
621  phases.get(0).getLastPropWrite<0>() = (float)rand() / (float)RAND_MAX;
622 
623  phases.get(1).getLastPosWrite()[0] = (float)rand() / (float)RAND_MAX;
624  phases.get(1).getLastPosWrite()[1] = (float)rand() / (float)RAND_MAX;
625  phases.get(1).getLastPosWrite()[2] = (float)rand() / (float)RAND_MAX;
626  phases.get(1).getLastPropWrite<0>() = (float)rand() / (float)RAND_MAX;
627 
628  phases.get(2).getLastPosWrite()[0] = (float)rand() / (float)RAND_MAX;
629  phases.get(2).getLastPosWrite()[1] = (float)rand() / (float)RAND_MAX;
630  phases.get(2).getLastPosWrite()[2] = (float)rand() / (float)RAND_MAX;
631  phases.get(2).getLastPropWrite<0>() = (float)rand() / (float)RAND_MAX;
632 
633  phases.get(3).getLastPosWrite()[0] = (float)rand() / (float)RAND_MAX;
634  phases.get(3).getLastPosWrite()[1] = (float)rand() / (float)RAND_MAX;
635  phases.get(3).getLastPosWrite()[2] = (float)rand() / (float)RAND_MAX;
636  phases.get(3).getLastPropWrite<0>() = (float)rand() / (float)RAND_MAX;
637  }
638 
639  phases.get(0).hostToDevicePos();
640  phases.get(1).hostToDevicePos();
641  phases.get(2).hostToDevicePos();
642  phases.get(3).hostToDevicePos();
643 
644  phases.get(0).template hostToDeviceProp<0>();
645  phases.get(1).template hostToDeviceProp<0>();
646  phases.get(2).template hostToDeviceProp<0>();
647  phases.get(3).template hostToDeviceProp<0>();
648 
649  phases.template hostToDevice<0>();
650 
652  output.resize(100 * phases.size());
653 
654  CUDA_LAUNCH_DIM3(vdmkt_simple,1,1,phases.toKernel(),output.toKernel());
655 
656  output.template deviceToHost<0>();
657 
658  bool match = true;
659  int k = 0;
660  for (int i = 0 ; i < phases.size() ; i++)
661  {
662  for (int j = 0 ; j < phases.get(i).size_local() ; j++)
663  {
664  match = output.template get<0>(k) == phases.get(i). template getProp<0>(j);
665  k++;
666  }
667  }
668 
669  BOOST_REQUIRE_EQUAL(match,true);
670 }
671 
672 BOOST_AUTO_TEST_CASE( vector_dist_multiphase_kernel_cl_test )
673 {
674  if (create_vcluster().getProcessingUnits() > 24)
675  {return;}
676 
677  // The domain
678  Box<3,float> box({0.0,0.0,0.0},{1.0,1.0,1.0});
679 
680  // Boundary conditions
681  size_t bc[3]={PERIODIC,PERIODIC,PERIODIC};
682 
683  // ghost, big enough to contain the interaction radius
684  Ghost<3,float> ghost(0.1);
685 
687  openfpm::vector_custd<decltype(phases.at(0).getCellListGPU(0.1))> cl_ph;
688 
689  // first phase
690  phases.add();
691  phases.get(0) = vector_dist_gpu<3,float, aggregate<float>>(0,box,bc,ghost);
692 
693  // The other 3 phases
694  phases.add();
695  phases.get(1) = vector_dist_gpu<3,float, aggregate<float>>(phases.get(0).getDecomposition(),0);
696  phases.add();
697  phases.get(2) = vector_dist_gpu<3,float, aggregate<float>>(phases.get(0).getDecomposition(),0);
698  phases.add();
699  phases.get(3) = vector_dist_gpu<3,float, aggregate<float>>(phases.get(0).getDecomposition(),0);
700 
701  for (size_t i = 0 ; i < 100 ; i++)
702  {
703  // Add a particle to all the phases
704  phases.get(0).add();
705  phases.get(1).add();
706  phases.get(2).add();
707  phases.get(3).add();
708 
709  phases.get(0).getLastPosWrite()[0] = (float)rand() / (float)RAND_MAX;
710  phases.get(0).getLastPosWrite()[1] = (float)rand() / (float)RAND_MAX;
711  phases.get(0).getLastPosWrite()[2] = (float)rand() / (float)RAND_MAX;
712  phases.get(0).getLastPropWrite<0>() = (float)rand() / (float)RAND_MAX;
713 
714  phases.get(1).getLastPosWrite()[0] = (float)rand() / (float)RAND_MAX;
715  phases.get(1).getLastPosWrite()[1] = (float)rand() / (float)RAND_MAX;
716  phases.get(1).getLastPosWrite()[2] = (float)rand() / (float)RAND_MAX;
717  phases.get(1).getLastPropWrite<0>() = (float)rand() / (float)RAND_MAX;
718 
719  phases.get(2).getLastPosWrite()[0] = (float)rand() / (float)RAND_MAX;
720  phases.get(2).getLastPosWrite()[1] = (float)rand() / (float)RAND_MAX;
721  phases.get(2).getLastPosWrite()[2] = (float)rand() / (float)RAND_MAX;
722  phases.get(2).getLastPropWrite<0>() = (float)rand() / (float)RAND_MAX;
723 
724  phases.get(3).getLastPosWrite()[0] = (float)rand() / (float)RAND_MAX;
725  phases.get(3).getLastPosWrite()[1] = (float)rand() / (float)RAND_MAX;
726  phases.get(3).getLastPosWrite()[2] = (float)rand() / (float)RAND_MAX;
727  phases.get(3).getLastPropWrite<0>() = (float)rand() / (float)RAND_MAX;
728  }
729 
730  // redistribute all
731 
732  size_t tot = 0;
733  size_t tot_g = 0;
734  for (size_t i = 0 ; i < phases.size() ; i++)
735  {
736  phases.get(i).hostToDevicePos();
737  phases.get(i).template hostToDeviceProp<0>();
738  phases.get(i).map(RUN_ON_DEVICE);
739  phases.get(i).template ghost_get<>(RUN_ON_DEVICE);
740  phases.get(i).deviceToHostPos();
741  phases.get(i).template deviceToHostProp<0>();
742  tot += phases.get(i).size_local();
743  tot_g += phases.get(i).size_local_with_ghost();
744  }
745 
746  // Add cell list to the vector
747 
748  for (size_t i = 0 ; i < phases.size() ; i++)
749  {
750  cl_ph.add(phases.get(i).getCellListGPU(0.1));
751  }
752 
753  //
754 
755  phases.template hostToDevice();
756  cl_ph.template hostToDevice();
757 
760  output.resize(tot);
761  output2.resize(tot_g);
762 
763  CUDA_LAUNCH_DIM3(vdmkt_simple_cl,1,1,phases.toKernel(),output.toKernel(),cl_ph.toKernel(),output2.toKernel());
764 
765  output.template deviceToHost<0>();
766 
767  bool match = true;
768  int k = 0;
769  for (int i = 0 ; i < phases.size() ; i++)
770  {
771  for (int j = 0 ; j < phases.get(i).size_local() ; j++)
772  {
773  match = output.template get<0>(k) == phases.get(i). template getProp<0>(j);
774  k++;
775  }
776  }
777 
778  BOOST_REQUIRE_EQUAL(match,true);
779 }
780 
781 BOOST_AUTO_TEST_SUITE_END()
782 
This structure define the operation add to use with copy general.
size_t size()
Stub size.
Definition: map_vector.hpp:211
Definition: Ghost.hpp:39
Distributed vector.
aggregate of properties, from a list of object if create a struct that follow the OPENFPM native stru...
Definition: aggregate.hpp:214
Implementation of 1-D std::vector like structure.
Definition: map_vector.hpp:202