8#ifndef SRC_TEST_ISOLATION_HPP_
9#define SRC_TEST_ISOLATION_HPP_
17BOOST_AUTO_TEST_SUITE( antoniol_test_isolation )
20BOOST_AUTO_TEST_CASE( CartDecomposition_test_2D )
28 size_t bc[2] = { NON_PERIODIC, NON_PERIODIC };
31 init_global_v_cluster(&boost::unit_test::framework::master_test_suite().argc,&boost::unit_test::framework::master_test_suite().argv);
46 size_t n_sub = n_proc * SUB_UNIT_FACTOR;
49 for (
int i = 0; i < 2; i++)
51 div[i] = openfpm::math::round_big_2(pow(n_sub,1.0/2));
58 dec.setParameters(div, box, bc, g);
61 dlb.setHeurisitc(DLB::Heuristic::UNBALANCE_THRLD);
62 dlb.setThresholdLevel(DLB::ThresholdLevel::THRLD_MEDIUM);
73 size_t weight_h = 5, weight_l = 1;
75 setComputationCosts(dec, dec.getNSubSubDomains(), center, radius, weight_h, weight_l);
77 dec.getDistribution().write(
"DLB_test_graph_0.vtk");
81 dec.getDistribution().write(
"DLB_test_graph_1.vtk");
83 float stime = 0.0, etime = 10.0, tstep = 0.1;
85 for(
float t = stime, i = 1; t < etime; t = t + tstep, i++)
90 center.get(0) += tstep;
91 center.get(1) += tstep;
95 center.get(0) -= tstep;
96 center.get(1) -= tstep;
99 setComputationCosts(dec, dec.getNSubSubDomains(), center, radius, weight_h, weight_l);
103 if(dec.rebalance(dlb))
104 dec.write(
"DLB_test_graph_cart_" + std::to_string(i+1) +
"_");
106 std::stringstream str;
107 str <<
"DLB_test_graph_" << i + 1 <<
".vtk";
108 dec.getDistribution().write(str.str());
112 for (
size_t i = 0; i < dec.getNIGhostBox(); i++)
115 size_t proc = dec.getIGhostBoxProcessor(i);
121 const openfpm::vector<size_t> & pr = dec.template ghost_processorID<CartDecomposition<2,float>::processor_id>(p);
125 for (
size_t j = 0; j < pr.
size(); j++)
127 if (pr.get(j) == proc)
128 { found =
true;
break;}
133 const openfpm::vector<size_t> pr2 = dec.template ghost_processorID<CartDecomposition<2,float>::processor_id>(p);
136 BOOST_REQUIRE_EQUAL(found,
true);
141 bool val = dec.check_consistency();
142 BOOST_REQUIRE_EQUAL(val,
true);
145BOOST_AUTO_TEST_CASE( CartDecomposition_test_2D_sar)
151 size_t bc[2] = { NON_PERIODIC, NON_PERIODIC };
154 init_global_v_cluster(&boost::unit_test::framework::master_test_suite().argc,&boost::unit_test::framework::master_test_suite().argv);
169 size_t n_sub = n_proc * SUB_UNIT_FACTOR;
172 for (
int i = 0; i < 2; i++)
174 div[i] = openfpm::math::round_big_2(pow(n_sub,1.0/2));
181 dec.setParameters(div, box, bc, g);
184 dlb.setHeurisitc(DLB::Heuristic::SAR_HEURISTIC);
195 size_t weight_h = 5, weight_l = 1;
197 size_t n_v = pow(div[0], 2);
199 setComputationCosts(dec, n_v, center, radius, weight_h, weight_l);
203 dec.getDistribution().write(
"DLB_test_graph_0.vtk");
205 float stime = 0.0, etime = 10.0, tstep = 0.1;
207 dlb.setSimulationStartTime(0);
208 dlb.setSimulationEndTime(10);
210 for(
float t = stime, i = 1; t < etime; t = t + tstep, i++)
212 dlb.startIteration();
216 center.get(0) += tstep;
217 center.get(1) += tstep;
221 center.get(0) -= tstep;
222 center.get(1) -= tstep;
225 setComputationCosts(dec, n_v, center, radius, weight_h, weight_l);
231 if(dec.rebalance(dlb))
233 dec.write(
"DLB_test_graph_cart_" + std::to_string(i) +
"_");
236 std::stringstream str;
237 str <<
"DLB_test_graph_" << i <<
".vtk";
238 dec.getDistribution().write(str.str());
242 for (
size_t i = 0; i < dec.getNIGhostBox(); i++)
245 size_t proc = dec.getIGhostBoxProcessor(i);
251 const openfpm::vector<size_t> & pr = dec.template ghost_processorID<CartDecomposition<2,float>::processor_id>(p);
255 for (
size_t j = 0; j < pr.
size(); j++)
257 if (pr.get(j) == proc)
258 { found =
true;
break;}
263 const openfpm::vector<size_t> pr2 = dec.template ghost_processorID<CartDecomposition<2,float>::processor_id>(p);
266 BOOST_REQUIRE_EQUAL(found,
true);
271 bool val = dec.check_consistency();
272 BOOST_REQUIRE_EQUAL(val,
true);
275BOOST_AUTO_TEST_CASE( CartDecomposition_test_3D)
281 size_t bc[3] = { NON_PERIODIC, NON_PERIODIC, NON_PERIODIC };
284 init_global_v_cluster(&boost::unit_test::framework::master_test_suite().argc,&boost::unit_test::framework::master_test_suite().argv);
299 size_t n_sub = n_proc * SUB_UNIT_FACTOR;
302 for (
int i = 0; i < 3; i++)
304 div[i] = openfpm::math::round_big_2(pow(n_sub,1.0/3));
311 dec.setParameters(div, box, bc, g);
314 dlb.setHeurisitc(DLB::Heuristic::UNBALANCE_THRLD);
315 dlb.setThresholdLevel(DLB::ThresholdLevel::THRLD_MEDIUM);
326 size_t weight_h = 5, weight_l = 1;
328 size_t n_v = pow(div[0], 3);
330 setComputationCosts3D(dec, n_v, center, radius, weight_h, weight_l);
334 dec.getDistribution().write(
"DLB_test_graph_0.vtk");
336 float stime = 0.0, etime = 10.0, tstep = 0.1;
338 for(
float t = stime, i = 1; t < etime; t = t + tstep, i++)
343 center.get(0) += tstep;
344 center.get(1) += tstep;
345 center.get(2) += tstep;
349 center.get(0) -= tstep;
350 center.get(1) -= tstep;
351 center.get(2) -= tstep;
354 setComputationCosts3D(dec, n_v, center, radius, weight_h, weight_l);
360 std::stringstream str;
361 str <<
"DLB_test_graph_" << i <<
".vtk";
362 dec.getDistribution().write(str.str());
366 for (
size_t i = 0; i < dec.getNIGhostBox(); i++)
369 size_t proc = dec.getIGhostBoxProcessor(i);
375 const openfpm::vector<size_t> & pr = dec.template ghost_processorID<CartDecomposition<3,float>::processor_id>(p);
379 for (
size_t j = 0; j < pr.
size(); j++)
381 if (pr.get(j) == proc)
382 { found =
true;
break;}
387 const openfpm::vector<size_t> pr2 = dec.template ghost_processorID<CartDecomposition<3,float>::processor_id>(p);
390 BOOST_REQUIRE_EQUAL(found,
true);
395 bool val = dec.check_consistency();
396 BOOST_REQUIRE_EQUAL(val,
true);
400BOOST_AUTO_TEST_CASE( dist_map_graph_use_cartesian)
409 size_t bc[3] = {NON_PERIODIC,NON_PERIODIC,NON_PERIODIC};
416 size_t div[3] = {8,8,8};
419 size_t gsz[3] = {8,8,8};
426 dec.setParameters(div, box, bc, g);
432 while (it_dec.isNext())
454 while (it_dec2.isNext())
456 auto key = it_dec2.get();
460 v.template get<0>()[0] = key.get(0);
461 v.template get<0>()[1] = key.get(1);
462 v.template get<0>()[2] = key.get(2);
464 size_t gid = g_sm.LinId(key);
475 std::default_random_engine rg;
476 std::uniform_int_distribution<size_t> d(0,g_sm.size()-1);
500 size_t lin_id = g_sm.LinId(key);
504 std::cout <<
"Error: " <<
" " << lin_id <<
" " << key.
to_string() <<
"\n";
526BOOST_AUTO_TEST_CASE( Parmetis_distribution_test_random_walk )
530 Vcluster & v_cl = *global_v_cluster;
535 std::default_random_engine eg;
536 std::uniform_real_distribution<float> ud(0.0f, 1.0f);
538 size_t nsz[] = { 0, 32, 4 };
541 print_test_v(
"Testing 3D random walk vector k<=",nsz[0]);
544 for (
size_t i = 0; i < 3; i++ )
548 BOOST_TEST_CHECKPOINT(
"Testing 3D random walk k=" << k );
556 size_t bc[3] = { NON_PERIODIC,NON_PERIODIC,NON_PERIODIC };
559 float factor = pow(global_v_cluster->getProcessingUnits()/2.0f,1.0f/3.0f);
565 vector_dist<3,float, Point_test<float>,
CartDecomposition<3, float, HeapMemory, ParMetisDistribution<3, float>>> vd(k,box,bc,ghost);
567 auto it = vd.getIterator();
573 vd.template getPos<s::x>(key)[0] = ud(eg);
574 vd.template getPos<s::x>(key)[1] = ud(eg);
575 vd.template getPos<s::x>(key)[2] = ud(eg);
582 vd.addComputationCosts();
584 vd.getDecomposition().getDistribution().write(
"parmetis_random_walk_" + std::to_string(0) +
".vtk");
588 for (
size_t j = 0; j < 10; j++)
590 auto it = vd.getDomainIterator();
596 vd.template getPos<s::x>(key)[0] += 0.01 * ud(eg);
597 vd.template getPos<s::x>(key)[1] += 0.01 * ud(eg);
598 vd.template getPos<s::x>(key)[2] += 0.01 * ud(eg);
612 vd.addComputationCosts();
614 vd.getDecomposition().rebalance(10);
618 vd.getDecomposition().getDistribution().write(
"parmetis_random_walk_" + std::to_string(j+1) +
".vtk");
620 size_t l = vd.size_local();
625 size_t cnt = total_n_part_lc(vd,bc);
632BOOST_AUTO_TEST_CASE( Parmetis_distribution_test_random_walk_2D )
638 Vcluster & v_cl = *global_v_cluster;
640 size_t JUST_EATEN = 5;
645 std::default_random_engine eg;
646 std::uniform_real_distribution<float> ud(0.0f, 0.5f);
650 print_test_v(
"Testing 2D random walk vector k<=",k);
652 BOOST_TEST_CHECKPOINT(
"Testing 2D random walk k=" << k );
660 size_t bc[2] = { PERIODIC, PERIODIC };
663 float factor = pow(global_v_cluster->getProcessingUnits()/2.0f,1.0f/3.0f);
669 vector_dist<2,float, Point_test<float>,
CartDecomposition<2, float, HeapMemory, ParMetisDistribution<2, float>>> vd(k,box,bc,ghost);
675 dlb.setHeurisitc(DLB::Heuristic::UNBALANCE_THRLD);
676 dlb.setThresholdLevel(DLB::ThresholdLevel::THRLD_MEDIUM);
678 auto it = vd.getIterator();
686 vd.template getPos<s::x>(key)[0] = ud(eg);
687 vd.template getPos<s::x>(key)[1] = ud(eg);
689 vd.template getPos<s::x>(key)[0] = ud(eg)*2;
690 vd.template getPos<s::x>(key)[1] = ud(eg)*2;
698 vd.addComputationCosts();
700 vd.getDecomposition().rebalance(dlb);
704 vd.getDecomposition().write(
"dec_init");
705 vd.getDecomposition().getDistribution().write(
"parmetis_random_walk_" + std::to_string(0) +
".vtk");
706 vd.write(
"particles_", 0, NO_GHOST);
709 for (
size_t j = 0; j < 50; j++)
711 std::cout <<
"Iteration " << (j+1) <<
"\n";
713 auto it = vd.getDomainIterator();
719 vd.template getPos<s::x>(key)[0] += 0.01 * ud(eg);
720 vd.template getPos<s::x>(key)[1] += 0.01 * ud(eg);
727 vd.addComputationCosts();
729 vd.getDecomposition().rebalance(dlb);
733 vd.getDecomposition().getDistribution().write(
"parmetis_random_walk_" + std::to_string(j+1) +
".vtk");
734 vd.write(
"particles_", j+1, NO_GHOST);
735 vd.getDecomposition().write(
"dec_");
737 size_t l = vd.size_local();
750BOOST_AUTO_TEST_CASE( Parmetis_distribution_test_prey_and_predators )
752 Vcluster & v_cl = *global_v_cluster;
757 size_t PREDATOR = 1, PREY = 0;
758 size_t ALIVE = 1, DEAD = 0;
761 float PRED_REPR = 0.1;
764 float PRED_EAT = 0.2;
767 float PREY_REPR = 0.1;
772 std::default_random_engine eg;
773 std::uniform_real_distribution<float> ud(0.0f, 1.0f);
777 print_test_v(
"Testing 2D random walk vector k<=",k);
779 BOOST_TEST_CHECKPOINT(
"Testing 2D random walk k=" << k );
787 size_t bc[2] = { PERIODIC, PERIODIC };
790 float factor = pow(global_v_cluster->getProcessingUnits()/2.0f,1.0f/3.0f);
793 float r_cut = 0.01 / factor;
799 vector_dist<2,float, animal, CartDecomposition<2, float, HeapMemory, ParMetisDistribution<2, float>>> vd(k,box,bc,ghost);
805 dlb.setHeurisitc(DLB::Heuristic::UNBALANCE_THRLD);
806 dlb.setThresholdLevel(DLB::ThresholdLevel::THRLD_MEDIUM);
808 auto it = vd.getIterator();
816 vd.template getPos<animal::pos>(key)[0] = ud(eg);
817 vd.template getPos<animal::pos>(key)[1] = ud(eg);
818 vd.template getProp<animal::genre>(key) = 0;
819 vd.template getProp<animal::status>(key) = 1;
820 vd.template getProp<animal::time_a>(key) = TIME_A;
822 vd.template getPos<animal::pos>(key)[0] = ud(eg);
823 vd.template getPos<animal::pos>(key)[1] = ud(eg);
824 vd.template getProp<animal::genre>(key) = 1;
825 vd.template getProp<animal::status>(key) = 1;
826 vd.template getProp<animal::time_a>(key) = TIME_A;
834 vd.addComputationCosts();
836 vd.getDecomposition().rebalance(dlb);
840 vd.getDecomposition().write(
"dec_init");
841 vd.getDecomposition().getDistribution().write(
"parmetis_random_walk_" + std::to_string(0) +
".vtk");
842 vd.write(
"particles_", 0, NO_GHOST);
845 for (
size_t j = 0; j < 50; j++)
847 std::cout <<
"Iteration " << (j+1) <<
"\n";
849 auto it = vd.getDomainIterator();
855 vd.template getPos<animal::pos>(key)[0] += 0.01 * ud(eg);
856 vd.template getPos<animal::pos>(key)[1] += 0.01 * ud(eg);
873 auto NN = vd.getCellList(0.01 / factor);
877 auto it2 = vd.getDomainIterator();
885 size_t gp = vd.getProp<animal::genre>(p);
886 size_t sp = vd.getProp<animal::status>(p);
888 auto Np = NN.getIterator(NN.getCell(vd.getPos<0>(p)));
894 size_t gq = vd.getProp<animal::genre>(q);
895 size_t sq = vd.getProp<animal::status>(q);
902 float distance = f.norm();
905 if (distance < 2*r_cut*sqrt(2) && sp == ALIVE)
907 if(gp == PREDATOR && gq == PREY && sq == ALIVE)
909 vd.getProp<animal::status>(q) = DEAD;
910 vd.getProp<animal::time_a>(q) = TIME_A;
912 else if (gp == PREY && gq == PREY && sq != DEAD)
917 vd.getLastProp<animal::genre>() = 0;
924 if(vd.getProp<animal::status>(p) == DEAD)
926 deads.add(p.getKey());
937 vd.addComputationCosts();
939 vd.getDecomposition().rebalance(dlb);
943 vd.getDecomposition().getDistribution().write(
"parmetis_random_walk_" + std::to_string(j+1) +
".vtk");
944 vd.write(
"particles_", j+1, NO_GHOST);
945 vd.getDecomposition().write(
"dec_");
947 size_t l = vd.size_local();
959BOOST_AUTO_TEST_SUITE_END()
This class represent an N-dimensional box.
This class decompose a space into sub-sub-domains and distribute them across processors.
Structure that store a graph in CSR format or basically in compressed adjacency matrix format.
auto getVertex(size_t id) -> decltype(v.get(id))
Function to access the vertexes.
void init()
Once added all the vertices this function must be called to initialize all the properties,...
void sync()
Execute all vertex requests and add them as ghosts inside this graph, they will be available until a ...
void add_vertex(const V &vrt, size_t id, size_t gid)
Add vertex vrt with global id and id properties.
void reqVertex(size_t gid)
Put a vertex request in queue.
This class implement the point shape in an N-dimensional space.
__device__ __host__ const T & get(unsigned int i) const
Get coordinate.
This class represent an N-dimensional box.
void execute()
Execute all the requests.
void sum(T &num)
Sum the numbers across all processors and get the result.
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.
Given the decomposition it create an iterator.
grid_key_dx is the key to access any element in the grid
__device__ __host__ void set_d(index_type i, index_type id)
Set the i index.
std::string to_string() const
convert the information into a string
__device__ __host__ index_type get(index_type i) const
Get the i index.
Implementation of 1-D std::vector like structure.
KeyT const ValueT ValueT OffsetIteratorT OffsetIteratorT int
[in] The number of segments that comprise the sorting data
aggregate of properties, from a list of object if create a struct that follow the OPENFPM native stru...