TSFIncrementallyConfigurableMatrixFactory.hpp
Go to the documentation of this file.
00001 /* @HEADER@ */
00002 /* ***********************************************************************
00003 // 
00004 //           TSFExtended: Trilinos Solver Framework Extended
00005 //                 Copyright (2004) Sandia Corporation
00006 // 
00007 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
00008 // license for use of this work by or on behalf of the U.S. Government.
00009 // 
00010 // This library is free software; you can redistribute it and/or modify
00011 // it under the terms of the GNU Lesser General Public License as
00012 // published by the Free Software Foundation; either version 2.1 of the
00013 // License, or (at your option) any later version.
00014 //  
00015 // This library is distributed in the hope that it will be useful, but
00016 // WITHOUT ANY WARRANTY; without even the implied warranty of
00017 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00018 // Lesser General Public License for more details.
00019 //  
00020 // You should have received a copy of the GNU Lesser General Public
00021 // License along with this library; if not, write to the Free Software
00022 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
00023 // USA
00024 // Questions? Contact Michael A. Heroux (maherou@sandia.gov) 
00025 // 
00026 // **********************************************************************/
00027 /* @HEADER@ */
00028 
00029 #ifndef TSF_INCREMENTALLYCONFIGURABLEMATRIXFACTORY_HPP
00030 #define TSF_INCREMENTALLYCONFIGURABLEMATRIXFACTORY_HPP
00031 
00032 #include "SundanceDefs.hpp"
00033 
00034 namespace TSFExtended
00035 {
00036   /** 
00037    * Class IncrementallyConfigurableMatrixFactory provides an abstract 
00038    * interface for row-at-a-time configuration of matrix factories.
00039    */
00040   class IncrementallyConfigurableMatrixFactory
00041   {
00042   public:
00043     /** Virtual dtor */
00044     virtual ~IncrementallyConfigurableMatrixFactory(){;}
00045 
00046     /** Initialize a set of nonzero elements in the matrix's graph.
00047      * @param globalRowIndex the global index of the row to which these
00048      * elements belong.
00049      * @param nElemsToInsert the number of elements being inserted in this
00050      * step
00051      * @param globalColumnIndices array of column indices. Must 
00052      * be nElemsToInsert in length. 
00053      */
00054     virtual void initializeNonzerosInRow(int globalRowIndex,
00055                                          int nElemsToInsert,
00056                                          const int* globalColumnIndices) = 0 ;
00057 
00058     /** 
00059      * Initialize nonzeros in a batch of rows. 
00060      */
00061     virtual void initializeNonzeroBatch(int numRows, 
00062                                         int rowBlockSize,
00063                                         const int* globalRowIndices,
00064                                         int numColumnsPerRow,
00065                                         const int* globalColumnIndices,
00066                                         const int* skipRow);
00067 
00068     /** Finalize values of the matrix. This is a hook for any
00069      * implementation-dependent steps that must be done after
00070      * loading of elements. */
00071     virtual void finalize() = 0 ;
00072 
00073   private:
00074     
00075     
00076   };
00077 
00078   /* Default implementation of initializeElementBatch */
00079   inline void IncrementallyConfigurableMatrixFactory
00080   ::initializeNonzeroBatch(int numRows, 
00081                            int rowBlockSize,
00082                            const int* globalRowIndices,
00083                            int numColumnsPerRow,
00084                            const int* globalColumnIndices,
00085                            const int* skipRow)
00086   {
00087     int numRowBlocks = numRows/rowBlockSize;
00088     int row = 0;
00089 
00090     for (int rb=0; rb<numRowBlocks; rb++)
00091       {
00092         const int* cols = globalColumnIndices + rb*numColumnsPerRow;
00093         for (int r=0; r<rowBlockSize; r++, row++)
00094           {
00095             if (skipRow[row]) continue;
00096             initializeNonzerosInRow(globalRowIndices[row], 
00097                                     numColumnsPerRow, cols);
00098           }
00099       }
00100   }
00101 }
00102 
00103 #endif

Site Contact