diff --git a/src/Grid/grid_dist_id.hpp b/src/Grid/grid_dist_id.hpp index f904ad9d14108b2dbe9f4f5b60f47ece1794fcdf..57929aea4163a9706a318873fb0eaedb547f9c38 100644 --- a/src/Grid/grid_dist_id.hpp +++ b/src/Grid/grid_dist_id.hpp @@ -89,8 +89,6 @@ class grid_dist_id //! It is unique across all the near processor std::unordered_map<size_t,size_t> g_id_to_external_ghost_box; - std::unordered_map<size_t,size_t> g_id_to_external_ghost_box_fix; - //! It map a global ghost id (g_id) to the internal ghost box information //! (is unique for processor), it is not unique across all the near processor openfpm::vector<std::unordered_map<size_t,size_t>> g_id_to_internal_ghost_box; @@ -198,7 +196,7 @@ class grid_dist_id // save the box and the sub-domain id (it is calculated as the linearization of P1) ::Box<dim,size_t> cvt = ib; - i_box_id bid_t; + i_box_id<dim> bid_t; bid_t.box = cvt; bid_t.g_id = dec.getProcessorIGhostId(i,j); bid_t.sub = dec.getProcessorIGhostSub(i,j); @@ -223,57 +221,6 @@ class grid_dist_id if (init_e_g_box == true) return; - // Get the number of near processors - for (size_t i = 0 ; i < dec.getNNProcessors() ; i++) - { - eg_box.add(); - auto&& pib = eg_box.last(); - - pib.prc = dec.IDtoProc(i); - for (size_t j = 0 ; j < dec.getProcessorNEGhost(i) ; j++) - { - // Get the external ghost boxes and transform into grid units - ::Box<dim,St> ib_dom = dec.getProcessorEGhostBox(i,j); - ib_dom -= cd_sm.getOrig(); - ::Box<dim,long int> ib = cd_sm.convertDomainSpaceIntoGridUnits(ib_dom,dec.periodicity()); - - // Check if ib is valid if not it mean that the internal ghost does not contain information so skip it - if (ib.isValid() == false) - continue; - - // save the box and the unique external ghost box id (linearization of P1) - // It is (locally) unique because it is ensured that external ghost boxes does not overlap - // Carefull it is not unique from the internal ghost box - - // sub domain id at which belong the external ghost box - size_t sub_id = dec.getProcessorEGhostSub(i,j); - - e_box_id bid_t; - bid_t.sub = sub_id; - bid_t.g_e_box = ib; - bid_t.l_e_box = ib; - bid_t.cmb = dec.getProcessorEGhostPos(i,j); - bid_t.g_id = dec.getProcessorEGhostId(i,j); - // Translate in local coordinate - Box<dim,long int> tb = ib; - tb -= gdb_ext.get(sub_id).origin; - bid_t.l_e_box = tb; - - pib.bid.add(bid_t); - - // Add the map between the global ghost box id and id of the external box in the vector - size_t g_id = dec.getProcessorEGhostId(i,j); - g_id_to_external_ghost_box[g_id] = pib.bid.size()-1; - } - } - - init_e_g_box = true; - - // Communicate the ig_box calculated to the other processor - - comb<dim> zero; - zero.zero(); - // Here we collect all the calculated internal ghost box in the sector different from 0 that this processor has openfpm::vector<size_t> prc; @@ -297,15 +244,15 @@ class grid_dist_id v_cl.SSendRecv(box_int_send,box_int_recv,prc,prc_recv,sz_recv); - eg_box_tmp.resize(dec.getNNProcessors()); + eg_box.resize(dec.getNNProcessors()); - for (size_t i = 0 ; i < eg_box_tmp.size() ; i++) - eg_box_tmp.get(i).prc = dec.IDtoProc(i); + for (size_t i = 0 ; i < eg_box.size() ; i++) + eg_box.get(i).prc = dec.IDtoProc(i); for (size_t i = 0 ; i < box_int_recv.size() ; i++) { size_t p_id = dec.ProctoID(prc_recv.get(i)); - auto&& pib = eg_box_tmp.get(p_id); + auto&& pib = eg_box.get(p_id); pib.prc = prc_recv.get(i); // For each received internal ghost box @@ -319,7 +266,7 @@ class grid_dist_id const openfpm::vector<size_t> & s_sub = dec.getSentSubdomains(p_id); size_t sub_id = s_sub.get(send_list_id); - e_box_id bid_t; + e_box_id<dim> bid_t; bid_t.sub = sub_id; bid_t.cmb = box_int_recv.get(i).get(j).cmb; bid_t.cmb.sign_flip(); @@ -333,32 +280,11 @@ class grid_dist_id pib.bid.add(bid_t); - g_id_to_external_ghost_box_fix[bid_t.g_id] = pib.bid.size()-1; - - size_t l_id = 0; - // convert the global id into local id - auto key = g_id_to_external_ghost_box.find(bid_t.g_id); - if (key != g_id_to_external_ghost_box.end()) // FOUND - l_id = key->second; - - Box<dim,long int> box_le = eg_box.get(p_id).bid.get(l_id).l_e_box; - Box<dim,long int> box_ge = eg_box.get(p_id).bid.get(l_id).g_e_box; - - if (box_le != bid_t.l_e_box || box_ge != bid_t.g_e_box || - eg_box.get(p_id).bid.get(l_id).cmb != bid_t.cmb || - eg_box.get(p_id).bid.get(l_id).sub != bid_t.sub) - { - int debug = 0; - debug++; - } + g_id_to_external_ghost_box[bid_t.g_id] = pib.bid.size()-1; } } - // switch - - g_id_to_external_ghost_box = g_id_to_external_ghost_box_fix; - eg_box.clear(); - eg_box = eg_box_tmp; + init_e_g_box = true; } bool init_local_i_g_box = false; @@ -413,33 +339,7 @@ class grid_dist_id if (init_local_e_g_box == true) return; - // Get the number of sub-domain - for (size_t i = 0 ; i < dec.getNSubDomain() ; i++) - { - loc_eg_box.add(); - auto&& pib = loc_eg_box.last(); - - for (size_t j = 0 ; j < dec.getLocalNEGhost(i) ; j++) - { - // Get the internal ghost boxes and transform into grid units - ::Box<dim,St> ib_dom = dec.getLocalEGhostBox(i,j); - ib_dom -= cd_sm.getOrig(); - ::Box<dim,long int> ib = cd_sm.convertDomainSpaceIntoGridUnits(ib_dom,dec.periodicity()); - - // Warning even if the ib is not a valid in grid unit we are forced to keep it - // otherwise the value returned from dec.getLocalEGhostSub(i,j) will point to an - // invalid or wrong box - - pib.bid.add(); - pib.bid.last().box = ib; - pib.bid.last().sub = dec.getLocalEGhostSub(i,j); - pib.bid.last().cmb = dec.getLocalEGhostPos(i,j); - } - } - - init_local_e_g_box = true; - - loc_eg_box_tmp.resize(dec.getNSubDomain()); + loc_eg_box.resize(dec.getNSubDomain()); // Get the number of sub-domain for (size_t i = 0 ; i < dec.getNSubDomain() ; i++) @@ -447,7 +347,7 @@ class grid_dist_id for (size_t j = 0 ; j < loc_ig_box.get(i).bid.size() ; j++) { size_t k = loc_ig_box.get(i).bid.get(j).sub; - auto & pib = loc_eg_box_tmp.get(k); + auto & pib = loc_eg_box.get(k); size_t s = loc_ig_box.get(i).bid.get(j).k; pib.bid.resize(dec.getLocalNEGhost(k)); @@ -456,19 +356,10 @@ class grid_dist_id pib.bid.get(s).sub = dec.getLocalEGhostSub(k,s); pib.bid.get(s).cmb = loc_ig_box.get(i).bid.get(j).cmb; pib.bid.get(s).cmb.sign_flip(); - - if (pib.bid.get(s).box != loc_eg_box.get(k).bid.get(s).box && - pib.bid.get(s).cmb != loc_eg_box.get(k).bid.get(s).cmb && - pib.bid.get(s).sub != loc_eg_box.get(k).bid.get(s).sub) - { - std::cout << "CAZZO" << std::endl; - int debug = 0; - debug++; - } } } - loc_eg_box = loc_eg_box_tmp; + init_local_e_g_box = true; } /*! \brief Sync the local ghost part @@ -525,9 +416,6 @@ class grid_dist_id // Option 1 gd.set(sub_dst.get(),gs,sub_src.get()); - // Option 2 -// gd.get_o(sub_dst.get()) = gs.get_o(sub_src.get()); - ++sub_src; ++sub_dst; } @@ -552,9 +440,6 @@ class grid_dist_id */ void Create() { - Box<dim,St> g_rnd_box; - for (size_t i = 0 ; i < dim ; i++) {g_rnd_box.setHigh(i,0.5); g_rnd_box.setLow(i,-0.5);} - // Get the number of local grid needed size_t n_grid = dec.getNSubDomain(); @@ -1260,128 +1145,6 @@ public: return loc_grid.get(v1.getSub()).template get<p>(v1.getKey()); } - /*! \brief it store a box, its unique id and the sub-domain from where it come from - * - */ - struct i_box_id - { - //! Box - ::Box<dim,long int> box; - - //! id - size_t g_id; - - //! r_sub id of the sub-domain in the sent list - size_t r_sub; - - //! Sector where it live the linked external ghost box - comb<dim> cmb; - - - - //! sub - size_t sub; - }; - - /*! \brief it store an internal ghost box, the linked external ghost box and the sub-domain from where - * it come from as internal ghost box - * - */ - struct i_lbox_id - { - //! Box - ::Box<dim,long int> box; - - //! sub-domain id - size_t sub; - - //! external ghost box linked to this internal ghost box - size_t k; - - //! combination - comb<dim> cmb; - }; - - /*! \brief It store the information about the external ghost box - * - * - */ - struct e_box_id - { - //! Box defining the external ghost box in global coordinates - ::Box<dim,long int> g_e_box; - - //! Box defining the external ghost box in local coordinates - ::Box<dim,long int> l_e_box; - - //! Sector position of the external ghost - comb<dim> cmb; - - //! Id - size_t g_id; - - //! sub_id in which sub-domain this box live - size_t sub; - }; - - /*! \brief It store the information about the local external ghost box - * - * - */ - struct e_lbox_id - { - //! Box defining the external ghost box in local coordinates - ::Box<dim,long int> box; - - //! Sector position of the local external ghost box - comb<dim> cmb; - - //! sub_id in which sub-domain this box live - size_t sub; - }; - - /*! \brief Per-processor Internal ghost box - * - */ - struct ip_box_grid - { - // ghost in grid units - openfpm::vector<i_box_id> bid; - - //! processor id - size_t prc; - }; - - /*! \brief local Internal ghost box - * - */ - struct i_lbox_grid - { - // ghost in grid units - openfpm::vector<i_lbox_id> bid; - }; - - /*! \brief Per-processor external ghost box - * - */ - struct ep_box_grid - { - // ghost in grid units - openfpm::vector<e_box_id> bid; - - //! processor id - size_t prc; - }; - - /*! \brief Per-processor external ghost box - * - */ - struct e_lbox_grid - { - // ghost in grid units - openfpm::vector<e_lbox_id> bid; - }; - //! Memory for the ghost sending buffer Memory g_send_prp_mem; @@ -1398,20 +1161,16 @@ public: bool init_fix_ie_g_box = false; //! Internal ghost boxes in grid units - openfpm::vector<ip_box_grid> ig_box; + openfpm::vector<ip_box_grid<dim>> ig_box; //! External ghost boxes in grid units - openfpm::vector<ep_box_grid> eg_box; - - openfpm::vector<ep_box_grid> eg_box_tmp; + openfpm::vector<ep_box_grid<dim>> eg_box; //! Local internal ghost boxes in grid units - openfpm::vector<i_lbox_grid> loc_ig_box; + openfpm::vector<i_lbox_grid<dim>> loc_ig_box; //! Local external ghost boxes in grid units - openfpm::vector<e_lbox_grid> loc_eg_box; - - openfpm::vector<e_lbox_grid> loc_eg_box_tmp; + openfpm::vector<e_lbox_grid<dim>> loc_eg_box; /*! \brief It synchronize the ghost parts * diff --git a/src/Grid/grid_dist_id_unit_test.hpp b/src/Grid/grid_dist_id_unit_test.cpp similarity index 99% rename from src/Grid/grid_dist_id_unit_test.hpp rename to src/Grid/grid_dist_id_unit_test.cpp index 4c650b9125386d8dd1b8ae8b89cadc06a91fc83a..b1c5cdde6b3d5851d45d92d39a8ee0ae8768a63c 100644 --- a/src/Grid/grid_dist_id_unit_test.hpp +++ b/src/Grid/grid_dist_id_unit_test.cpp @@ -1,6 +1,10 @@ #ifndef GRID_DIST_UNIT_TEST_HPP #define GRID_DIST_UNIT_TEST_HPP +#define BOOST_TEST_DYN_LINK +#include <boost/test/unit_test.hpp> + +#include "Point_test.hpp" #include "grid_dist_id.hpp" #include "data_type/scalar.hpp" #include "data_type/aggregate.hpp" diff --git a/src/Grid/grid_dist_id_unit_test_unb_ghost.hpp b/src/Grid/grid_dist_id_unit_test_unb_ghost.hpp index 3299c95a3789141200d21ed4055bbca423ae26dd..171d10388de2eaaaf922814687e8d3b9e94f117f 100644 --- a/src/Grid/grid_dist_id_unit_test_unb_ghost.hpp +++ b/src/Grid/grid_dist_id_unit_test_unb_ghost.hpp @@ -235,7 +235,7 @@ void Test3D_unb_ghost_periodic(const Box<3,float> & domain, long int k) if (g_dist.template get<0>(key) != -1 && out_p == true) out_cnt++; - if ( /*g_dist.template get<0>(key) != -1 &&*/ info.LinId(key_g) != g_dist.template get<0>(key) ) + if ( g_dist.template get<0>(key) != -1 && info.LinId(key_g) != g_dist.template get<0>(key) ) match &= false; ++dom_gi; diff --git a/src/Grid/grid_dist_util.hpp b/src/Grid/grid_dist_util.hpp index 1947079bc3a12f97096e96c5d6840569415a172b..2981c19900f97e5bf192c353fcf0d003faf5bcee 100644 --- a/src/Grid/grid_dist_util.hpp +++ b/src/Grid/grid_dist_util.hpp @@ -48,9 +48,6 @@ template<unsigned int dim> periodicity<dim> create_non_periodic() */ template<int dim, typename Decomposition> inline void create_gdb_ext(openfpm::vector<GBoxes<Decomposition::dims>> & gdb_ext, Decomposition & dec, CellDecomposer_sm<Decomposition::dims,typename Decomposition::stype,shift<dim,typename Decomposition::stype>> & cd_sm) { - Box<Decomposition::dims, typename Decomposition::stype> g_rnd_box; - for (size_t i = 0 ; i < Decomposition::dims ; i++) {g_rnd_box.setHigh(i,0.5); g_rnd_box.setLow(i,-0.5);} - // Get the number of local grid needed size_t n_grid = dec.getNSubDomain(); @@ -112,4 +109,126 @@ template<int dim, typename Decomposition> inline void create_gdb_ext(openfpm::ve spacing[i] = cd_sm.getCellBox().getP2()[i]; } +/*! \brief it store a box, its unique id and the sub-domain from where it come from + * + */ +template<unsigned int dim> struct i_box_id +{ + //! Box + ::Box<dim,long int> box; + + //! id + size_t g_id; + + //! r_sub id of the sub-domain in the sent list + size_t r_sub; + + //! Sector where it live the linked external ghost box + comb<dim> cmb; + + + + //! sub + size_t sub; +}; + +/*! \brief it store an internal ghost box, the linked external ghost box and the sub-domain from where + * it come from as internal ghost box + * + */ +template<unsigned int dim> struct i_lbox_id +{ + //! Box + ::Box<dim,long int> box; + + //! sub-domain id + size_t sub; + + //! external ghost box linked to this internal ghost box + size_t k; + + //! combination + comb<dim> cmb; +}; + +/*! \brief It store the information about the external ghost box + * + * + */ +template <unsigned int dim> struct e_box_id +{ + //! Box defining the external ghost box in global coordinates + ::Box<dim,long int> g_e_box; + + //! Box defining the external ghost box in local coordinates + ::Box<dim,long int> l_e_box; + + //! Sector position of the external ghost + comb<dim> cmb; + + //! Id + size_t g_id; + + //! sub_id in which sub-domain this box live + size_t sub; +}; + +/*! \brief It store the information about the local external ghost box + * + * + */ +template <unsigned int dim> struct e_lbox_id +{ + //! Box defining the external ghost box in local coordinates + ::Box<dim,long int> box; + + //! Sector position of the local external ghost box + comb<dim> cmb; + + //! sub_id in which sub-domain this box live + size_t sub; +}; + +/*! \brief Per-processor Internal ghost box + * + */ +template <unsigned int dim> struct ip_box_grid +{ + // ghost in grid units + openfpm::vector<i_box_id<dim>> bid; + + //! processor id + size_t prc; +}; + +/*! \brief local Internal ghost box + * + */ +template <unsigned int dim> struct i_lbox_grid +{ + // ghost in grid units + openfpm::vector<i_lbox_id<dim>> bid; +}; + +/*! \brief Per-processor external ghost box + * + */ +template <unsigned int dim>struct ep_box_grid +{ + // ghost in grid units + openfpm::vector<e_box_id<dim>> bid; + + //! processor id + size_t prc; +}; + +/*! \brief Per-processor external ghost box + * + */ +template <unsigned int dim> struct e_lbox_grid +{ + // ghost in grid units + openfpm::vector<e_lbox_id<dim>> bid; +}; + #endif /* SRC_GRID_GRID_DIST_UTIL_HPP_ */ diff --git a/src/Makefile.am b/src/Makefile.am index 9ed5530bd1f0bbfc126721f4cf7c8a8b76d1d05d..464b261ff4de1cf4aef1d9fa0deca5e85d8dbdde 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -1,7 +1,7 @@ -LINKLIBS = $(METIS_LIB) $(PTHREAD_LIBS) $(OPT_LIBS) $(BOOST_LDFLAGS) $(BOOST_IOSTREAMS_LIB) $(CUDA_LIBS) $(PETSC_LIB) $(HDF5_LDFLAGS) $(HDF5_LIBS) $(PARMETIS_LIB) +LINKLIBS = $(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) noinst_PROGRAMS = pdata -pdata_SOURCES = main.cpp lib/pdata.cpp test_multiple_o.cpp ../openfpm_devices/src/memory/HeapMemory.cpp ../openfpm_devices/src/memory/PtrMemory.cpp ../openfpm_vcluster/src/VCluster.cpp ../openfpm_devices/src/Memleak_check.cpp +pdata_SOURCES = main.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.cpp ../openfpm_devices/src/Memleak_check.cpp pdata_CXXFLAGS = $(PETSC_INCLUDE) $(HDF5_CPPFLAGS) $(CUDA_CFLAGS) $(INCLUDES_PATH) $(PARMETIS_INCLUDE) $(METIS_INCLUDE) $(BOOST_CPPFLAGS) $(H5PART_INCLUDE) -DPARALLEL_IO -Wno-unused-local-typedefs pdata_CFLAGS = $(CUDA_CFLAGS) pdata_LDADD = $(LINKLIBS) -lmetis -lparmetis diff --git a/src/dec_optimizer_unit_test.hpp b/src/dec_optimizer_unit_test.hpp index deaa903ee5935cc05630e6ad2eecf98f19e4476c..0d0d05b70e85e54e00c2419d706eb13a36579ef9 100644 --- a/src/dec_optimizer_unit_test.hpp +++ b/src/dec_optimizer_unit_test.hpp @@ -122,24 +122,11 @@ BOOST_AUTO_TEST_CASE( dec_optimizer_test_use_p) for(size_t i = 0 ; i < box_nn_processor.size() ; i++) { - bool nn[] = {false,false,false,false,false,false,false,false}; - BOOST_REQUIRE_EQUAL(box_nn_processor.get(i).size(),7ul); + BOOST_REQUIRE_EQUAL(box_nn_processor.get(i).size(),8ul); for (size_t j = 0 ; j < box_nn_processor.get(i).size(); j++) { BOOST_REQUIRE(box_nn_processor.get(i).get(j) < 8); - nn[box_nn_processor.get(i).get(j)] = true; } - - // search the neighborhood - - size_t cnt = 0; - for(size_t i = 0 ; i < 8 ; i++) - { - if (nn[i] == false) - cnt++; - } - - BOOST_REQUIRE_EQUAL(cnt,1ul); } // check diff --git a/src/main.cpp b/src/main.cpp index 3a554a6e44ba254cfb243b548d73b408f899f7c7..3da9319f0a056e40d032dc90e54177035c9fa4fa 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,5 +1,4 @@ #include <iostream> -#include "config.h" #define NO_WARNING #include "Graph/CartesianGraphFactory.hpp" @@ -7,8 +6,21 @@ #define BOOST_DISABLE_ASSERTS -#define BOOST_TEST_MODULE "C++ test module for OpenFPM_pdata project" -#include <boost/test/included/unit_test.hpp> +#include "config.h" +#define BOOST_TEST_DYN_LINK +#include <boost/test/unit_test.hpp> + +// initialization function: +bool init_unit_test() +{ + return true; +} + +// entry point: +int main(int argc, char* argv[]) +{ + return boost::unit_test::unit_test_main( &init_unit_test, argc, argv ); +} #include "Grid/grid_dist_id.hpp" #include "Point_test.hpp" @@ -24,7 +36,6 @@ #include "Decomposition/ORB_unit_test.hpp" #include "Decomposition/Distribution/metis_util_unit_test.hpp" #include "dec_optimizer_unit_test.hpp" -#include "Grid/grid_dist_id_unit_test.hpp" #include "Vector/vector_dist_unit_test.hpp" #include "Decomposition/Distribution/Distribution_unit_tests.hpp" //#include "DLB/DLB_unit_test.hpp"