1#define BOOST_TEST_DYN_LINK
2#include <boost/test/unit_test.hpp>
4#include "Decomposition/CartDecomposition.hpp"
5#include "util/mathutil.hpp"
6#include "nn_processor_unit_test.hpp"
8BOOST_AUTO_TEST_SUITE (CartDecomposition_test)
10#define SUB_UNIT_FACTOR 1024
14 float radius2 = pow(radius, 2);
20 for (
size_t i = 0; i < n_v; i++)
24 eq = pow((pos[0] - center.
get(0)), 2) + pow((pos[1] - center.
get(1)), 2);
35 float radius2 = radius * radius;
41 for (
size_t i = 0; i < n_v; i++)
45 eq = pow((pos[0] - center.
get(0)), 2) + pow((pos[1] - center.
get(1)), 2) + pow((pos[2] - center.
get(2)), 2);
56BOOST_AUTO_TEST_CASE( CartDecomposition_non_periodic_test)
70 size_t n_sub = n_proc * SUB_UNIT_FACTOR;
73 for (
int i = 0; i < 3; i++)
74 { div[i] = openfpm::math::round_big_2(pow(n_sub,1.0/3));}
80 size_t bc[] = { NON_PERIODIC, NON_PERIODIC, NON_PERIODIC };
100 for (
size_t j = 0; j < pr.
size(); j++)
102 if (pr.get(j) == proc)
103 { found =
true;
break;}
111 BOOST_REQUIRE_EQUAL(found,
true);
117 BOOST_REQUIRE_EQUAL(val,
true);
127 BOOST_REQUIRE_EQUAL(ret,
true);
138 BOOST_REQUIRE_EQUAL(ret,
true);
142 BOOST_REQUIRE_EQUAL(ret,
true);
145BOOST_AUTO_TEST_CASE( CartDecomposition_periodic_test)
160 size_t n_sub = n_proc * SUB_UNIT_FACTOR;
163 for (
int i = 0; i < 3; i++)
164 { div[i] = openfpm::math::round_big_2(pow(n_sub,1.0/3));}
170 size_t bc[] = { PERIODIC, PERIODIC, PERIODIC };
192 for (
size_t j = 0; j < pr.
size(); j++)
194 if (pr.get(j) == proc)
195 { found =
true;
break;}
203 BOOST_REQUIRE_EQUAL(found,
true);
208 BOOST_REQUIRE_EQUAL(val,
true);
217 BOOST_REQUIRE_EQUAL(ret,
true);
230 BOOST_REQUIRE_EQUAL(ret,
true);
234 BOOST_REQUIRE_EQUAL(ret,
true);
240BOOST_AUTO_TEST_CASE( CartDecomposition_ext_non_periodic_test)
254 size_t n_sub = n_proc * SUB_UNIT_FACTOR;
257 for (
int i = 0 ; i < 3 ; i++)
258 {div[i] = openfpm::math::round_big_2(pow(n_sub,1.0/3));}
264 size_t bc[] = {NON_PERIODIC,NON_PERIODIC,NON_PERIODIC};
277 dec_ext.setParameters(dec,g,box_ext);
284 BOOST_REQUIRE_EQUAL(dec_ext.getNSubDomain(),dec.
getNSubDomain());
287 for (
size_t i = 0; i < dec_ext.getNSubDomain() ; i++)
289 volume += dec_ext.getSubDomain(i).getVolume();
290 BOOST_REQUIRE_EQUAL(dec_ext.getSubDomain(i).isContained(dec.
getSubDomain(i)),
true);
296 BOOST_REQUIRE_CLOSE(volume,1.728,0.0001);
300 double volume_g = 0.0;
301 double volume_ge = 0.0;
308 volume_ge += dec_ext.getProcessorEGhostBox(p,i).getVolume();
310 BOOST_REQUIRE_EQUAL(dec_ext.getProcessorEGhostBox(p,i).isContained(dec_ext.getProcessorEGhostBox(p,i)),
true);
320 BOOST_REQUIRE(volume_ge > volume_g*1.05);
330 volume_ge += dec_ext.getProcessorIGhostBox(p,i).getVolume();
331 BOOST_REQUIRE_EQUAL(dec_ext.getProcessorIGhostBox(p,i).isContained(dec.
getProcessorIGhostBox(p,i)),
true);
341 BOOST_REQUIRE(volume_ge > volume_g*1.05);
345BOOST_AUTO_TEST_CASE( CartDecomposition_check_cross_consistency_between_proc_idbc_and_ghost )
355 size_t bc[3] = {PERIODIC,PERIODIC,PERIODIC};
358 Box<3, double> box( { -0.01, -0.01, 0.0 }, { 0.01, 0.01, 0.003 });
368 Point<3,double> p1({-0.0067499999999999999237,-0.0012499999999999995923,0.001250000000000000026});
369 Point<3,double> p2({-0.0067499999999999999237,-0.0012499999999999993755,0.001250000000000000026});
379 if (vcl.
rank() == proc2)
381 BOOST_REQUIRE(vp_id2.size() != 0);
382 BOOST_REQUIRE(vp_id1.
size() == 0);
385 if (vcl.
rank() == proc1)
387 BOOST_REQUIRE(vp_id2.size() == 0 );
388 BOOST_REQUIRE(vp_id1.
size() != 0 );
393BOOST_AUTO_TEST_CASE( CartDecomposition_check_cross_consistency_between_proc_idbc_and_ghost2 )
400 size_t bc[3] = {PERIODIC,PERIODIC,PERIODIC};
403 Box<3, double> box( { -0.01, -0.01, 0.0 }, { 0.01, 0.01, 0.003 });
413 for (
size_t j = 0 ; j < 3 ; j++ )
431 BOOST_REQUIRE(proc1 < vcl.
size());
432 BOOST_REQUIRE(proc2 < vcl.
size());
439 if (vcl.
rank() == proc2)
441 BOOST_REQUIRE(vp_id2.size() != 0);
442 BOOST_REQUIRE(vp_id1.
size() == 0);
445 if (vcl.
rank() == proc1)
447 BOOST_REQUIRE(vp_id2.size() == 0 );
448 BOOST_REQUIRE(vp_id1.
size() != 0 );
464 BOOST_REQUIRE(proc1 < vcl.
size());
465 BOOST_REQUIRE(proc2 < vcl.
size());
472 if (vcl.
rank() == proc2)
474 BOOST_REQUIRE(vp_id4.size() != 0);
475 BOOST_REQUIRE(vp_id3.
size() == 0);
478 if (vcl.
rank() == proc1)
480 BOOST_REQUIRE(vp_id4.size() == 0 );
481 BOOST_REQUIRE(vp_id3.
size() != 0 );
491BOOST_AUTO_TEST_CASE( CartDecomposition_non_periodic_test_dist_grid)
506 size_t n_sub = n_proc * SUB_UNIT_FACTOR*4*4*4;
509 for (
int i = 0; i < 3; i++)
510 {div[i] = openfpm::math::round_big_2(pow(n_sub,1.0/3));}
513 for (
int i = 0; i < 3; i++)
514 {div_sub[i] = div[i] / 4;}
522 size_t bc[] = { NON_PERIODIC, NON_PERIODIC, NON_PERIODIC };
542 for (
size_t j = 0; j < pr.
size(); j++)
544 if (pr.get(j) == proc)
545 { found =
true;
break;}
553 BOOST_REQUIRE_EQUAL(found,
true);
559 BOOST_REQUIRE_EQUAL(val,
true);
562BOOST_AUTO_TEST_CASE( CartDecomposition_nsub_algo_functions_test)
567 nsub_to_div2<3>(div,n_sub,3);
569 BOOST_REQUIRE_EQUAL(div[0],8ul);
570 BOOST_REQUIRE_EQUAL(div[1],8ul);
571 BOOST_REQUIRE_EQUAL(div[2],8ul);
573 nsub_to_div2<3>(div,n_sub,2);
575 BOOST_REQUIRE_EQUAL(div[0],16ul);
576 BOOST_REQUIRE_EQUAL(div[1],16ul);
577 BOOST_REQUIRE_EQUAL(div[2],1ul);
579 nsub_to_div2<3>(div,n_sub,1);
581 BOOST_REQUIRE_EQUAL(div[0],128ul);
582 BOOST_REQUIRE_EQUAL(div[1],1ul);
583 BOOST_REQUIRE_EQUAL(div[2],1ul);
586 nsub_to_div<3>(div,n_sub,3);
588 BOOST_REQUIRE_EQUAL(div[0],5ul);
589 BOOST_REQUIRE_EQUAL(div[1],5ul);
590 BOOST_REQUIRE_EQUAL(div[2],5ul);
592 nsub_to_div<3>(div,n_sub,2);
594 BOOST_REQUIRE_EQUAL(div[0],13ul);
595 BOOST_REQUIRE_EQUAL(div[1],13ul);
596 BOOST_REQUIRE_EQUAL(div[2],1ul);
598 nsub_to_div<3>(div,n_sub,1);
600 BOOST_REQUIRE_EQUAL(div[0],192ul);
601 BOOST_REQUIRE_EQUAL(div[1],1ul);
602 BOOST_REQUIRE_EQUAL(div[2],1ul);
610 for(
size_t i = 0 ; i < 50 ; i++)
612 domain.setLow(i,0.0);
613 domain.setHigh(i,1.0);
614 bc[i] = NON_PERIODIC;
624 auto & v_cl = create_vcluster();
625 if (v_cl.size() == 1)
627 for (
size_t i = 0 ; i < 50 ; i++)
630 {BOOST_REQUIRE_EQUAL(div2[i],2ul);}
632 {BOOST_REQUIRE_EQUAL(div2[i],1ul);}
636 if (v_cl.size() == 2)
638 for (
size_t i = 0 ; i < 50 ; i++)
641 {BOOST_REQUIRE_EQUAL(div2[i],2ul);}
643 {BOOST_REQUIRE_EQUAL(div2[i],1ul);}
647 if (v_cl.size() == 3)
649 for (
size_t i = 0 ; i < 50 ; i++)
652 {BOOST_REQUIRE_EQUAL(div2[i],13ul);}
654 {BOOST_REQUIRE_EQUAL(div2[i],1ul);}
658 if (v_cl.size() == 4)
660 for (
size_t i = 0 ; i < 50 ; i++)
663 {BOOST_REQUIRE_EQUAL(div2[i],2ul);}
665 {BOOST_REQUIRE_EQUAL(div2[i],1ul);}
669 if (v_cl.size() == 5)
671 for (
size_t i = 0 ; i < 50 ; i++)
674 {BOOST_REQUIRE_EQUAL(div2[i],2ul);}
676 {BOOST_REQUIRE_EQUAL(div2[i],1ul);}
680 if (v_cl.size() == 6)
682 for (
size_t i = 0 ; i < 50 ; i++)
685 {BOOST_REQUIRE_EQUAL(div2[i],7ul);}
687 {BOOST_REQUIRE_EQUAL(div2[i],1ul);}
692BOOST_AUTO_TEST_SUITE_END()
This class represent an N-dimensional box.
__device__ __host__ T getLow(int i) const
get the i-coordinate of the low bound interval of the box
__device__ __host__ T getHigh(int i) const
get the high interval of the box
class to select the returned id by ghost_processorID
class to select the returned id by ghost_processorID
This class decompose a space into sub-sub-domains and distribute them across processors.
This class decompose a space into sub-sub-domains and distribute them across processors.
void setGoodParameters(::Box< dim, T > &domain_, const size_t(&bc)[dim], const Ghost< dim, T > &ghost, size_t dec_gran, const grid_sm< dim, void > &sec_dist=grid_sm< dim, void >())
Set the best parameters for the decomposition.
bool check_consistency()
function to check the consistency of the information of the decomposition
size_t processorIDBC(encapc< 1, Point< dim, T >, Mem > p)
Given a point return in which processor the point/particle should go.
void decompose(dec_options opt=dec_options::DEC_NONE)
Start decomposition.
CartDecomposition< dim, T, Memory, layout_base, Distribution > duplicate(const Ghost< dim, T > &g) const
It create another object that contain the same decomposition information but with different ghost box...
bool is_equal(CartDecomposition< dim, T, Memory > &cart)
Check if the CartDecomposition contain the same information.
void getParameters(size_t(&div_)[dim])
return the parameters of the decomposition
void getSubSubDomainPosition(size_t id, T(&pos)[dim])
function that return the position of the cell in the space
void setSubSubDomainComputationCost(size_t id, size_t weight)
Function that set the computational cost for a of a sub-sub domain.
size_t getNSubDomain()
Get the number of local sub-domains.
SpaceBox< dim, T > getSubDomain(size_t lc)
Get the local sub-domain.
void setParameters(const size_t(&div_)[dim], ::Box< dim, T > &domain_, const size_t(&bc)[dim], const Ghost< dim, T > &ghost, const grid_sm< dim, void > &sec_dist=grid_sm< dim, void >())
Set the parameter of the decomposition.
bool is_equal_ng(CartDecomposition< dim, T, Memory > &cart)
Check if the CartDecomposition contain the same information with the exception of the ghost part It i...
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.
size_t rank()
Get the process unit id.
size_t size()
Get the total number of processors.
void sum(T &num)
Sum the numbers across all processors and get the result.
size_t getProcessingUnits()
Get the total number of processors.
Implementation of VCluster class.
size_t getProcessorNEGhost(size_t id) const
Get the number of External ghost boxes for one processor id.
const openfpm::vector< size_t > ghost_processorID(const Point< dim, T > &p, const int opt=MULTIPLE)
Given a position it return if the position belong to any neighborhood processor ghost (Internal ghost...
size_t getIGhostBoxProcessor(size_t b_id) const
Given the internal ghost box id, it return the near processor at witch belong or the near processor t...
inline ::Box< dim, T > getIGhostBox(size_t b_id) const
Given the internal ghost box id, it return the internal ghost box.
const ::Box< dim, T > & getProcessorEGhostBox(size_t id, size_t j) const
Get the j External ghost box.
const ::Box< dim, T > & getProcessorIGhostBox(size_t id, size_t j) const
Get the j Internal ghost box for one processor.
size_t getProcessorNIGhost(size_t id) const
Get the number of Internal ghost boxes for one processor.
size_t getNIGhostBox() const
Return the total number of the calculated internal ghost boxes.
size_t getNNProcessors() const
Get the number of Near processors.
Implementation of 1-D std::vector like structure.