SparseLU_column_bmod.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 // 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 
11 /*
12 
13  * NOTE: This file is the modified version of xcolumn_bmod.c file in SuperLU
14 
15  * -- SuperLU routine (version 3.0) --
16  * Univ. of California Berkeley, Xerox Palo Alto Research Center,
17  * and Lawrence Berkeley National Lab.
18  * October 15, 2003
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_BMOD_H
32 #define SPARSELU_COLUMN_BMOD_H
33 
34 #include "./InternalHeaderCheck.h"
35 
36 namespace Eigen {
37 
38 namespace internal {
54 template <typename Scalar, typename StorageIndex>
55 Index SparseLUImpl<Scalar,StorageIndex>::column_bmod(const Index jcol, const Index nseg, BlockScalarVector dense, ScalarVector& tempv,
56  BlockIndexVector segrep, BlockIndexVector repfnz, Index fpanelc, GlobalLU_t& glu)
57 {
58  Index jsupno, k, ksub, krep, ksupno;
59  Index lptr, nrow, isub, irow, nextlu, new_next, ufirst;
60  Index fsupc, nsupc, nsupr, luptr, kfnz, no_zeros;
61  /* krep = representative of current k-th supernode
62  * fsupc = first supernodal column
63  * nsupc = number of columns in a supernode
64  * nsupr = number of rows in a supernode
65  * luptr = location of supernodal LU-block in storage
66  * kfnz = first nonz in the k-th supernodal segment
67  * no_zeros = no lf leading zeros in a supernodal U-segment
68  */
69 
70  jsupno = glu.supno(jcol);
71  // For each nonzero supernode segment of U[*,j] in topological order
72  k = nseg - 1;
73  Index d_fsupc; // distance between the first column of the current panel and the
74  // first column of the current snode
75  Index fst_col; // First column within small LU update
76  Index segsize;
77  for (ksub = 0; ksub < nseg; ksub++)
78  {
79  krep = segrep(k); k--;
80  ksupno = glu.supno(krep);
81  if (jsupno != ksupno )
82  {
83  // outside the rectangular supernode
84  fsupc = glu.xsup(ksupno);
85  fst_col = (std::max)(fsupc, fpanelc);
86 
87  // Distance from the current supernode to the current panel;
88  // d_fsupc = 0 if fsupc > fpanelc
89  d_fsupc = fst_col - fsupc;
90 
91  luptr = glu.xlusup(fst_col) + d_fsupc;
92  lptr = glu.xlsub(fsupc) + d_fsupc;
93 
94  kfnz = repfnz(krep);
95  kfnz = (std::max)(kfnz, fpanelc);
96 
97  segsize = krep - kfnz + 1;
98  nsupc = krep - fst_col + 1;
99  nsupr = glu.xlsub(fsupc+1) - glu.xlsub(fsupc);
100  nrow = nsupr - d_fsupc - nsupc;
101  Index lda = glu.xlusup(fst_col+1) - glu.xlusup(fst_col);
102 
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)
123  new_next += offset;
124  while (new_next > glu.nzlumax )
125  {
126  mem = memXpand<ScalarVector>(glu.lusup, glu.nzlumax, nextlu, LUSUP, glu.num_expansions);
127  if (mem) return mem;
128  }
129 
130  for (isub = glu.xlsub(fsupc); isub < glu.xlsub(fsupc+1); isub++)
131  {
132  irow = glu.lsub(isub);
133  glu.lusup(nextlu) = dense(irow);
134  dense(irow) = Scalar(0.0);
135  ++nextlu;
136  }
137 
138  if(offset)
139  {
140  glu.lusup.segment(nextlu,offset).setZero();
141  nextlu += offset;
142  }
143  glu.xlusup(jcol + 1) = StorageIndex(nextlu); // close L\U(*,jcol);
144 
145  /* For more updates within the panel (also within the current supernode),
146  * should start from the first column of the panel, or the first column
147  * of the supernode, whichever is bigger. There are two cases:
148  * 1) fsupc < fpanelc, then fst_col <-- fpanelc
149  * 2) fsupc >= fpanelc, then fst_col <-- fsupc
150  */
151  fst_col = (std::max)(fsupc, fpanelc);
152 
153  if (fst_col < jcol)
154  {
155  // Distance between the current supernode and the current panel
156  // d_fsupc = 0 if fsupc >= fpanelc
157  d_fsupc = fst_col - fsupc;
158 
159  lptr = glu.xlsub(fsupc) + d_fsupc;
160  luptr = glu.xlusup(fst_col) + d_fsupc;
161  nsupr = glu.xlsub(fsupc+1) - glu.xlsub(fsupc); // leading dimension
162  nsupc = jcol - fst_col; // excluding jcol
163  nrow = nsupr - d_fsupc - nsupc;
164 
165  // points to the beginning of jcol in snode L\U(jsupno)
166  ufirst = glu.xlusup(jcol) + d_fsupc;
167  Index lda = glu.xlusup(jcol+1) - glu.xlusup(jcol);
168  MappedMatrixBlock A( &(glu.lusup.data()[luptr]), nsupc, nsupc, OuterStride<>(lda) );
169  VectorBlock<ScalarVector> u(glu.lusup, ufirst, nsupc);
170  u = A.template triangularView<UnitLower>().solve(u);
171 
172  new (&A) MappedMatrixBlock ( &(glu.lusup.data()[luptr+nsupc]), nrow, nsupc, OuterStride<>(lda) );
173  VectorBlock<ScalarVector> l(glu.lusup, ufirst+nsupc, nrow);
174  l.noalias() -= A * u;
175 
176  } // End if fst_col
177  return 0;
178 }
179 
180 } // end namespace internal
181 } // end namespace Eigen
182 
183 #endif // SPARSELU_COLUMN_BMOD_H
MatrixXcf A
bfloat16() max(const bfloat16 &a, const bfloat16 &b)
Definition: BFloat16.h:690
: InteropHeaders
Definition: Core:139
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition: Meta.h:82