diff --git a/dist_graph_0_test.vtk b/dist_graph_0_test.vtk deleted file mode 100644 index 8e7e4041ce10eb5c4a446562d88d5aad5a76479b..0000000000000000000000000000000000000000 --- a/dist_graph_0_test.vtk +++ /dev/null @@ -1,274 +0,0 @@ -# vtk DataFile Version 3.0 -Graph -ASCII -DATASET POLYDATA -POINTS 16 float -0.500000 0.000000 0.000000 -0.750000 0.000000 0.000000 -0.500000 0.250000 0.000000 -0.750000 0.250000 0.000000 -0.000000 0.000000 0.000000 -0.250000 0.000000 0.000000 -0.000000 0.250000 0.000000 -0.250000 0.250000 0.000000 -0.500000 0.500000 0.000000 -0.750000 0.500000 0.000000 -0.500000 0.750000 0.000000 -0.750000 0.750000 0.000000 -0.000000 0.500000 0.000000 -0.250000 0.500000 0.000000 -0.000000 0.750000 0.000000 -0.250000 0.750000 0.000000 -VERTICES 16 32 -1 0 -1 1 -1 2 -1 3 -1 4 -1 5 -1 6 -1 7 -1 8 -1 9 -1 10 -1 11 -1 12 -1 13 -1 14 -1 15 -LINES 48 144 -2 0 1 -2 0 5 -2 0 2 -2 1 0 -2 1 3 -2 2 3 -2 2 7 -2 2 8 -2 2 0 -2 3 2 -2 3 9 -2 3 1 -2 4 5 -2 4 6 -2 5 0 -2 5 4 -2 5 7 -2 6 7 -2 6 12 -2 6 4 -2 7 2 -2 7 6 -2 7 13 -2 7 5 -2 8 9 -2 8 13 -2 8 10 -2 8 2 -2 9 8 -2 9 11 -2 9 3 -2 10 11 -2 10 15 -2 10 8 -2 11 10 -2 11 9 -2 12 13 -2 12 14 -2 12 6 -2 13 8 -2 13 12 -2 13 15 -2 13 7 -2 14 15 -2 14 12 -2 15 10 -2 15 14 -2 15 13 -POINT_DATA 16 -VECTORS x float -0.500000 0.000000 0.000000 -0.750000 0.000000 0.000000 -0.500000 0.250000 0.000000 -0.750000 0.250000 0.000000 -0.000000 0.000000 0.000000 -0.250000 0.000000 0.000000 -0.000000 0.250000 0.000000 -0.250000 0.250000 0.000000 -0.500000 0.500000 0.000000 -0.750000 0.500000 0.000000 -0.500000 0.750000 0.000000 -0.750000 0.750000 0.000000 -0.000000 0.500000 0.000000 -0.250000 0.500000 0.000000 -0.000000 0.750000 0.000000 -0.250000 0.750000 0.000000 -SCALARS id unsigned_long -LOOKUP_TABLE default -0 -1 -2 -3 -4 -5 -6 -7 -8 -9 -10 -11 -12 -13 -14 -15 -SCALARS global_id unsigned_long -LOOKUP_TABLE default -2 -3 -6 -7 -0 -1 -4 -5 -10 -11 -14 -15 -8 -9 -12 -13 -CELL_DATA 64 -SCALARS srcgid unsigned_long -LOOKUP_TABLE default -0 -0 -0 -0 -0 -0 -0 -0 -0 -0 -0 -0 -0 -0 -0 -0 -2 -2 -2 -3 -3 -6 -6 -6 -6 -7 -7 -7 -0 -0 -1 -1 -1 -4 -4 -4 -5 -5 -5 -5 -10 -10 -10 -10 -11 -11 -11 -14 -14 -14 -15 -15 -8 -8 -8 -9 -9 -9 -9 -12 -12 -13 -13 -13 -SCALARS dstgid unsigned_long -LOOKUP_TABLE default -0 -0 -0 -0 -0 -0 -0 -0 -0 -0 -0 -0 -0 -0 -0 -0 -3 -1 -6 -2 -7 -7 -5 -10 -2 -6 -11 -3 -1 -4 -2 -0 -5 -5 -8 -0 -6 -4 -9 -1 -11 -9 -14 -6 -10 -15 -7 -15 -13 -10 -14 -11 -9 -12 -4 -10 -8 -13 -5 -13 -8 -14 -12 -9 diff --git a/dist_graph_1_test.vtk b/dist_graph_1_test.vtk deleted file mode 100644 index a28bfade997a6f4ea0d6656c7de44d939521988d..0000000000000000000000000000000000000000 --- a/dist_graph_1_test.vtk +++ /dev/null @@ -1,274 +0,0 @@ -# vtk DataFile Version 3.0 -Graph -ASCII -DATASET POLYDATA -POINTS 16 float -0.500000 0.000000 0.000000 -0.750000 0.000000 0.000000 -0.500000 0.250000 0.000000 -0.750000 0.250000 0.000000 -0.500000 0.500000 0.000000 -0.750000 0.500000 0.000000 -0.000000 0.750000 0.000000 -0.000000 0.500000 0.000000 -0.000000 0.000000 0.000000 -0.250000 0.000000 0.000000 -0.000000 0.250000 0.000000 -0.250000 0.250000 0.000000 -0.500000 0.750000 0.000000 -0.750000 0.750000 0.000000 -0.250000 0.500000 0.000000 -0.250000 0.750000 0.000000 -VERTICES 16 32 -1 0 -1 1 -1 2 -1 3 -1 4 -1 5 -1 6 -1 7 -1 8 -1 9 -1 10 -1 11 -1 12 -1 13 -1 14 -1 15 -LINES 48 144 -2 0 1 -2 0 9 -2 0 2 -2 1 0 -2 1 3 -2 2 3 -2 2 11 -2 2 4 -2 2 0 -2 3 2 -2 3 5 -2 3 1 -2 4 5 -2 4 14 -2 4 12 -2 4 2 -2 5 4 -2 5 13 -2 5 3 -2 6 15 -2 6 7 -2 7 14 -2 7 6 -2 7 10 -2 8 9 -2 8 10 -2 9 0 -2 9 8 -2 9 11 -2 10 11 -2 10 7 -2 10 8 -2 11 2 -2 11 10 -2 11 14 -2 11 9 -2 12 13 -2 12 15 -2 12 4 -2 13 12 -2 13 5 -2 14 4 -2 14 7 -2 14 15 -2 14 11 -2 15 12 -2 15 6 -2 15 14 -POINT_DATA 16 -VECTORS x float -0.500000 0.000000 0.000000 -0.750000 0.000000 0.000000 -0.500000 0.250000 0.000000 -0.750000 0.250000 0.000000 -0.500000 0.500000 0.000000 -0.750000 0.500000 0.000000 -0.000000 0.750000 0.000000 -0.000000 0.500000 0.000000 -0.000000 0.000000 0.000000 -0.250000 0.000000 0.000000 -0.000000 0.250000 0.000000 -0.250000 0.250000 0.000000 -0.500000 0.750000 0.000000 -0.750000 0.750000 0.000000 -0.250000 0.500000 0.000000 -0.250000 0.750000 0.000000 -SCALARS id unsigned_long -LOOKUP_TABLE default -0 -1 -2 -3 -5 -6 -7 -4 -8 -9 -10 -11 -12 -13 -14 -15 -SCALARS global_id unsigned_long -LOOKUP_TABLE default -2 -3 -6 -7 -10 -11 -12 -8 -0 -1 -4 -5 -14 -15 -9 -13 -CELL_DATA 64 -SCALARS srcgid unsigned_long -LOOKUP_TABLE default -0 -0 -0 -0 -0 -0 -0 -0 -0 -0 -0 -0 -0 -0 -0 -0 -2 -2 -2 -3 -3 -6 -6 -6 -6 -7 -7 -7 -10 -10 -10 -10 -11 -11 -11 -12 -12 -8 -8 -8 -0 -0 -1 -1 -1 -4 -4 -4 -5 -5 -5 -5 -14 -14 -14 -15 -15 -9 -9 -9 -9 -13 -13 -13 -SCALARS dstgid unsigned_long -LOOKUP_TABLE default -0 -0 -0 -0 -0 -0 -0 -0 -0 -0 -0 -0 -0 -0 -0 -0 -3 -1 -6 -2 -7 -7 -5 -10 -2 -6 -11 -3 -11 -9 -14 -6 -10 -15 -7 -13 -8 -9 -12 -4 -1 -4 -2 -0 -5 -5 -8 -0 -6 -4 -9 -1 -15 -13 -10 -14 -11 -10 -8 -13 -5 -14 -12 -9 diff --git a/openfpm_data b/openfpm_data index 7e41886aadce576e0e46c8f0eb60ba11473b64ca..524a87a925b8230b019264ca957293f686974f88 160000 --- a/openfpm_data +++ b/openfpm_data @@ -1 +1 @@ -Subproject commit 7e41886aadce576e0e46c8f0eb60ba11473b64ca +Subproject commit 524a87a925b8230b019264ca957293f686974f88 diff --git a/openfpm_io b/openfpm_io index dbc37efff49ac7622db19f3944422e496fc5cdc6..136310cb5b8b776eb405f58d5721c879a8d013b5 160000 --- a/openfpm_io +++ b/openfpm_io @@ -1 +1 @@ -Subproject commit dbc37efff49ac7622db19f3944422e496fc5cdc6 +Subproject commit 136310cb5b8b776eb405f58d5721c879a8d013b5 diff --git a/src/Decomposition/CartDecomposition.hpp b/src/Decomposition/CartDecomposition.hpp index 621c64baa8430bb117cf2ca5811278829d26ad40..28245e258c1591044376e9a5c954594c9ba48c6c 100755 --- a/src/Decomposition/CartDecomposition.hpp +++ b/src/Decomposition/CartDecomposition.hpp @@ -137,6 +137,18 @@ 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; + /*! \brief Constructor, it decompose and distribute the sub-domains across the processors * * \param v_cl Virtual cluster, used internally for communications @@ -356,18 +368,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: /*! \brief Cart decomposition constructor @@ -478,8 +478,8 @@ public: | | | | | | | | | | | | +--------------+---+---------------------------+----+ | - | | - +-----------------------------------+ + | | + +-----------------------------------+ \endverbatim @@ -510,8 +510,8 @@ public: | | | | | | | | | | | | +--------------+------------------------------------+ | | - | | | | - +----------------------------------------+----+------------------------------+ + | | | | + +----------------------------------------+----+------------------------------+ \endverbatim @@ -523,18 +523,18 @@ public: * * \verbatim - ^ p2[1] - | - | - +----+----+ - | | - | | - p1[0]<-----+ +----> p2[0] - | | - | | - +----+----+ - | - v p1[1] + ^ p2[1] + | + | + +----+----+ + | | + | | + p1[0]<-----+ +----> p2[0] + | | + | | + +----+----+ + | + v p1[1] \endverbatim @@ -655,7 +655,7 @@ public: dist.decompose(); - createSubdomains(v_cl); + //createSubdomains(v_cl); } /*! \brief Refine the decomposition, available only for ParMetis distribution, for Metis it is a null call @@ -681,7 +681,7 @@ public: dlb.setUnbalance(unbalance); if (v_cl.getProcessUnitID() == 0) { - //std::cout << std::setprecision(3) << unbalance << "\n"; + std::cout << std::setprecision(3) << unbalance << "\n"; } } diff --git a/src/Decomposition/CartDecomposition_unit_test.hpp b/src/Decomposition/CartDecomposition_unit_test.hpp index b762530dc74d55244de905e68eac1e98e8c6c139..115a094e6cd1a190c064faeb63b46df3ea92bef8 100755 --- a/src/Decomposition/CartDecomposition_unit_test.hpp +++ b/src/Decomposition/CartDecomposition_unit_test.hpp @@ -144,8 +144,8 @@ BOOST_AUTO_TEST_CASE( CartDecomposition_test_2D ) dec.rebalance(dlb); dec.printCurrentDecomposition(i+1); - } + } // create a ghost border dec.calculateGhostBoxes(); @@ -271,17 +271,6 @@ BOOST_AUTO_TEST_CASE( CartDecomposition_test_2D_sar) dec.printCurrentDecomposition(i); } - //print statistics - /* - if(vcl.getProcessUnitID() == 0) - { - float avg = dec.getTotalMovedV()/((etime-stime)/tstep); - - std::cout << "Moved vertices average: " << avg << "\n"; - std::cout << "Max number of moved vertices: " << dec.getMaxMovedV() << "\n"; - } - */ - // create a ghost border dec.calculateGhostBoxes(); @@ -379,7 +368,7 @@ BOOST_AUTO_TEST_CASE( CartDecomposition_test_3D) float stime = 0.0, etime = 10.0, tstep = 0.1; - for(float t = stime, i = 1, t_sim = 1; t < etime; t = t + tstep, i++) + for(float t = stime, i = 1; t < etime; t = t + tstep, i++) { if(t < etime/2) diff --git a/src/Decomposition/DistParMetisDistribution.hpp b/src/Decomposition/DistParMetisDistribution.hpp index b97b1e2aa4b495a7b82f352246f9734f225b9dbe..49e136fcee59997bb6e244532bcbf9d6ed624717 100644 --- a/src/Decomposition/DistParMetisDistribution.hpp +++ b/src/Decomposition/DistParMetisDistribution.hpp @@ -91,10 +91,12 @@ public: //! Create sub graph DistGraphFactory<dim, DistGraph_CSR<nm_v, nm_e>> dist_g_factory; - sub_g = dist_g_factory.template construct<NO_EDGE, nm_v::id, nm_v::global_id, nm_e::srcgid, nm_e::dstgid, T, dim - 1, 0, 1, 2>(gr.getSize(), domain); + sub_g = dist_g_factory.template construct<NO_EDGE, T, dim - 1, 0, 1, 2>(gr.getSize(), domain); sub_g.getDecompositionVector(vtxdist); - for(size_t i=0; i< sub_g.getNVertex(); i++) - sub_g.vertex(i).template get<nm_v::x>()[2] = 0; + + if (dim == 2) + for (size_t i = 0; i < sub_g.getNVertex(); i++) + sub_g.vertex(i).template get<nm_v::x>()[2] = 0; } @@ -120,13 +122,12 @@ public: //! Get result partition for this processors idx_t *partition = parmetis_graph.getPartition(); - for (size_t i = 0; i < sub_g.getNVertex(); ++i) + for (size_t i = 0, j = sub_g.firstId(); i < sub_g.getNVertex() && j <= sub_g.lastId(); i++, j++) { if (partition[i] != v_cl.getProcessUnitID()) - sub_g.q_move(i, partition[i]); + sub_g.q_move(sub_g.nodeById(j), partition[i]); } sub_g.redistribute(); - } /*! \brief Refine current decomposition @@ -146,27 +147,12 @@ public: //! Get result partition for this processors idx_t *partition = parmetis_graph.getPartition(); - for (size_t i = 0; i < sub_g.getNVertex(); ++i) + for (size_t i = 0, j = sub_g.firstId(); i < sub_g.getNVertex() && j <= sub_g.lastId(); i++, j++) { if (partition[i] != v_cl.getProcessUnitID()) - sub_g.q_move(i, partition[i]); + sub_g.q_move(sub_g.nodeById(j), partition[i]); } - sub_g.redistribute(); - - /* - for (size_t i = 0; i < sub_g.getNVertex(); i++) - { - // Add weight to vertex and migration cost - std::cout << "g " << sub_g.vertex(i).template get<nm_v::global_id>() << "-" << sub_g.vertex(i).template get<nm_v::id>() << " -> "; - - // Create the adjacency list and the weights for edges - for (size_t s = 0; s < sub_g.getNChilds(i); s++) - { - std::cout << sub_g.getChild(i, s) << " "; - } - std::cout << "\n"; - }*/ } /*! \brief Compute the unbalance value @@ -175,13 +161,11 @@ public: */ float getUnbalance() { - long t_cost = 0; + long t_cost = getProcessorLoad(); long min, max, sum; float unbalance; - t_cost = getProcessorLoad(); - min = t_cost; max = t_cost; sum = t_cost; @@ -191,7 +175,7 @@ public: v_cl.sum(sum); v_cl.execute(); - unbalance = ((float) (max - min)) / (float) sum; + unbalance = ((float) (max - min)) / (((float) sum) / v_cl.getProcessingUnits()); return unbalance * 100; } @@ -221,8 +205,7 @@ public: */ inline void setVertexWeight(size_t id, size_t weight) { - if (!verticesGotWeights) - verticesGotWeights = true; + verticesGotWeights = true; if (id >= sub_g.getNVertex()) std::cerr << "Weight - Such vertex doesn't exist (id = " << id << ", " << "total size = " << sub_g.getNVertex() << ")\n"; @@ -344,25 +327,8 @@ public: */ void printCurrentDecomposition(int id) { - if (v_cl.getProcessUnitID() == 0) - { - sub_g.deleteGhosts(); - - for (size_t i = 0; i < sub_g.getTotNVertex(); ++i) - { - sub_g.reqVertex(i); - } - } - - sub_g.sync(); - - if (v_cl.getProcessUnitID() == 0) - { - VTKWriter<DistGraph_CSR<nm_v, nm_e>, DIST_GRAPH> gv2(sub_g); - gv2.write("test_dist_graph_" + std::to_string(id) + ".vtk"); - - sub_g.deleteGhosts(); - } + VTKWriter<DistGraph_CSR<nm_v, nm_e>, DIST_GRAPH> gv2(sub_g); + gv2.write("test_dist_graph_" + std::to_string(id) + ".vtk"); } }; diff --git a/src/Decomposition/ParMetisDistribution.hpp b/src/Decomposition/ParMetisDistribution.hpp index f915f5d6df68871bee4c3a5e6ca8163ef928e8c5..cb0df5c08af3ae91507a3b6a67b4ae13443c505c 100644 --- a/src/Decomposition/ParMetisDistribution.hpp +++ b/src/Decomposition/ParMetisDistribution.hpp @@ -398,6 +398,7 @@ public: unbalance = ((float) (max - min)) / (float) sum; + std::cout << std::endl; return unbalance * 100; } diff --git a/src/Graph/CartesianGraphFactory_unit_test.hpp b/src/Graph/CartesianGraphFactory_unit_test.hpp index bbba04e43234a0093b49a14d2c5e22b9d471257e..08690f901e68a5a953f866fef741cf5ef8d8a95e 100644 --- a/src/Graph/CartesianGraphFactory_unit_test.hpp +++ b/src/Graph/CartesianGraphFactory_unit_test.hpp @@ -4,7 +4,7 @@ #include "Graph/CartesianGraphFactory.hpp" #include "Graph/map_graph.hpp" -#define GS_SIZE 8 +#define GS_SIZE 64 /*! * diff --git a/src/Graph/DistCartesianGraphFactory_unit_test.hpp b/src/Graph/DistCartesianGraphFactory_unit_test.hpp index 82f5ef178000a6c8f8ef1661850446ebc3074c31..a2beccafa74cead9adfac8faf2038af8c5962ebc 100644 --- a/src/Graph/DistCartesianGraphFactory_unit_test.hpp +++ b/src/Graph/DistCartesianGraphFactory_unit_test.hpp @@ -225,7 +225,6 @@ BOOST_AUTO_TEST_CASE( DistCartesianGraphFactory_2D_use) // try to pack Packer<size_t,HeapMemory>::pack(mem, 3, sts); - node n = gd.vertex(0); Packer<decltype(gd.vertex(0)),HeapMemory>::pack(mem,gd.vertex(0), sts); Packer<decltype(gd.vertex(0)),HeapMemory>::pack(mem,gd.vertex(1), sts); Packer<decltype(gd.vertex(0)),HeapMemory>::pack(mem,gd.vertex(2), sts); @@ -312,7 +311,7 @@ BOOST_AUTO_TEST_CASE( DistCartesianGraphFactory_2D_use) v.resize(size); - for(int i = 0; i < size; i++){ + for(size_t i = 0; i < size; i++){ node v_n; Unpacker<node,HeapMemory>::unpack(mem,v_n,ps); v.set(i, v_n); @@ -336,7 +335,7 @@ BOOST_AUTO_TEST_CASE( DistCartesianGraphFactory_2D_use) v.resize(size); - for(int i = 0; i < size; i++){ + for(size_t i = 0; i < size; i++){ node v_n; Unpacker<node,HeapMemory>::unpack(mem,v_n,ps); v.set(i, v_n); diff --git a/src/Graph/dist_map_graph.hpp b/src/Graph/dist_map_graph.hpp index 93f2c0f40844a5091c0c873b75f60dc166fff886..ee67614a6cf448ffd0d5c0803358adbe4aa51f96 100644 --- a/src/Graph/dist_map_graph.hpp +++ b/src/Graph/dist_map_graph.hpp @@ -429,7 +429,7 @@ class DistGraph_CSR { if (sgp.size() == vcl.getProcessingUnits()) { - for (int p = 0; p < vcl.getProcessingUnits(); ++p) + for (size_t p = 0; p < vcl.getProcessingUnits(); ++p) { sgp.get(p).send_v.clear(); sgp.get(p).send_v_m.clear(); @@ -444,7 +444,7 @@ class DistGraph_CSR { sgp.resize(vcl.getProcessingUnits()); - for (int p = 0; p < vcl.getProcessingUnits(); ++p) + for (size_t p = 0; p < vcl.getProcessingUnits(); ++p) { openfpm::vector<V> s_v; openfpm::vector<v_info> s_v_m; @@ -524,7 +524,7 @@ class DistGraph_CSR */ size_t getVProcessor(size_t v) { - for (int i = 1; i < vtxdist.size() - 1; ++i) + for (size_t i = 1; i < vtxdist.size() - 1; ++i) { if (v < vtxdist.get(i)) { @@ -577,7 +577,7 @@ class DistGraph_CSR // prepare slot for number of vertices Packer<size_t, HeapMemory>::packRequest(pap_prp); - for (int j = 0; j < vp_size; j++) + for (size_t j = 0; j < vp_size; j++) { // prepare slot for vertex Packer<V, HeapMemory>::packRequest(pap_prp); @@ -589,7 +589,7 @@ class DistGraph_CSR Packer<size_t, HeapMemory>::packRequest(pap_prp); // prepare slots for the children - for (int k = 0; k < sgp.get(pc).send_es.get(j); k++) + for (size_t k = 0; k < sgp.get(pc).send_es.get(j); k++) { // prepare slot for edge Packer<E, HeapMemory>::packRequest(pap_prp); @@ -617,7 +617,7 @@ class DistGraph_CSR // Pack total size Packer<size_t, HeapMemory>::pack(mem, vp_size, sts); - for (int j = 0; j < vp_size; j++) + for (size_t j = 0; j < vp_size; j++) { // Pack the vertex Packer<decltype(sgp.get(pc).send_v.get(0)), HeapMemory>::pack(mem, sgp.get(pc).send_v.get(j), sts); @@ -629,7 +629,7 @@ class DistGraph_CSR Packer<size_t, HeapMemory>::pack(mem, sgp.get(pc).send_es.get(j), sts); // Pack children - for (int k = 0; k < sgp.get(pc).send_es.get(j); k++) + for (size_t k = 0; k < sgp.get(pc).send_es.get(j); k++) { // Pack the edge Packer<decltype(sgp.get(pc).send_e.get(0)), HeapMemory>::pack(mem, sgp.get(pc).send_e.get(e_it), sts); @@ -668,7 +668,7 @@ class DistGraph_CSR // take previous last item size_t prev = getNVertex(); - for (int j = prev; j < prev + r_size; j++) + for (size_t j = prev; j < prev + r_size; j++) { // unpack the vertex V v_n; @@ -689,7 +689,7 @@ class DistGraph_CSR Unpacker<size_t, HeapMemory>::unpack(mem, s, ps); // prepare slots for the children - for (int k = 0; k < s; k++) + for (size_t k = 0; k < s; k++) { // unpack edge E e_n; @@ -882,7 +882,7 @@ class DistGraph_CSR openfpm::vector<openfpm::vector<size_t>> resp_rmi(vcl.getProcessingUnits()); // Prepare re-mapping info response - for (int i = 0; i < req_rmi.size(); ++i) + for (size_t i = 0; i < req_rmi.size(); ++i) { for (size_t j = 0; j < req_rmi.get(i).size(); ++j) { @@ -944,7 +944,7 @@ class DistGraph_CSR */ size_t getInfoProc(size_t vid) { - for (int i = 0; i < fvtxdist.size() - 1; ++i) + for (size_t i = 0; i < fvtxdist.size() - 1; ++i) { if (vid >= fvtxdist.get(i) && vid < fvtxdist.get(i + 1)) { @@ -1017,6 +1017,7 @@ public: dup.id2glb = id2glb; dup.glb2loc = glb2loc; dup.e.swap(e.duplicate()); + dup.e_m.swap(e_m.duplicate()); dup.e_l.swap(e_l.duplicate()); dup.e_invalid.swap(e_invalid.duplicate()); dup.vtxdist.swap(vtxdist.duplicate()); @@ -1096,7 +1097,7 @@ public: { v.resize(vtxdist.size()); - for (int i = 0; i < vtxdist.size(); ++i) + for (size_t i = 0; i < vtxdist.size(); ++i) { v.get(i) = vtxdist.get(i); } @@ -1120,7 +1121,7 @@ public: vtxdist.resize(vcl.getProcessingUnits() + 1); fvtxdist.resize(vcl.getProcessingUnits() + 1); - for (int i = 0; i < vtxdist.size(); ++i) + for (size_t i = 0; i < vtxdist.size(); ++i) { vtxdist.get(i) = v.get(i); fvtxdist.get(i) = v.get(i); @@ -1136,7 +1137,7 @@ public: fvtxdist.resize(vcl.getProcessingUnits() + 1); - for (int i = 0; i < vtxdist.size(); ++i) + for (size_t i = 0; i < vtxdist.size(); ++i) { fvtxdist.get(i) = vtxdist.get(i); } @@ -1316,7 +1317,14 @@ public: */ size_t nodeById(size_t id) const { - return glb2loc.at(id2glb.at(id)); + try + { + return glb2loc.at(id2glb.at(id)); + } + catch (const std::out_of_range& oor) + { + std::cout << "Node not found by glb: "<< id <<std::endl; + } } /*! /brief Get the first id of the graph @@ -1635,32 +1643,6 @@ public: return e_l.template get<e_map::vid>(v.get() * v_slot + i); } - /*! \brief add vertex - * - * \param vrt Vertex properties - * - */ - inline void addVertex(const V & vrt) - { - // Add the vertex - v.add(vrt); - - // Update id to global map - id2glb.insert( { vrt.template get<V::id>(), vrt.template get<V::global_id>() }); - - // Update global id to local index - glb2loc.insert( { vrt.template get<V::global_id>(), v.size() - 1 }); - - // Update global id to id - glb2id.insert( { vrt.template get<V::global_id>(), vrt.template get<V::id>() }); - - // Set the number of adjacent vertex for this vertex to 0 - v_l.add(0ul); - - // Add a slot for the vertex adjacency list - e_l.resize(e_l.size() + v_slot); - } - /*! \brief Add vertex vrt with global id and id properties * * \param vrt vertex object to add @@ -1939,6 +1921,7 @@ public: v.swap(g.v); v_m.swap(g.v_m); e.swap(g.e); + e_m.swap(g.e_m); v_l.swap(g.v_l); glb2id = g.glb2id; id2glb = g.id2glb; @@ -1964,6 +1947,7 @@ public: v.swap(g.v); v_m.swap(g.v_m); e.swap(g.e); + e_m.swap(g.e_m); v_l.swap(g.v_l); glb2id = g.glb2id; id2glb = g.id2glb; @@ -2076,9 +2060,10 @@ public: for (auto gh : ghs_map) { epos += getNChilds(glb2loc.at(gh.first)); + id2glb.erase(glb2id.at(gh.first)); glb2loc.erase(gh.first); glb2id.erase(gh.first); - id2glb.erase(gh.first); + } //resize all structures to delete the ghosts @@ -2103,6 +2088,8 @@ public: template<bool toRemove = true> //TODO make it private and create wrapper in public void q_move(size_t i, size_t t) { + //std::cout << vcl.getProcessUnitID() <<" moving " << getVertexId(i) << " local " << i << " to " << t << std::endl; + // Check if a 'useless' move has been requested if (t == vcl.getProcessUnitID()) { @@ -2161,16 +2148,16 @@ public: if (glbi_map.size() == 0) initGlbimap(); - //std::cout<< "TEMP DBG::deleteGhosts\n"; + //std::cout << "TEMP DBG::deleteGhosts\n"; deleteGhosts(); - //std::cout<< "TEMP DBG::exchangeVertices\n"; + //std::cout << "TEMP DBG::exchangeVertices\n"; exchangeVertices<false>(); - //std::cout<< "TEMP DBG::updateVtxdist\n"; + //std::cout << "TEMP DBG::updateVtxdist\n"; updateVtxdist(); - //std::cout<< "TEMP DBG::remap\n"; + //std::cout << "TEMP DBG::remap\n"; remap(); } diff --git a/src/Graph/dist_map_graph_unit_test.hpp b/src/Graph/dist_map_graph_unit_test.hpp index 125ce7e32decb2e386a164041ac68791bb81948b..c68f97c6f7c1b2b570e3395bf7e2c53542ddf1f5 100644 --- a/src/Graph/dist_map_graph_unit_test.hpp +++ b/src/Graph/dist_map_graph_unit_test.hpp @@ -152,26 +152,16 @@ BOOST_AUTO_TEST_CASE( dist_map_graph_use_4p) //! [Request some vertices given global ids] - //gd.deleteGhosts(); - gd.reqVertex(13); gd.reqVertex(1); gd.reqVertex(14); gd.sync(); - //BOOST_REQUIRE_EQUAL(gd.getVertex(13).template get<vx::global_id>(), 13); - //BOOST_REQUIRE_EQUAL(gd.getVertex(1).template get<vx::global_id>(), 1); - //BOOST_REQUIRE_EQUAL(gd.getVertex(14).template get<vx::global_id>(), 14); - gd.reqVertex(15); gd.reqVertex(2); gd.reqVertex(10); gd.sync(); - //BOOST_REQUIRE_EQUAL(gd.getVertex(15).template get<vx::global_id>(), 15); - //BOOST_REQUIRE_EQUAL(gd.getVertex(2).template get<vx::global_id>(), 2); - //BOOST_REQUIRE_EQUAL(gd.getVertex(10).template get<vx::global_id>(), 10); - gd.deleteGhosts(); //! [Exchange n vertices and edges packed] @@ -254,11 +244,14 @@ BOOST_AUTO_TEST_CASE( dist_map_graph_use_4p) } } -BOOST_AUTO_TEST_CASE( dist_map_graph_use_4p_redistribution) +BOOST_AUTO_TEST_CASE( dist_map_graph_use_redistribution) { //! Vcluster Vcluster & vcl = *global_v_cluster; + if(vcl.getProcessingUnits() != 4) + return; + //! Initialize the global VCluster init_global_v_cluster(&boost::unit_test::framework::master_test_suite().argc,&boost::unit_test::framework::master_test_suite().argv); @@ -277,11 +270,6 @@ BOOST_AUTO_TEST_CASE( dist_map_graph_use_4p_redistribution) for(size_t i=0; i< gd.getNVertex(); i++) gd.vertex(i).template get<vx::x>()[2] = 0; - for(size_t i=0; i< gd.getNVertex(); i++) - std::cout << gd.getVertexId(i) << " "; - - std::cout << "\n"; - if (vcl.getProcessUnitID() == 0) { gd.q_move(0,1); @@ -308,27 +296,13 @@ BOOST_AUTO_TEST_CASE( dist_map_graph_use_4p_redistribution) gd.redistribute(); - if (vcl.getProcessUnitID() == 0) - { - gd.deleteGhosts(); - - for (size_t i = 0; i < gd.getTotNVertex(); ++i) - { - gd.reqVertex(i); - } - } + VTKWriter<DistGraph_CSR<vx, ed>, DIST_GRAPH> gv2(gd); + gv2.write("dist_graph_redistribution_0.vtk"); - gd.sync(); - - if (vcl.getProcessUnitID() == 0) + if(vcl.getProcessUnitID() == 0) { - VTKWriter<DistGraph_CSR<vx, ed>, GRAPH> gv2(gd); - gv2.write("dist_graph_0.vtk"); - - bool test = compare("dist_graph_0.vtk","dist_graph_0_test.vtk"); - //BOOST_REQUIRE_EQUAL(true,test); - - gd.deleteGhosts(); + bool test = compare("dist_graph_redistribution_0.vtk", "dist_graph_redistribution_0_test.vtk"); + BOOST_REQUIRE_EQUAL(true,test); } if (vcl.getProcessUnitID() == 2) @@ -345,36 +319,24 @@ BOOST_AUTO_TEST_CASE( dist_map_graph_use_4p_redistribution) gd.redistribute(); - if (vcl.getProcessUnitID() == 0) - { - gd.deleteGhosts(); - - for (size_t i = 0; i < gd.getTotNVertex(); ++i) - { - gd.reqVertex(i); - } - } - - gd.sync(); + gv2.write("dist_graph_redistribution_1.vtk"); - if (vcl.getProcessUnitID() == 0) + if(vcl.getProcessUnitID() == 0) { - VTKWriter<DistGraph_CSR<vx, ed>, DIST_GRAPH> gv2(gd); - gv2.write("dist_graph_1.vtk"); - - bool test = compare("dist_graph_1.vtk","dist_graph_1_test.vtk"); - //BOOST_REQUIRE_EQUAL(true,test); - - gd.deleteGhosts(); + bool test = compare("dist_graph_redistribution_1.vtk","dist_graph_redistribution_1_test.vtk"); + BOOST_REQUIRE_EQUAL(true,test); } } -BOOST_AUTO_TEST_CASE( dist_map_graph_use_4p_free_add) +BOOST_AUTO_TEST_CASE( dist_map_graph_use_free_add) { //! Vcluster Vcluster & vcl = *global_v_cluster; + if(vcl.getProcessingUnits() != 4) + return; + //! Initialize the global VCluster init_global_v_cluster(&boost::unit_test::framework::master_test_suite().argc,&boost::unit_test::framework::master_test_suite().argv); @@ -442,17 +404,6 @@ BOOST_AUTO_TEST_CASE( dist_map_graph_use_4p_free_add) } } - std::cout << vcl.getProcessUnitID()<< " "; - for(size_t i = 0; i < gd.getNVertex(); i++) - { - - for(size_t j =0; j< gd.getNChilds(i); j++) - { - std::cout << gd.getChildDstGid(i, j) << " "; - } - } - std::cout << "\n\n"; - if(vcl.getProcessUnitID() == 0) gd.reqVertex(5); @@ -486,44 +437,13 @@ BOOST_AUTO_TEST_CASE( dist_map_graph_use_4p_free_add) gd.redistribute(); - for (int i = 0; i < gd.getNVertex(); ++i) - { - std::cout << gd.getVertexId(i) << " "; - } - std::cout << "\n"; - - std::cout << vcl.getProcessUnitID()<< " "; - for(size_t i = 0; i < gd.getNVertex(); i++) - { - - for(size_t j =0; j< gd.getNChilds(i); j++) - { - std::cout << gd.getChildDstGid(i, j) << " "; - } - } - std::cout << "\n\n"; - - if (vcl.getProcessUnitID() == 0) - { - gd.deleteGhosts(); - - for (size_t i = 0; i < gd.getTotNVertex(); ++i) - { - gd.reqVertex(i); - } - } - - gd.sync(); + VTKWriter<DistGraph_CSR<vx, ed>, DIST_GRAPH> gv2(gd); + gv2.write("dist_graph_free_0.vtk"); - if (vcl.getProcessUnitID() == 0) + if(vcl.getProcessUnitID() == 0) { - VTKWriter<DistGraph_CSR<vx, ed>, DIST_GRAPH> gv2(gd); - gv2.write("dist_graph_0_free.vtk"); - - bool test = compare("dist_graph_0_free.vtk","dist_graph_0_free_test.vtk"); - //BOOST_REQUIRE_EQUAL(true,test); - - gd.deleteGhosts(); + bool test = compare("dist_graph_free_0.vtk", "dist_graph_free_0_test.vtk"); + BOOST_REQUIRE_EQUAL(true,test); } if (vcl.getProcessUnitID() == 2) @@ -540,29 +460,13 @@ BOOST_AUTO_TEST_CASE( dist_map_graph_use_4p_free_add) gd.redistribute(); - if (vcl.getProcessUnitID() == 0) - { - gd.deleteGhosts(); + gv2.write("dist_graph_free_1.vtk"); - for (size_t i = 0; i < gd.getTotNVertex(); ++i) - { - gd.reqVertex(i); - } - } - - gd.sync(); - - if (vcl.getProcessUnitID() == 0) + if(vcl.getProcessUnitID() == 0) { - VTKWriter<DistGraph_CSR<vx, ed>, DIST_GRAPH> gv2(gd); - gv2.write("dist_graph_1_free.vtk"); - - bool test = compare("dist_graph_1_free.vtk","dist_graph_1_free_test.vtk"); - //BOOST_REQUIRE_EQUAL(true,test); - - gd.deleteGhosts(); + bool test = compare("dist_graph_free_1.vtk", "dist_graph_free_1_test.vtk"); + BOOST_REQUIRE_EQUAL(true,test); } - } BOOST_AUTO_TEST_SUITE_END() diff --git a/src/main.cpp b/src/main.cpp index c50c14f1013d9ced61c2292681a27d4b239c2334..a1415740dc263d7084cc82b586331611153ce37d 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -29,5 +29,6 @@ #include "Grid/grid_dist_id_unit_test.hpp" #include "Vector/vector_dist_unit_test.hpp" //#include "Decomposition/DLB_unit_test.hpp" -//#include "Graph/dist_map_graph_unit_test.hpp" +#include "Graph/dist_map_graph_unit_test.hpp" #include "Graph/DistGraphFactory.hpp" +#include "parmetis_dist_util_unit_test.hpp" diff --git a/src/parmetis_dist_util.hpp b/src/parmetis_dist_util.hpp index 5ca627344a0e7297051bbb9a4cb1ca01a2ac6a6d..a9713995ed429b437f8088f45094a1e2f5178b88 100755 --- a/src/parmetis_dist_util.hpp +++ b/src/parmetis_dist_util.hpp @@ -141,46 +141,34 @@ class DistParmetis // actual position size_t id = 0; - // for each vertex calculate the position of the starting point in the adjacency list for (size_t i = 0, j = sub_g.firstId(); i < sub_g.getNVertex() && j <= sub_g.lastId(); i++, j++) { + size_t idx = sub_g.nodeById(j); + // Add weight to vertex and migration cost - Mg.vwgt[i] = sub_g.vertex(sub_g.nodeById(j)).template get<nm_v::computation>(); - Mg.vsize[i] = sub_g.vertex(sub_g.nodeById(j)).template get<nm_v::migration>(); + Mg.vwgt[i] = sub_g.vertex(idx).template get<nm_v::computation>(); + Mg.vsize[i] = sub_g.vertex(idx).template get<nm_v::migration>(); // Calculate the starting point in the adjacency list Mg.xadj[id] = prev; // Create the adjacency list and the weights for edges - for (size_t s = 0; s < sub_g.getNChilds(sub_g.nodeById(j)); s++) + for (size_t s = 0; s < sub_g.getNChilds(idx); s++) { - Mg.adjncy[prev + s] = sub_g.getChild(sub_g.nodeById(j), s); + Mg.adjncy[prev + s] = sub_g.getChild(idx, s); - Mg.adjwgt[prev + s] = sub_g.getChildEdge(sub_g.nodeById(j), s).template get<nm_e::communication>(); + Mg.adjwgt[prev + s] = sub_g.getChildEdge(idx, s).template get<nm_e::communication>(); } // update the position for the next vertex - prev += sub_g.getNChilds(sub_g.nodeById(j)); + prev += sub_g.getNChilds(idx); id++; } // Fill the last point Mg.xadj[id] = prev; - /* - std::cout << p_id << "--------------------------------------\n"; - for (int i = 0; i <= sub_g.getNVertex(); i++) - { - std::cout << Mg.xadj[i] << " "; - } - std::cout << "\n\n"; - - for (int i = 0; i < sub_g.getNEdge(); i++) - { - std::cout << Mg.adjncy[i] << " "; - } - std::cout << "-----------------------------------------------------\n\n"; - */ + } public: @@ -347,7 +335,7 @@ public: //! This is used to indicate if the graph is weighted. Mg.wgtflag = new idx_t[1]; - Mg.wgtflag[0] = 2; + Mg.wgtflag[0] = 3; } /*! \brief Decompose the graph @@ -371,13 +359,10 @@ public: */ // For each vertex store the processor that contain the data - for (size_t j = 0, id = 0; j < sub_g.getNVertex(); j++, id++) + for (size_t id = 0, j = sub_g.firstId(); id < sub_g.getNVertex() && j <= sub_g.lastId(); id++, j++) { - - sub_g.vertex(j).template get<i>() = Mg.part[id]; - + sub_g.vertex(sub_g.nodeById(j)).template get<i>() = Mg.part[id]; } - } /*! \brief Refine the graph @@ -390,20 +375,13 @@ public: void refine(Graph & sub_g) { // Refine - for (int j = 0; j < sub_g.getVtxdist()->size(); ++j) { - std::cout << sub_g.getVtxdist()->get(j) << " "; - } - std::cout << "\n"; - ParMETIS_V3_PartKway((idx_t *) sub_g.getVtxdist()->getPointer(), Mg.xadj, Mg.adjncy, Mg.vwgt, Mg.adjwgt, Mg.wgtflag, Mg.numflag, Mg.ncon, Mg.nparts, Mg.tpwgts, Mg.ubvec, Mg.options, Mg.edgecut, Mg.part, &comm); - //ParMETIS_V3_AdaptiveRepart((idx_t *) sub_g.getVtxdist()->getPointer(), Mg.xadj, Mg.adjncy, Mg.vwgt, Mg.vsize, Mg.adjwgt, Mg.wgtflag, Mg.numflag, Mg.ncon, Mg.nparts, Mg.tpwgts, Mg.ubvec, Mg.itr, Mg.options, Mg.edgecut, Mg.part, &comm); + //ParMETIS_V3_PartKway((idx_t *) sub_g.getVtxdist()->getPointer(), Mg.xadj, Mg.adjncy, Mg.vwgt, Mg.adjwgt, Mg.wgtflag, Mg.numflag, Mg.ncon, Mg.nparts, Mg.tpwgts, Mg.ubvec, Mg.options, Mg.edgecut, Mg.part, &comm); + ParMETIS_V3_AdaptiveRepart((idx_t *) sub_g.getVtxdist()->getPointer(), Mg.xadj, Mg.adjncy, Mg.vwgt, Mg.vsize, Mg.adjwgt, Mg.wgtflag, Mg.numflag, Mg.ncon, Mg.nparts, Mg.tpwgts, Mg.ubvec, Mg.itr, Mg.options, Mg.edgecut, Mg.part, &comm); // For each vertex store the processor that contain the data - - for (size_t j = 0, id = 0; j < sub_g.getNVertex(); j++, id++) + for (size_t id = 0, j = sub_g.firstId(); id < sub_g.getNVertex() && j <= sub_g.lastId(); id++, j++) { - - sub_g.vertex(j).template get<i>() = Mg.part[id]; - + sub_g.vertex(sub_g.nodeById(j)).template get<i>() = Mg.part[id]; } } diff --git a/src/parmetis_util.hpp b/src/parmetis_util.hpp index 62ef9576c5954403522d4ae5191cd7e6f2523ba7..89b34e7528fe2f5bcba5b09e9d1f7c1e8e7da21a 100755 --- a/src/parmetis_util.hpp +++ b/src/parmetis_util.hpp @@ -191,92 +191,8 @@ class Parmetis // Fill the last point Mg.xadj[id] = prev; - - /* - std::cout << p_id << " ------------"; - for (int i = 0; i <= sub_g.getNVertex(); i++) { - std::cout << Mg.vwgt[i] << " "; - } - std::cout << "\n"; - - - if (p_id == 0) { - std::cout << p_id << "\n"; - for (int i = 0; i <= sub_g.getNVertex(); i++) { - std::cout << Mg.xadj[i] << " "; - } - std::cout << "\n\n"; - - for (int i = 0; i < sub_g.getNEdge(); i++) { - std::cout << Mg.adjwgt[i] << " "; - } - std::cout << "\n\n"; - */ - - } - /*! \brief Construct Adjacency list - * - * \param g Reference graph to get informations - * - */ - /* - void constructAdjList(Graph &refGraph, idx_t* &old_vtxdist ) { - // create xadj and adjlist - Mg.vwgt = new idx_t[g.getNVertex()]; - Mg.xadj = new idx_t[g.getNVertex() + 1]; - Mg.adjncy = new idx_t[g.getNEdge()]; - - //! starting point in the adjacency list - size_t prev = 0; - - // actual position - size_t id = 0; - - // for each vertex calculate the position of the starting point in the adjacency list - for (size_t i = 0; i < g.getNVertex(); i++) { - - // Add weight to vertex - Mg.vwgt[i] = g.vertex(i).template get<nm_v::computation>(); - - // Calculate the starting point in the adjacency list - Mg.xadj[id] = prev; - - // Create the adjacency list and the weights for edges - for (size_t s = 0; s < refGraph.getNChilds(i); s++) { - - size_t child = refGraph.getChild(i, s); - - // Check if child is not in this processor - if(child > old_vtxdist[p_id+1] || child < old_vtxdist[p_id]) - - Mg.adjncy[prev + s] = child; - } - - // update the position for the next vertex - prev += refGraph.getNChilds(i); - - id++; - } - - // Fill the last point - Mg.xadj[id] = prev; - - - std::cout << p_id << "\n"; - for(int i=0; i<= g.getNVertex();i++){ - std::cout << Mg.xadj[i] << " "; - } - std::cout << "\n\n"; - for(int i=0; i< g.getNEdge();i++){ - std::cout << Mg.adjncy[i] << " "; - } - std::cout << "\n\n"; - - - } - */ public: /*! \brief Constructor @@ -449,10 +365,10 @@ public: //! This is used to indicate if the graph is weighted. wgtflag can take one of four values: Mg.wgtflag = new idx_t[1]; - if(w) - Mg.wgtflag[0] = 3; - else - Mg.wgtflag[0] = 0; + //if(w) + Mg.wgtflag[0] = 2; + //else + //Mg.wgtflag[0] = 0; } /*! \brief Decompose the graph @@ -479,9 +395,7 @@ public: // For each vertex store the processor that contain the data for (size_t j = 0, id = 0; j < sub_g.getNVertex(); j++, id++) { - sub_g.vertex(j).template get<i>() = Mg.part[id]; - } } @@ -505,9 +419,7 @@ public: for (size_t j = 0, id = 0; j < sub_g.getNVertex(); j++, id++) { - sub_g.vertex(j).template get<i>() = Mg.part[id]; - } }