Commit 30140d91 authored by Pietro Incardona's avatar Pietro Incardona

Test Suite working with Parmetis

parent 5e916b35
...@@ -12,7 +12,6 @@ ...@@ -12,7 +12,6 @@
#include <cmath> #include <cmath>
#include "VCluster.hpp" #include "VCluster.hpp"
#include "Graph/CartesianGraphFactory.hpp" #include "Graph/CartesianGraphFactory.hpp"
#include "Graph/DistCartesianGraphFactory.hpp"
#include "Decomposition.hpp" #include "Decomposition.hpp"
#include "Vector/map_vector.hpp" #include "Vector/map_vector.hpp"
#include <vector> #include <vector>
...@@ -393,6 +392,133 @@ public: ...@@ -393,6 +392,133 @@ public:
} }
} }
/*! It calculate the internal ghost boxes
*
* Example: Processor 10 calculate
* B8_0 B9_0 B9_1 and B5_0
*
*
*
\verbatim
+----------------------------------------------------+
| |
| Processor 8 |
| Sub+domain 0 +-----------------------------------+
| | |
| | |
++--------------+---+---------------------------+----+ Processor 9 |
| | | B8_0 | | Subdomain 0 |
| +------------------------------------+ |
| | | | | |
| | | |B9_0| |
| | B | Local processor | | |
| Processor 5 | 5 | Subdomain 0 | | |
| Subdomain 0 | _ | +----------------------------------------+
| | 0 | | | |
| | | | | |
| | | | | Processor 9 |
| | | |B9_1| Subdomain 1 |
| | | | | |
| | | | | |
| | | | | |
+--------------+---+---------------------------+----+ |
| |
+-----------------------------------+
\endverbatim
and also
G8_0 G9_0 G9_1 G5_0 (External ghost boxes)
+----------------------------------------------------+
| Processor 8 |
| Subdomain 0 +-----------------------------------+
| | |
| +---------------------------------------------+ |
| | G8_0 | | |
+-----+---------------+------------------------------------+ | Processor 9 |
| | | | | Subdomain 0 |
| | | |G9_0| |
| | | | | |
| | | | | |
| | | Local processor | | |
| Processor 5 | | Sub+domain 0 | | |
| Subdomain 0 | | +-----------------------------------+
| | | | | |
| | G | | | |
| | 5 | | | Processor 9 |
| | | | | | Subdomain 1 |
| | 0 | |G9_1| |
| | | | | |
| | | | | |
+---------------------+------------------------------------+ | |
| | | |
+----------------------------------------+----+------------------------------+
\endverbatim
*
*
*
* \param ghost margins for each dimensions (p1 negative part) (p2 positive part)
*
*
\verbatim
^ p2[1]
|
|
+----+----+
| |
| |
p1[0]<-----+ +----> p2[0]
| |
| |
+----+----+
|
v p1[1]
\endverbatim
*
*
*/
void calculateGhostBoxes()
{
#ifdef DEBUG
// the ghost margins are assumed to be smaller
// than one sub-domain
for (size_t i = 0; i < dim; i++)
{
if (fabs(ghost.template getLow(i)) >= ss_box.getHigh(i) || ghost.template getHigh(i) >= ss_box.getHigh(i))
{
std::cerr << "Error " << __FILE__ << ":" << __LINE__ << " : Ghost are bigger than one sub-domain" << "\n";
}
}
#endif
// Intersect all the local sub-domains with the sub-domains of the contiguous processors
// create the internal structures that store ghost information
ie_ghost<dim, T>::create_box_nn_processor_ext(v_cl, ghost, sub_domains, box_nn_processor, *this);
ie_ghost<dim, T>::create_box_nn_processor_int(v_cl, ghost, sub_domains, box_nn_processor, *this);
ie_loc_ghost<dim,T>::create(sub_domains,domain,ghost,bc);
// get the smallest sub-domain dimension on each direction
for (size_t i = 0; i < dim; i++)
{
if (fabs(ghost.template getLow(i)) >= ss_box.getHigh(i) || ghost.template getHigh(i) >= ss_box.getHigh(i))
{
std::cerr << "Error " << __FILE__ << ":" << __LINE__ << " : Ghost are bigger than one sub-domain" << "\n";
}
}
}
public: public:
static constexpr int dims = dim; static constexpr int dims = dim;
...@@ -574,132 +700,6 @@ public: ...@@ -574,132 +700,6 @@ public:
} }
} }
/*! It calculate the internal ghost boxes
*
* Example: Processor 10 calculate
* B8_0 B9_0 B9_1 and B5_0
*
*
*
\verbatim
+----------------------------------------------------+
| |
| Processor 8 |
| Sub+domain 0 +-----------------------------------+
| | |
| | |
++--------------+---+---------------------------+----+ Processor 9 |
| | | B8_0 | | Subdomain 0 |
| +------------------------------------+ |
| | | | | |
| | | |B9_0| |
| | B | Local processor | | |
| Processor 5 | 5 | Subdomain 0 | | |
| Subdomain 0 | _ | +----------------------------------------+
| | 0 | | | |
| | | | | |
| | | | | Processor 9 |
| | | |B9_1| Subdomain 1 |
| | | | | |
| | | | | |
| | | | | |
+--------------+---+---------------------------+----+ |
| |
+-----------------------------------+
\endverbatim
and also
G8_0 G9_0 G9_1 G5_0 (External ghost boxes)
+----------------------------------------------------+
| Processor 8 |
| Subdomain 0 +-----------------------------------+
| | |
| +---------------------------------------------+ |
| | G8_0 | | |
+-----+---------------+------------------------------------+ | Processor 9 |
| | | | | Subdomain 0 |
| | | |G9_0| |
| | | | | |
| | | | | |
| | | Local processor | | |
| Processor 5 | | Sub+domain 0 | | |
| Subdomain 0 | | +-----------------------------------+
| | | | | |
| | G | | | |
| | 5 | | | Processor 9 |
| | | | | | Subdomain 1 |
| | 0 | |G9_1| |
| | | | | |
| | | | | |
+---------------------+------------------------------------+ | |
| | | |
+----------------------------------------+----+------------------------------+
\endverbatim
*
*
*
* \param ghost margins for each dimensions (p1 negative part) (p2 positive part)
*
*
\verbatim
^ p2[1]
|
|
+----+----+
| |
| |
p1[0]<-----+ +----> p2[0]
| |
| |
+----+----+
|
v p1[1]
\endverbatim
*
*
*/
void calculateGhostBoxes()
{
#ifdef DEBUG
// the ghost margins are assumed to be smaller
// than one sub-domain
for (size_t i = 0; i < dim; i++)
{
if (fabs(ghost.template getLow(i)) >= ss_box.getHigh(i) || ghost.template getHigh(i) >= ss_box.getHigh(i))
{
std::cerr << "Error " << __FILE__ << ":" << __LINE__ << " : Ghost are bigger than one sub-domain" << "\n";
}
}
#endif
// Intersect all the local sub-domains with the sub-domains of the contiguous processors
// create the internal structures that store ghost information
ie_ghost<dim, T>::create_box_nn_processor_ext(v_cl, ghost, sub_domains, box_nn_processor, *this);
ie_ghost<dim, T>::create_box_nn_processor_int(v_cl, ghost, sub_domains, box_nn_processor, *this);
ie_loc_ghost<dim,T>::create(sub_domains,domain,ghost,bc);
// get the smallest sub-domain dimension on each direction
for (size_t i = 0; i < dim; i++)
{
if (fabs(ghost.template getLow(i)) >= ss_box.getHigh(i) || ghost.template getHigh(i) >= ss_box.getHigh(i))
{
std::cerr << "Error " << __FILE__ << ":" << __LINE__ << " : Ghost are bigger than one sub-domain" << "\n";
}
}
}
/*! \brief It create another object that contain the same decomposition information but with different ghost boxes /*! \brief It create another object that contain the same decomposition information but with different ghost boxes
* *
* \param g ghost * \param g ghost
......
...@@ -50,384 +50,7 @@ void setComputationCosts3D(CartDecomposition<3, float> &dec, size_t n_v, Point<3 ...@@ -50,384 +50,7 @@ void setComputationCosts3D(CartDecomposition<3, float> &dec, size_t n_v, Point<3
} }
} }
BOOST_AUTO_TEST_CASE( CartDecomposition_test_2D )
{
//size_t balance_values_4p_64[] = {2.86,2.86,2.86,6.7,7.43,4.9,8.07,1.82,1.82,4.47,5.3};
// Vcluster
Vcluster & vcl = *global_v_cluster;
// non-periodic boundary condition
size_t bc[2] = { NON_PERIODIC, NON_PERIODIC };
// Initialize the global VCluster
init_global_v_cluster(&boost::unit_test::framework::master_test_suite().argc,&boost::unit_test::framework::master_test_suite().argv);
//! [Create CartDecomposition]
CartDecomposition<2, float> dec(vcl);
// Init DLB tool
DLB dlb(vcl);
// Physical domain
Box<2, float> box( { 0.0, 0.0 }, { 10.0, 10.0 });
size_t div[2];
// Get the number of processor and calculate the number of sub-domain
// for each processor (SUB_UNIT_FACTOR=64)
size_t n_proc = vcl.getProcessingUnits();
size_t n_sub = n_proc * SUB_UNIT_FACTOR;
// Set the number of sub-domains on each dimension (in a scalable way)
for (int i = 0; i < 2; i++)
{
div[i] = openfpm::math::round_big_2(pow(n_sub,1.0/2));
}
// Define ghost
Ghost<2, float> g(0.01);
// Decompose
dec.setParameters(div, box, bc, g);
// Set unbalance threshold
dlb.setHeurisitc(DLB::Heuristic::UNBALANCE_THRLD);
dlb.setThresholdLevel(DLB::ThresholdLevel::THRLD_MEDIUM);
// Add weights to points
// First create the center of the weights distribution, check it is coherent to the size of the domain
Point<2, float> center( { 2.0, 2.0 });
// Radius of the weights distribution
float radius = 2.0;
// Weight if the distribution (high)
size_t weight_h = 5, weight_l = 1;
setComputationCosts(dec, dec.getNSubSubDomains(), center, radius, weight_h, weight_l);
dec.getDistribution().write("DLB_test_graph_0.vtk");
dec.decompose();
dec.getDistribution().write("DLB_test_graph_1.vtk");
float stime = 0.0, etime = 10.0, tstep = 0.1;
for(float t = stime, i = 1; t < etime; t = t + tstep, i++)
{
if(t < etime/2)
{
center.get(0) += tstep;
center.get(1) += tstep;
}
else
{
center.get(0) -= tstep;
center.get(1) -= tstep;
}
setComputationCosts(dec, dec.getNSubSubDomains(), center, radius, weight_h, weight_l);
dlb.endIteration();
if(dec.rebalance(dlb))
dec.write("DLB_test_graph_cart_" + std::to_string(i+1) + "_");
std::stringstream str;
str << "DLB_test_graph_" << i + 1 << ".vtk";
dec.getDistribution().write(str.str());
}
// For each calculated ghost box
for (size_t i = 0; i < dec.getNIGhostBox(); i++)
{
SpaceBox<2,float> b = dec.getIGhostBox(i);
size_t proc = dec.getIGhostBoxProcessor(i);
// sample one point inside the box
Point<2,float> p = b.rnd();
// Check that ghost_processorsID return that processor number
const openfpm::vector<size_t> & pr = dec.template ghost_processorID<CartDecomposition<2,float>::processor_id>(p);
bool found = false;
for (size_t j = 0; j < pr.size(); j++)
{
if (pr.get(j) == proc)
{ found = true; break;}
}
if (found == false)
{
const openfpm::vector<size_t> pr2 = dec.template ghost_processorID<CartDecomposition<2,float>::processor_id>(p);
}
BOOST_REQUIRE_EQUAL(found,true);
}
// Check the consistency
bool val = dec.check_consistency();
BOOST_REQUIRE_EQUAL(val,true);
}
BOOST_AUTO_TEST_CASE( CartDecomposition_test_2D_sar)
{
// Vcluster
Vcluster & vcl = *global_v_cluster;
// non-periodic boundary condition
size_t bc[2] = { NON_PERIODIC, NON_PERIODIC };
// Initialize the global VCluster
init_global_v_cluster(&boost::unit_test::framework::master_test_suite().argc,&boost::unit_test::framework::master_test_suite().argv);
//! [Create CartDecomposition]
CartDecomposition<2, float> dec(vcl);
// Init DLB tool
DLB dlb(vcl);
// Physical domain
Box<2, float> box( { 0.0, 0.0 }, { 10.0, 10.0 });
size_t div[2];
// Get the number of processor and calculate the number of sub-domain
// for each processor (SUB_UNIT_FACTOR=64)
size_t n_proc = vcl.getProcessingUnits();
size_t n_sub = n_proc * SUB_UNIT_FACTOR;
// Set the number of sub-domains on each dimension (in a scalable way)
for (int i = 0; i < 2; i++)
{
div[i] = openfpm::math::round_big_2(pow(n_sub,1.0/2));
}
// Define ghost
Ghost<2, float> g(0.01);
// Decompose
dec.setParameters(div, box, bc, g);
// Set type of heuristic
dlb.setHeurisitc(DLB::Heuristic::SAR_HEURISTIC);
// Add weights to points
// First create the center of the weights distribution, check it is coherent to the size of the domain
Point<2, float> center( { 2.0, 2.0 });
// Radius of the weights distribution
float radius = 2.0;
// Weight if the distribution (high)
size_t weight_h = 5, weight_l = 1;
size_t n_v = pow(div[0], 2);
setComputationCosts(dec, n_v, center, radius, weight_h, weight_l);
dec.decompose();
dec.getDistribution().write("DLB_test_graph_0.vtk");
float stime = 0.0, etime = 10.0, tstep = 0.1;
dlb.setSimulationStartTime(0);
dlb.setSimulationEndTime(10);
for(float t = stime, i = 1; t < etime; t = t + tstep, i++)
{
dlb.startIteration();
if(t < etime/2)
{
center.get(0) += tstep;
center.get(1) += tstep;
}
else
{
center.get(0) -= tstep;
center.get(1) -= tstep;
}
setComputationCosts(dec, n_v, center, radius, weight_h, weight_l);
sleep((n_v/dec.getProcessorLoad())/vcl.getProcessingUnits());
dlb.endIteration();
if(dec.rebalance(dlb))
{
dec.write("DLB_test_graph_cart_" + std::to_string(i) + "_");
}
std::stringstream str;
str << "DLB_test_graph_" << i << ".vtk";
dec.getDistribution().write(str.str());
}
// For each calculated ghost box
for (size_t i = 0; i < dec.getNIGhostBox(); i++)
{
SpaceBox<2,float> b = dec.getIGhostBox(i);
size_t proc = dec.getIGhostBoxProcessor(i);
// sample one point inside the box
Point<2,float> p = b.rnd();
// Check that ghost_processorsID return that processor number
const openfpm::vector<size_t> & pr = dec.template ghost_processorID<CartDecomposition<2,float>::processor_id>(p);
bool found = false;
for (size_t j = 0; j < pr.size(); j++)
{
if (pr.get(j) == proc)
{ found = true; break;}
}
if (found == false)
{
const openfpm::vector<size_t> pr2 = dec.template ghost_processorID<CartDecomposition<2,float>::processor_id>(p);
}
BOOST_REQUIRE_EQUAL(found,true);
}
// Check the consistency
bool val = dec.check_consistency();
BOOST_REQUIRE_EQUAL(val,true);
}
BOOST_AUTO_TEST_CASE( CartDecomposition_test_3D)
{
// Vcluster
Vcluster & vcl = *global_v_cluster;
// non-periodic boundary condition
size_t bc[3] = { NON_PERIODIC, NON_PERIODIC, NON_PERIODIC };
// Initialize the global VCluster
init_global_v_cluster(&boost::unit_test::framework::master_test_suite().argc,&boost::unit_test::framework::master_test_suite().argv);
//! [Create CartDecomposition]
CartDecomposition<3, float> dec(vcl);
// Init DLB tool
DLB dlb(vcl);
// Physical domain
Box<3, float> box( { 0.0, 0.0, 0.0 }, { 10.0, 10.0, 10.0 });
size_t div[3];
// Get the number of processor and calculate the number of sub-domain
// for each processor (SUB_UNIT_FACTOR=64)
size_t n_proc = vcl.getProcessingUnits();
size_t n_sub = n_proc * SUB_UNIT_FACTOR;
// Set the number of sub-domains on each dimension (in a scalable way)
for (int i = 0; i < 3; i++)
{
div[i] = openfpm::math::round_big_2(pow(n_sub,1.0/3));
}
// Define ghost
Ghost<3, float> g(0.01);
// Decompose
dec.setParameters(div, box, bc, g);
// Set unbalance threshold
dlb.setHeurisitc(DLB::Heuristic::UNBALANCE_THRLD);
dlb.setThresholdLevel(DLB::ThresholdLevel::THRLD_MEDIUM);
// Add weights to points
// First create the center of the weights distribution, check it is coherent to the size of the domain
Point<3, float> center( { 2.0, 2.0, 2.0 });
// Radius of the weights distribution
float radius = 2.0;
// Weight if the distribution (high)
size_t weight_h = 5, weight_l = 1;
size_t n_v = pow(div[0], 3);
setComputationCosts3D(dec, n_v, center, radius, weight_h, weight_l);
dec.decompose();
dec.getDistribution().write("DLB_test_graph_0.vtk");
float stime = 0.0, etime = 10.0, tstep = 0.1;
for(float t = stime, i = 1; t < etime; t = t + tstep, i++)
{
if(t < etime/2)
{
center.get(0) += tstep;
center.get(1) += tstep;
center.get(2) += tstep;
}
else
{
center.get(0) -= tstep;
center.get(1) -= tstep;
center.get(2) -= tstep;
}
setComputationCosts3D(dec, n_v, center, radius, weight_h, weight_l);
dlb.endIteration();
dec.rebalance(dlb);
std::stringstream str;
str << "DLB_test_graph_" << i << ".vtk";
dec.getDistribution().write(str.str());
}
// For each calculated ghost box
for (size_t i = 0; i < dec.getNIGhostBox(); i++)
{
SpaceBox<3,float> b = dec.getIGhostBox(i);
size_t proc = dec.getIGhostBoxProcessor(i);
// sample one point inside the box
Point<3,float> p = b.rnd();
// Check that ghost_processorsID return that processor number
const openfpm::vector<size_t> & pr = dec.template ghost_processorID<CartDecomposition<3,float>::processor_id>(p);
bool found = false;
for (size_t j = 0; j < pr.size(); j++)
{
if (pr.get(j) == proc)
{ found = true; break;}
}
if (found == false)
{
const openfpm::vector<size_t> pr2 = dec.template ghost_processorID<CartDecomposition<3,float>::processor_id>(p);
}
BOOST_REQUIRE_EQUAL(found,true);
}
// Check the consistency
bool val = dec.check_consistency();
BOOST_REQUIRE_EQUAL(val,true);
}
BOOST_AUTO_TEST_CASE( CartDecomposition_non_periodic_test) BOOST_AUTO_TEST_CASE( CartDecomposition_non_periodic_test)
{ {
...@@ -656,15 +279,14 @@ BOOST_AUTO_TEST_CASE( CartDecomposition_ext_non_periodic_test) ...@@ -656,15 +279,14 @@ BOOST_AUTO_TEST_CASE( CartDecomposition_ext_non_periodic_test)
dec.setParameters(div,box,bc,g); dec.setParameters(div,box,bc,g);
dec.decompose(); dec.decompose();
// create a ghost border
dec.calculateGhostBoxes();
//! [Extend CartDecomposition] //! [Extend CartDecomposition]
Box<3,float> box_ext({-0.1,-0.1,-0.1},{1.1,1.1,1.1}); Box<3,float> box_ext({-0.1,-0.1,-0.1},{1.1,1.1,1.1});
// Use the old decomposition to extend on a bigger domain // Use the old decomposition to extend on a bigger domain
/* CartDecomposition_ext<3,float> dec_ext(dec,g,box_ext); CartDecomposition_ext<3,float> dec_ext(vcl);
dec_ext.setParameters(dec,g,box_ext);
//! [Extend CartDecomposition] //! [Extend CartDecomposition]
...@@ -683,7 +305,7 @@ BOOST_AUTO_TEST_CASE( CartDecomposition_ext_non_periodic_test) ...@@ -683,7 +305,7 @@ BOOST_AUTO_TEST_CASE( CartDecomposition_ext_non_periodic_test)
vcl.sum(volume); vcl.sum(volume);
vcl.execute(); vcl.execute();