Eigen  5.0.1
 
Loading...
Searching...
No Matches
SparseLU_column_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 xcolumn_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_COLUMN_BMOD_H
33#define SPARSELU_COLUMN_BMOD_H
34
35// IWYU pragma: private
36#include "./InternalHeaderCheck.h"
37
38namespace Eigen {
39
40namespace internal {
56template <typename Scalar, typename StorageIndex>
57Index SparseLUImpl<Scalar, StorageIndex>::column_bmod(const Index jcol, const Index nseg, BlockScalarVector dense,
58 ScalarVector& tempv, BlockIndexVector segrep,
59 BlockIndexVector repfnz, Index fpanelc, GlobalLU_t& glu) {
60 Index jsupno, k, ksub, krep, ksupno;
61 Index lptr, nrow, isub, irow, nextlu, new_next, ufirst;
62 Index fsupc, nsupc, nsupr, luptr, kfnz, no_zeros;
63 /* krep = representative of current k-th supernode
64 * fsupc = first supernodal column
65 * nsupc = number of columns in a supernode
66 * nsupr = number of rows in a supernode
67 * luptr = location of supernodal LU-block in storage
68 * kfnz = first nonz in the k-th supernodal segment
69 * no_zeros = no of leading zeros in a supernodal U-segment
70 */
71
72 jsupno = glu.supno(jcol);
73 // For each nonzero supernode segment of U[*,j] in topological order
74 k = nseg - 1;
75 Index d_fsupc; // distance between the first column of the current panel and the
76 // first column of the current snode
77 Index fst_col; // First column within small LU update
78 Index segsize;
79 for (ksub = 0; ksub < nseg; ksub++) {
80 krep = segrep(k);
81 k--;
82 ksupno = glu.supno(krep);
83 if (jsupno != ksupno) {
84 // outside the rectangular supernode
85 fsupc = glu.xsup(ksupno);
86 fst_col = (std::max)(fsupc, fpanelc);
87
88 // Distance from the current supernode to the current panel;
89 // d_fsupc = 0 if fsupc > fpanelc
90 d_fsupc = fst_col - fsupc;
91
92 luptr = glu.xlusup(fst_col) + d_fsupc;
93 lptr = glu.xlsub(fsupc) + d_fsupc;
94
95 kfnz = repfnz(krep);
96 kfnz = (std::max)(kfnz, fpanelc);
97
98 segsize = krep - kfnz + 1;
99 nsupc = krep - fst_col + 1;
100 nsupr = glu.xlsub(fsupc + 1) - glu.xlsub(fsupc);
101 nrow = nsupr - d_fsupc - nsupc;
102 Index lda = glu.xlusup(fst_col + 1) - glu.xlusup(fst_col);
103
104 // Perform a triangular solver and block update,
105 // then scatter the result of sup-col update to dense
106 no_zeros = kfnz - fst_col;
107 if (segsize == 1)
108 LU_kernel_bmod<1>::run(segsize, dense, tempv, glu.lusup, luptr, lda, nrow, glu.lsub, lptr, no_zeros);
109 else
110 LU_kernel_bmod<Dynamic>::run(segsize, dense, tempv, glu.lusup, luptr, lda, nrow, glu.lsub, lptr, no_zeros);
111 } // end if jsupno
112 } // end for each segment
113
114 // Process the supernodal portion of L\U[*,j]
115 nextlu = glu.xlusup(jcol);
116 fsupc = glu.xsup(jsupno);
117
118 // copy the SPA dense into L\U[*,j]
119 Index mem;
120 new_next = nextlu + glu.xlsub(fsupc + 1) - glu.xlsub(fsupc);
121 Index offset = internal::first_multiple<Index>(new_next, internal::packet_traits<Scalar>::size) - new_next;
122 if (offset) new_next += offset;
123 while (new_next > glu.nzlumax) {
124 mem = memXpand<ScalarVector>(glu.lusup, glu.nzlumax, nextlu, LUSUP, glu.num_expansions);
125 if (mem) return mem;
126 }
127
128 for (isub = glu.xlsub(fsupc); isub < glu.xlsub(fsupc + 1); isub++) {
129 irow = glu.lsub(isub);
130 glu.lusup(nextlu) = dense(irow);
131 dense(irow) = Scalar(0.0);
132 ++nextlu;
133 }
134
135 if (offset) {
136 glu.lusup.segment(nextlu, offset).setZero();
137 nextlu += offset;
138 }
139 glu.xlusup(jcol + 1) = StorageIndex(nextlu); // close L\U(*,jcol);
140
141 /* For more updates within the panel (also within the current supernode),
142 * should start from the first column of the panel, or the first column
143 * of the supernode, whichever is bigger. There are two cases:
144 * 1) fsupc < fpanelc, then fst_col <-- fpanelc
145 * 2) fsupc >= fpanelc, then fst_col <-- fsupc
146 */
147 fst_col = (std::max)(fsupc, fpanelc);
148
149 if (fst_col < jcol) {
150 // Distance between the current supernode and the current panel
151 // d_fsupc = 0 if fsupc >= fpanelc
152 d_fsupc = fst_col - fsupc;
153
154 lptr = glu.xlsub(fsupc) + d_fsupc;
155 luptr = glu.xlusup(fst_col) + d_fsupc;
156 nsupr = glu.xlsub(fsupc + 1) - glu.xlsub(fsupc); // leading dimension
157 nsupc = jcol - fst_col; // excluding jcol
158 nrow = nsupr - d_fsupc - nsupc;
159
160 // points to the beginning of jcol in snode L\U(jsupno)
161 ufirst = glu.xlusup(jcol) + d_fsupc;
162 Index lda = glu.xlusup(jcol + 1) - glu.xlusup(jcol);
163 MappedMatrixBlock A(&(glu.lusup.data()[luptr]), nsupc, nsupc, OuterStride<>(lda));
164 VectorBlock<ScalarVector> u(glu.lusup, ufirst, nsupc);
165 u = A.template triangularView<UnitLower>().solve(u);
166
167 new (&A) MappedMatrixBlock(&(glu.lusup.data()[luptr + nsupc]), nrow, nsupc, OuterStride<>(lda));
168 VectorBlock<ScalarVector> l(glu.lusup, ufirst + nsupc, nrow);
169 l.noalias() -= A * u;
170
171 } // End if fst_col
172 return 0;
173}
174
175} // end namespace internal
176} // end namespace Eigen
177
178#endif // SPARSELU_COLUMN_BMOD_H
Index column_bmod(const Index jcol, const Index nseg, BlockScalarVector dense, ScalarVector &tempv, BlockIndexVector segrep, BlockIndexVector repfnz, Index fpanelc, GlobalLU_t &glu)
Performs numeric block updates (sup-col) in topological order.
Definition SparseLU_column_bmod.h:57