8 #ifndef SRC_DECOMPOSITION_DISTPARMETISDISTRIBUTION_HPP_ 9 #define SRC_DECOMPOSITION_DISTPARMETISDISTRIBUTION_HPP_ 11 #include "SubdomainGraphNodes.hpp" 12 #include "parmetis_dist_util.hpp" 13 #include "Graph/dist_map_graph.hpp" 14 #include "Graph/DistGraphFactory.hpp" 16 template<
unsigned int dim,
typename T>
61 static void *
message_receive(
size_t msg_i,
size_t total_msg,
size_t total_p,
size_t i,
size_t ri,
void * ptr)
65 v->get(i).resize(msg_i /
sizeof(idx_t));
67 return &(v->get(i).get(0));
95 g = dist_g_factory.template construct<NO_EDGE, T, dim - 1, 0>(
gr.
getSize(),
domain);
100 g.
vertex(i).template get<nm_v_x>()[2] = 0;
181 return unbalance * 100;
194 std::cerr << __FILE__ <<
":" << __LINE__ <<
" Position - Such vertex doesn't exist (id = " <<
id <<
", " <<
"total size = " <<
g.
getNVertex() <<
")\n";
197 pos[0] =
g.
vertex(
id).template get<nm_v_x>()[0];
198 pos[1] =
g.
vertex(
id).template get<nm_v_x>()[1];
200 pos[2] =
g.
vertex(
id).template get<nm_v_x>()[2];
214 std::cerr << __FILE__ <<
":" << __LINE__ <<
"Weight - Such vertex doesn't exist (id = " <<
id <<
", " <<
"total size = " <<
g.
getNVertex() <<
")\n";
218 g.
vertex(
id).template get<nm_v_computation>() = weight;
242 std::cerr << __FILE__ <<
":" << __LINE__ <<
"Such vertex doesn't exist (id = " <<
id <<
", " <<
"total size = " <<
g.
getTotNVertex() <<
")\n";
245 return g.
vertex(
id).template get<nm_v_computation>();
258 load +=
g.
vertex(i).template get<nm_v_computation>();
292 std::cerr << __FILE__ <<
":" << __LINE__ <<
"Migration - Such vertex doesn't exist (id = " <<
id <<
", " <<
"total size = " <<
g.
getNVertex() <<
")\n";
295 g.
vertex(
id).template get<nm_v_migration>() = migration;
306 g.
getChildEdge(v_id, e).template get<nm_e::communication>() = communication;
329 std::cerr <<
"Neighbors - Such vertex doesn't exist (id = " <<
id <<
", " <<
"total size = " <<
g.
getNVertex() <<
")\n";
339 void write(
const std::string & file)
342 gv2.write(std::to_string(file +
".vtk"));
size_t getNChilds(size_t c) const
Return the number of children of a vertex.
void q_move(size_t i, size_t t)
Prepare to send vertex i from the local processor to the target processor.
size_t getProcessUnitID()
Get the process unit id.
size_t getNVertex() const
Return the number of the vertices in this subgraph.
size_t getTotalMovedV()
return number of moved vertices in all iterations so far
void setCommunicationCost(size_t v_id, size_t e, size_t communication)
Set communication cost of the edge id.
static void * message_receive(size_t msg_i, size_t total_msg, size_t total_p, size_t i, size_t ri, void *ptr)
Callback of the sendrecv to set the size of the array received.
size_t getProcessorLoad()
Compute the processor load counting the total weights of its vertices.
size_t getNSubSubDomainNeighbors(size_t id)
Returns total number of neighbors of the sub-sub-domain id.
DistGraph_CSR< nm_v< dim >, nm_e > & getGraph()
Get the current graph (main)
void getDecompositionVector(openfpm::vector< idx_t > &v)
Operator to access the decomposition vector.
void swap(DistGraph_CSR< V, E > &g)
Swap the memory of g with this graph.
size_t g_moved
Number of moved vertices in all iterations.
openfpm::vector< openfpm::vector< size_t > > v_per_proc
Init data structure to keep trace of new vertices distribution in processors (needed to update main g...
size_t getVertexWeight(size_t id)
function that get the weight of the vertex
void write(const std::string &file)
Print current graph and save it to file.
auto getChildEdge(size_t v, size_t v_e) -> decltype(e.get(0))
Get the vertex edge.
size_t getMaxMovedV()
return number of moved vertices in all iterations so far
Helper class to define Metis graph.
void reset(Graph &sub_g)
Reset graph and reconstruct it.
Implementation of VCluster class.
DistParMetisDistribution(Vcluster<> &v_cl)
void execute()
Execute all the requests.
grid_sm< dim, void > gr
Structure that store the cartesian grid information.
void getSubSubDomainPosition(size_t id, T(&pos)[dim])
function that return the position of the vertex in the space
void setComputationCost(size_t id, size_t weight)
Function that set the weight of the vertex.
DistGraph_CSR< nm_v< dim >, nm_e > g
Processor sub-sub-domain graph.
size_t getNSubSubDomains()
Returns total number of sub-sub-domains in the distribution graph.
sub-domain edge graph node
const size_t(& getSize() const)[N]
Return the size of the grid as an array.
DistParmetis< DistGraph_CSR< nm_v< dim >, nm_e > > parmetis_graph
Convert the graph to parmetis format.
size_t nodeById(size_t id) const
operator to access the vertex position index by id property
Box< dim, T > domain
rectangular domain to decompose
openfpm::vector< openfpm::vector< idx_t > > partitions
partitions
size_t getProcessingUnits()
Get the total number of processors.
Structure that store a graph in CSR format or basically in compressed adjacency matrix format.
void redistribute()
Redistribute function that wraps different stages of the redistribution.
const DistParMetisDistribution< dim, T > & operator=(const DistParMetisDistribution< dim, T > &dist)
copy operator
size_t m_moved
Max number of moved vertices in all iterations.
This class represent an N-dimensional box.
idx_t * getPartition()
Get graph partition vector.
void sum(T &num)
Sum the numbers across all processors and get the result.
void refine()
Refine current decomposition.
void initSubGraph(Graph &sub_g)
Set the Sub-graph.
This class construct a cartesian graph.
void setMigrationCost(size_t id, size_t migration)
Set migration cost of the vertex id.
void decompose()
Create first decomposition, it divides the graph in slices and give each slice to a processor.
void createCartGraph(grid_sm< dim, void > &grid, Box< dim, T > dom)
Initialize the distribution graph.
size_t getTotNVertex() const
Return the total number of the vertices.
void max(T &num)
Get the maximum number across all processors (or reduction with infinity norm)
It model an expression expr1 + ... exprn.
openfpm::vector< idx_t > vtxdist
Init vtxdist needed for Parmetis.
bool weightsAreUsed()
Checks if weights are used on the vertices.
float getUnbalance()
Compute the unbalance value.
const DistParMetisDistribution< dim, T > & operator=(DistParMetisDistribution< dim, T > &&dist)
copy operator
auto vertex(size_t id) -> decltype(v.get(id))
Function to access the vertexes.
bool verticesGotWeights
Flag to check if weights are used on vertices.
void min(T &num)
Get the minimum number across all processors (or reduction with insinity norm)