SparseLU_column_dfs.h
Go to the documentation of this file.
1 // This file is part of Eigen, a lightweight C++ template library
2 // for linear algebra.
3 //
4 // Copyright (C) 2012 Désiré Nuentsa-Wakam <desire.nuentsa_wakam@inria.fr>
5 //
6 // This Source Code Form is subject to the terms of the Mozilla
7 // Public License v. 2.0. If a copy of the MPL was not distributed
8 // with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 
10 /*
11 
12  * NOTE: This file is the modified version of [s,d,c,z]column_dfs.c file in SuperLU
13 
14  * -- SuperLU routine (version 2.0) --
15  * Univ. of California Berkeley, Xerox Palo Alto Research Center,
16  * and Lawrence Berkeley National Lab.
17  * November 15, 1997
18  *
19  * Copyright (c) 1994 by Xerox Corporation. All rights reserved.
20  *
21  * THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY
22  * EXPRESSED OR IMPLIED. ANY USE IS AT YOUR OWN RISK.
23  *
24  * Permission is hereby granted to use or copy this program for any
25  * purpose, provided the above notices are retained on all copies.
26  * Permission to modify the code and to distribute modified code is
27  * granted, provided the above notices are retained, and a notice that
28  * the code was modified is included with the above copyright notice.
29  */
30 #ifndef SPARSELU_COLUMN_DFS_H
31 #define SPARSELU_COLUMN_DFS_H
32 
33 template <typename Scalar, typename StorageIndex> class SparseLUImpl;
34 #include "./InternalHeaderCheck.h"
35 
36 namespace Eigen {
37 
38 namespace internal {
39 
40 template<typename IndexVector, typename ScalarVector>
41 struct column_dfs_traits : no_assignment_operator
42 {
43  typedef typename ScalarVector::Scalar Scalar;
44  typedef typename IndexVector::Scalar StorageIndex;
45  column_dfs_traits(Index jcol, Index& jsuper, typename SparseLUImpl<Scalar, StorageIndex>::GlobalLU_t& glu, SparseLUImpl<Scalar, StorageIndex>& luImpl)
46  : m_jcol(jcol), m_jsuper_ref(jsuper), m_glu(glu), m_luImpl(luImpl)
47  {}
48  bool update_segrep(Index /*krep*/, Index /*jj*/)
49  {
50  return true;
51  }
52  void mem_expand(IndexVector& lsub, Index& nextl, Index chmark)
53  {
54  if (nextl >= m_glu.nzlmax)
55  m_luImpl.memXpand(lsub, m_glu.nzlmax, nextl, LSUB, m_glu.num_expansions);
56  if (chmark != (m_jcol-1)) m_jsuper_ref = emptyIdxLU;
57  }
58  enum { ExpandMem = true };
59 
60  Index m_jcol;
61  Index& m_jsuper_ref;
64 };
65 
66 
94 template <typename Scalar, typename StorageIndex>
95 Index SparseLUImpl<Scalar,StorageIndex>::column_dfs(const Index m, const Index jcol, IndexVector& perm_r, Index maxsuper, Index& nseg,
96  BlockIndexVector lsub_col, IndexVector& segrep, BlockIndexVector repfnz, IndexVector& xprune,
97  IndexVector& marker, IndexVector& parent, IndexVector& xplore, GlobalLU_t& glu)
98 {
99 
100  Index jsuper = glu.supno(jcol);
101  Index nextl = glu.xlsub(jcol);
102  VectorBlock<IndexVector> marker2(marker, 2*m, m);
103 
104 
105  column_dfs_traits<IndexVector, ScalarVector> traits(jcol, jsuper, glu, *this);
106 
107  // For each nonzero in A(*,jcol) do dfs
108  for (Index k = 0; ((k < m) ? lsub_col[k] != emptyIdxLU : false) ; k++)
109  {
110  Index krow = lsub_col(k);
111  lsub_col(k) = emptyIdxLU;
112  Index kmark = marker2(krow);
113 
114  // krow was visited before, go to the next nonz;
115  if (kmark == jcol) continue;
116 
117  dfs_kernel(StorageIndex(jcol), perm_r, nseg, glu.lsub, segrep, repfnz, xprune, marker2, parent,
118  xplore, glu, nextl, krow, traits);
119  } // for each nonzero ...
120 
121  Index fsupc;
122  StorageIndex nsuper = glu.supno(jcol);
123  StorageIndex jcolp1 = StorageIndex(jcol) + 1;
124  Index jcolm1 = jcol - 1;
125 
126  // check to see if j belongs in the same supernode as j-1
127  if ( jcol == 0 )
128  { // Do nothing for column 0
129  nsuper = glu.supno(0) = 0 ;
130  }
131  else
132  {
133  fsupc = glu.xsup(nsuper);
134  StorageIndex jptr = glu.xlsub(jcol); // Not yet compressed
135  StorageIndex jm1ptr = glu.xlsub(jcolm1);
136 
137  // Use supernodes of type T2 : see SuperLU paper
138  if ( (nextl-jptr != jptr-jm1ptr-1) ) jsuper = emptyIdxLU;
139 
140  // Make sure the number of columns in a supernode doesn't
141  // exceed threshold
142  if ( (jcol - fsupc) >= maxsuper) jsuper = emptyIdxLU;
143 
144  /* If jcol starts a new supernode, reclaim storage space in
145  * glu.lsub from previous supernode. Note we only store
146  * the subscript set of the first and last columns of
147  * a supernode. (first for num values, last for pruning)
148  */
149  if (jsuper == emptyIdxLU)
150  { // starts a new supernode
151  if ( (fsupc < jcolm1-1) )
152  { // >= 3 columns in nsuper
153  StorageIndex ito = glu.xlsub(fsupc+1);
154  glu.xlsub(jcolm1) = ito;
155  StorageIndex istop = ito + jptr - jm1ptr;
156  xprune(jcolm1) = istop; // initialize xprune(jcol-1)
157  glu.xlsub(jcol) = istop;
158 
159  for (StorageIndex ifrom = jm1ptr; ifrom < nextl; ++ifrom, ++ito)
160  glu.lsub(ito) = glu.lsub(ifrom);
161  nextl = ito; // = istop + length(jcol)
162  }
163  nsuper++;
164  glu.supno(jcol) = nsuper;
165  } // if a new supernode
166  } // end else: jcol > 0
167 
168  // Tidy up the pointers before exit
169  glu.xsup(nsuper+1) = jcolp1;
170  glu.supno(jcolp1) = nsuper;
171  xprune(jcol) = StorageIndex(nextl); // Initialize upper bound for pruning
172  glu.xlsub(jcolp1) = StorageIndex(nextl);
173 
174  return 0;
175 }
176 
177 } // end namespace internal
178 
179 } // end namespace Eigen
180 
181 #endif
Matrix3f m
: InteropHeaders
Definition: Core:139
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition: Meta.h:82