8 #ifndef PARMETIS_UTIL_HPP
9 #define PARMETIS_UTIL_HPP
13 #include "VTKWriter/VTKWriter.hpp"
14 #include "VCluster/VCluster.hpp"
15 #include "Graph/ids.hpp"
17 #define PARMETIS_ERROR_OBJECT std::runtime_error("Runtime Parmetis error");
90 #define BALANCE_CC_O(c) c+1
98 template<
typename Graph>
108 MPI_Comm
comm = (MPI_Comm)NULL;
153 nedge += g.getNChilds(m2g.find(j)->second.id);
157 Mg.
xadj =
new idx_t[nvertex + 1];
174 gid idx = m2g.find(i)->second;
177 Mg.
vwgt[j] = g.vertex(idx.id).template get<nm_v::computation>();
178 Mg.
vsize[j] = g.vertex(idx.id).template get<nm_v::migration>();
184 for (
size_t s = 0; s < g.getNChilds(idx.id); s++)
187 size_t child = g.getChild(idx.id, s);
189 Mg.
adjncy[prev + s] = g.vertex(child).template get<nm_v::id>();
190 Mg.
adjwgt[prev + s] = g.getChildEdge(idx.id, s).template get<nm_e::communication>();
194 prev += g.getNChilds(idx.id);
214 :v_cl(v_cl), nc(nc),
n_dec(0)
218 if (
sizeof(idx_t) != 8)
220 std::cerr << __FILE__ <<
":" << __LINE__ <<
" Error detected invalid installation of Parmetis. OpenFPM support Parmetis/Metis version with 64 bit idx_t" << std::endl;
221 ACTION_ON_ERROR(PARMETIS_ERROR_OBJECT);
227 MPI_Comm_dup(MPI_COMM_WORLD, &
comm);
330 if (is_openfpm_init() ==
true)
331 MPI_Comm_free(&
comm);
344 const std::unordered_map<rid, gid> & m2g,
370 ParMETIS_V3_PartKway((idx_t *) vtxdist.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);
384 ParMETIS_V3_RefineKway((idx_t *) vtxdist.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);
396 ParMETIS_V3_AdaptiveRepart((idx_t *)vtxdist.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);
488 Mg.
itr =
new real_t[1];
498 for (
size_t s = 0; s < (size_t)
Mg.
nparts[0]; s++)
550 MPI_Comm_dup(pm.comm, &
comm);
const Parmetis< Graph > & operator=(Parmetis< Graph > &&pm)
Copy the object.
void refine(openfpm::vector< rid > &vtxdist)
Refine the graph.
void decompose(const openfpm::vector< rid > &vtxdist)
Decompose the graph.
rid last
last re-mapped id
idx_t * xadj
For each vertex it store the adjacency lost start for the vertex i.
size_t getProcessUnitID()
Get the process unit id.
idx_t * part
Is a output vector containing the partition for each vertex.
void setDistTol(real_t tol)
Distribution tolerance.
idx_t * adjncy
For each vertex it store a list of all neighborhood vertex.
void initSubGraph(Graph &g, const openfpm::vector< rid > &vtxdist, const std::unordered_map< rid, gid > &m2g, bool w)
Set the Sub-graph.
const Parmetis< Graph > & operator=(const Parmetis< Graph > &pm)
Copy the object.
size_t get_ndec()
Get the decomposition counter.
idx_t * vsize
Array of the vertex size, basically is the total communication amount.
Helper class to define Metis graph.
void redecompose(openfpm::vector< rid > &vtxdist)
Redecompose the graph.
real_t * itr
This parameter describes the ratio of inter-processor communication time compared to data redistri- b...
idx_t * adjwgt
The weight of the edge.
Implementation of VCluster class.
idx_t * nvtxs
The number of vertices in the graph.
idx_t * wgtflag
This is used to indicate if the graph is weighted. wgtflag can take one of four values: ...
size_t nc
nc Number of partition
idx_t * options
Additional option for the graph partitioning.
void reset(Graph &g, const openfpm::vector< rid > &vtxdist, const std::unordered_map< rid, gid > &m2g, bool vgw)
Reset graph and reconstruct it.
idx_t * edgecut
Upon successful completion, the number of edges that are cut by the partitioning is written to this p...
idx_t * numflag
This is used to indicate the numbering scheme that is used for the vtxdist, xadj, adjncy...
real_t * ubvec
For each partition load imbalance tollerated.
idx_t * nparts
number of part to partition the graph
void constructAdjList(Graph &g, const std::unordered_map< rid, gid > &m2g)
Construct Adjacency list.
rid first
first re-mapped id
idx_t * objval
return the total comunication cost for each partition
size_t nvertex
number of vertices that the processor has
real_t * tpwgts
Desired weight for each partition (one for each constrain)
Parmetis_graph Mg
Graph in metis reppresentation.
idx_t * vwgt
Array that store the weight for each vertex.
real_t dist_tol
Distribution tolerance.
MPI_Comm comm
Communticator for OpenMPI.
Parmetis(Vcluster &v_cl, size_t nc)
Constructor.
void setDefaultParameters(bool w)
Seth the default parameters for parmetis.
int p_id
Process rank information.
idx_t * getPartition()
Get graph partition vector.
size_t n_dec
indicate how many time decompose/refine/re-decompose has been called