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");
91#define BALANCE_CC_O(c) c+1
98template<
typename Graph>
108 MPI_Comm
comm = (MPI_Comm)NULL;
155 nedge += g.getNChilds(m2g.find(j)->second.id);
186 gid idx = m2g.find(i)->second;
189 Mg.
vwgt[j] = g.vertex(idx.id).template get<nm_v_computation>();
190 Mg.
vsize[j] = g.vertex(idx.id).template get<nm_v_migration>();
196 for (
size_t s = 0; s < g.getNChilds(idx.id); s++)
199 size_t child = g.getChild(idx.id, s);
201 Mg.
adjncy[prev + s] = g.vertex(child).template get<nm_v_id>();
202 Mg.
adjwgt[prev + s] = g.getChildEdge(idx.id, s).template get<nm_e::communication>();
206 prev += g.getNChilds(idx.id);
230 if (
sizeof(idx_t) != 8)
232 std::cerr << __FILE__ <<
":" << __LINE__ <<
" Error detected invalid installation of Parmetis. OpenFPM support Parmetis/Metis version with 64 bit idx_t" << std::endl;
233 ACTION_ON_ERROR(PARMETIS_ERROR_OBJECT);
239 MPI_Comm_dup(MPI_COMM_WORLD, &
comm);
357 if (is_openfpm_init() ==
true)
358 {MPI_Comm_free(&
comm);}
371 const std::unordered_map<rid, gid> & m2g,
395 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);
409 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);
421 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);
502 Mg.
itr =
new real_t[1];
518 for (
size_t s = 0; s < (size_t)
Mg.
nparts[0]; s++)
555 if (
comm != MPI_COMM_NULL){MPI_Comm_free(&
comm);}
577 if (
comm != MPI_COMM_NULL){MPI_Comm_free(&
comm);}
578 MPI_Comm_dup(pm.comm, &
comm);
Helper class to define Metis graph.
MPI_Comm comm
Communticator for OpenMPI.
size_t nc
nc Number of partition
void constructAdjList(Graph &g, const std::unordered_map< rid, gid > &m2g)
Construct Adjacency list.
size_t get_ndec()
Get the decomposition counter.
void redecompose(openfpm::vector< rid > &vtxdist)
Redecompose the graph.
size_t nvertex
number of vertices that the processor has
Parmetis(Vcluster<> &v_cl, size_t nc)
Constructor.
real_t dist_tol
Distribution tolerance.
void reset(Graph &g, const openfpm::vector< rid > &vtxdist, const std::unordered_map< rid, gid > &m2g, bool vgw)
Reset graph and reconstruct it.
rid first
first re-mapped id
const Parmetis< Graph > & operator=(Parmetis< Graph > &&pm)
Copy the object.
const Parmetis< Graph > & operator=(const Parmetis< Graph > &pm)
Copy the object.
size_t n_dec
indicate how many time decompose/refine/re-decompose has been called
idx_t * getPartition()
Get graph partition vector.
void setDefaultParameters(bool w)
Seth the default parameters for parmetis.
void setDistTol(real_t tol)
Distribution tolerance.
void refine(openfpm::vector< rid > &vtxdist)
Refine the graph.
void initSubGraph(Graph &g, const openfpm::vector< rid > &vtxdist, const std::unordered_map< rid, gid > &m2g, bool w)
Set the Sub-graph.
void decompose(const openfpm::vector< rid > &vtxdist)
Decompose the graph.
rid last
last re-mapped id
int p_id
Process rank information.
Parmetis_graph Mg
Graph in metis reppresentation.
size_t getProcessUnitID()
Get the process unit id.
Implementation of VCluster class.
Implementation of 1-D std::vector like structure.
idx_t * adjncy
For each vertex it store a list of all neighborhood vertex.
real_t * itr
This parameter describes the ratio of inter-processor communication time compared to data redistri- b...
idx_t * part
Is a output vector containing the partition for each vertex.
idx_t * edgecut
Upon successful completion, the number of edges that are cut by the partitioning is written to this p...
idx_t * vwgt
Array that store the weight for each vertex.
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 * vsize
Array of the vertex size, basically is the total communication amount.
idx_t * adjwgt
The weight of the edge.
idx_t * nvtxs
The number of vertices in the graph.
idx_t * xadj
For each vertex it store the adjacency lost start for the vertex i.
idx_t * wgtflag
This is used to indicate if the graph is weighted. wgtflag can take one of four values:
idx_t * options
Additional option for the graph partitioning.
idx_t * objval
return the total comunication cost for each partition
real_t * tpwgts
Desired weight for each partition (one for each constrain)
idx_t * nparts
number of part to partition the graph