12 #ifndef _SF_PARTITIONING_H
13 #define _SF_PARTITIONING_H
28 template<
class T,
class S>
42 template<
class T,
class S>
52 parmetis_partitioner() : _unbalance(1.01f), _ncommon(2)
55 parmetis_partitioner(
float ub,
short nc) : _unbalance(ub), _ncommon(nc)
65 inline void operator()(
const meshdata<T, S> & mesh, vector<T> & part)
67 MPI_Comm comm = mesh.comm;
70 MPI_Comm_size(comm, &size); MPI_Comm_rank(comm, &rank);
72 part.resize(mesh.l_numelem);
80 vector<idx_t> elemdist_cnt(size), elemdist_dsp(size+1);
81 idx_t numelem = mesh.l_numelem;
82 MPI_Allgather(&numelem,
sizeof(idx_t), MPI_BYTE, elemdist_cnt.data(),
sizeof(idx_t), MPI_BYTE, comm);
86 idx_t ncommonnod = _ncommon;
89 idx_t* elemwgt = NULL;
92 vector<real_t> tpwgts(nparts*ncon);
93 for(
size_t i=0; i<tpwgts.size(); i++) tpwgts[i] = (
float)1. / (float)(nparts*ncon);
95 vector<real_t> ubvec(ncon);
96 for (
int i = 0; i < ncon; i++ ) ubvec[i] = _unbalance;
98 vector<idx_t> opt(4, 0);
101 vector<idx_t> eptr(mesh.dsp.size()), eind(mesh.con.size());
102 vec_assign(eptr.data(), mesh.dsp.data(), eptr.size());
104 const vector<T> & rnod = mesh.get_numbering(
NBR_REF);
105 for(
size_t i=0; i<mesh.con.size(); i++) eind[i] = rnod[mesh.con[i]];
107 vector<idx_t> pm_part(mesh.l_numelem);
110 ParMETIS_V3_PartMeshKway(elemdist_dsp.data(),
126 vec_assign(part.data(), pm_part.data(), part.size());
133 template<
class T,
class S>
139 int size; MPI_Comm_size(mesh.
comm, &size);
152 T elemsize = mesh.
dsp[i+1] - dsp;
154 for(T j=0; j<elemsize; j++) {
155 T v = mesh.
con[dsp+j];
156 avrg.
x += mesh.
xyz[v*3+0];
157 avrg.
y += mesh.
xyz[v*3+1];
158 avrg.
z += mesh.
xyz[v*3+2];
160 avrg.
x /= S(elemsize);
161 avrg.
y /= S(elemsize);
162 avrg.
z /= S(elemsize);
171 partitioner(mesh.
comm, ctr, size, part);
173 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