Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-04-19 09:06:42

0001 // This file is part of Eigen, a lightweight C++ template library
0002 // for linear algebra.
0003 //
0004 // Copyright (C) 2012 Désiré Nuentsa-Wakam <desire.nuentsa_wakam@inria.fr>
0005 // Copyright (C) 2012 Gael Guennebaud <gael.guennebaud@inria.fr>
0006 //
0007 // This Source Code Form is subject to the terms of the Mozilla
0008 // Public License v. 2.0. If a copy of the MPL was not distributed
0009 // with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
0010 
0011 /* 
0012  
0013  * NOTE: This file is the modified version of xcolumn_bmod.c file in SuperLU 
0014  
0015  * -- SuperLU routine (version 3.0) --
0016  * Univ. of California Berkeley, Xerox Palo Alto Research Center,
0017  * and Lawrence Berkeley National Lab.
0018  * October 15, 2003
0019  *
0020  * Copyright (c) 1994 by Xerox Corporation.  All rights reserved.
0021  *
0022  * THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY
0023  * EXPRESSED OR IMPLIED.  ANY USE IS AT YOUR OWN RISK.
0024  *
0025  * Permission is hereby granted to use or copy this program for any
0026  * purpose, provided the above notices are retained on all copies.
0027  * Permission to modify the code and to distribute modified code is
0028  * granted, provided the above notices are retained, and a notice that
0029  * the code was modified is included with the above copyright notice.
0030  */
0031 #ifndef SPARSELU_COLUMN_BMOD_H
0032 #define SPARSELU_COLUMN_BMOD_H
0033 
0034 namespace RivetEigen {
0035 
0036 namespace internal {
0037 /**
0038  * \brief Performs numeric block updates (sup-col) in topological order
0039  * 
0040  * \param jcol current column to update
0041  * \param nseg Number of segments in the U part
0042  * \param dense Store the full representation of the column
0043  * \param tempv working array 
0044  * \param segrep segment representative ...
0045  * \param repfnz ??? First nonzero column in each row ???  ...
0046  * \param fpanelc First column in the current panel
0047  * \param glu Global LU data. 
0048  * \return 0 - successful return 
0049  *         > 0 - number of bytes allocated when run out of space
0050  * 
0051  */
0052 template <typename Scalar, typename StorageIndex>
0053 Index SparseLUImpl<Scalar,StorageIndex>::column_bmod(const Index jcol, const Index nseg, BlockScalarVector dense, ScalarVector& tempv,
0054                                                      BlockIndexVector segrep, BlockIndexVector repfnz, Index fpanelc, GlobalLU_t& glu)
0055 {
0056   Index  jsupno, k, ksub, krep, ksupno; 
0057   Index lptr, nrow, isub, irow, nextlu, new_next, ufirst; 
0058   Index fsupc, nsupc, nsupr, luptr, kfnz, no_zeros; 
0059   /* krep = representative of current k-th supernode
0060     * fsupc =  first supernodal column
0061     * nsupc = number of columns in a supernode
0062     * nsupr = number of rows in a supernode
0063     * luptr = location of supernodal LU-block in storage
0064     * kfnz = first nonz in the k-th supernodal segment
0065     * no_zeros = no lf leading zeros in a supernodal U-segment
0066     */
0067   
0068   jsupno = glu.supno(jcol);
0069   // For each nonzero supernode segment of U[*,j] in topological order 
0070   k = nseg - 1; 
0071   Index d_fsupc; // distance between the first column of the current panel and the 
0072                // first column of the current snode
0073   Index fst_col; // First column within small LU update
0074   Index segsize; 
0075   for (ksub = 0; ksub < nseg; ksub++)
0076   {
0077     krep = segrep(k); k--; 
0078     ksupno = glu.supno(krep); 
0079     if (jsupno != ksupno )
0080     {
0081       // outside the rectangular supernode 
0082       fsupc = glu.xsup(ksupno); 
0083       fst_col = (std::max)(fsupc, fpanelc); 
0084       
0085       // Distance from the current supernode to the current panel; 
0086       // d_fsupc = 0 if fsupc > fpanelc
0087       d_fsupc = fst_col - fsupc; 
0088       
0089       luptr = glu.xlusup(fst_col) + d_fsupc; 
0090       lptr = glu.xlsub(fsupc) + d_fsupc; 
0091       
0092       kfnz = repfnz(krep); 
0093       kfnz = (std::max)(kfnz, fpanelc); 
0094       
0095       segsize = krep - kfnz + 1; 
0096       nsupc = krep - fst_col + 1; 
0097       nsupr = glu.xlsub(fsupc+1) - glu.xlsub(fsupc); 
0098       nrow = nsupr - d_fsupc - nsupc;
0099       Index lda = glu.xlusup(fst_col+1) - glu.xlusup(fst_col);
0100       
0101       
0102       // Perform a triangular solver and block update, 
0103       // then scatter the result of sup-col update to dense
0104       no_zeros = kfnz - fst_col; 
0105       if(segsize==1)
0106         LU_kernel_bmod<1>::run(segsize, dense, tempv, glu.lusup, luptr, lda, nrow, glu.lsub, lptr, no_zeros);
0107       else
0108         LU_kernel_bmod<Dynamic>::run(segsize, dense, tempv, glu.lusup, luptr, lda, nrow, glu.lsub, lptr, no_zeros);
0109     } // end if jsupno 
0110   } // end for each segment
0111   
0112   // Process the supernodal portion of  L\U[*,j]
0113   nextlu = glu.xlusup(jcol); 
0114   fsupc = glu.xsup(jsupno);
0115   
0116   // copy the SPA dense into L\U[*,j]
0117   Index mem; 
0118   new_next = nextlu + glu.xlsub(fsupc + 1) - glu.xlsub(fsupc); 
0119   Index offset = internal::first_multiple<Index>(new_next, internal::packet_traits<Scalar>::size) - new_next;
0120   if(offset)
0121     new_next += offset;
0122   while (new_next > glu.nzlumax )
0123   {
0124     mem = memXpand<ScalarVector>(glu.lusup, glu.nzlumax, nextlu, LUSUP, glu.num_expansions);  
0125     if (mem) return mem; 
0126   }
0127   
0128   for (isub = glu.xlsub(fsupc); isub < glu.xlsub(fsupc+1); isub++)
0129   {
0130     irow = glu.lsub(isub);
0131     glu.lusup(nextlu) = dense(irow);
0132     dense(irow) = Scalar(0.0); 
0133     ++nextlu; 
0134   }
0135   
0136   if(offset)
0137   {
0138     glu.lusup.segment(nextlu,offset).setZero();
0139     nextlu += offset;
0140   }
0141   glu.xlusup(jcol + 1) = StorageIndex(nextlu);  // close L\U(*,jcol); 
0142   
0143   /* For more updates within the panel (also within the current supernode),
0144    * should start from the first column of the panel, or the first column
0145    * of the supernode, whichever is bigger. There are two cases:
0146    *  1) fsupc < fpanelc, then fst_col <-- fpanelc
0147    *  2) fsupc >= fpanelc, then fst_col <-- fsupc
0148    */
0149   fst_col = (std::max)(fsupc, fpanelc); 
0150   
0151   if (fst_col  < jcol)
0152   {
0153     // Distance between the current supernode and the current panel
0154     // d_fsupc = 0 if fsupc >= fpanelc
0155     d_fsupc = fst_col - fsupc; 
0156     
0157     lptr = glu.xlsub(fsupc) + d_fsupc; 
0158     luptr = glu.xlusup(fst_col) + d_fsupc; 
0159     nsupr = glu.xlsub(fsupc+1) - glu.xlsub(fsupc); // leading dimension
0160     nsupc = jcol - fst_col; // excluding jcol 
0161     nrow = nsupr - d_fsupc - nsupc; 
0162     
0163     // points to the beginning of jcol in snode L\U(jsupno) 
0164     ufirst = glu.xlusup(jcol) + d_fsupc; 
0165     Index lda = glu.xlusup(jcol+1) - glu.xlusup(jcol);
0166     MappedMatrixBlock A( &(glu.lusup.data()[luptr]), nsupc, nsupc, OuterStride<>(lda) );
0167     VectorBlock<ScalarVector> u(glu.lusup, ufirst, nsupc); 
0168     u = A.template triangularView<UnitLower>().solve(u); 
0169     
0170     new (&A) MappedMatrixBlock ( &(glu.lusup.data()[luptr+nsupc]), nrow, nsupc, OuterStride<>(lda) );
0171     VectorBlock<ScalarVector> l(glu.lusup, ufirst+nsupc, nrow); 
0172     l.noalias() -= A * u;
0173     
0174   } // End if fst_col
0175   return 0; 
0176 }
0177 
0178 } // end namespace internal
0179 } // end namespace RivetEigen
0180 
0181 #endif // SPARSELU_COLUMN_BMOD_H