2012-05-30 18:09:26 +02:00
|
|
|
// This file is part of Eigen, a lightweight C++ template library
|
|
|
|
|
// for linear algebra.
|
|
|
|
|
//
|
|
|
|
|
// Copyright (C) 2012 Désiré Nuentsa-Wakam <desire.nuentsa_wakam@inria.fr>
|
|
|
|
|
//
|
|
|
|
|
// Eigen is free software; you can redistribute it and/or
|
|
|
|
|
// modify it under the terms of the GNU Lesser General Public
|
|
|
|
|
// License as published by the Free Software Foundation; either
|
|
|
|
|
// version 3 of the License, or (at your option) any later version.
|
|
|
|
|
//
|
|
|
|
|
// Alternatively, you can redistribute it and/or
|
|
|
|
|
// modify it under the terms of the GNU General Public License as
|
|
|
|
|
// published by the Free Software Foundation; either version 2 of
|
|
|
|
|
// the License, or (at your option) any later version.
|
|
|
|
|
//
|
|
|
|
|
// Eigen is distributed in the hope that it will be useful, but WITHOUT ANY
|
|
|
|
|
// WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
|
|
|
|
// FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License or the
|
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
|
//
|
|
|
|
|
// You should have received a copy of the GNU Lesser General Public
|
|
|
|
|
// License and a copy of the GNU General Public License along with
|
|
|
|
|
// Eigen. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
|
|
|
|
* NOTE: This file is the modified version of xcolumn_bmod.c file in SuperLU
|
|
|
|
|
|
|
|
|
|
* -- SuperLU routine (version 3.0) --
|
|
|
|
|
* Univ. of California Berkeley, Xerox Palo Alto Research Center,
|
|
|
|
|
* and Lawrence Berkeley National Lab.
|
|
|
|
|
* October 15, 2003
|
|
|
|
|
*
|
|
|
|
|
* Copyright (c) 1994 by Xerox Corporation. All rights reserved.
|
|
|
|
|
*
|
|
|
|
|
* THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY
|
|
|
|
|
* EXPRESSED OR IMPLIED. ANY USE IS AT YOUR OWN RISK.
|
|
|
|
|
*
|
|
|
|
|
* Permission is hereby granted to use or copy this program for any
|
|
|
|
|
* purpose, provided the above notices are retained on all copies.
|
|
|
|
|
* Permission to modify the code and to distribute modified code is
|
|
|
|
|
* granted, provided the above notices are retained, and a notice that
|
|
|
|
|
* the code was modified is included with the above copyright notice.
|
|
|
|
|
*/
|
|
|
|
|
#ifndef SPARSELU_COLUMN_BMOD_H
|
|
|
|
|
#define SPARSELU_COLUMN_BMOD_H
|
2012-06-13 18:26:05 +02:00
|
|
|
|
2012-05-30 18:09:26 +02:00
|
|
|
/**
|
|
|
|
|
* \brief Performs numeric block updates (sup-col) in topological order
|
|
|
|
|
*
|
|
|
|
|
* \param jcol current column to update
|
|
|
|
|
* \param nseg Number of segments in the U part
|
|
|
|
|
* \param dense Store the full representation of the column
|
|
|
|
|
* \param tempv working array
|
|
|
|
|
* \param segrep segment representative ...
|
|
|
|
|
* \param repfnz ??? First nonzero column in each row ??? ...
|
|
|
|
|
* \param fpanelc First column in the current panel
|
2012-06-12 18:19:59 +02:00
|
|
|
* \param glu Global LU data.
|
2012-05-30 18:09:26 +02:00
|
|
|
* \return 0 - successful return
|
|
|
|
|
* > 0 - number of bytes allocated when run out of space
|
|
|
|
|
*
|
|
|
|
|
*/
|
2012-06-14 18:45:04 +02:00
|
|
|
template <typename IndexVector, typename ScalarVector, typename BlockIndexVector, typename BlockScalarVector>
|
|
|
|
|
int LU_column_bmod(const int jcol, const int nseg, BlockScalarVector& dense, ScalarVector& tempv, BlockIndexVector& segrep, BlockIndexVector& repfnz, int fpanelc, LU_GlobalLU_t<IndexVector, ScalarVector>& glu)
|
2012-05-30 18:09:26 +02:00
|
|
|
{
|
2012-06-14 18:45:04 +02:00
|
|
|
typedef typename IndexVector::Scalar Index;
|
2012-06-13 18:26:05 +02:00
|
|
|
typedef typename ScalarVector::Scalar Scalar;
|
2012-06-14 18:45:04 +02:00
|
|
|
int jsupno, k, ksub, krep, ksupno;
|
2012-06-13 18:26:05 +02:00
|
|
|
int lptr, nrow, isub, i, irow, nextlu, new_next, ufirst;
|
2012-06-12 18:19:59 +02:00
|
|
|
int fsupc, nsupc, nsupr, luptr, kfnz, no_zeros;
|
2012-05-30 18:09:26 +02:00
|
|
|
/* krep = representative of current k-th supernode
|
|
|
|
|
* fsupc = first supernodal column
|
|
|
|
|
* nsupc = number of columns in a supernode
|
|
|
|
|
* nsupr = number of rows in a supernode
|
|
|
|
|
* luptr = location of supernodal LU-block in storage
|
|
|
|
|
* kfnz = first nonz in the k-th supernodal segment
|
2012-06-12 18:19:59 +02:00
|
|
|
* no_zeros = no lf leading zeros in a supernodal U-segment
|
2012-05-30 18:09:26 +02:00
|
|
|
*/
|
2012-06-12 18:19:59 +02:00
|
|
|
IndexVector& xsup = glu.xsup;
|
|
|
|
|
IndexVector& supno = glu.supno;
|
|
|
|
|
IndexVector& lsub = glu.lsub;
|
|
|
|
|
IndexVector& xlsub = glu.xlsub;
|
|
|
|
|
IndexVector& xlusup = glu.xlusup;
|
|
|
|
|
ScalarVector& lusup = glu.lusup;
|
|
|
|
|
Index& nzlumax = glu.nzlumax;
|
2012-06-07 19:06:22 +02:00
|
|
|
|
2012-06-13 18:26:05 +02:00
|
|
|
jsupno = supno(jcol);
|
2012-05-30 18:09:26 +02:00
|
|
|
// For each nonzero supernode segment of U[*,j] in topological order
|
|
|
|
|
k = nseg - 1;
|
2012-06-12 18:19:59 +02:00
|
|
|
int d_fsupc; // distance between the first column of the current panel and the
|
|
|
|
|
// first column of the current snode
|
|
|
|
|
int fst_col; // First column within small LU update
|
|
|
|
|
int segsize;
|
2012-05-30 18:09:26 +02:00
|
|
|
for (ksub = 0; ksub < nseg; ksub++)
|
|
|
|
|
{
|
|
|
|
|
krep = segrep(k); k--;
|
|
|
|
|
ksupno = supno(krep);
|
|
|
|
|
if (jsupno != ksupno )
|
|
|
|
|
{
|
|
|
|
|
// outside the rectangular supernode
|
|
|
|
|
fsupc = xsup(ksupno);
|
|
|
|
|
fst_col = std::max(fsupc, fpanelc);
|
|
|
|
|
|
|
|
|
|
// Distance from the current supernode to the current panel;
|
|
|
|
|
// d_fsupc = 0 if fsupc > fpanelc
|
|
|
|
|
d_fsupc = fst_col - fsupc;
|
|
|
|
|
|
|
|
|
|
luptr = xlusup(fst_col) + d_fsupc;
|
|
|
|
|
lptr = xlsub(fsupc) + d_fsupc;
|
|
|
|
|
|
|
|
|
|
kfnz = repfnz(krep);
|
|
|
|
|
kfnz = std::max(kfnz, fpanelc);
|
|
|
|
|
|
|
|
|
|
segsize = krep - kfnz + 1;
|
|
|
|
|
nsupc = krep - fst_col + 1;
|
|
|
|
|
nsupr = xlsub(fsupc+1) - xlsub(fsupc);
|
|
|
|
|
nrow = nsupr - d_fsupc - nsupc;
|
|
|
|
|
|
|
|
|
|
// NOTE Unlike the original implementation in SuperLU, the only feature
|
2012-06-12 18:19:59 +02:00
|
|
|
// available here is a sup-col update.
|
2012-05-30 18:09:26 +02:00
|
|
|
|
|
|
|
|
// Perform a triangular solver and block update,
|
|
|
|
|
// then scatter the result of sup-col update to dense
|
|
|
|
|
no_zeros = kfnz - fst_col;
|
|
|
|
|
// First, copy U[*,j] segment from dense(*) to tempv(*)
|
|
|
|
|
isub = lptr + no_zeros;
|
2012-06-12 18:19:59 +02:00
|
|
|
for (i = 0; i < segsize; i++)
|
2012-05-30 18:09:26 +02:00
|
|
|
{
|
|
|
|
|
irow = lsub(isub);
|
2012-06-12 18:19:59 +02:00
|
|
|
tempv(i) = dense(irow);
|
2012-05-30 18:09:26 +02:00
|
|
|
++isub;
|
|
|
|
|
}
|
|
|
|
|
// Dense triangular solve -- start effective triangle
|
|
|
|
|
luptr += nsupr * no_zeros + no_zeros;
|
|
|
|
|
// Form Eigen matrix and vector
|
|
|
|
|
Map<Matrix<Scalar,Dynamic,Dynamic>, 0, OuterStride<> > A( &(lusup.data()[luptr]), segsize, segsize, OuterStride<>(nsupr) );
|
2012-06-12 18:19:59 +02:00
|
|
|
VectorBlock<ScalarVector> u(tempv, 0, segsize);
|
|
|
|
|
|
2012-06-13 18:26:05 +02:00
|
|
|
u = A.template triangularView<Lower>().solve(u);
|
2012-05-30 18:09:26 +02:00
|
|
|
|
|
|
|
|
// Dense matrix-vector product y <-- A*x
|
|
|
|
|
luptr += segsize;
|
2012-06-12 18:19:59 +02:00
|
|
|
new (&A) Map<Matrix<Scalar,Dynamic, Dynamic>, 0, OuterStride<> > ( &(lusup.data()[luptr]), nrow, segsize, OuterStride<>(nsupr) );
|
|
|
|
|
VectorBlock<ScalarVector> l(tempv, segsize, nrow);
|
2012-05-30 18:09:26 +02:00
|
|
|
l= A * u;
|
|
|
|
|
|
|
|
|
|
// Scatter tempv[] into SPA dense[] as a temporary storage
|
|
|
|
|
isub = lptr + no_zeros;
|
2012-06-12 18:19:59 +02:00
|
|
|
for (i = 0; i < segsize; i++)
|
2012-05-30 18:09:26 +02:00
|
|
|
{
|
|
|
|
|
irow = lsub(isub);
|
|
|
|
|
dense(irow) = tempv(i);
|
|
|
|
|
tempv(i) = Scalar(0.0);
|
|
|
|
|
++isub;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Scatter l into SPA dense[]
|
|
|
|
|
for (i = 0; i < nrow; i++)
|
|
|
|
|
{
|
|
|
|
|
irow = lsub(isub);
|
2012-06-12 18:19:59 +02:00
|
|
|
dense(irow) -= l(i);
|
|
|
|
|
l(i) = Scalar(0.0);
|
2012-05-30 18:09:26 +02:00
|
|
|
++isub;
|
|
|
|
|
}
|
|
|
|
|
} // end if jsupno
|
|
|
|
|
} // end for each segment
|
|
|
|
|
|
|
|
|
|
// Process the supernodal portion of L\U[*,j]
|
|
|
|
|
nextlu = xlusup(jcol);
|
|
|
|
|
fsupc = xsup(jsupno);
|
|
|
|
|
|
|
|
|
|
// copy the SPA dense into L\U[*,j]
|
2012-06-13 18:26:05 +02:00
|
|
|
int mem;
|
2012-05-30 18:09:26 +02:00
|
|
|
new_next = nextlu + xlsub(fsupc + 1) - xlsub(fsupc);
|
|
|
|
|
while (new_next > nzlumax )
|
|
|
|
|
{
|
2012-06-13 18:26:05 +02:00
|
|
|
mem = LUMemXpand<ScalarVector>(glu.lusup, nzlumax, nextlu, LUSUP, glu.num_expansions);
|
2012-06-07 19:06:22 +02:00
|
|
|
if (mem) return mem;
|
2012-05-30 18:09:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (isub = xlsub(fsupc); isub < xlsub(fsupc+1); isub++)
|
|
|
|
|
{
|
|
|
|
|
irow = lsub(isub);
|
2012-06-13 18:26:05 +02:00
|
|
|
lusup(nextlu) = dense(irow);
|
2012-05-30 18:09:26 +02:00
|
|
|
dense(irow) = Scalar(0.0);
|
|
|
|
|
++nextlu;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
xlusup(jcol + 1) = nextlu; // close L\U(*,jcol);
|
|
|
|
|
|
|
|
|
|
/* For more updates within the panel (also within the current supernode),
|
|
|
|
|
* should start from the first column of the panel, or the first column
|
|
|
|
|
* of the supernode, whichever is bigger. There are two cases:
|
2012-06-12 18:19:59 +02:00
|
|
|
* 1) fsupc < fpanelc, then fst_col <-- fpanelc
|
|
|
|
|
* 2) fsupc >= fpanelc, then fst_col <-- fsupc
|
2012-05-30 18:09:26 +02:00
|
|
|
*/
|
|
|
|
|
fst_col = std::max(fsupc, fpanelc);
|
|
|
|
|
|
|
|
|
|
if (fst_col < jcol)
|
|
|
|
|
{
|
|
|
|
|
// Distance between the current supernode and the current panel
|
|
|
|
|
// d_fsupc = 0 if fsupc >= fpanelc
|
|
|
|
|
d_fsupc = fst_col - fsupc;
|
|
|
|
|
|
|
|
|
|
lptr = xlsub(fsupc) + d_fsupc;
|
|
|
|
|
luptr = xlusup(fst_col) + d_fsupc;
|
|
|
|
|
nsupr = xlsub(fsupc+1) - xlsub(fsupc); // leading dimension
|
|
|
|
|
nsupc = jcol - fst_col; // excluding jcol
|
|
|
|
|
nrow = nsupr - d_fsupc - nsupc;
|
|
|
|
|
|
|
|
|
|
// points to the beginning of jcol in snode L\U(jsupno)
|
|
|
|
|
ufirst = xlusup(jcol) + d_fsupc;
|
|
|
|
|
Map<Matrix<Scalar,Dynamic,Dynamic>, 0, OuterStride<> > A( &(lusup.data()[luptr]), nsupc, nsupc, OuterStride<>(nsupr) );
|
2012-06-12 18:19:59 +02:00
|
|
|
VectorBlock<ScalarVector> u(lusup, ufirst, nsupc);
|
2012-06-14 18:45:04 +02:00
|
|
|
u = A.template triangularView<Lower>().solve(u);
|
2012-05-30 18:09:26 +02:00
|
|
|
|
|
|
|
|
new (&A) Map<Matrix<Scalar,Dynamic,Dynamic>, 0, OuterStride<> > ( &(lusup.data()[luptr+nsupc]), nrow, nsupc, OuterStride<>(nsupr) );
|
2012-06-12 18:19:59 +02:00
|
|
|
VectorBlock<ScalarVector> l(lusup, ufirst+nsupc, nrow);
|
2012-05-30 18:09:26 +02:00
|
|
|
l = l - A * u;
|
|
|
|
|
|
|
|
|
|
} // End if fst_col
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
#endif
|