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"
16template<
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"));
This class represent an N-dimensional box.
This class construct a cartesian graph.
Structure that store a graph in CSR format or basically in compressed adjacency matrix format.
size_t getNVertex() const
Return the number of the vertices in this subgraph.
void swap(DistGraph_CSR< V, E > &g)
Swap the memory of g with this graph.
size_t getTotNVertex() const
Return the total number of the vertices.
void q_move(size_t i, size_t t)
Prepare to send vertex i from the local processor to the target processor.
size_t nodeById(size_t id) const
operator to access the vertex position index by id property
void redistribute()
Redistribute function that wraps different stages of the redistribution.
void getDecompositionVector(openfpm::vector< idx_t > &v)
Operator to access the decomposition vector.
size_t getNChilds(size_t c) const
Return the number of children of a vertex.
auto vertex(size_t id) -> decltype(v.get(id))
Function to access the vertexes.
auto getChildEdge(size_t v, size_t v_e) -> decltype(e.get(0))
Get the vertex edge.
void getSubSubDomainPosition(size_t id, T(&pos)[dim])
function that return the position of the vertex in the space
size_t getProcessorLoad()
Compute the processor load counting the total weights of its vertices.
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.
Box< dim, T > domain
rectangular domain to decompose
void write(const std::string &file)
Print current graph and save it to file.
void refine()
Refine current decomposition.
size_t getTotalMovedV()
return number of moved vertices in all iterations so far
bool verticesGotWeights
Flag to check if weights are used on vertices.
void decompose()
Create first decomposition, it divides the graph in slices and give each slice to a processor.
const DistParMetisDistribution< dim, T > & operator=(const DistParMetisDistribution< dim, T > &dist)
copy operator
bool weightsAreUsed()
Checks if weights are used on the vertices.
DistParMetisDistribution(Vcluster<> &v_cl)
openfpm::vector< openfpm::vector< idx_t > > partitions
partitions
void createCartGraph(grid_sm< dim, void > &grid, Box< dim, T > dom)
Initialize the distribution graph.
float getUnbalance()
Compute the unbalance value.
const DistParMetisDistribution< dim, T > & operator=(DistParMetisDistribution< dim, T > &&dist)
copy operator
DistGraph_CSR< nm_v< dim >, nm_e > g
Processor sub-sub-domain graph.
void setMigrationCost(size_t id, size_t migration)
Set migration cost of the vertex id.
size_t getVertexWeight(size_t id)
function that get the weight of the vertex
void setComputationCost(size_t id, size_t weight)
Function that set the weight of the vertex.
openfpm::vector< idx_t > vtxdist
Init vtxdist needed for Parmetis.
size_t getMaxMovedV()
return number of moved vertices in all iterations so far
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 getNSubSubDomainNeighbors(size_t id)
Returns total number of neighbors of the sub-sub-domain id.
size_t g_moved
Number of moved vertices in all iterations.
void setCommunicationCost(size_t v_id, size_t e, size_t communication)
Set communication cost of the edge id.
size_t getNSubSubDomains()
Returns total number of sub-sub-domains in the distribution graph.
grid_sm< dim, void > gr
Structure that store the cartesian grid information.
size_t m_moved
Max number of moved vertices in all iterations.
DistParmetis< DistGraph_CSR< nm_v< dim >, nm_e > > parmetis_graph
Convert the graph to parmetis format.
DistGraph_CSR< nm_v< dim >, nm_e > & getGraph()
Get the current graph (main)
Helper class to define Metis graph.
idx_t * getPartition()
Get graph partition vector.
void initSubGraph(Graph &sub_g)
Set the Sub-graph.
void reset(Graph &sub_g)
Reset graph and reconstruct it.
void execute()
Execute all the requests.
void sum(T &num)
Sum the numbers across all processors and get the result.
size_t getProcessUnitID()
Get the process unit id.
void min(T &num)
Get the minimum number across all processors (or reduction with insinity norm)
size_t getProcessingUnits()
Get the total number of processors.
void max(T &num)
Get the maximum number across all processors (or reduction with infinity norm)
Implementation of VCluster class.
__device__ __host__ const size_t(& getSize() const)[N]
Return the size of the grid as an array.
Implementation of 1-D std::vector like structure.
sub-domain edge graph node
It model an expression expr1 + ... exprn.