27 #ifndef _SF_PARTITIONING_H
28 #define _SF_PARTITIONING_H
43 template<
class T,
class S>
57 template<
class T,
class S>
67 parmetis_partitioner() : _unbalance(1.01f), _ncommon(2)
70 parmetis_partitioner(
float ub,
short nc) : _unbalance(ub), _ncommon(nc)
80 inline void operator()(
const meshdata<T, S> & mesh, vector<T> & part)
82 MPI_Comm comm = mesh.comm;
85 MPI_Comm_size(comm, &size); MPI_Comm_rank(comm, &rank);
87 part.resize(mesh.l_numelem);
95 vector<idx_t> elemdist_cnt(size), elemdist_dsp(size+1);
96 idx_t numelem = mesh.l_numelem;
97 MPI_Allgather(&numelem,
sizeof(idx_t), MPI_BYTE, elemdist_cnt.data(),
sizeof(idx_t), MPI_BYTE, comm);
101 int ncommonnod = _ncommon;
104 idx_t* elemwgt = NULL;
107 vector<real_t> tpwgts(nparts*ncon);
108 for(
size_t i=0; i<tpwgts.size(); i++) tpwgts[i] = (
float)1. / (float)(nparts*ncon);
110 vector<real_t> ubvec(ncon);
111 for (
int i = 0; i < ncon; i++ ) ubvec[i] = _unbalance;
113 vector<int> opt(4, 0);
116 vector<idx_t> eptr(mesh.dsp.size()), eind(mesh.con.size());
117 vec_assign(eptr.data(), mesh.dsp.data(), eptr.size());
119 const vector<T> & rnod = mesh.get_numbering(
NBR_REF);
120 for(
size_t i=0; i<mesh.con.size(); i++) eind[i] = rnod[mesh.con[i]];
122 vector<idx_t> pm_part(mesh.l_numelem);
125 ParMETIS_V3_PartMeshKway(elemdist_dsp.data(),
141 vec_assign(part.data(), pm_part.data(), part.size());
148 template<
class T,
class S>
154 int size; MPI_Comm_size(mesh.
comm, &size);
167 T elemsize = mesh.
dsp[i+1] - dsp;
169 for(T j=0; j<elemsize; j++) {
170 T v = mesh.
con[dsp+j];
171 avrg.
x += mesh.
xyz[v*3+0];
172 avrg.
y += mesh.
xyz[v*3+1];
173 avrg.
z += mesh.
xyz[v*3+2];
175 avrg.
x /= S(elemsize);
176 avrg.
y /= S(elemsize);
177 avrg.
z /= S(elemsize);
186 partitioner(mesh.
comm, ctr, size, part);
188 part_vec.
assign(part.begin(), part.end());
The vector class and related algorithms.
Abstract base class for a mesh partitioner.
virtual void operator()(const meshdata< T, S > &mesh, vector< T > &part)=0
void operator()(const meshdata< T, S > &mesh, vector< T > &part_vec)
The mesh storage class. It contains both element and vertex data.
vector< T > dsp
connectivity starting index of each element
size_t l_numelem
local number of elements
vector< S > xyz
node cooridnates
MPI_Comm comm
the parallel mesh is defined on a MPI world
A vector storing arbitrary data.
void resize(size_t n)
Resize a vector.
void assign(InputIterator s, InputIterator e)
Assign a memory range.
kdtree based partitioning classes.
void dsp_from_cnt(const vector< T > &cnt, vector< T > &dsp)
Compute displacements from counts.
void vec_assign(S *lhs, const V *rhs, size_t size)
Assign the values in rhs to lhs. The data-type of rhs is cast to the type of lhs.
@ NBR_REF
The nodal numbering of the reference mesh (the one stored on HD).
minimalistic internal point struct