Commit 3eed4d7c authored by incardon's avatar incardon

ghost_get and ghost_put with retaining send buffer

parent 3f2faea8
......@@ -1013,6 +1013,7 @@ public:
calculateGhostBoxes();
domain_nn_calculator_cart<dim>::reset();
domain_nn_calculator_cart<dim>::setParameters(proc_box);
}
/*! \brief Refine the decomposition, available only for ParMetis distribution, for Metis it is a null call
......@@ -1034,6 +1035,7 @@ public:
calculateGhostBoxes();
domain_nn_calculator_cart<dim>::reset();
domain_nn_calculator_cart<dim>::setParameters(proc_box);
}
/*! \brief Refine the decomposition, available only for ParMetis distribution, for Metis it is a null call
......@@ -1055,6 +1057,7 @@ public:
calculateGhostBoxes();
domain_nn_calculator_cart<dim>::reset();
domain_nn_calculator_cart<dim>::setParameters(proc_box);
}
/*! \brief Refine the decomposition, available only for ParMetis distribution, for Metis it is a null call
......@@ -1283,9 +1286,9 @@ public:
* \param gs grid extension
*
*/
openfpm::vector<size_t> & getDomainCells(grid_key_dx<dim> & shift, grid_key_dx<dim> & cell_shift, grid_sm<dim,void> & gs)
openfpm::vector<size_t> & getDomainCells()
{
return domain_nn_calculator_cart<dim>::getDomainCells(shift,cell_shift,gs,proc_box,loc_box);
return domain_nn_calculator_cart<dim>::getDomainCells();
}
/*! \brief Get the CRS domain Cells
......@@ -1296,11 +1299,23 @@ public:
* \param shift Cell padding
* \param cell_shift where the domain cell start
* \param gs grid extension
* \param loc_box processor sub-domains
*
*/
openfpm::vector<size_t> & getCRSDomainCells(grid_key_dx<dim> & shift, grid_key_dx<dim> & cell_shift, grid_sm<dim,void> & gs)
openfpm::vector<size_t> & getCRSDomainCells()
{
return domain_nn_calculator_cart<dim>::getCRSDomainCells(shift,cell_shift,gs,proc_box,loc_box);
return domain_nn_calculator_cart<dim>::getCRSDomainCells();
}
/*! \brief set NN parameters to calculate cell-list neighborhood
*
* \param shift to apply in cell linearization
* \param gs cell grid
*
*/
void setNNParameters(grid_key_dx<dim> & shift, grid_sm<dim,void> & gs)
{
domain_nn_calculator_cart<dim>::setNNParameters(loc_box, shift, gs);
}
/*! \brief Get the CRS anomalous cells
......@@ -1316,9 +1331,9 @@ public:
* \return the anomalous cells with neighborhood
*
*/
openfpm::vector<subsub_lin<dim>> & getCRSAnomDomainCells(grid_key_dx<dim> & shift, grid_key_dx<dim> & cell_shift, grid_sm<dim,void> & gs)
openfpm::vector<subsub_lin<dim>> & getCRSAnomDomainCells()
{
return domain_nn_calculator_cart<dim>::getCRSAnomDomainCells(shift,cell_shift,gs,proc_box,loc_box);
return domain_nn_calculator_cart<dim>::getCRSAnomDomainCells();
}
/*! \brief Check if the particle is local considering boundary conditions
......
......@@ -8,6 +8,9 @@
#ifndef SRC_DECOMPOSITION_DOMAIN_NN_CALCULATOR_CART_HPP_
#define SRC_DECOMPOSITION_DOMAIN_NN_CALCULATOR_CART_HPP_
#include <Vector/map_vector.hpp>
#include "NN/CellList/ParticleItCRS_Cells.hpp"
/*! \brief This class calculate processor domains and neighborhood
* of each processor domain
*
......@@ -20,49 +23,39 @@ class domain_nn_calculator_cart
//! True if domain and anomalous domain cells are computed
bool are_domain_anom_computed;
//! Are linearized the domain cells
bool are_dom_cells_lin;
//! Are linearized the CRS domain cell
bool are_dom_lin;
//! are linearized the CRS anomalous cells
bool are_anom_lin;
/////////////////////////////// CRS //////////////////////
//! anomalous cell neighborhood for CRS
openfpm::vector<subsub<dim>> anom;
//! Set of anomalous CRS domain cells linearized
openfpm::vector<subsub_lin<dim>> anom_lin;
//! Set of normal domain cells for CRS
openfpm::vector<grid_key_dx<dim>> dom;
//! Set of domain cells
openfpm::vector<grid_key_dx<dim>> dom_cells;
//! Linearization is calculated out of a shift and grid dimension this is the shift
grid_key_dx<dim> shift_calc_dom;
//! Linearization is calculated out of a grid dimensions this is the grid dimension
grid_sm<dim,void> gs_calc_dom;
//! Linearization is calculated out of a shift and grid dimension this is the shift
grid_key_dx<dim> shift_calc_anom;
//! Linearization is calculated out of a grid dimensions this is the grid dimension
grid_sm<dim,void> gs_calc_anom;
//! Set of normal CRS domain cells linearized
openfpm::vector<size_t> dom_lin;
//! Set of anomalous CRS domain cells linearized
openfpm::vector<subsub_lin<dim>> anom_lin;
////////////////////////////////// DOMAIN CELLS ///////////////////////
//! Set of domain cells
openfpm::vector<grid_key_dx<dim>> dom_cells;
//! Set of linearized domain cells
openfpm::vector<size_t> dom_cells_lin;
//////////////////////////////////////////////////////////////
//! Processor box
Box<dim,long int> proc_box;
//! Processor cells-grid
grid_sm<dim,void> gs;
//! key with all coordinates set to one
grid_key_dx<dim> one;
/*! \brief Calculate the subdomain that are in the skin part of the domain
*
\verbatim
......@@ -114,7 +107,6 @@ class domain_nn_calculator_cart
openfpm::vector<grid_key_dx<dim>> & dom_subsub,
openfpm::vector<grid_key_dx<dim>> & dom_cells,
const ::Box<dim,long int> & proc_box,
grid_key_dx<dim> & shift,
const openfpm::vector<::Box<dim, size_t>> & loc_box)
{
// Reset dom and dom_subsub
......@@ -123,13 +115,21 @@ class domain_nn_calculator_cart
size_t sz[dim];
// ----Grid size = proc_box.getHigh(j) - proc_box.getLow(j)
// +2 is padding
for (size_t j = 0 ; j < dim ; j++)
sz[j] = proc_box.getHigh(j) - proc_box.getLow(j) + 2;
sz[j] = proc_box.getHigh(j) - proc_box.getLow(j) + 2 + 1;
gs.setDimensions(sz);
// Set the grid
grid_cpu<dim, aggregate<openfpm::vector<grid_key_dx<dim>>> > g(sz);
grid_cpu<dim, aggregate<openfpm::vector<grid_key_dx<dim>> >> g(sz);
g.setMemory();
for (size_t i = 0 ; i < dim ; i++)
one.set_d(i,1);
// Calculate the csr neighborhood
openfpm::vector<std::pair<grid_key_dx<dim>,grid_key_dx<dim>>> csr;
NNcalc_csr(csr);
......@@ -142,8 +142,8 @@ class domain_nn_calculator_cart
for (size_t j = 0 ; j < dim ; j++)
{
start.set_d(j,loc_box.template get<0>(i)[j] - proc_box.getLow(j));
stop.set_d(j,loc_box.template get<1>(i)[j] - proc_box.getLow(j));
start.set_d(j,loc_box.template get<0>(i)[j] - proc_box.getLow(j) + 1);
stop.set_d(j,loc_box.template get<1>(i)[j] - proc_box.getLow(j) + 1);
}
grid_key_dx_iterator_sub<dim> sub(g.getGrid(),start,stop);
......@@ -156,10 +156,10 @@ class domain_nn_calculator_cart
{
grid_key_dx<dim> src = key + csr.get(j).first;
grid_key_dx<dim> dst = key + csr.get(j).second;
g.template get<0>(src).add(dst + shift);
g.template get<0>(src).add(dst);
}
dom_cells.add(key + shift);
dom_cells.add(key - one);
++sub;
}
......@@ -178,152 +178,154 @@ class domain_nn_calculator_cart
if (g.template get<0>(key).size() == openfpm::math::pow(3,dim)/2+1)
{
// Add in the list of the normal neighborhood list
dom_subsub.add(key + shift);
dom_subsub.add(key - one);
}
else if (g.template get<0>(key).size() != 0)
{
sub_keys.add();
sub_keys.last().subsub = key + shift;
sub_keys.last().subsub = key - one;
// Adding the neighborhood of the cell
sub_keys.last().NN_subsub = g.template get<0>(key);
sub_keys.last().NN_subsub.resize(g.template get<0>(key).size());
for (size_t i = 0 ; i < g.template get<0>(key).size() ; i++)
sub_keys.last().NN_subsub.get(i) = g.template get<0>(key).get(i) - one;
}
++it;
}
}
/*! \brief Linearize the sub-sub-domains
*
* \param anon set of grid keys to linearize
* \param anom_lin linearized output
* \param shift shifting
*
*/
void linearize_subsub(const openfpm::vector<subsub<dim>> & anom,
openfpm::vector<subsub_lin<dim>> & anom_lin,
const grid_key_dx<dim> & shift,
const grid_sm<dim,void> & gs)
{
anom_lin.clear();
for (size_t i = 0 ; i < anom.size() ; i++)
{
anom_lin.add();
anom_lin.last().subsub = gs.LinId(anom.get(i).subsub + shift);
long int self_cell = -1;
for (size_t j = 0 ; j < anom.get(i).NN_subsub.size() ; j++)
{
anom_lin.get(i).NN_subsub.add((long int)gs.LinId(anom.get(i).NN_subsub.get(j) + shift) - anom_lin.get(i).subsub);
// This indicate that for example in the neighborhood of one cell it-self is included in the list
// For example the cell 100 is in the neighborhood of the cell 100
if (anom_lin.get(i).NN_subsub.last() == 0)
self_cell = anom_lin.get(i).NN_subsub.size() - 1;
}
// if exist the self interacting cell (Example cell 100 neighborhood of cell 100), this cell MUST BE ALWAYS at the beginning
if (self_cell != -1)
{
// bring the self-cell into the beginning
size_t tmp = anom_lin.get(i).NN_subsub.get(0);
anom_lin.get(i).NN_subsub.get(0) = 0;
anom_lin.get(i).NN_subsub.get(self_cell) = tmp;
}
}
}
public:
domain_nn_calculator_cart()
:are_domain_anom_computed(false),are_dom_cells_lin(false),are_dom_lin(false),are_anom_lin(false)
{}
:are_domain_anom_computed(false)
{
}
/*! \brief Get the domain Cells
/*! \brief Set parameters to calculate the cell neighborhood
*
* \param shift Shifting point
* \param gs grid extension
* \param proc_box processor bounding box
* \param loc_box set of local sub-domains
* \param proc_box processor cells box
*
* \return The set of domain cells
*/
void setParameters(const Box<dim,long int> & proc_box)
{
this->proc_box = proc_box;
}
/*! \brief Set parameters to calculate the cell neighborhood
*
* \param shift to apply in the linearization
* \param loc_box set of local sub-domains
*
*/
openfpm::vector<size_t> & getDomainCells(grid_key_dx<dim> & shift, grid_key_dx<dim> & cell_shift, grid_sm<dim,void> & gs, Box<dim,size_t> & proc_box, openfpm::vector<::Box<dim, size_t>> & loc_box)
void setNNParameters(openfpm::vector<::Box<dim, size_t>> & loc_box,
const grid_key_dx<dim> & shift,
const grid_sm<dim,void> & gs)
{
if (are_domain_anom_computed == false)
{
CalculateDomAndAnomCells(anom,dom,dom_cells,proc_box,shift,loc_box);
CalculateDomAndAnomCells(anom,dom,dom_cells,proc_box,loc_box);
are_domain_anom_computed = true;
}
if (are_dom_cells_lin == false)
{
dom_cells_lin.clear();
shift_calc_dom = shift;
gs_calc_dom = gs;
for (size_t i = 0 ; i < dom_cells.size() ; i++)
dom_cells_lin.add(gs.LinId(dom_cells.get(i) - cell_shift));
dom_cells_lin.add(gs.LinId(dom_cells.get(i) + shift));
are_dom_cells_lin = true;
dom_lin.clear();
for (size_t i = 0 ; i < dom.size() ; i++)
dom_lin.add(gs.LinId(dom.get(i) + shift));
linearize_subsub(anom,anom_lin,shift,gs);
}
}
/*! \brief Get the domain Cells
*
* \param loc_box set of local sub-domains
*
* \return The set of domain cells
*
*/
openfpm::vector<size_t> & getDomainCells()
{
return dom_cells_lin;
}
/*! \brief Get the domain Cells
*
* \param shift Shifting point
* \param gs grid extension
* \param proc_box processor bounding box
* \param loc_box set of local sub-domains
*
* \return The set of domain cells
*
*/
openfpm::vector<size_t> & getCRSDomainCells(grid_key_dx<dim> & shift, grid_key_dx<dim> & cell_shift, grid_sm<dim,void> & gs, Box<dim,size_t> & proc_box, openfpm::vector<::Box<dim, size_t>> & loc_box)
openfpm::vector<size_t> & getCRSDomainCells()
{
if (are_domain_anom_computed == false)
{
CalculateDomAndAnomCells(anom,dom,dom_cells,proc_box,shift,loc_box);
are_domain_anom_computed = true;
}
if (are_dom_lin == false)
{
dom_lin.clear();
shift_calc_dom = shift;
gs_calc_dom = gs;
for (size_t i = 0 ; i < dom.size() ; i++)
dom_lin.add(gs.LinId(dom.get(i) - cell_shift));
are_dom_lin = true;
}
return dom_lin;
}
/*! \brief Get the domain anomalous cells
*
* \param shift Shifting point
* \param gs grid extension
* \param proc_box processor bounding box
* \param loc_box set of local sub-domains
*
* \return The set of anomalous cells
*
*/
openfpm::vector<subsub_lin<dim>> & getCRSAnomDomainCells(grid_key_dx<dim> & shift, grid_key_dx<dim> & cell_shift, grid_sm<dim,void> & gs, Box<dim,size_t> & proc_box, openfpm::vector<::Box<dim, size_t>> & loc_box)
openfpm::vector<subsub_lin<dim>> & getCRSAnomDomainCells()
{
// if the neighborhood of each sub-sub-domains has not been calculated, calculate it
if (are_domain_anom_computed == false)
{
CalculateDomAndAnomCells(anom,dom,dom_cells,proc_box,shift,loc_box);
are_domain_anom_computed = true;
}
if (are_anom_lin == false)
{
anom_lin.clear();
shift_calc_anom = shift;
gs_calc_anom = gs;
for (size_t i = 0 ; i < anom.size() ; i++)
{
anom_lin.add();
anom_lin.last().subsub = gs.LinId(anom.get(i).subsub - cell_shift);
long int self_cell = -1;
for (size_t j = 0 ; j < anom.get(i).NN_subsub.size() ; j++)
{
anom_lin.get(i).NN_subsub.add((long int)gs.LinId(anom.get(i).NN_subsub.get(j) - cell_shift) - anom_lin.get(i).subsub);
// This indicate that for example in the neighborhood of one cell it-self is included in the list
// For example the cell 100 is in the neighborhood of the cell 100
if (anom_lin.get(i).NN_subsub.last() == 0)
self_cell = anom_lin.get(i).NN_subsub.size() - 1;
}
// if exist the self interacting cell (Example cell 100 neighborhood of cell 100), this cell MUST BE ALWAYS at the beginning
if (self_cell != -1)
{
// bring the self-cell into the beginning
size_t tmp = anom_lin.get(i).NN_subsub.get(0);
anom_lin.get(i).NN_subsub.get(0) = 0;
anom_lin.get(i).NN_subsub.get(self_cell) = tmp;
}
}
are_anom_lin = true;
}
return anom_lin;
}
/*! \brief In case you have to recompute the indexes
*
*
*/
void reset()
{
are_domain_anom_computed = false;
are_dom_lin = false;
are_anom_lin = false;
}
};
......
......@@ -260,7 +260,7 @@ void Test3D_decit(const Box<3,float> & domain, long int k)
// create a grid iterator from the decomposition
grid_dist_id_iterator_dec<CartDecomposition<3,float>> it_dec(g_dist.getDecomposition(),sz,{0,0,0},{sz[0]-2,sz[1]-2,sz[2]-2});
grid_dist_id_iterator_dec<CartDecomposition<3,float>> it_dec(g_dist.getDecomposition(),sz,{0,0,0},{(long int)sz[0]-2,(long int)sz[1]-2,(long int)sz[2]-2});
while (dom.isNext())
{
......
LINKLIBS = $(OPENMP_LDFLAGS) $(LIBHILBERT_LIB) $(METIS_LIB) $(PTHREAD_LIBS) $(OPT_LIBS) $(BOOST_LDFLAGS) $(BOOST_IOSTREAMS_LIB) $(CUDA_LIBS) $(PETSC_LIB) $(HDF5_LDFLAGS) $(HDF5_LIBS) $(PARMETIS_LIB) $(BOOST_UNIT_TEST_FRAMEWORK_LIB) $(BOOST_CHRONO_LIB) $(BOOST_TIMER_LIB) $(BOOST_SYSTEM_LIB) $(LIBIFCORE)
noinst_PROGRAMS = pdata
pdata_SOURCES = main.cpp pdata_performance.cpp Grid/grid_dist_id_unit_test.cpp lib/pdata.cpp test_multiple_o.cpp ../openfpm_devices/src/memory/HeapMemory.cpp ../openfpm_devices/src/memory/PtrMemory.cpp ../openfpm_vcluster/src/VCluster/VCluster.cpp ../openfpm_devices/src/Memleak_check.cpp
pdata_CXXFLAGS = $(OPENMP_CFLAGS) $(AM_CXXFLAGS) $(LIBHILBERT_INCLUDE) $(PETSC_INCLUDE) $(HDF5_CPPFLAGS) $(CUDA_CFLAGS) $(INCLUDES_PATH) $(PARMETIS_INCLUDE) $(METIS_INCLUDE) $(BOOST_CPPFLAGS) $(H5PART_INCLUDE) -DPARALLEL_IO -Wno-unused-local-typedefs
......@@ -16,6 +17,10 @@ nobase_include_HEADERS = Decomposition/CartDecomposition.hpp Decomposition/CartD
Graph/ids.hpp Graph/dist_map_graph.hpp Graph/DistGraphFactory.hpp \
DLB/DLB.hpp DLB/LB_Model.hpp
#testa_SOURCES = Decomposition/Domain_NN_calculator_cart_unit_test.cpp ../openfpm_devices/src/memory/HeapMemory.cpp ../openfpm_vcluster/src/VCluster/VCluster.cpp
#testa_LDADD = $(LINKLIBS)
#testa_CXXFLAGS = $(OPENMP_CFLAGS) $(AM_CXXFLAGS) $(LIBHILBERT_INCLUDE) $(PETSC_INCLUDE) $(HDF5_CPPFLAGS) $(CUDA_CFLAGS) $(INCLUDES_PATH) $(PARMETIS_INCLUDE) $(METIS_INCLUDE) $(BOOST_CPPFLAGS) $(H5PART_INCLUDE) -DPARALLEL_IO -Wno-unused-local-typedefs
lib_LIBRARIES = libofpm_pdata.a
libofpm_pdata_a_SOURCES = lib/pdata.cpp
libofpm_pdata_a_CXXFLAGS = $(OPENMP_CFLAGS) $(AM_CXXFLAGS) $(INCLUDES_PATH) $(BOOST_CPPFLAGS) -I/usr/local/include -Wno-unused-local-typedefs
......
......@@ -72,9 +72,11 @@ class vector_dist_iterator
* \return the actual key
*
*/
vect_dist_key_dx get()
inline vect_dist_key_dx get()
{
return vect_dist_key_dx(v_it);
vect_dist_key_dx v;
v.setKey(v_it);
return v;
}
/*! \brief Reset the iterator
......
......@@ -416,6 +416,20 @@ public:
return v_pos.template get<0>(vec_key.getKey());
}
/*! \brief Get the position of an element
*
* see the vector_dist iterator usage to get an element key
*
* \param vec_key element
*
* \return the position of the element in space
*
*/
inline auto getPos(size_t vec_key) const -> decltype(v_pos.template get<0>(vec_key))
{
return v_pos.template get<0>(vec_key);
}
/*! \brief Get the property of an element
*
* see the vector_dist iterator usage to get an element key
......@@ -446,6 +460,21 @@ public:
return v_prp.template get<id>(vec_key.getKey());
}
/*! \brief Get the property of an element
*
* see the vector_dist iterator usage to get an element key
*
* \tparam id property id
* \param vec_key vector element
*
* \return return the selected property of the vector element
*
*/
template<unsigned int id> inline auto getProp(size_t vec_key) const -> const decltype(v_prp.template get<id>(vec_key))
{
return v_prp.template get<id>(vec_key);
}
#endif
///////////////////// Read and Write function
......@@ -673,6 +702,34 @@ public:
return cell_list;
}
/*! \brief return the neighborhood cells of a cells to do symmetric interactions
*
* \warning Used in in combination of getNNIteratorSym in a Cell-list
*
* \return the neighborhood cells of a cell
*
*
*/
/* const openfpm::vector<subsub_lin<dim>> & getNNCells(size_t cell) const
{
return getDecomposition().getDomainCellNNSym();
}*/
/*! \brief Construct a cell list symmetric based on a cut of radius
*
* \tparam CellL CellList type to construct
*
* \param r_cut interation radius, or size of each cell
*
* \return the Cell list
*
*/
template<typename CellL = CellList<dim, St, FAST, shift<dim, St> > > CellL getCellListSymNoBind(St r_cut)
{
return getCellList(r_cut);
}
/*! \brief Construct a cell list starting from the stored particles
*
* \tparam CellL CellList type to construct
......@@ -927,20 +984,19 @@ public:
auto & NN = ver.getInternalCellList();
// Shift
grid_key_dx<dim> cell_shift = NN.getShift();
// Shift
grid_key_dx<dim> shift = NN.getShift();
grid_key_dx<dim> shift;
// Add padding
for (size_t i = 0 ; i < dim ; i++)
shift.set_d(i,shift.get(i) + NN.getPadding(i));
shift.set_d(i,NN.getPadding(i));
grid_sm<dim,void> gs = NN.getInternalGrid();
getDecomposition().setNNParameters(shift,gs);
ver.createVerletCrs(r_cut,g_m,v_pos,
getDecomposition().getCRSDomainCells(shift,cell_shift,gs),
getDecomposition().getCRSAnomDomainCells(shift,cell_shift,gs));
getDecomposition().getCRSDomainCells(),
getDecomposition().getCRSAnomDomainCells());
ver.set_ndec(getDecomposition().get_ndec());
......@@ -1022,20 +1078,19 @@ public:
if (to_reconstruct == false)
{
// Shift
grid_key_dx<dim> cell_shift = NN.getShift();
// Shift
grid_key_dx<dim> shift = NN.getShift();
grid_key_dx<dim> shift;
// Add padding
for (size_t i = 0 ; i < dim ; i++)
shift.set_d(i,shift.get(i) + NN.getPadding(i));
shift.set_d(i,NN.getPadding(i));
grid_sm<dim,void> gs = NN.getInternalGrid();
getDecomposition().setNNParameters(shift,gs);
ver.updateCrs(getDecomposition().getDomain(),r_cut,v_pos,g_m,
getDecomposition().getCRSDomainCells(shift,cell_shift,gs),
getDecomposition().getCRSAnomDomainCells(shift,cell_shift,gs));
getDecomposition().getCRSDomainCells(),
getDecomposition().getCRSAnomDomainCells());
}
else
{
......@@ -1284,18 +1339,17 @@ public:
#endif