SparseLU_column_bmod.h
Go to the documentation of this file.
00001 // This file is part of Eigen, a lightweight C++ template library
00002 // for linear algebra.
00003 //
00004 // Copyright (C) 2012 Désiré Nuentsa-Wakam <desire.nuentsa_wakam@inria.fr>
00005 // Copyright (C) 2012 Gael Guennebaud <gael.guennebaud@inria.fr>
00006 //
00007 // This Source Code Form is subject to the terms of the Mozilla
00008 // Public License v. 2.0. If a copy of the MPL was not distributed
00009 // with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
00010 
00011 /* 
00012  
00013  * NOTE: This file is the modified version of xcolumn_bmod.c file in SuperLU 
00014  
00015  * -- SuperLU routine (version 3.0) --
00016  * Univ. of California Berkeley, Xerox Palo Alto Research Center,
00017  * and Lawrence Berkeley National Lab.
00018  * October 15, 2003
00019  *
00020  * Copyright (c) 1994 by Xerox Corporation.  All rights reserved.
00021  *
00022  * THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY
00023  * EXPRESSED OR IMPLIED.  ANY USE IS AT YOUR OWN RISK.
00024  *
00025  * Permission is hereby granted to use or copy this program for any
00026  * purpose, provided the above notices are retained on all copies.
00027  * Permission to modify the code and to distribute modified code is
00028  * granted, provided the above notices are retained, and a notice that
00029  * the code was modified is included with the above copyright notice.
00030  */
00031 #ifndef SPARSELU_COLUMN_BMOD_H
00032 #define SPARSELU_COLUMN_BMOD_H
00033 
00034 namespace Eigen {
00035 
00036 namespace internal {
00052 template <typename Scalar, typename Index>
00053 Index SparseLUImpl<Scalar,Index>::column_bmod(const Index jcol, const Index nseg, BlockScalarVector dense, ScalarVector& tempv, BlockIndexVector segrep, BlockIndexVector repfnz, Index fpanelc, GlobalLU_t& glu)
00054 {
00055   Index  jsupno, k, ksub, krep, ksupno; 
00056   Index lptr, nrow, isub, irow, nextlu, new_next, ufirst; 
00057   Index fsupc, nsupc, nsupr, luptr, kfnz, no_zeros; 
00058   /* krep = representative of current k-th supernode
00059     * fsupc =  first supernodal column
00060     * nsupc = number of columns in a supernode
00061     * nsupr = number of rows in a supernode
00062     * luptr = location of supernodal LU-block in storage
00063     * kfnz = first nonz in the k-th supernodal segment
00064     * no_zeros = no lf leading zeros in a supernodal U-segment
00065     */
00066   
00067   jsupno = glu.supno(jcol);
00068   // For each nonzero supernode segment of U[*,j] in topological order 
00069   k = nseg - 1; 
00070   Index d_fsupc; // distance between the first column of the current panel and the 
00071                // first column of the current snode
00072   Index fst_col; // First column within small LU update
00073   Index segsize; 
00074   for (ksub = 0; ksub < nseg; ksub++)
00075   {
00076     krep = segrep(k); k--; 
00077     ksupno = glu.supno(krep); 
00078     if (jsupno != ksupno )
00079     {
00080       // outside the rectangular supernode 
00081       fsupc = glu.xsup(ksupno); 
00082       fst_col = (std::max)(fsupc, fpanelc); 
00083       
00084       // Distance from the current supernode to the current panel; 
00085       // d_fsupc = 0 if fsupc > fpanelc
00086       d_fsupc = fst_col - fsupc; 
00087       
00088       luptr = glu.xlusup(fst_col) + d_fsupc; 
00089       lptr = glu.xlsub(fsupc) + d_fsupc; 
00090       
00091       kfnz = repfnz(krep); 
00092       kfnz = (std::max)(kfnz, fpanelc); 
00093       
00094       segsize = krep - kfnz + 1; 
00095       nsupc = krep - fst_col + 1; 
00096       nsupr = glu.xlsub(fsupc+1) - glu.xlsub(fsupc); 
00097       nrow = nsupr - d_fsupc - nsupc;
00098       Index lda = glu.xlusup(fst_col+1) - glu.xlusup(fst_col);
00099       
00100       
00101       // Perform a triangular solver and block update, 
00102       // then scatter the result of sup-col update to dense
00103       no_zeros = kfnz - fst_col; 
00104       if(segsize==1)
00105         LU_kernel_bmod<1>::run(segsize, dense, tempv, glu.lusup, luptr, lda, nrow, glu.lsub, lptr, no_zeros);
00106       else
00107         LU_kernel_bmod<Dynamic>::run(segsize, dense, tempv, glu.lusup, luptr, lda, nrow, glu.lsub, lptr, no_zeros);
00108     } // end if jsupno 
00109   } // end for each segment
00110   
00111   // Process the supernodal portion of  L\U[*,j]
00112   nextlu = glu.xlusup(jcol); 
00113   fsupc = glu.xsup(jsupno);
00114   
00115   // copy the SPA dense into L\U[*,j]
00116   Index mem; 
00117   new_next = nextlu + glu.xlsub(fsupc + 1) - glu.xlsub(fsupc); 
00118   Index offset = internal::first_multiple<Index>(new_next, internal::packet_traits<Scalar>::size) - new_next;
00119   if(offset)
00120     new_next += offset;
00121   while (new_next > glu.nzlumax )
00122   {
00123     mem = memXpand<ScalarVector>(glu.lusup, glu.nzlumax, nextlu, LUSUP, glu.num_expansions);  
00124     if (mem) return mem; 
00125   }
00126   
00127   for (isub = glu.xlsub(fsupc); isub < glu.xlsub(fsupc+1); isub++)
00128   {
00129     irow = glu.lsub(isub);
00130     glu.lusup(nextlu) = dense(irow);
00131     dense(irow) = Scalar(0.0); 
00132     ++nextlu; 
00133   }
00134   
00135   if(offset)
00136   {
00137     glu.lusup.segment(nextlu,offset).setZero();
00138     nextlu += offset;
00139   }
00140   glu.xlusup(jcol + 1) = nextlu;  // close L\U(*,jcol); 
00141   
00142   /* For more updates within the panel (also within the current supernode),
00143    * should start from the first column of the panel, or the first column
00144    * of the supernode, whichever is bigger. There are two cases:
00145    *  1) fsupc < fpanelc, then fst_col <-- fpanelc
00146    *  2) fsupc >= fpanelc, then fst_col <-- fsupc
00147    */
00148   fst_col = (std::max)(fsupc, fpanelc); 
00149   
00150   if (fst_col  < jcol)
00151   {
00152     // Distance between the current supernode and the current panel
00153     // d_fsupc = 0 if fsupc >= fpanelc
00154     d_fsupc = fst_col - fsupc; 
00155     
00156     lptr = glu.xlsub(fsupc) + d_fsupc; 
00157     luptr = glu.xlusup(fst_col) + d_fsupc; 
00158     nsupr = glu.xlsub(fsupc+1) - glu.xlsub(fsupc); // leading dimension
00159     nsupc = jcol - fst_col; // excluding jcol 
00160     nrow = nsupr - d_fsupc - nsupc; 
00161     
00162     // points to the beginning of jcol in snode L\U(jsupno) 
00163     ufirst = glu.xlusup(jcol) + d_fsupc; 
00164     Index lda = glu.xlusup(jcol+1) - glu.xlusup(jcol);
00165     Map<Matrix<Scalar,Dynamic,Dynamic>, 0,  OuterStride<> > A( &(glu.lusup.data()[luptr]), nsupc, nsupc, OuterStride<>(lda) ); 
00166     VectorBlock<ScalarVector> u(glu.lusup, ufirst, nsupc); 
00167     u = A.template triangularView<UnitLower>().solve(u); 
00168     
00169     new (&A) Map<Matrix<Scalar,Dynamic,Dynamic>, 0, OuterStride<> > ( &(glu.lusup.data()[luptr+nsupc]), nrow, nsupc, OuterStride<>(lda) ); 
00170     VectorBlock<ScalarVector> l(glu.lusup, ufirst+nsupc, nrow); 
00171     l.noalias() -= A * u;
00172     
00173   } // End if fst_col
00174   return 0; 
00175 }
00176 
00177 } // end namespace internal
00178 } // end namespace Eigen
00179 
00180 #endif // SPARSELU_COLUMN_BMOD_H


acado
Author(s): Milan Vukov, Rien Quirynen
autogenerated on Thu Aug 27 2015 12:00:34