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