1 #ifndef VIENNACL_MISC_GIBBS_POOLE_STOCKMEYER_HPP
2 #define VIENNACL_MISC_GIBBS_POOLE_STOCKMEYER_HPP
62 template<
typename MatrixType>
64 std::vector<int>
const & rg)
66 std::vector< std::vector<int> > rgc;
67 std::vector< std::vector<int> > rgc_sorted;
68 std::vector< std::vector<int> > sort_ind;
69 std::vector<int> ind(2);
72 std::vector<bool> inr(static_cast<vcl_size_t>(n),
true);
82 for (
int i = 0; i < n; i++)
84 if (!inr[static_cast<vcl_size_t>(i)])
99 if (!inr[static_cast<vcl_size_t>(c)])
104 for (
typename MatrixType::value_type::const_iterator it = matrix[static_cast<vcl_size_t>(c)].begin(); it != matrix[
static_cast<vcl_size_t>(c)].end(); it++)
106 if (it->first == c)
continue;
107 if (inr[static_cast<vcl_size_t>(it->first)])
continue;
109 q.push_back(it->first);
118 ind[0] =
static_cast<int>(i);
119 ind[1] =
static_cast<int>(rgc[i].size());
120 sort_ind.push_back(ind);
124 rgc_sorted.push_back(rgc[static_cast<vcl_size_t>(sort_ind[rgc.size()-1-i][0])]);
149 template<
typename MatrixType>
154 std::vector<int> r(n);
155 std::vector< std::vector<int> > rl;
159 std::vector< std::vector<int> > nodes;
160 std::vector<bool> inr(n,
false);
161 std::vector<bool> isn(n,
false);
162 std::vector<int> tmp(2);
165 std::vector< std::vector<int> > lg;
166 std::vector< std::vector<int> > lh;
167 std::vector< std::vector<int> > ls;
168 std::map< int, std::vector<int> > lap;
170 std::vector< std::vector<int> > rgc;
175 std::vector<int> wvs;
176 std::vector<int> wvsg;
177 std::vector<int> wvsh;
186 while (current_dof < static_cast<int>(n))
195 deg =
static_cast<int>(matrix[i].size() - 1);
196 if (deg_min < 0 || deg < deg_min)
198 g =
static_cast<int>(i);
211 for (
vcl_size_t i = 0; i < lg.back().size(); i++)
213 tmp[0] = lg.back()[i];
214 tmp[1] =
static_cast<int>(matrix[
static_cast<vcl_size_t>(lg.back()[i])].
size() - 1);
215 nodes.push_back(tmp);
220 lg.back()[i] = nodes[i][0];
225 for (
vcl_size_t i = 0; i < lg.back().size(); i++)
229 if (lh.size() > lg.size())
236 if (m_min < 0 || m < m_min)
254 lap[lg[i][j]].resize(2);
255 lap[lg[i][j]][0] =
static_cast<int>(i);
260 lap[lh[i][j]][1] = static_cast<int>(lg.size() - 1 - i);
264 ls.resize(lg.size());
265 for (std::map<
int, std::vector<int> >::iterator it = lap.begin();
266 it != lap.end(); it++)
268 if ((it->second)[0] == (it->second)[1])
269 ls[
static_cast<vcl_size_t>((it->second)[0])].push_back(it->first);
271 rg.push_back(it->first);
279 wvs.resize(ls.size());
280 wvsg.resize(ls.size());
281 wvsh.resize(ls.size());
286 wvs[j] =
static_cast<int>(ls[j].size());
287 wvsg[j] =
static_cast<int>(ls[j].size());
288 wvsh[j] =
static_cast<int>(ls[j].size());
290 for (
vcl_size_t j = 0; j < rgc[i].size(); j++)
292 (wvsg[
static_cast<vcl_size_t>(lap[rgc[i][j]][0])])++;
293 (wvsh[
static_cast<vcl_size_t>(lap[rgc[i][j]][1])])++;
299 if (wvsg[j] > wvs[j])
301 if (wvsh[j] > wvs[j])
304 if (k3 < k4 || (k3 == k4 && k1 <= k2) )
305 for (
vcl_size_t j = 0; j < rgc[i].size(); j++)
306 ls[static_cast<vcl_size_t>(lap[rgc[i][j]][0])].push_back(rgc[i][j]);
308 for (
vcl_size_t j = 0; j < rgc[i].size(); j++)
309 ls[static_cast<vcl_size_t>(lap[rgc[i][j]][1])].push_back(rgc[i][j]);
314 rl.resize(ls.size());
327 for (
vcl_size_t i = 0; i < rl[l-1].size(); i++)
329 isn.assign(n,
false);
330 for (std::map<int, double>::const_iterator it = matrix[static_cast<vcl_size_t>(rl[l-1][i])].begin();
331 it != matrix[
static_cast<vcl_size_t>(rl[l-1][i])].end();
334 if (it->first == rl[l-1][i])
continue;
335 isn[
static_cast<vcl_size_t>(it->first)] =
true;
340 if (inr[static_cast<vcl_size_t>(ls[l][j])])
continue;
341 if (!isn[static_cast<vcl_size_t>(ls[l][j])])
continue;
343 tmp[1] =
static_cast<int>(matrix[
static_cast<vcl_size_t>(ls[l][j])].
size() - 1);
344 nodes.push_back(tmp);
349 rl[l].push_back(nodes[j][0]);
350 r[
static_cast<vcl_size_t>(nodes[j][0])] = current_dof++;
351 inr[
static_cast<vcl_size_t>(nodes[j][0])] =
true;
358 isn.assign(n,
false);
359 for (std::map<int, double>::const_iterator it = matrix[static_cast<vcl_size_t>(rl[l][i])].begin();
360 it != matrix[
static_cast<vcl_size_t>(rl[l][i])].end();
363 if (it->first == rl[l][i])
continue;
364 isn[
static_cast<vcl_size_t>(it->first)] =
true;
369 if (inr[static_cast<vcl_size_t>(ls[l][j])])
continue;
370 if (!isn[static_cast<vcl_size_t>(ls[l][j])])
continue;
372 tmp[1] =
static_cast<int>(matrix[
static_cast<vcl_size_t>(ls[l][j])].
size() - 1);
373 nodes.push_back(tmp);
378 rl[l].push_back(nodes[j][0]);
379 r[
static_cast<vcl_size_t>(nodes[j][0])] = current_dof++;
380 inr[
static_cast<vcl_size_t>(nodes[j][0])] =
true;
385 if (rl[l].
size() < ls[l].size())
390 if (inr[static_cast<vcl_size_t>(ls[l][j])])
continue;
391 deg =
static_cast<int>(matrix[
static_cast<vcl_size_t>(ls[l][j])].
size() - 1);
392 if (deg_min < 0 || deg < deg_min)
398 rl[l].push_back(ind_min);
399 r[
static_cast<vcl_size_t>(ind_min)] = current_dof++;
std::vector< IndexT > reorder(std::vector< std::map< IndexT, ValueT > > const &matrix, cuthill_mckee_tag)
Function for the calculation of a node number permutation to reduce the bandwidth of an incidence mat...
This file provides the forward declarations for the main types used within ViennaCL.
T max(const T &lhs, const T &rhs)
Maximum.
void generate_layering(MatrixT const &matrix, std::vector< std::vector< IndexT > > &layer_list)
Function to generate a node layering as a tree structure.
vcl_size_t size(VectorType const &vec)
Generic routine for obtaining the size of a vector (ViennaCL, uBLAS, etc.)
Tag class for identifying the Gibbs-Poole-Stockmeyer algorithm for reducing the bandwidth of a sparse...
std::vector< std::vector< int > > gps_rg_components(MatrixType const &matrix, int n, std::vector< int > const &rg)
Implementation of several flavors of the Cuthill-McKee algorithm. Experimental.
int calc_layering_width(std::vector< std::vector< int > > const &l)
bool cuthill_mckee_comp_func(std::vector< int > const &a, std::vector< int > const &b)