Commit 31c40ecd authored by incardon's avatar incardon

General fixing and improve for distributed vector

parent 92096731
......@@ -939,7 +939,7 @@ pdata-VCluster.o: ../../OpenFPM_vcluster/src/VCluster.cpp \
/usr/include/boost/multi_array/view.hpp \
/usr/include/boost/functional.hpp /usr/include/boost/call_traits.hpp \
/usr/include/boost/detail/call_traits.hpp \
../../OpenFPM_data/src/ct_array.hpp \
../../OpenFPM_data/src/util/ct_array.hpp \
../../OpenFPM_data/src/memory_array.hpp \
../../OpenFPM_data/src/memory.hpp ../../OpenFPM_data/src/memory.hpp \
../../OpenFPM_data/src/util/meta_copy.hpp \
......@@ -955,14 +955,17 @@ pdata-VCluster.o: ../../OpenFPM_vcluster/src/VCluster.cpp \
../../OpenFPM_data/src/Grid/grid_key.hpp \
../../OpenFPM_data/src/Grid/comb.hpp \
../../OpenFPM_data/src/Grid/grid_key_expression.hpp \
../../OpenFPM_data/src/Space/Shape/Point.hpp \
../../OpenFPM_data/src/Grid/Encap.hpp \
../../OpenFPM_data/src/Space/Shape/Point.hpp \
../../OpenFPM_data/src/Grid/grid_key.hpp \
../../OpenFPM_data/src/Grid/Encap.hpp \
../../OpenFPM_data/src/memory_array.hpp \
../../OpenFPM_devices/src/memory/HeapMemory.hpp \
../../OpenFPM_data/src/Vector/vect_isel.hpp \
../../OpenFPM_data/src/common.hpp \
../../OpenFPM_data/src/util/object_s_di.hpp \
../../OpenFPM_data/src/util/for_each_ref.hpp \
/usr/include/boost/fusion/include/size.hpp \
../../OpenFPM_data/src/Vector/map_vector_std.hpp \
../../OpenFPM_vcluster/src/MPI_IallreduceW.hpp
......@@ -3024,7 +3027,7 @@ pdata-VCluster.o: ../../OpenFPM_vcluster/src/VCluster.cpp \
/usr/include/boost/detail/call_traits.hpp:
../../OpenFPM_data/src/ct_array.hpp:
../../OpenFPM_data/src/util/ct_array.hpp:
../../OpenFPM_data/src/memory_array.hpp:
......@@ -3058,10 +3061,10 @@ pdata-VCluster.o: ../../OpenFPM_vcluster/src/VCluster.cpp \
../../OpenFPM_data/src/Grid/grid_key_expression.hpp:
../../OpenFPM_data/src/Space/Shape/Point.hpp:
../../OpenFPM_data/src/Grid/Encap.hpp:
../../OpenFPM_data/src/Space/Shape/Point.hpp:
../../OpenFPM_data/src/Grid/grid_key.hpp:
../../OpenFPM_data/src/Grid/Encap.hpp:
......@@ -3074,6 +3077,12 @@ pdata-VCluster.o: ../../OpenFPM_vcluster/src/VCluster.cpp \
../../OpenFPM_data/src/common.hpp:
../../OpenFPM_data/src/util/object_s_di.hpp:
../../OpenFPM_data/src/util/for_each_ref.hpp:
/usr/include/boost/fusion/include/size.hpp:
../../OpenFPM_data/src/Vector/map_vector_std.hpp:
../../OpenFPM_vcluster/src/MPI_IallreduceW.hpp:
......@@ -901,7 +901,7 @@ pdata-main.o: main.cpp /usr/include/stdc-predef.h \
/usr/include/boost/multi_array/view.hpp \
/usr/include/boost/functional.hpp /usr/include/boost/call_traits.hpp \
/usr/include/boost/detail/call_traits.hpp \
../../OpenFPM_data/src/ct_array.hpp \
../../OpenFPM_data/src/util/ct_array.hpp \
../../OpenFPM_data/src/memory_array.hpp \
../../OpenFPM_data/src/memory.hpp ../../OpenFPM_data/src/memory.hpp \
../../OpenFPM_data/src/util/meta_copy.hpp \
......@@ -920,14 +920,18 @@ pdata-main.o: main.cpp /usr/include/stdc-predef.h \
../../OpenFPM_data/src/Grid/grid_key.hpp \
../../OpenFPM_data/src/Grid/comb.hpp \
../../OpenFPM_data/src/Grid/grid_key_expression.hpp \
../../OpenFPM_data/src/Space/Shape/Point.hpp \
../../OpenFPM_data/src/Grid/Encap.hpp \
../../OpenFPM_data/src/Space/Shape/Point.hpp \
../../OpenFPM_data/src/Grid/grid_key.hpp \
../../OpenFPM_data/src/Grid/Encap.hpp \
../../OpenFPM_data/src/memory_array.hpp \
../../OpenFPM_devices/src/memory/HeapMemory.hpp \
../../OpenFPM_data/src/Vector/vect_isel.hpp \
../../OpenFPM_data/src/common.hpp /home/i-bird/MPI/include/mpi.h \
../../OpenFPM_data/src/common.hpp \
../../OpenFPM_data/src/util/object_s_di.hpp \
../../OpenFPM_data/src/util/for_each_ref.hpp \
/usr/include/boost/fusion/include/size.hpp \
/home/i-bird/MPI/include/mpi.h \
/home/i-bird/MPI/include/mpi_portable_platform.h \
/home/i-bird/MPI/include/openmpi/ompi/mpi/cxx/mpicxx.h \
/home/i-bird/MPI/include/openmpi/ompi/mpi/cxx/constants.h \
......@@ -1291,11 +1295,12 @@ pdata-main.o: main.cpp /usr/include/stdc-predef.h \
../../OpenFPM_data/src/Space/Shape/Box.hpp \
../../OpenFPM_data/src/Space/Ghost.hpp Grid/grid_dist_id_iterator.hpp \
Grid/grid_dist_key.hpp ../../OpenFPM_data/src/Point_test.hpp \
../../OpenFPM_data/src/base_type.hpp Decomposition/CartDecomposition.hpp \
Decomposition/Decomposition.hpp ../../OpenFPM_data/src/global_const.hpp \
SubdomainGraphNodes.hpp metis_util.hpp \
../../metis_install/include/metis.h /usr/include/inttypes.h \
../../OpenFPM_IO/src/VTKWriter.hpp \
../../OpenFPM_data/src/base_type.hpp \
../../OpenFPM_data/src/Point_orig.hpp \
Decomposition/CartDecomposition.hpp Decomposition/Decomposition.hpp \
../../OpenFPM_data/src/global_const.hpp SubdomainGraphNodes.hpp \
metis_util.hpp ../../metis_install/include/metis.h \
/usr/include/inttypes.h ../../OpenFPM_IO/src/VTKWriter.hpp \
../../OpenFPM_IO/src/VTKWriter_graph.hpp \
../../OpenFPM_IO/src/VTKWriter_vector_box.hpp \
/usr/include/boost/math/special_functions/pow.hpp \
......@@ -1362,13 +1367,14 @@ pdata-main.o: main.cpp /usr/include/stdc-predef.h \
/usr/include/boost/config/abi_prefix.hpp \
/usr/include/boost/config/abi_suffix.hpp dec_optimizer.hpp \
../../OpenFPM_data/src/NN/CellList/CellDecomposer.hpp \
../../OpenFPM_data/src/Space/Matrix.hpp \
/usr/include/c++/4.8.3/unordered_map \
/usr/include/c++/4.8.3/bits/hashtable.h \
/usr/include/c++/4.8.3/bits/hashtable_policy.h \
/usr/include/c++/4.8.3/bits/unordered_map.h \
../../OpenFPM_data/src/NN/CellList/CellList.hpp \
../../OpenFPM_data/src/NN/CellList/CellListFast.hpp \
../../OpenFPM_data/src/NN/CellList/CellDecomposer.hpp \
../../OpenFPM_data/src/NN/CellList/CellListFast.hpp \
../../OpenFPM_data/src/NN/CellList/CellNNIterator.hpp \
../../OpenFPM_data/src/NN/CellList/CellListBal.hpp \
../../OpenFPM_data/src/NN/CellList/CellListMem.hpp \
......@@ -1387,9 +1393,8 @@ pdata-main.o: main.cpp /usr/include/stdc-predef.h \
../../OpenFPM_devices/src/memory/PtrMemory.hpp \
../../OpenFPM_data/src/util/object_util.hpp \
../../OpenFPM_data/src/util/object_creator.hpp \
../../OpenFPM_data/src/util/object_copy.hpp \
../../OpenFPM_data/src/util/for_each_ref.hpp \
/usr/include/boost/fusion/include/size.hpp \
../../OpenFPM_data/src/util/object_s_di.hpp \
../../OpenFPM_data/src/util/object_si_d.hpp \
../../OpenFPM_devices/src/memory/ExtPreAlloc.hpp \
Decomposition/CartDecomposition_unit_test.hpp \
Decomposition/CartDecomposition.hpp
......@@ -3372,7 +3377,7 @@ Graph/CartesianGraphFactory.hpp:
/usr/include/boost/detail/call_traits.hpp:
../../OpenFPM_data/src/ct_array.hpp:
../../OpenFPM_data/src/util/ct_array.hpp:
../../OpenFPM_data/src/memory_array.hpp:
......@@ -3414,10 +3419,10 @@ Graph/CartesianGraphFactory.hpp:
../../OpenFPM_data/src/Grid/grid_key_expression.hpp:
../../OpenFPM_data/src/Space/Shape/Point.hpp:
../../OpenFPM_data/src/Grid/Encap.hpp:
../../OpenFPM_data/src/Space/Shape/Point.hpp:
../../OpenFPM_data/src/Grid/grid_key.hpp:
../../OpenFPM_data/src/Grid/Encap.hpp:
......@@ -3430,6 +3435,12 @@ Graph/CartesianGraphFactory.hpp:
../../OpenFPM_data/src/common.hpp:
../../OpenFPM_data/src/util/object_s_di.hpp:
../../OpenFPM_data/src/util/for_each_ref.hpp:
/usr/include/boost/fusion/include/size.hpp:
/home/i-bird/MPI/include/mpi.h:
/home/i-bird/MPI/include/mpi_portable_platform.h:
......@@ -4248,6 +4259,8 @@ Grid/grid_dist_key.hpp:
../../OpenFPM_data/src/base_type.hpp:
../../OpenFPM_data/src/Point_orig.hpp:
Decomposition/CartDecomposition.hpp:
Decomposition/Decomposition.hpp:
......@@ -4398,6 +4411,8 @@ dec_optimizer.hpp:
../../OpenFPM_data/src/NN/CellList/CellDecomposer.hpp:
../../OpenFPM_data/src/Space/Matrix.hpp:
/usr/include/c++/4.8.3/unordered_map:
/usr/include/c++/4.8.3/bits/hashtable.h:
......@@ -4408,10 +4423,10 @@ dec_optimizer.hpp:
../../OpenFPM_data/src/NN/CellList/CellList.hpp:
../../OpenFPM_data/src/NN/CellList/CellListFast.hpp:
../../OpenFPM_data/src/NN/CellList/CellDecomposer.hpp:
../../OpenFPM_data/src/NN/CellList/CellListFast.hpp:
../../OpenFPM_data/src/NN/CellList/CellNNIterator.hpp:
../../OpenFPM_data/src/NN/CellList/CellListBal.hpp:
......@@ -4466,11 +4481,9 @@ Vector/vector_dist_key.hpp:
../../OpenFPM_data/src/util/object_creator.hpp:
../../OpenFPM_data/src/util/object_copy.hpp:
../../OpenFPM_data/src/util/object_s_di.hpp:
../../OpenFPM_data/src/util/for_each_ref.hpp:
/usr/include/boost/fusion/include/size.hpp:
../../OpenFPM_data/src/util/object_si_d.hpp:
../../OpenFPM_devices/src/memory/ExtPreAlloc.hpp:
......
This diff is collapsed.
......@@ -39,7 +39,36 @@ BOOST_AUTO_TEST_CASE( CartDecomposition_test_use)
// create a ghost border
dec.calculateGhostBoxes(g);
//
// 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)
{
int debug = 0;
debug++;
const openfpm::vector<size_t> pr2 = dec.template ghost_processorID<CartDecomposition<3,float>::processor_id>(p);
}
BOOST_REQUIRE_EQUAL(found,true);
}
}
BOOST_AUTO_TEST_SUITE_END()
......
This diff is collapsed.
......@@ -27,11 +27,12 @@ class vector_dist_iterator
/*! \brief Constructor of the distributed grid
*
* \param gk std::vector of the local grid
* \param gk the set of local vectors
* \param offset iterator starting point
*
*/
vector_dist_iterator(Vcluster_object_array<device_v> & gk)
:v_c(0),vList(gk),v_it(0)
vector_dist_iterator(Vcluster_object_array<device_v> & gk, size_t offset = 0)
:v_c(0),vList(gk),v_it(offset)
{
}
......
......@@ -18,9 +18,11 @@ BOOST_AUTO_TEST_CASE( vector_dist_iterator_test_use )
typedef Point_test<float> p;
typedef Point<2,float> s;
Vcluster & v_cl = *global_v_cluster;
// set the seed
// create the random generator engine
std::srand(global_v_cluster->getProcessUnitID());
std::srand(v_cl.getProcessUnitID());
std::default_random_engine eg;
std::uniform_real_distribution<float> ud(0.0f, 1.0f);
......@@ -42,7 +44,7 @@ BOOST_AUTO_TEST_CASE( vector_dist_iterator_test_use )
vd.map();
// Check if we have all the local particles
size_t cnt = 0;
auto & ct = vd.getDecomposition();
it = vd.getIterator();
......@@ -50,10 +52,91 @@ BOOST_AUTO_TEST_CASE( vector_dist_iterator_test_use )
{
auto key = it.get();
// Check if local otherwise print the particle value
// Check if local
BOOST_REQUIRE_EQUAL(ct.isLocal(vd.template getPos<s::x>(key)),true);
cnt++;
++it;
}
//
v_cl.reduce(cnt);
v_cl.execute();
BOOST_REQUIRE_EQUAL(cnt,4096);
}
BOOST_AUTO_TEST_CASE( vector_dist_ghost )
{
// Communication object
Vcluster & v_cl = *global_v_cluster;
typedef Point_test<float> p;
typedef Point<2,float> s;
Box<2,float> box({0.0,0.0},{1.0,1.0});
size_t g_div[]= {1000,1000};
// processor division on y direction
size_t point_div = g_div[1] / v_cl.getProcessingUnits();
// Create a grid info
grid_sm<2,void> g_info(g_div);
// Calculate the grid spacing
Point<2,float> spacing = box.getP2();
spacing = spacing / g_div;
// middle spacing
Point<2,float> m_spacing = spacing / 2;
// create a sub iterator
grid_key_dx<2> start(0,point_div * v_cl.getProcessUnitID());
grid_key_dx<2> stop(999,point_div * (v_cl.getProcessUnitID() + 1) - 1);
auto g_sub = g_info.getSubIterator(start,stop);
// Vector of particles
vector_dist<Point<2,float>, Point_test<float>, Box<2,float>, CartDecomposition<2,float> > vd(g_info.size(),box);
auto it = vd.getIterator();
while (it.isNext())
{
auto key_v = it.get();
auto key = g_sub.get();
// set the particle position
vd.template getPos<s::x>(key_v)[0] = key.get(0) * spacing[0] + m_spacing[0];
vd.template getPos<s::x>(key_v)[1] = key.get(1) * spacing[1] + m_spacing[1];
if (vd.template getPos<s::x>(key_v)[0] >= 1.0 || vd.template getPos<s::x>(key_v)[1] >= 1.0)
{
int debug = 0;
debug++;
}
++g_sub;
++it;
}
// redistribute the particles according to the decomposition
vd.map();
// Fill the scalar with the particle position
const auto & ct = vd.getDecomposition();
it = vd.getIterator();
while (it.isNext())
{
auto key = it.get();
// fill with the processor ID where these particle live
vd.template getProp<p::s>(key) = vd.getPos<s::x>(key)[0] + vd.getPos<s::x>(key)[1] * 16;
vd.template getProp<p::v>(key)[0] = v_cl.getProcessUnitID();
vd.template getProp<p::v>(key)[1] = v_cl.getProcessUnitID();
vd.template getProp<p::v>(key)[2] = v_cl.getProcessUnitID();
++it;
}
......@@ -63,8 +146,58 @@ BOOST_AUTO_TEST_CASE( vector_dist_iterator_test_use )
vd.setGhost(g);
// do a ghost get
vd.template ghost_get<p::s,p::v>();
// Get the decomposition
const auto & dec = vd.getDecomposition();
// Get the ghost external boxes
openfpm::vector<size_t> vb(dec.getNGhostBox());
// Get the ghost iterator
auto g_it = vd.getGhostIterator();
// Check if the ghost particles contain the correct information
while (g_it.isNext())
{
auto key = g_it.get();
float x0 = vd.getPos<s::x>(key)[0];
float x1 = vd.getPos<s::x>(key)[1] * 16;
float scalar = vd.template getProp<p::s>(key);
// Check the received data
BOOST_REQUIRE_EQUAL(vd.getPos<s::x>(key)[0] + vd.getPos<s::x>(key)[1] * 16,vd.template getProp<p::s>(key));
bool is_in = false;
size_t b = 0;
// check if the received data is in one of the ghost boxes
for ( ; b < dec.getNGhostBox() ; b++)
{
if (dec.getGhostBox(b).isInside(vd.getPos<s::x>(key)) == true)
{is_in = true; break;}
}
BOOST_REQUIRE_EQUAL(is_in,true);
// Check that the particle come from the correct processor
BOOST_REQUIRE_EQUAL(vd.getProp<p::v>(key)[0],dec.getGhostBoxProcessor(b));
// Add
vb.get(b)++;
++g_it;
}
CellDecomposer_sm<2,float> cd(SpaceBox<2,float>(box),g_div,0);
for (size_t i = 0 ; i < vb.size() ; i++)
{
// Calculate how many particle should be in the box
size_t n_point = cd.getGridPoints(dec.getGhostBox(i)).getVolume();
BOOST_REQUIRE_EQUAL(n_point,vb.get(i));
}
}
BOOST_AUTO_TEST_SUITE_END()
......
......@@ -106,6 +106,68 @@ class dec_optimizer
private:
/*! \brief Expand one wavefront
*
* \param v_w wavefronts
* \param w_comb wavefront expansion combinations
* \param d direction of expansion
*
*/
void expand_one_wf(openfpm::vector<wavefront<dim>> & v_w, std::vector<comb<dim>> & w_comb , size_t d)
{
for (int j = 0 ; j < dim ; j++)
{
v_w.template get<wavefront<dim>::stop>(d)[j] = v_w.template get<wavefront<dim>::stop>(d)[j] + w_comb[d].c[j];
v_w.template get<wavefront<dim>::start>(d)[j] = v_w.template get<wavefront<dim>::start>(d)[j] + w_comb[d].c[j];
}
}
/*! \brief Adjust the other wavefronts
*
* \param d direction
*
*/
void adjust_others_wf(openfpm::vector<wavefront<dim>> & v_w, HyperCube<dim> & hyp, std::vector<comb<dim>> & w_comb, size_t d)
{
// expand the intersection of the wavefronts
std::vector<comb<dim>> q_comb = SubHyperCube<dim,dim-1>::getCombinations_R(w_comb[d],dim-2);
// Eliminate the w_comb[d] direction
for (int k = 0 ; k < q_comb.size() ; k++)
{
for (int j = 0 ; j < dim ; j++)
{
if (w_comb[d].c[j] != 0)
{
q_comb[k].c[j] = 0;
}
}
}
// for all the combinations
for (int j = 0 ; j < q_comb.size() ; j++)
{
size_t id = hyp.LinId(q_comb[j]);
// get the combination of the direction d
bool is_pos = hyp.isPositive(d);
// is positive, modify the stop point or the starting point
for (int s = 0 ; s < dim ; s++)
{
if (is_pos == true)
{v_w.template get<wavefront<dim>::stop>(id)[s] = v_w.template get<wavefront<dim>::stop>(id)[s] + w_comb[d].c[s];}
else
{v_w.template get<wavefront<dim>::start>(id)[s] = v_w.template get<wavefront<dim>::start>(id)[s] + w_comb[d].c[s];}
}
}
}
/* \brief Fill the wavefront position
*
* \tparam prp property to set
......@@ -192,16 +254,13 @@ private:
}
}
// take the wavefront expand on direction d of one
// Create an Hyper-cube
HyperCube<dim> hyp;
for (int d = 0 ; d < v_w.size() ; d++)
{
// expand the wavefront
for (int j = 0 ; j < dim ; j++)
{
v_w.template get<wavefront<dim>::start>(d)[j] = v_w.template get<wavefront<dim>::start>(d)[j] + w_comb[d].c[j];
v_w.template get<wavefront<dim>::stop>(d)[j] = v_w.template get<wavefront<dim>::stop>(d)[j] + w_comb[d].c[j];
}
expand_one_wf(v_w,w_comb,d);
adjust_others_wf(v_w,hyp,w_comb,d);
}
// for each expanded wavefront create a sub-grid iterator and add the sub-domain
......
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