Commit 1069d063 authored by Pietro Incardona's avatar Pietro Incardona
Browse files

ParMetis cleaned and with map

parent bdc560d1
openfpm_data @ 85dcf644
Subproject commit 7b47257e320d89574044006513fba47a469ac415 Subproject commit 85dcf64440298004d2951277b2dbd31592b5d9b0
...@@ -163,9 +163,6 @@ BOOST_AUTO_TEST_CASE( Parmetis_distribution_test) ...@@ -163,9 +163,6 @@ BOOST_AUTO_TEST_CASE( Parmetis_distribution_test)
ParMetisDistribution<3,float> pmet_dist(v_cl); ParMetisDistribution<3,float> pmet_dist(v_cl);
// Make the result reproducible
pmet_dist.onTest();
// Physical domain // Physical domain
Box<3,float> box({0.0,0.0,0.0},{10.0,10.0,10.0}); Box<3,float> box({0.0,0.0,0.0},{10.0,10.0,10.0});
......
...@@ -70,19 +70,12 @@ class ParMetisDistribution ...@@ -70,19 +70,12 @@ class ParMetisDistribution
//! Init data structure to keep trace of new vertices distribution in processors (needed to update main graph) //! Init data structure to keep trace of new vertices distribution in processors (needed to update main graph)
openfpm::vector<openfpm::vector<size_t>> v_per_proc; openfpm::vector<openfpm::vector<size_t>> v_per_proc;
//! Number of moved vertices in all iterations //! Hashmap to access to the global position given the re-mapped one (needed for access the map)
size_t g_moved = 0; std::unordered_map<size_t, size_t> m2g;
//! Max number of moved vertices in all iterations
size_t m_moved = 0;
//! Flag to check if weights are used on vertices //! Flag to check if weights are used on vertices
bool verticesGotWeights = false; bool verticesGotWeights = false;
//! Flag that indicate if we are doing a test (In general it fix the seed)
bool testing = false;
/*! \brief Update main graph ad subgraph with the received data of the partitions from the other processors /*! \brief Update main graph ad subgraph with the received data of the partitions from the other processors
* *
*/ */
...@@ -111,14 +104,14 @@ class ParMetisDistribution ...@@ -111,14 +104,14 @@ class ParMetisDistribution
n_vtxdist.get(partitions.get(i).get(k) + 1)++; n_vtxdist.get(partitions.get(i).get(k) + 1)++;
// for statistics // for statistics
if (gp.vertexByMapId(l).template get<nm_v::proc_id>() != (size_t)partitions.get(i).get(k)) if (vertexByMapId(l).template get<nm_v::proc_id>() != (size_t)partitions.get(i).get(k))
moved++; moved++;
// Update proc id in the vertex (using the old map) // Update proc id in the vertex (using the old map)
gp.vertexByMapId(l).template get<nm_v::proc_id>() = partitions.get(i).get(k); vertexByMapId(l).template get<nm_v::proc_id>() = partitions.get(i).get(k);
// Add vertex to temporary structure of distribution (needed to update main graph) // Add vertex to temporary structure of distribution (needed to update main graph)
v_per_proc.get(partitions.get(i).get(k)).add(gp.getVertexGlobalId(l)); v_per_proc.get(partitions.get(i).get(k)).add(getVertexGlobalId(l));
} }
} }
...@@ -135,16 +128,10 @@ class ParMetisDistribution ...@@ -135,16 +128,10 @@ class ParMetisDistribution
{ {
for (size_t j = (size_t)vtxdist.get(p), i = 0; j < (size_t)vtxdist.get(p + 1); j++, i++) for (size_t j = (size_t)vtxdist.get(p), i = 0; j < (size_t)vtxdist.get(p + 1); j++, i++)
{ {
gp.setMapId(j, v_per_proc.get(p).get(i)); setMapId(j, v_per_proc.get(p).get(i));
gp.vertex(v_per_proc.get(p).get(i)).template get<nm_v::id>() = j; gp.vertex(v_per_proc.get(p).get(i)).template get<nm_v::id>() = j;
} }
} }
g_moved += moved;
if (moved > m_moved)
m_moved = moved;
} }
void createMapsFromGlobalGraph(openfpm::vector<size_t> & vtxdist) void createMapsFromGlobalGraph(openfpm::vector<size_t> & vtxdist)
...@@ -159,6 +146,54 @@ class ParMetisDistribution ...@@ -159,6 +146,54 @@ class ParMetisDistribution
}*/ }*/
} }
/*! \brief operator to access the vertex by mapped position
*
* operator to access the vertex
*
* \param id re-mapped id of the vertex to access
*
*/
inline auto vertexByMapId(size_t id) -> decltype( gp.vertex(m2g.find(id)->second) )
{
return gp.vertex(m2g.find(id)->second);
}
/*! \brief operator to remap vertex to a new position
*
* \param n re-mapped position
* \param g global position
*
*/
inline void setMapId(size_t n, size_t g)
{
m2g[n] = g;
}
/*! \brief Get the global id of the vertex given the re-mapped one
*
* \param remapped id
* \return global id
*
*/
size_t getVertexGlobalId(size_t n)
{
return m2g.find(n)->second;
}
/*! \brief operator to init ids vector
*
* operator to init ids vector
*
*/
void initLocalToGlobalMap()
{
m2g.clear();
for (size_t i = 0; i < gp.getNVertex(); i++)
{
m2g.insert( { i, i });
}
}
/*! \brief Callback of the sendrecv to set the size of the array received /*! \brief Callback of the sendrecv to set the size of the array received
* *
* \param msg_i Index of the message * \param msg_i Index of the message
...@@ -228,7 +263,7 @@ public: ...@@ -228,7 +263,7 @@ public:
// Create a cartesian grid graph // Create a cartesian grid graph
CartesianGraphFactory<dim, Graph_CSR<nm_v, nm_e>> g_factory_part; CartesianGraphFactory<dim, Graph_CSR<nm_v, nm_e>> g_factory_part;
gp = g_factory_part.template construct<NO_EDGE, nm_v::id, T, dim - 1, 0, 1, 2>(gr.getSize(), domain, bc); gp = g_factory_part.template construct<NO_EDGE, nm_v::id, T, dim - 1, 0, 1, 2>(gr.getSize(), domain, bc);
gp.initLocalToGlobalMap(); initLocalToGlobalMap();
//! Get the number of processing units //! Get the number of processing units
size_t Np = v_cl.getProcessingUnits(); size_t Np = v_cl.getProcessingUnits();
...@@ -285,7 +320,7 @@ public: ...@@ -285,7 +320,7 @@ public:
// Number of local vertex // Number of local vertex
size_t nl_vertex = vtxdist.get(p_id+1) - vtxdist.get(p_id); size_t nl_vertex = vtxdist.get(p_id+1) - vtxdist.get(p_id);
parmetis_graph.initSubGraph(gp, vtxdist, gp.getMap(), verticesGotWeights); parmetis_graph.initSubGraph(gp, vtxdist, m2g, verticesGotWeights);
//! Decompose //! Decompose
parmetis_graph.decompose<nm_v::proc_id>(vtxdist); parmetis_graph.decompose<nm_v::proc_id>(vtxdist);
...@@ -318,11 +353,6 @@ public: ...@@ -318,11 +353,6 @@ public:
// Update graphs with the received data // Update graphs with the received data
updateGraphs(); updateGraphs();
// reset statistical variables, we only need it in refinement
g_moved = 0;
m_moved = 0;
} }
/*! \brief Refine current decomposition /*! \brief Refine current decomposition
...@@ -340,7 +370,7 @@ public: ...@@ -340,7 +370,7 @@ public:
size_t nl_vertex = vtxdist.get(p_id+1) - vtxdist.get(p_id); size_t nl_vertex = vtxdist.get(p_id+1) - vtxdist.get(p_id);
// Reset parmetis graph and reconstruct it // Reset parmetis graph and reconstruct it
parmetis_graph.reset(gp, vtxdist, gp.getMap()); parmetis_graph.reset(gp, vtxdist, m2g);
// Refine // Refine
parmetis_graph.refine<nm_v::proc_id>(vtxdist); parmetis_graph.refine<nm_v::proc_id>(vtxdist);
...@@ -489,36 +519,12 @@ public: ...@@ -489,36 +519,12 @@ public:
for (size_t i = (size_t)vtxdist.get(p_id); i < (size_t)vtxdist.get(p_id+1) ; i++) for (size_t i = (size_t)vtxdist.get(p_id); i < (size_t)vtxdist.get(p_id+1) ; i++)
{ {
load += gp.vertex(gp.getMap().find(i)->second).template get<nm_v::computation>(); load += gp.vertex(m2g.find(i)->second).template get<nm_v::computation>();
} }
//std::cout << v_cl.getProcessUnitID() << " weight " << load << " size " << sub_g.getNVertex() << "\n"; //std::cout << v_cl.getProcessUnitID() << " weight " << load << " size " << sub_g.getNVertex() << "\n";
return load; return load;
} }
/*! \brief return number of moved vertices in all iterations so far
*
* \param id vertex id
*
* \return vector with x, y, z
*
*/
size_t getTotalMovedV()
{
return g_moved;
}
/*! \brief return number of moved vertices in all iterations so far
*
* \param id vertex id
*
* \return vector with x, y, z
*
*/
size_t getMaxMovedV()
{
return m_moved;
}
/*! \brief Set migration cost of the vertex id /*! \brief Set migration cost of the vertex id
* *
* \param id of the vertex to update * \param id of the vertex to update
...@@ -568,16 +574,6 @@ public: ...@@ -568,16 +574,6 @@ public:
return gp.getNChilds(id); return gp.getNChilds(id);
} }
/*! \brief It set the Class on test mode
*
* At the moment it fix the seed to have reproducible results
*
*/
void onTest()
{
testing = true;
}
/*! \brief Print the current distribution and save it to VTK file /*! \brief Print the current distribution and save it to VTK file
* *
* \param file filename * \param file filename
......
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