1#define BOOST_TEST_DYN_LINK
2#include <boost/test/unit_test.hpp>
4#include "Vector/vector_dist_multiphase_functions.hpp"
5#include "VCluster/VCluster.hpp"
6#include "Vector/vector_dist.hpp"
8BOOST_AUTO_TEST_SUITE( vector_dist_multiphase_gpu_test )
10BOOST_AUTO_TEST_CASE( vector_dist_multiphase_gpu_cell_list_test )
12 if (create_vcluster().getProcessingUnits() > 24)
15 size_t sz[3] = {60,60,40};
18 Box<3,float> box({-1000.0,-1000.0,-1000.0},{2000.0,2000.0,1000.0});
21 size_t bc[3]={PERIODIC,PERIODIC,PERIODIC};
40 auto g_it = phases.get(0).getGridIterator(sz);
44 auto key = g_it.get();
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);
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);
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);
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);
72 for (
size_t i = 0 ; i < 4 ; i++)
79 for (
size_t p = 0 ; p < phases.
size() ; p++)
83 for (
size_t j = 0 ; j < phases.get(p).size_local() ; j++)
85 vt.add(phases.get(p).getPos((j + p*133) % phases.get(p).size_local()));
87 phases.get(p).getPosVector().swap(vt);
91 for (
size_t i = 0 ; i < 4 ; i++)
93 phases.get(i).ghost_get<>();
97 auto CL_phase0 = phases.get(0).getCellList(r_cut);
98 auto CL_phase1 = phases.get(1).getCellList(r_cut);
101 auto NN_ver01 = createVerlet(phases.get(0),phases.get(1),CL_phase1,r_cut);
106 auto it = phases.get(0).getDomainIterator();
111 auto Np = NN_ver01.getNNIterator<NO_CHECK>(p.getKey());
124 ret &= nn_count == 7ul;
129 BOOST_REQUIRE_EQUAL(ret,
true);
132 for (
size_t i = 0 ; i < 4 ; i++)
135 phases.get(i).ghost_get<>();
141 auto CL_all = createCellListM<2>(phases,r_cut);
144 auto NNver0_all = createVerletM<2>(0,phases.get(0),phases,CL_all,r_cut);
146 it = phases.get(0).getDomainIterator();
151 auto Np = NNver0_all.getNNIterator<NO_CHECK>(p.getKey());
153 size_t nn_cout[4] = {0,0,0,0};
159 auto ph_q = Np.getV();
166 ret &= nn_cout[0] == 7;
167 ret &= nn_cout[1] == 7;
168 ret &= nn_cout[2] == 7;
169 ret &= nn_cout[3] == 7;
174 BOOST_REQUIRE_EQUAL(ret,
true);
178BOOST_AUTO_TEST_CASE( vector_dist_multiphase_cell_list_sym_test )
180 if (create_vcluster().getProcessingUnits() > 24)
183 size_t sz[3] = {60,60,40};
186 Box<3,float> box({-1000.0,-1000.0,-1000.0},{2000.0,2000.0,1000.0});
189 size_t bc[3]={PERIODIC,PERIODIC,PERIODIC};
208 auto g_it = phases.get(0).getGridIterator(sz);
210 while (g_it.isNext())
212 auto key = g_it.get();
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;
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;
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;
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;
244 for (
size_t i = 0 ; i < 4 ; i++)
251 for (
size_t p = 0 ; p < phases.
size() ; p++)
255 for (
size_t j = 0 ; j < phases.get(p).size_local() ; j++)
257 vt.add(phases.get(p).getPos((j + p*133) % phases.get(p).size_local()));
259 phases.get(p).getPosVector().swap(vt);
263 for (
size_t i = 0 ; i < 4 ; i++)
265 phases.get(i).ghost_get<0>();
269 auto CL_phase0 = phases.get(0).getCellListSym(r_cut);
270 auto CL_phase1 = phases.get(1).getCellListSym(r_cut);
273 auto NN_ver01 = createVerletSym(phases.get(0),phases.get(1),CL_phase1,r_cut);
278 auto it = phases.get(0).getDomainIterator();
283 auto Np = NN_ver01.getNNIterator<NO_CHECK>(p.getKey());
291 phases.get(0).getPropWrite<0>(p)++;
292 phases.get(1).getPropWrite<0>(q)++;
300 phases.get(0).ghost_put<
add_,0>();
301 phases.get(1).ghost_put<
add_,0>();
305 phases.get(1).getDomainIterator();
309 it = phases.get(0).getDomainIterator();
314 ret &= phases.get(0).getPropRead<0>(p) == 7;
315 ret &= phases.get(1).getPropRead<0>(p) == 7;
320 BOOST_REQUIRE_EQUAL(ret,
true);
323 for (
size_t i = 0 ; i < 4 ; i++)
326 phases.get(i).ghost_get<>();
331 for (
size_t i = 0 ; i < phases.
size() ; i++)
333 it = phases.get(i).getDomainAndGhostIterator();
338 phases.get(i).getPropWrite<0>(p) = 0;
347 auto CL_all = createCellListSymM<2>(phases,r_cut);
349 typedef decltype(createVerletSymM<2>(0,phases.get(0),phases,CL_all,r_cut)) verlet_type;
351 verlet_type NNver_all[4];
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);
361 for (
size_t i = 0 ; i < phases.
size() ; i++)
363 it = phases.get(i).getDomainIterator();
368 auto Np = NNver_all[i].getNNIterator<NO_CHECK>(p.getKey());
377 auto ph_q = Np.getV();
379 phases.get(i).getPropWrite<0>(p)++;
380 phases.get(ph_q).getPropWrite<0>(q)++;
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>();
396 it = phases.get(1).getDomainIterator();
397 it = phases.get(2).getDomainIterator();
398 it = phases.get(3).getDomainIterator();
402 it = phases.get(0).getDomainIterator();
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;
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;
423 BOOST_REQUIRE_EQUAL(ret,
true);
426template<
typename mp_vector_type,
typename output_type>
427__global__
void vdmkt(mp_vector_type mp_v, output_type ot)
430 for (
int i = 0 ; i < mp_v.size() ; i++)
432 for (
int j = 0 ; j < mp_v.template get<0>(i).size() ; j++)
434 ot.template get<0>(k) = mp_v.template get<0>(i).
template getProp<0>(j);
440template<
typename mp_vector_type,
typename output_type>
441__global__
void vdmkt_simple(mp_vector_type mp_v, output_type ot)
445 for (
int i = 0 ; i < mp_v.size() ; i++)
447 for (
int j = 0 ; j < mp_v.get(i).size_local() ; j++)
449 ot.template get<0>(k) = mp_v.get(i).template getProp<0>(j);
455template<
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)
460 for (
int i = 0 ; i < mp_v.size() ; i++)
462 for (
int j = 0 ; j < mp_v.get(i).size_local() ; j++)
464 ot.template get<0>(k) = mp_v.get(i).template getProp<0>(j);
470 for (
int i = 0 ; i < cl.size() ; i++)
472 for (
int j = 0 ; j < cl.get(i).getNCells() ; j++)
474 for (
int k = 0 ; k < cl.get(i).getNelements(j) ; k++)
476 auto s = cl.get(i).get(j,k);
478 ot2.template get<0>(k) = s;
488BOOST_AUTO_TEST_CASE( vector_dist_multiphase_kernel_test )
490 if (create_vcluster().getProcessingUnits() > 24)
494 Box<3,float> box({-1000.0,-1000.0,-1000.0},{2000.0,2000.0,1000.0});
497 size_t bc[3]={PERIODIC,PERIODIC,PERIODIC};
507 phases.add_no_device();
511 phases.add_no_device();
513 phases.add_no_device();
515 phases.add_no_device();
518 for (
size_t i = 0 ; i < 100 ; i++)
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();
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;
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;
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;
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;
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();
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>();
557 phases.template hostToDevice<0>();
560 output.resize(100 * phases.
size());
562 CUDA_LAUNCH_DIM3(vdmkt,1,1,phases.toKernel(),output.toKernel());
564 output.template deviceToHost<0>();
568 for (
int i = 0 ; i < phases.
size() ; i++)
570 for (
int j = 0 ; j < phases.template get<0>(i).size_local() ; j++)
572 match = output.template get<0>(k) == phases.template get<0>(i).
template getProp<0>(j);
577 BOOST_REQUIRE_EQUAL(match,
true);
580BOOST_AUTO_TEST_CASE( vector_dist_multiphase_kernel_test_simplified )
582 if (create_vcluster().getProcessingUnits() > 24)
586 Box<3,float> box({-1000.0,-1000.0,-1000.0},{2000.0,2000.0,1000.0});
589 size_t bc[3]={PERIODIC,PERIODIC,PERIODIC};
610 for (
size_t i = 0 ; i < 100 ; i++)
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;
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;
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;
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;
639 phases.get(0).hostToDevicePos();
640 phases.get(1).hostToDevicePos();
641 phases.get(2).hostToDevicePos();
642 phases.get(3).hostToDevicePos();
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>();
649 phases.template hostToDevice<0>();
652 output.resize(100 * phases.
size());
654 CUDA_LAUNCH_DIM3(vdmkt_simple,1,1,phases.toKernel(),output.toKernel());
656 output.template deviceToHost<0>();
660 for (
int i = 0 ; i < phases.
size() ; i++)
662 for (
int j = 0 ; j < phases.get(i).size_local() ; j++)
664 match = output.template get<0>(k) == phases.get(i).
template getProp<0>(j);
669 BOOST_REQUIRE_EQUAL(match,
true);
672BOOST_AUTO_TEST_CASE( vector_dist_multiphase_kernel_cl_test )
674 if (create_vcluster().getProcessingUnits() > 24)
681 size_t bc[3]={PERIODIC,PERIODIC,PERIODIC};
701 for (
size_t i = 0 ; i < 100 ; i++)
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;
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;
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;
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;
734 for (
size_t i = 0 ; i < phases.
size() ; i++)
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();
748 for (
size_t i = 0 ; i < phases.
size() ; i++)
750 cl_ph.add(phases.get(i).getCellListGPU(0.1));
755 phases.template hostToDevice();
756 cl_ph.template hostToDevice();
761 output2.resize(tot_g);
763 CUDA_LAUNCH_DIM3(vdmkt_simple_cl,1,1,phases.toKernel(),output.toKernel(),cl_ph.toKernel(),output2.toKernel());
765 output.template deviceToHost<0>();
769 for (
int i = 0 ; i < phases.
size() ; i++)
771 for (
int j = 0 ; j < phases.get(i).size_local() ; j++)
773 match = output.template get<0>(k) == phases.get(i).
template getProp<0>(j);
778 BOOST_REQUIRE_EQUAL(match,
true);
781BOOST_AUTO_TEST_SUITE_END()
This class represent an N-dimensional box.
Implementation of 1-D std::vector like structure.
This structure define the operation add to use with copy general.
aggregate of properties, from a list of object if create a struct that follow the OPENFPM native stru...