Eigen  5.0.1
 
Loading...
Searching...
No Matches
SparseLU_panel_bmod.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// Copyright (C) 2012 Gael Guennebaud <gael.guennebaud@inria.fr>
6//
7// This Source Code Form is subject to the terms of the Mozilla
8// Public License v. 2.0. If a copy of the MPL was not distributed
9// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
10// SPDX-License-Identifier: MPL-2.0
11
12/*
13
14 * NOTE: This file is the modified version of [s,d,c,z]panel_bmod.c file in SuperLU
15
16 * -- SuperLU routine (version 3.0) --
17 * Univ. of California Berkeley, Xerox Palo Alto Research Center,
18 * and Lawrence Berkeley National Lab.
19 * October 15, 2003
20 *
21 * Copyright (c) 1994 by Xerox Corporation. All rights reserved.
22 *
23 * THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY
24 * EXPRESSED OR IMPLIED. ANY USE IS AT YOUR OWN RISK.
25 *
26 * Permission is hereby granted to use or copy this program for any
27 * purpose, provided the above notices are retained on all copies.
28 * Permission to modify the code and to distribute modified code is
29 * granted, provided the above notices are retained, and a notice that
30 * the code was modified is included with the above copyright notice.
31 */
32#ifndef SPARSELU_PANEL_BMOD_H
33#define SPARSELU_PANEL_BMOD_H
34
35// IWYU pragma: private
36#include "./InternalHeaderCheck.h"
37
38namespace Eigen {
39namespace internal {
40
59template <typename Scalar, typename StorageIndex>
60void SparseLUImpl<Scalar, StorageIndex>::panel_bmod(const Index m, const Index w, const Index jcol, const Index nseg,
61 ScalarVector& dense, ScalarVector& tempv, IndexVector& segrep,
62 IndexVector& repfnz, GlobalLU_t& glu) {
63 Index ksub, jj, nextl_col;
64 Index fsupc, nsupc, nsupr, nrow;
65 Index krep, kfnz;
66 Index lptr; // points to the row subscripts of a supernode
67 Index luptr; // ...
68 Index segsize, no_zeros;
69 // For each nonz supernode segment of U[*,j] in topological order
70 Index k = nseg - 1;
71 const Index PacketSize = internal::packet_traits<Scalar>::size;
72
73 for (ksub = 0; ksub < nseg; ksub++) { // For each updating supernode
74 /* krep = representative of current k-th supernode
75 * fsupc = first supernodal column
76 * nsupc = number of columns in a supernode
77 * nsupr = number of rows in a supernode
78 */
79 krep = segrep(k);
80 k--;
81 fsupc = glu.xsup(glu.supno(krep));
82 nsupc = krep - fsupc + 1;
83 nsupr = glu.xlsub(fsupc + 1) - glu.xlsub(fsupc);
84 nrow = nsupr - nsupc;
85 lptr = glu.xlsub(fsupc);
86
87 // loop over the panel columns to detect the actual number of columns and rows
88 Index u_rows = 0;
89 Index u_cols = 0;
90 for (jj = jcol; jj < jcol + w; jj++) {
91 nextl_col = (jj - jcol) * m;
92 VectorBlock<IndexVector> repfnz_col(repfnz, nextl_col, m); // First nonzero column index for each row
93
94 kfnz = repfnz_col(krep);
95 if (kfnz == emptyIdxLU) continue; // skip any zero segment
96
97 segsize = krep - kfnz + 1;
98 u_cols++;
99 u_rows = (std::max)(segsize, u_rows);
100 }
101
102 if (nsupc >= 2) {
103 Index ldu = internal::first_multiple<Index>(u_rows, PacketSize);
104 Map<ScalarMatrix, Aligned, OuterStride<> > U(tempv.data(), u_rows, u_cols, OuterStride<>(ldu));
105
106 // gather U
107 Index u_col = 0;
108 for (jj = jcol; jj < jcol + w; jj++) {
109 nextl_col = (jj - jcol) * m;
110 VectorBlock<IndexVector> repfnz_col(repfnz, nextl_col, m); // First nonzero column index for each row
111 VectorBlock<ScalarVector> dense_col(dense, nextl_col, m); // Scatter/gather entire matrix column from/to here
112
113 kfnz = repfnz_col(krep);
114 if (kfnz == emptyIdxLU) continue; // skip any zero segment
115
116 segsize = krep - kfnz + 1;
117 luptr = glu.xlusup(fsupc);
118 no_zeros = kfnz - fsupc;
119
120 Index isub = lptr + no_zeros;
121 Index off = u_rows - segsize;
122 for (Index i = 0; i < off; i++) U(i, u_col) = Scalar(0);
123 for (Index i = 0; i < segsize; i++) {
124 Index irow = glu.lsub(isub);
125 U(i + off, u_col) = dense_col(irow);
126 ++isub;
127 }
128 u_col++;
129 }
130 // solve U = A^-1 U
131 luptr = glu.xlusup(fsupc);
132 Index lda = glu.xlusup(fsupc + 1) - glu.xlusup(fsupc);
133 no_zeros = (krep - u_rows + 1) - fsupc;
134 luptr += lda * no_zeros + no_zeros;
135 MappedMatrixBlock A(glu.lusup.data() + luptr, u_rows, u_rows, OuterStride<>(lda));
136 U = A.template triangularView<UnitLower>().solve(U);
137
138 // update
139 luptr += u_rows;
140 MappedMatrixBlock B(glu.lusup.data() + luptr, nrow, u_rows, OuterStride<>(lda));
141 eigen_assert(tempv.size() > w * ldu + nrow * w + 1);
142
143 Index ldl = internal::first_multiple<Index>(nrow, PacketSize);
144 Index offset = (PacketSize - internal::first_default_aligned(B.data(), PacketSize)) % PacketSize;
145 MappedMatrixBlock L(tempv.data() + w * ldu + offset, nrow, u_cols, OuterStride<>(ldl));
146
147 L.noalias() = B * U;
148
149 // scatter U and L
150 u_col = 0;
151 for (jj = jcol; jj < jcol + w; jj++) {
152 nextl_col = (jj - jcol) * m;
153 VectorBlock<IndexVector> repfnz_col(repfnz, nextl_col, m); // First nonzero column index for each row
154 VectorBlock<ScalarVector> dense_col(dense, nextl_col, m); // Scatter/gather entire matrix column from/to here
155
156 kfnz = repfnz_col(krep);
157 if (kfnz == emptyIdxLU) continue; // skip any zero segment
158
159 segsize = krep - kfnz + 1;
160 no_zeros = kfnz - fsupc;
161 Index isub = lptr + no_zeros;
162
163 Index off = u_rows - segsize;
164 for (Index i = 0; i < segsize; i++) {
165 Index irow = glu.lsub(isub++);
166 dense_col(irow) = U.coeff(i + off, u_col);
167 U.coeffRef(i + off, u_col) = Scalar(0);
168 }
169
170 // Scatter l into SPA dense[]
171 for (Index i = 0; i < nrow; i++) {
172 Index irow = glu.lsub(isub++);
173 dense_col(irow) -= L.coeff(i, u_col);
174 L.coeffRef(i, u_col) = Scalar(0);
175 }
176 u_col++;
177 }
178 } else // level 2 only
179 {
180 // Sequence through each column in the panel
181 for (jj = jcol; jj < jcol + w; jj++) {
182 nextl_col = (jj - jcol) * m;
183 VectorBlock<IndexVector> repfnz_col(repfnz, nextl_col, m); // First nonzero column index for each row
184 VectorBlock<ScalarVector> dense_col(dense, nextl_col, m); // Scatter/gather entire matrix column from/to here
185
186 kfnz = repfnz_col(krep);
187 if (kfnz == emptyIdxLU) continue; // skip any zero segment
188
189 segsize = krep - kfnz + 1;
190 luptr = glu.xlusup(fsupc);
191
192 Index lda = glu.xlusup(fsupc + 1) - glu.xlusup(fsupc); // nsupr
193
194 // Perform a triangular solve and block update,
195 // then scatter the result of sup-col update to dense[]
196 no_zeros = kfnz - fsupc;
197 if (segsize == 1)
198 LU_kernel_bmod<1>::run(segsize, dense_col, tempv, glu.lusup, luptr, lda, nrow, glu.lsub, lptr, no_zeros);
199 else if (segsize == 2)
200 LU_kernel_bmod<2>::run(segsize, dense_col, tempv, glu.lusup, luptr, lda, nrow, glu.lsub, lptr, no_zeros);
201 else if (segsize == 3)
202 LU_kernel_bmod<3>::run(segsize, dense_col, tempv, glu.lusup, luptr, lda, nrow, glu.lsub, lptr, no_zeros);
203 else
204 LU_kernel_bmod<Dynamic>::run(segsize, dense_col, tempv, glu.lusup, luptr, lda, nrow, glu.lsub, lptr,
205 no_zeros);
206 } // End for each column in the panel
207 }
208
209 } // End for each updating supernode
210} // end panel bmod
211
212} // end namespace internal
213
214} // end namespace Eigen
215
216#endif // SPARSELU_PANEL_BMOD_H
A matrix or vector expression mapping an existing array of data.
Definition Map.h:97
constexpr const Scalar * data() const
Definition PlainObjectBase.h:261
Expression of a fixed-size or dynamic-size sub-vector.
Definition VectorBlock.h:59
void panel_bmod(const Index m, const Index w, const Index jcol, const Index nseg, ScalarVector &dense, ScalarVector &tempv, IndexVector &segrep, IndexVector &repfnz, GlobalLU_t &glu)
Performs numeric block updates (sup-panel) in topological order.
Definition SparseLU_panel_bmod.h:60