Eigen  3.4.90 (git rev 5a9f66fb35d03a4da9ef8976e67a61b30aa16dcf)
 
Loading...
Searching...
No Matches
SparseLU_column_dfs.h
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 <[email protected]>
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
33template <typename Scalar, typename StorageIndex>
34class SparseLUImpl;
35// IWYU pragma: private
36#include "./InternalHeaderCheck.h"
37
38namespace Eigen {
39
40namespace internal {
41
42template <typename IndexVector, typename ScalarVector>
43struct column_dfs_traits : no_assignment_operator {
44 typedef typename ScalarVector::Scalar Scalar;
45 typedef typename IndexVector::Scalar StorageIndex;
46 column_dfs_traits(Index jcol, Index& jsuper, typename SparseLUImpl<Scalar, StorageIndex>::GlobalLU_t& glu,
47 SparseLUImpl<Scalar, StorageIndex>& luImpl)
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
56 Index m_jcol;
57 Index& m_jsuper_ref;
58 typename SparseLUImpl<Scalar, StorageIndex>::GlobalLU_t& m_glu;
59 SparseLUImpl<Scalar, StorageIndex>& m_luImpl;
60};
61
89template <typename Scalar, typename StorageIndex>
90Index SparseLUImpl<Scalar, StorageIndex>::column_dfs(const Index m, const Index jcol, IndexVector& perm_r,
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
Namespace containing all symbols from the Eigen library.
Definition Core:137