Commit 7c95a7ff authored by incardon's avatar incardon

Adding operators= to CartDecomposition and subclasses

parent aed24a54
openfpm_vcluster @ 2ce2e82e
Subproject commit b57540c803a8b7c269013f4a3c59b3f148d71edc
Subproject commit 2ce2e82e1b2b9acd6616e8eb32ec745ed16c791a
......@@ -31,14 +31,7 @@
#define CARTDEC_ERROR 2000lu
// Macro that decide what to do in case of error
#ifdef STOP_ON_ERROR
#define ACTION_ON_ERROR() exit(1);
#elif defined(THROW_ON_ERROR)
#define ACTION_ON_ERROR() throw CARTDEC_ERROR;
#else
#define ACTION_ON_ERROR()
#endif
#include "util/se_util.hpp"
/**
* \brief This class decompose a space into subspaces
......@@ -127,6 +120,21 @@ private:
//! Cell-list that store the geometrical information of the local internal ghost boxes
CellList<dim,T,FAST> lgeo_cell;
// Heap memory receiver
HeapMemory hp_recv;
// vector v_proc
openfpm::vector<size_t> v_proc;
// Receive counter
size_t recv_cnt;
// reference counter of the object in case is shared between object
long int ref_cnt;
// Save the ghost boundaries
Ghost<dim,T> ghost;
/*! \brief Constructor, it decompose and distribute the sub-domains across the processors
*
* \param v_cl Virtual cluster, used internally for communications
......@@ -286,10 +294,6 @@ private:
lgeo_cell.Initialize(domain,div,orig);
}
// Save the ghost boundaries
Ghost<dim,T> ghost;
/*! \brief Create the subspaces that decompose your domain
*
*/
......@@ -325,19 +329,6 @@ private:
}
}
// Heap memory receiver
HeapMemory hp_recv;
// vector v_proc
openfpm::vector<size_t> v_proc;
// Receive counter
size_t recv_cnt;
// reference counter of the object in case is shared between object
long int ref_cnt;
public:
//! Increment the reference counter
......@@ -366,6 +357,28 @@ public:
bbox.zero();
}
/*! \brief Cartesian decomposition copy constructor
*
* \param cart object to copy
*
*/
CartDecomposition(const CartDecomposition<dim,T,Memory,Domain> & cart)
:nn_prcs<dim,T>(cart.v_cl),v_cl(cart.v_cl),ref_cnt(0)
{
this->operator=(cart);
}
/*! \brief Cartesian decomposition copy constructor
*
* \param cart object to copy
*
*/
CartDecomposition(CartDecomposition<dim,T,Memory,Domain> && cart)
:nn_prcs<dim,T>(cart.v_cl),v_cl(cart.v_cl),ref_cnt(0)
{
this->operator=(cart);
}
//! Cartesian decomposition destructor
~CartDecomposition()
{}
......@@ -536,7 +549,7 @@ p1[0]<-----+ +----> p2[0]
{
if (ghost.template getLow(i) >= domain.template getHigh(i) / gr.size(i) || ghost.template getHigh(i) >= domain.template getHigh(i) / gr.size(i))
{
std::cerr << "Error " << __FILE__ << ":" << __LINE__ << " : Ghost are bigger than one domain" << "\n";
std::cerr << "Error " << __FILE__ << ":" << __LINE__ << " : Ghost are bigger than one sub-domain" << "\n";
}
}
#endif
......@@ -557,11 +570,100 @@ p1[0]<-----+ +----> p2[0]
{
if (ghost.template getLow(i) >= ss_box.getHigh(i) || ghost.template getHigh(i) >= domain.template getHigh(i) / gr.size(i))
{
std::cerr << "Error " << __FILE__ << ":" << __LINE__ << " : Ghost are bigger than one domain" << "\n";
std::cerr << "Error " << __FILE__ << ":" << __LINE__ << " : Ghost are bigger than one sub-domain" << "\n";
}
}
}
/*! \brief It create anothe object that contain the same information and act in the same way
*
* \return a duplicated decomposition
*
*/
CartDecomposition<dim,T,Memory,Domain> duplicate()
{
CartDecomposition<dim,T,Memory,Domain> cart(v_cl);
(static_cast<ie_loc_ghost<dim,T>*>(&cart))->operator=(static_cast<ie_loc_ghost<dim,T>>(*this));
(static_cast<nn_prcs<dim,T>*>(&cart))->operator=(static_cast<nn_prcs<dim,T>>(*this));
(static_cast<ie_ghost<dim,T>*>(&cart))->operator=(static_cast<ie_ghost<dim,T>>(*this));
cart.sub_domains = sub_domains;
cart.box_nn_processor = box_nn_processor;
cart.fine_s = fine_s;
cart.gr = gr;
cart.cd = cd;
cart.domain = domain;
std::copy(spacing,spacing+3,cart.spacing);
//! Runtime virtual cluster
cart.v_cl = v_cl;
//! Cell-list that store the geometrical information of the local internal ghost boxes
cart.lgeo_cell = lgeo_cell;
cart.ghost = ghost;
return cart;
}
/*! \brief Copy the element
*
* \param cart element to copy
*
*/
CartDecomposition<dim,T,Memory,Domain> & operator=(const CartDecomposition & cart)
{
static_cast<ie_loc_ghost<dim,T>*>(this)->operator=(static_cast<ie_loc_ghost<dim,T>>(cart));
static_cast<nn_prcs<dim,T>*>(this)->operator=(static_cast<nn_prcs<dim,T>>(cart));
static_cast<ie_ghost<dim,T>*>(this)->operator=(static_cast<ie_ghost<dim,T>>(cart));
sub_domains = cart.sub_domains;
box_nn_processor = cart.box_nn_processor;
fine_s = cart.fine_s;
gr = cart.gr;
cd = cart.cd;
domain = cart.domain;
std::copy(cart.spacing,cart.spacing+3,spacing);
//! Runtime virtual cluster
v_cl = cart.v_cl;
//! Cell-list that store the geometrical information of the local internal ghost boxes
lgeo_cell = cart.lgeo_cell;
ghost = cart.ghost;
return *this;
}
/*! \brief Copy the element, move semantic
*
* \param cart element to copy
*
*/
CartDecomposition<dim,T,Memory,Domain> & operator=(CartDecomposition && cart)
{
static_cast<ie_loc_ghost<dim,T>*>(this)->operator=(static_cast<ie_loc_ghost<dim,T>*>(cart));
static_cast<nn_prcs<dim,T>*>(this)->operator=(static_cast<nn_prcs<dim,T>*>(cart));
static_cast<ie_ghost<dim,T>*>(this)->operator=(static_cast<ie_ghost<dim,T>*>(cart));
sub_domains.swap(cart.sub_domains);
box_nn_processor.swap(cart.box_nn_processor);
fine_s.swap(cart.fine_s);
gr = cart.gr;
cd = cart.cd;
domain = cart.domain;
std::copy(cart.spacing,cart.spacing+3,spacing);
//! Runtime virtual cluster
v_cl = cart.v_cl;
//! Cell-list that store the geometrical information of the local internal ghost boxes
lgeo_cell.swap(cart.lgeo_cell);
ghost = cart.ghost;
return *this;
}
/*! \brief The default grid size
*
* The default grid is always an isotropic grid that adapt with the number of processors,
......
......@@ -75,6 +75,17 @@ BOOST_AUTO_TEST_CASE( CartDecomposition_test_use)
bool val = dec.check_consistency();
BOOST_REQUIRE_EQUAL(val,true);
// We duplicate the decomposition
CartDecomposition<3,float> dec2 = dec.duplicate();
// We duplicate the decomposition redefining the ghost
// Define ghost
Ghost<3,float> g3(0.02);
// We duplicate the decomposition refefining the ghost
// CartDecomposition<3,float> dec3 = dec.duplicate(g3);
}
BOOST_AUTO_TEST_SUITE_END()
......
......@@ -131,6 +131,49 @@ struct N_box
// Near processor sub-domains
typename openfpm::vector<::Box<dim,T>> bx;
//! Default constructor
N_box() {};
//! Copy constructor
N_box(const N_box<dim,T> & b)
{
this->operator=(b);
}
//! Copy constructor
N_box(N_box<dim,T> && b)
{
this->operator=(b);
}
/*! \brief Copy the element
*
* \param ele element to copy
*
*/
N_box<dim,T> & operator=(const N_box<dim,T> & ele)
{
id = ele.id;
bx = ele.bx;
return * this;
}
/*! \brief Copy the element
*
* \param ele element to copy
*
*/
N_box<dim,T> & operator=(N_box<dim,T> && ele)
{
id = ele.id;
bx.swap(ele.bx);
return * this;
}
};
// It store all the boxes of the near processors in a linear array
......
......@@ -127,6 +127,43 @@ protected:
public:
//! Default constructor
ie_loc_ghost() {};
//! Constructor from another ie_loc_ghost
ie_loc_ghost(const ie_loc_ghost<dim,T> & ilg)
{
this->operator=(ilg);
};
//! Constructor from temporal ie_loc_ghost
ie_loc_ghost(ie_loc_ghost<dim,T> && ilg)
{
this->operator=(ilg);
}
/*! \brief copy the ie_loc_ghost
*
* \param ilg object to copy
*
*/
ie_loc_ghost<dim,T> & operator=(const ie_loc_ghost<dim,T> & ilg)
{
loc_ghost_box = ilg.loc_ghost_box;
return *this;
}
/*! \brief copy the ie_loc_ghost
*
* \param ilg object to copy
*
*/
ie_loc_ghost<dim,T> & operator=(ie_loc_ghost<dim,T> && ilg)
{
loc_ghost_box.swap(ilg.loc_ghost_box);
return *this;
}
/*! \brief Get the number of external local ghost box for each sub-domain
*
* \param id sub-domain id
......
......@@ -69,6 +69,52 @@ public:
nn_prcs(Vcluster & v_cl)
:v_cl(v_cl){}
//! Constructor from another ie_loc_ghost
nn_prcs(const nn_prcs<dim,T> & ilg)
:v_cl(ilg.v_cl)
{
this->operator=(ilg);
};
//! Constructor from temporal ie_loc_ghost
nn_prcs(nn_prcs<dim,T> && ilg)
:v_cl(ilg.v_cl)
{
this->operator=(ilg);
}
/*! \brief Copy the object
*
* \param nnp object to copy
*
*/
nn_prcs<dim,T> & operator=(const nn_prcs<dim,T> & nnp)
{
v_cl = nnp.v_cl;
nn_processors = nnp.nn_processors;
nn_processor_subdomains = nnp.nn_processor_subdomains;
proc_adj_box = nnp.proc_adj_box;
boxes = nnp.boxes;
return *this;
}
/*! \brief Copy the object
*
* \param nnp object to copy
*
*/
nn_prcs<dim,T> & operator=(nn_prcs<dim,T> && nnp)
{
v_cl = nnp.v_cl;
nn_processors.swap(nnp.nn_processors);
nn_processor_subdomains.swap(nnp.nn_processor_subdomains);
proc_adj_box.swap(nnp.proc_adj_box);
boxes = nnp.boxes;
return *this;
}
/*! \brief Create the list of adjacent processors and the list of adjacent sub-domains
*
* \param box_nn_processors
......@@ -219,7 +265,7 @@ public:
* \return the set of adjacent sub-domain comming from the processor p_id
*
*/
inline const N_box<dim,T> getExternalAdjSubdomain(size_t p_id) const
inline const N_box<dim,T> & getExternalAdjSubdomain(size_t p_id) const
{
auto key = nn_processor_subdomains.find(p_id);
#ifdef DEBUG
......
......@@ -396,6 +396,16 @@ class grid_dist_id
gdb_ext.last().Dbox = sp_t;
gdb_ext.last().Dbox -= sp_tg.getP1();
gdb_ext.last().GDbox = sp_tg;
gdb_ext.last().GDbox -= sp_tg.getP1();
/* if (gdb_ext.last().GDbox.getHigh(0) == gdb_ext.last().Dbox.getHigh(0) &&
gdb_ext.last().GDbox.getHigh(1) == gdb_ext.last().Dbox.getHigh(1))
{
int debug = 0;
debug++;
}*/
// center to zero
sp_tg -= sp_tg.getP1();
......@@ -503,7 +513,7 @@ public:
* \param g Ghost given in grid units
*
*/
grid_dist_id(const size_t (& g_sz)[dim],const Box<dim,St> & domain, const Ghost<dim,size_t> & g)
grid_dist_id(const size_t (& g_sz)[dim],const Box<dim,St> & domain, const Ghost<dim,long int> & g)
:domain(domain),dec(*new Decomposition(*global_v_cluster)),v_cl(*global_v_cluster),ginfo(g_sz),ginfo_v(g_sz)
{
InitializeCellDecomposer(g_sz);
......@@ -512,12 +522,12 @@ public:
Box<dim,St> sp = cd_sm.getCellBox();
// enlarge 0.001 of the spacing
sp.magnify_fix_P1(0.001);
sp.magnify_fix_P1(1.1);
// set the ghost
for (size_t i = 0 ; i < dim ; i++)
{
ghost.setLow(i,sp.getHigh(i));
ghost.setLow(i,-sp.getHigh(i));
ghost.setHigh(i,sp.getHigh(i));
}
......@@ -532,7 +542,7 @@ public:
* \param g Ghost given in grid units
*
*/
grid_dist_id(Decomposition & dec, const size_t (& g_sz)[dim],const Box<dim,St> & domain, const Ghost<dim,size_t> & g)
grid_dist_id(Decomposition & dec, const size_t (& g_sz)[dim],const Box<dim,St> & domain, const Ghost<dim,long int> & g)
:domain(domain),dec(dec),v_cl(*global_v_cluster),ginfo(g_sz),ginfo_v(g_sz)
{
InitializeCellDecomposer(g_sz);
......@@ -541,12 +551,12 @@ public:
Box<dim,St> sp = cd_sm.getCellBox();
// enlarge 0.001 of the spacing
sp.magnify_fix_P1(0.001);
sp.magnify_fix_P1(1.1);
// set the ghost
for (size_t i = 0 ; i < dim ; i++)
{
ghost.setLow(i,sp.getHigh(i));
ghost.setLow(i,-sp.getHigh(i));
ghost.setHigh(i,sp.getHigh(i));
}
......
......@@ -548,11 +548,8 @@ void Test3D_gg(const Box<3,float> & domain, long int k, long int gk)
sz[1] = k;
sz[2] = k;
// factor
float factor = pow(global_v_cluster->getProcessingUnits()/2.0f,1.0f/3.0f);
// Ghost
Ghost<3,size_t> g(gk);
Ghost<3,long int> g(gk);
// Distributed grid with id decomposition
grid_dist_id<3, float, scalar<float>, CartDecomposition<3,float>> g_dist(sz,domain,g);
......@@ -569,8 +566,12 @@ void Test3D_gg(const Box<3,float> & domain, long int k, long int gk)
for (size_t i = 0 ; i < lg.size() ; i++)
{
BOOST_REQUIRE_EQUAL(lg.get(i).Dbox.getLow(i),gk);
BOOST_REQUIRE_EQUAL(lg.get(i).GDbox.getHigh(i)- lg.get(i).Dbox.getHigh(i),gk);
BOOST_REQUIRE(lg.get(i).Dbox.getLow(i) >= gk);
if ((lg.get(i).GDbox.getHigh(i) - lg.get(i).Dbox.getHigh(i)) < gk)
{
std::cout << "DIOCANE: " << gk << " " << (lg.get(i).GDbox.getHigh(i) - lg.get(i).Dbox.getHigh(i)) << "\n";
}
BOOST_REQUIRE((lg.get(i).GDbox.getHigh(i) - lg.get(i).Dbox.getHigh(i)) >= gk);
}
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment