diff --git a/openfpm_vcluster b/openfpm_vcluster index a483d6d5b89507593b0d7e0f74ffcc59b61bcba4..d209394f00b1fe089f8c473465fd29da78a5ba48 160000 --- a/openfpm_vcluster +++ b/openfpm_vcluster @@ -1 +1 @@ -Subproject commit a483d6d5b89507593b0d7e0f74ffcc59b61bcba4 +Subproject commit d209394f00b1fe089f8c473465fd29da78a5ba48 diff --git a/src/Decomposition/CartDecomposition.hpp b/src/Decomposition/CartDecomposition.hpp index 9380f80b1780046a0235e40a83ae60ab323f4f6c..f19e8d848765760143d0ddb30cccd2d8e6412a36 100644 --- a/src/Decomposition/CartDecomposition.hpp +++ b/src/Decomposition/CartDecomposition.hpp @@ -375,7 +375,7 @@ public: * */ CartDecomposition(Vcluster & v_cl) - :nn_prcs<dim,T>(v_cl),v_cl(v_cl),ref_cnt(0) + :nn_prcs<dim,T>(v_cl),v_cl(v_cl),ref_cnt(0),recv_cnt(0) { // Reset the box to zero bbox.zero(); @@ -387,7 +387,7 @@ public: * */ CartDecomposition(const CartDecomposition<dim,T,Memory,Domain> & cart) - :nn_prcs<dim,T>(cart.v_cl),v_cl(cart.v_cl),ref_cnt(0) + :nn_prcs<dim,T>(cart.v_cl),v_cl(cart.v_cl),ref_cnt(0),recv_cnt(0) { this->operator=(cart); } @@ -398,7 +398,7 @@ public: * */ CartDecomposition(CartDecomposition<dim,T,Memory,Domain> && cart) - :nn_prcs<dim,T>(cart.v_cl),v_cl(cart.v_cl),ref_cnt(0) + :nn_prcs<dim,T>(cart.v_cl),v_cl(cart.v_cl),ref_cnt(0),recv_cnt(0) { this->operator=(cart); } diff --git a/src/Decomposition/common.hpp b/src/Decomposition/common.hpp index 6006b179a418d4aba2a43f58656f26a4f06e36fe..b3f0380328e81865f12a70ffd9e80fd939fccf5f 100644 --- a/src/Decomposition/common.hpp +++ b/src/Decomposition/common.hpp @@ -119,6 +119,7 @@ struct Box_sub_k long int k; Box_sub_k() + :k(-1) { cmb.zero(); } @@ -192,6 +193,7 @@ struct N_box //! Default constructor N_box() + :id((size_t)-1) {}; //! Copy constructor diff --git a/src/Decomposition/nn_processor.hpp b/src/Decomposition/nn_processor.hpp index bd410d78625bf8e76920d2bb78b3fb38594b3b26..05a23e01914313e997bda1f0f95d3f9f7ed2b270 100644 --- a/src/Decomposition/nn_processor.hpp +++ b/src/Decomposition/nn_processor.hpp @@ -186,11 +186,12 @@ class nn_prcs public: nn_prcs(Vcluster & v_cl) - :v_cl(v_cl),aBC(false){} + :v_cl(v_cl),aBC(false),recv_cnt(0) + {} //! Constructor from another nn_prcs nn_prcs(const nn_prcs<dim,T> & ilg) - :v_cl(ilg.v_cl),aBC(false) + :v_cl(ilg.v_cl),aBC(false),recv_cnt(0) { this->operator=(ilg); }; diff --git a/src/Grid/grid_dist_id_iterator_sub.hpp b/src/Grid/grid_dist_id_iterator_sub.hpp index a3c96cc419cb8a58600ad55a7a4b365f8f42343c..96f04fb65e96da0bfc234e85b44628b2f4e8e683 100644 --- a/src/Grid/grid_dist_id_iterator_sub.hpp +++ b/src/Grid/grid_dist_id_iterator_sub.hpp @@ -131,7 +131,7 @@ class grid_dist_iterator_sub * */ grid_dist_iterator_sub(const grid_dist_iterator_sub<dim,device_grid> & tmp) - :g_c(tmp.g_c),gList(tmp.gList),gdb_ext(gdb_ext),m(tmp.m) + :g_c(tmp.g_c),gList(tmp.gList),gdb_ext(tmp.gdb_ext),m(tmp.m) { a_it.reinitialize(tmp.a_it); } diff --git a/src/Grid/grid_dist_id_unit_test.hpp b/src/Grid/grid_dist_id_unit_test.hpp index 44b9b4237c5bfde77eb4596309fd28b26439e156..870d8314533afd7d6b3209b36499d5461971c2d6 100644 --- a/src/Grid/grid_dist_id_unit_test.hpp +++ b/src/Grid/grid_dist_id_unit_test.hpp @@ -1002,6 +1002,8 @@ void Test3D_dup(const Box<3,float> & domain, long int k) BOOST_REQUIRE_EQUAL(g_dist2->getDecomposition().ref(),1); bool ret = g_dist2->getDecomposition().check_consistency(); BOOST_REQUIRE_EQUAL(ret,true); + + delete g_dist2; } } diff --git a/src/Vector/vector_dist.hpp b/src/Vector/vector_dist.hpp index 66ab018a195c585b21bc634029dd0f5513a042ec..75a638372e2088fc0242df16ac9fd2316a4eded1 100644 --- a/src/Vector/vector_dist.hpp +++ b/src/Vector/vector_dist.hpp @@ -122,6 +122,50 @@ private: //! Total size of the received buffer size_t recv_cnt; + /*! \brief Label particles for mappings + * + * \param lbl_p Particle labeled + * \param p_map processor map (for each processor 1=comunication required 0=no communication) + * \param prc_sz processor send buffer size (number of particles) + * \param opart id of the particles to send + * + */ + void labelParticleMap(openfpm::vector<size_t> & lbl_p, openfpm::vector<size_t> & p_map, openfpm::vector<size_t> & prc_sz, openfpm::vector<size_t> & opart) + { + // resize the label buffer + prc_sz.resize(v_cl.getProcessingUnits()); + p_map.resize(v_cl.getProcessingUnits()); + lbl_p.resize(v_pos.size()); + + auto it = v_pos.getIterator(); + + // Label all the particles with the processor id where they should go + while (it.isNext()) + { + auto key = it.get(); + + // Apply the boundary conditions + dec.applyPointBC(v_pos.get(key)); + + size_t p_id = dec.processorIDBC(v_pos.get(key)); + + lbl_p.get(key) = p_id; + + // Particle toe move + if (p_id != v_cl.getProcessUnitID()) + { + p_map.get(p_id) = 1; + prc_sz.get(p_id)++; + + opart.add(key); + } + + // Add processors and add size + + ++it; + } + } + /*! \brief Label the particles * * It count the number of particle to send to each processors and save its ids @@ -435,7 +479,7 @@ public: * */ vector_dist(size_t np, Box<dim,St> box, const size_t (& bc)[dim] ,const Ghost<dim,St> & g) - :dec(*global_v_cluster),v_cl(*global_v_cluster) + :dec(*global_v_cluster),v_cl(*global_v_cluster),recv_cnt(0) { #ifdef SE_CLASS2 check_new(this,8,VECTOR_DIST_EVENT,4); @@ -476,9 +520,6 @@ public: // and create the ghost boxes dec.calculateGhostBoxes(); - - Point<dim,St> p; - p.zero(); } ~vector_dist() @@ -558,6 +599,9 @@ public: */ void map() { + // Labeling particles + openfpm::vector<size_t> lbl_p; + // outgoing particles-id openfpm::vector<size_t> opart; @@ -575,41 +619,11 @@ public: v_prp.resize(g_m); // Contain the processor id of each particle (basically where they have to go) - openfpm::vector<size_t> lbl_p(v_pos.size()); - - auto it = v_pos.getIterator(); - - // Label all the particles with the processor id where they should go - while (it.isNext()) - { - auto key = it.get(); - - // Apply the boundary conditions - dec.applyPointBC(v_pos.get(key)); - - size_t p_id = dec.processorIDBC(v_pos.get(key)); - - lbl_p.get(key) = p_id; - - // It has to communicate - if (p_id != v_cl.getProcessUnitID()) - { - p_map.get(p_id) = 1; - prc_sz.get(p_id)++; - - opart.add(key); - } - - // Add processors and add size - - ++it; - } + labelParticleMap(lbl_p,p_map,prc_sz,opart); - // resize the map + // Calculate the sending buffer size for each processor, put this information in + // a contiguous buffer p_map_req.resize(v_cl.getProcessingUnits()); - - // Create the sz and prc buffer - openfpm::vector<size_t> prc_sz_r; openfpm::vector<size_t> prc_r; @@ -623,7 +637,7 @@ public: } } - // Allocate all the buffers + // Allocate the send buffers openfpm::vector<pos_prop> pb(prc_r.size()); @@ -652,7 +666,7 @@ public: openfpm::vector<size_t> prc_cnt(prc_r.size()); prc_cnt.fill(0); - it = lbl_p.getIterator(); + auto it = lbl_p.getIterator(); while (it.isNext()) { @@ -695,7 +709,7 @@ public: recv_cnt = 0; v_cl.sendrecvMultipleMessagesPCX(prc_sz_r.size(),&p_map.get(0), (size_t *)prc_sz_r.getPointer(), (size_t *)prc_r.getPointer() , (void **)ptr.getPointer() , vector_dist::message_alloc_map, this ,NEED_ALL_SIZE); - // overwrite the outcoming particle with the incoming particle and resize the vectors + // Process the incoming particles size_t total_element = 0; size_t o_p_id = 0; @@ -746,7 +760,7 @@ public: total_element += n_ele; } - // remove the hole (out-going particles) in the vector + // remove the (out-going particles) in the vector v_pos.remove(opart,o_p_id); v_prp.remove(opart,o_p_id);