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>
35 // IWYU pragma: private
36 #include "./InternalHeaderCheck.h"
37 
38 namespace Eigen {
39 
40 namespace internal {
41 
42 template <typename IndexVector, typename ScalarVector>
44  typedef typename ScalarVector::Scalar Scalar;
48  : m_jcol(jcol), m_jsuper_ref(jsuper), m_glu(glu), m_luImpl(luImpl) {}
49  bool update_segrep(Index /*krep*/, Index /*jj*/) { return true; }
50  void mem_expand(IndexVector& lsub, Index& nextl, Index chmark) {
51  if (nextl >= m_glu.nzlmax) m_luImpl.memXpand(lsub, m_glu.nzlmax, nextl, LSUB, m_glu.num_expansions);
52  if (chmark != (m_jcol - 1)) m_jsuper_ref = emptyIdxLU;
53  }
54  enum { ExpandMem = true };
55 
60 };
61 
89 template <typename Scalar, typename StorageIndex>
91  Index maxsuper, Index& nseg, BlockIndexVector lsub_col,
92  IndexVector& segrep, BlockIndexVector repfnz, IndexVector& xprune,
93  IndexVector& marker, IndexVector& parent, IndexVector& xplore,
94  GlobalLU_t& glu) {
95  Index jsuper = glu.supno(jcol);
96  Index nextl = glu.xlsub(jcol);
97  VectorBlock<IndexVector> marker2(marker, 2 * m, m);
98 
99  column_dfs_traits<IndexVector, ScalarVector> traits(jcol, jsuper, glu, *this);
100 
101  // For each nonzero in A(*,jcol) do dfs
102  for (Index k = 0; ((k < m) ? lsub_col[k] != emptyIdxLU : false); k++) {
103  Index krow = lsub_col(k);
104  lsub_col(k) = emptyIdxLU;
105  Index kmark = marker2(krow);
106 
107  // krow was visited before, go to the next nonz;
108  if (kmark == jcol) continue;
109 
110  dfs_kernel(StorageIndex(jcol), perm_r, nseg, glu.lsub, segrep, repfnz, xprune, marker2, parent, xplore, glu, nextl,
111  krow, traits);
112  } // for each nonzero ...
113 
114  Index fsupc;
115  StorageIndex nsuper = glu.supno(jcol);
116  StorageIndex jcolp1 = StorageIndex(jcol) + 1;
117  Index jcolm1 = jcol - 1;
118 
119  // check to see if j belongs in the same supernode as j-1
120  if (jcol == 0) { // Do nothing for column 0
121  nsuper = glu.supno(0) = 0;
122  } else {
123  fsupc = glu.xsup(nsuper);
124  StorageIndex jptr = glu.xlsub(jcol); // Not yet compressed
125  StorageIndex jm1ptr = glu.xlsub(jcolm1);
126 
127  // Use supernodes of type T2 : see SuperLU paper
128  if ((nextl - jptr != jptr - jm1ptr - 1)) jsuper = emptyIdxLU;
129 
130  // Make sure the number of columns in a supernode doesn't
131  // exceed threshold
132  if ((jcol - fsupc) >= maxsuper) jsuper = emptyIdxLU;
133 
134  /* If jcol starts a new supernode, reclaim storage space in
135  * glu.lsub from previous supernode. Note we only store
136  * the subscript set of the first and last columns of
137  * a supernode. (first for num values, last for pruning)
138  */
139  if (jsuper == emptyIdxLU) { // starts a new supernode
140  if ((fsupc < jcolm1 - 1)) { // >= 3 columns in nsuper
141  StorageIndex ito = glu.xlsub(fsupc + 1);
142  glu.xlsub(jcolm1) = ito;
143  StorageIndex istop = ito + jptr - jm1ptr;
144  xprune(jcolm1) = istop; // initialize xprune(jcol-1)
145  glu.xlsub(jcol) = istop;
146 
147  for (StorageIndex ifrom = jm1ptr; ifrom < nextl; ++ifrom, ++ito) glu.lsub(ito) = glu.lsub(ifrom);
148  nextl = ito; // = istop + length(jcol)
149  }
150  nsuper++;
151  glu.supno(jcol) = nsuper;
152  } // if a new supernode
153  } // end else: jcol > 0
154 
155  // Tidy up the pointers before exit
156  glu.xsup(nsuper + 1) = jcolp1;
157  glu.supno(jcolp1) = nsuper;
158  xprune(jcol) = StorageIndex(nextl); // Initialize upper bound for pruning
159  glu.xlsub(jcolp1) = StorageIndex(nextl);
160 
161  return 0;
162 }
163 
164 } // end namespace internal
165 
166 } // end namespace Eigen
167 
168 #endif
SCALAR Scalar
Definition: bench_gemm.cpp:45
A matrix or vector expression mapping an existing expression.
Definition: Ref.h:264
Expression of a fixed-size or dynamic-size sub-vector.
Definition: VectorBlock.h:58
Definition: SparseLUImpl.h:23
Index column_dfs(const Index m, const Index jcol, IndexVector &perm_r, Index maxsuper, Index &nseg, BlockIndexVector lsub_col, IndexVector &segrep, BlockIndexVector repfnz, IndexVector &xprune, IndexVector &marker, IndexVector &parent, IndexVector &xplore, GlobalLU_t &glu)
Performs a symbolic factorization on column jcol and decide the supernode boundary.
Definition: SparseLU_column_dfs.h:90
Definition: XprHelper.h:134
Definition: SparseLU_column_dfs.h:34
int * m
Definition: level2_cplx_impl.h:294
char char char int int * k
Definition: level2_impl.h:374
@ LSUB
Definition: SparseLU_Structs.h:77
@ emptyIdxLU
Definition: SparseLU_Memory.h:41
Namespace containing all symbols from the Eigen library.
Definition: bench_norm.cpp:70
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition: Meta.h:83
Definition: Eigen_Colamd.h:49
Definition: SparseLU_Structs.h:80
IndexVector xsup
Definition: SparseLU_Structs.h:82
IndexVector supno
Definition: SparseLU_Structs.h:83
IndexVector lsub
Definition: SparseLU_Structs.h:85
IndexVector xlsub
Definition: SparseLU_Structs.h:87
Definition: SparseLU_column_dfs.h:43
bool update_segrep(Index, Index)
Definition: SparseLU_column_dfs.h:49
@ ExpandMem
Definition: SparseLU_column_dfs.h:54
SparseLUImpl< Scalar, StorageIndex > & m_luImpl
Definition: SparseLU_column_dfs.h:59
void mem_expand(IndexVector &lsub, Index &nextl, Index chmark)
Definition: SparseLU_column_dfs.h:50
IndexVector::Scalar StorageIndex
Definition: SparseLU_column_dfs.h:45
column_dfs_traits(Index jcol, Index &jsuper, typename SparseLUImpl< Scalar, StorageIndex >::GlobalLU_t &glu, SparseLUImpl< Scalar, StorageIndex > &luImpl)
Definition: SparseLU_column_dfs.h:46
Index & m_jsuper_ref
Definition: SparseLU_column_dfs.h:57
SparseLUImpl< Scalar, StorageIndex >::GlobalLU_t & m_glu
Definition: SparseLU_column_dfs.h:58
ScalarVector::Scalar Scalar
Definition: SparseLU_column_dfs.h:44
Index m_jcol
Definition: SparseLU_column_dfs.h:56
Definition: ForwardDeclarations.h:21
int num_expansions
Definition: slu_cdefs.h:104
int nzlmax
Definition: slu_cdefs.h:99