sym-ildl  1.2
Incomplete LDL' factorizations of indefinite symmetric and skew-symmetric matrices.
lilc_matrix_sym_rcm.h
1 // -*- mode: c++ -*-
2 #ifndef _LILC_MATRIX_SYM_RCM_H_
3 #define _LILC_MATRIX_SYM_RCM_H_
4 
5 namespace {
9 template <class el_type>
10 struct by_degree {
12  by_degree(lilc_matrix<el_type>* mat) : A(mat) {}
13  bool operator()(int const &a, int const &b) const {
14  int deg_a = A->list[a].size() + A->m_idx[a].size();
15  int deg_b = A->list[b].size() + A->m_idx[b].size();
16 
17  if (A->m_idx[a].size() > 0 && A->m_idx[a][0] == a) deg_a--;
18  if (A->m_idx[b].size() > 0 && A->m_idx[b][0] == b) deg_b--;
19 
20  if (deg_a == deg_b) return a > b;
21  return deg_a < deg_b;
22  }
23 };
24 }
25 
26 template<class el_type>
27 inline void lilc_matrix<el_type> :: sym_rcm(vector<int>& perm) {
28  int i, s;
29  vector<bool> visited(m_n_cols, false);
30  vector<int> lvl_set;
31  for (i = 0; i < m_n_cols; i++) {
32  if (visited[i]) continue;
33 
34  lvl_set.clear();
35  s = i;
36  find_root(s);
37  lvl_set.push_back(s);
38  perm.push_back(s);
39 
40  by_degree<el_type> sorter(this);
41 
42  visited[s] = true;
43  while (find_level_set(lvl_set, visited)) {
44  sort(lvl_set.begin(), lvl_set.end(), sorter);
45  perm.insert( perm.end(), lvl_set.begin(), lvl_set.end() );
46  }
47  }
48 
49  reverse(perm.begin(), perm.end());
50 }
51 
52 #endif
vector< idx_vector_type > m_idx
The row/col indices. The way m_idx is used depends on whether the matrix is in LIL-C or LIL-R...
Definition: lil_sparse_matrix.h:35
A list-of-lists (LIL) matrix in column oriented format.
Definition: lilc_matrix.h:9
void sym_rcm(vector< int > &perm)
Returns a Reverse Cuthill-McKee ordering of the matrix A (stored in perm).
Definition: lilc_matrix_sym_rcm.h:27
std::vector< std::vector< int > > list
A list of linked lists that gives the non-zero elements in each row of A. Since at any time we may sw...
Definition: lilc_matrix_declarations.h:44