Amesos Package Browser (Single Doxygen Collection) Development
Amesos_Klu.h
Go to the documentation of this file.
00001 // @HEADER
00002 // ***********************************************************************
00003 // 
00004 //                Amesos: Direct Sparse Solver Package
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 
00039 #ifndef AMESOS_KLU_H
00040 #define AMESOS_KLU_H
00041 
00042 #include "Amesos_ConfigDefs.h"
00043 #include "Amesos_BaseSolver.h"
00044 #include "Amesos_NoCopiable.h"
00045 #include "Amesos_Utils.h"
00046 #include "Amesos_Time.h"
00047 #include "Amesos_Status.h"
00048 #include "Amesos_Control.h"
00049 #include "Epetra_LinearProblem.h"
00050 #include "Epetra_Time.h"
00051 #include "Epetra_Import.h"
00052 #ifdef EPETRA_MPI
00053 #include "Epetra_MpiComm.h"
00054 #else
00055 #include "Epetra_Comm.h"
00056 #endif
00057 #include "Epetra_CrsGraph.h"
00058 #include "Epetra_CrsMatrix.h"
00059 
00060 // class EpetraExt::MultiVector_Reindex ;
00061 // class EpetraExt::CrsMatrix_Reindex ;
00063 
00101 // Amesos_Klu_Pimpl contains a pointer to two structures defined in 
00102 // klu.h:  klu_symbolic and klu_numeric.  This prevents Amesos_Klu.h 
00103 // from having to include klu.h.
00104 //
00105 //  Doxygen does not handle forward class references well.
00106 #ifndef DOXYGEN_SHOULD_SKIP_THIS
00107 class Amesos_Klu_Pimpl ; 
00108 class Amesos_StandardIndex ; 
00109 #endif
00110 
00111 class Amesos_Klu: public Amesos_BaseSolver,  
00112                   private Amesos_Time, 
00113                   private Amesos_NoCopiable, 
00114                   private Amesos_Utils, 
00115                   private Amesos_Control, 
00116                   private Amesos_Status { 
00117 
00118 public: 
00119 
00121 
00122 
00129   Amesos_Klu(const Epetra_LinearProblem& LinearProblem );
00130 
00132   ~Amesos_Klu(void);
00133   
00135 
00136 
00137   int SymbolicFactorization() ;
00138 
00139   int NumericFactorization() ;
00140 
00141   int Solve();
00142 
00144 
00145 
00147   const Epetra_LinearProblem *GetProblem() const { return(Problem_); };
00148 
00150 
00153   bool MatrixShapeOK() const ;
00154 
00156 
00160   int SetUseTranspose(bool UseTranspose_in) {UseTranspose_ = UseTranspose_in; return(0);};
00161 
00162   bool UseTranspose() const {return(UseTranspose_);};
00163 
00164   const Epetra_Comm & Comm() const {return(GetProblem()->GetOperator()->Comm());};
00165 
00166   int SetParameters( Teuchos::ParameterList &ParameterList );
00167 
00169   int NumSymbolicFact() const { return( Amesos_Status::NumSymbolicFact_ ); }
00170 
00172   int NumNumericFact() const { return( Amesos_Status::NumNumericFact_ ); }
00173 
00175   int NumSolve() const { return( Amesos_Status::NumSolve_ ); }
00176 
00178   void PrintTiming() const;
00179   
00181   void PrintStatus() const;
00182 
00184   void GetTiming( Teuchos::ParameterList &TimingParameterList ) const { Amesos_Time::GetTiming( TimingParameterList ); }
00185   
00186 private:  
00187   
00189 
00190 
00191   /*
00192   CreateLocalMatrixAndExporters - Prepare to convert matrix and vectors to serial 
00193     Preconditions:
00194       Problem_ must be set 
00195   
00196     Postconditions:
00197       UseDataInPlace_ is set to 1 if the input matrix can be used in place, i.e.
00198         1)  is entirely stored on process 0
00199         2)  range map and domain map are same as the row map
00200       The following are only set if (! UseDataInPlace_ )"
00201         SerialMap_ 
00202   ImportToSerial_
00203   SerialCrsMatrixA_ 
00204 
00205       SerialMatrix_ 
00206    */
00207   int CreateLocalMatrixAndExporters() ;
00208   /*
00209     ExportToSerial
00210     Preconditions:
00211        UseDataInPlace_ must be set
00212        ImportToSerial and SerialCrsMatrixA_ must be set if UseDataInPlace_ != 1
00213     Postconditions
00214        SerialMatrix_ points to a serial version of the matrix
00215    */
00216   int ExportToSerial() ;
00217   /*
00218     ConvertToKluCRS - Convert matrix to form expected by Klu: Ai, Ap, Aval
00219     Preconditions:
00220       numentries_, RowMatrixA_, ImportToSerial_, StdIndexMatrix_, Reindex_ 
00221     Postconditions:
00222       SerialCrsMatrixA_
00223   */
00224   int ConvertToKluCRS(bool firsttime);     
00225 
00226   /*
00227     PerformSymbolicFactorization - Call Klu to perform symbolic factorization
00228     Preconditions:
00229       UseDataInPlace_ must be set to 1 if the input matrix is entirely stored on process 0
00230       Ap, Ai and Aval point to a compressed row storage version of the input matrix A.
00231     Postconditions:
00232       Symbolic points to an KLU internal opaque object containing the
00233         symbolic factorization and accompanying information.  
00234       SymbolicFactorizationOK_ = true; 
00235     Note:  All action is performed on process 0
00236 
00237     Returns non-zero if the symbolic factorization failed
00238   */
00239       
00240   int PerformSymbolicFactorization(); 
00241 
00242   /*
00243     PerformNumericFactorization - Call Klu to perform numeric factorization
00244     Preconditions:
00245       UseDataInPlace_ must be set 
00246       Ap, Ai and Aval point to a compressed row storage version of the input matrix A.
00247       Symbolic must be set
00248     Postconditions:
00249       Numeric points to an KLU internal opaque object containing the
00250         numeric factorization and accompanying information.  
00251       NumericFactorizationOK_ = true; 
00252     Note:  All action is performed on process 0
00253   */
00254   int PerformNumericFactorization(); 
00255 
00256   // @}
00257   
00258   int SerialXlda_ ;
00259 
00260 #ifdef Bug_8212
00261   int *lose_this_;
00262 #endif
00263   //
00264   //  PrivateKluData_ contains pointers to data needed by klu whose
00265   //  data structures are defined by klu.h
00266   //
00267   Teuchos::RCP<Amesos_Klu_Pimpl> PrivateKluData_; 
00268   Teuchos::RCP<Amesos_StandardIndex> StdIndex_; 
00269   Teuchos::RCP<Amesos_StandardIndex> StdIndexRange_; 
00270   Teuchos::RCP<Amesos_StandardIndex> StdIndexDomain_; 
00271 
00276   std::vector <int> Ap;
00277   std::vector <int> VecAi;
00278   std::vector <double> VecAval;
00279   double* Aval;
00280   int *Ai;
00281 
00283   int UseDataInPlace_;
00285   int numentries_;
00287   int NumGlobalElements_;
00288 
00290   Epetra_RowMatrix* RowMatrixA_;
00292   Epetra_CrsMatrix* CrsMatrixA_;
00293 #if 0
00294 
00295   Teuchos::RCP<EpetraExt::MultiVector_Reindex> VecTrans_;
00297   Teuchos::RCP<EpetraExt::CrsMatrix_Reindex> MatTrans_;
00299   Teuchos::RCP<Epetra_Map> ContiguousMap_;
00300 #endif
00301 
00302   Teuchos::RCP<Epetra_Map> SerialMap_;
00304   Teuchos::RCP<Epetra_CrsMatrix> SerialCrsMatrixA_;
00306   Epetra_RowMatrix* StdIndexMatrix_ ; 
00307   Epetra_MultiVector* StdIndexDomainVector_ ; 
00308   Epetra_MultiVector* StdIndexRangeVector_ ; 
00310   Epetra_RowMatrix* SerialMatrix_ ; 
00311 
00313   //  serially, StorageOptimized, the LHS and RHS are assumed to be available 
00314   //  when SymbolicFactorization is called and not to change (address or number
00315   //  of vectors) thereafter.  
00316   bool TrustMe_;
00318   int NumVectors_; 
00320   double *SerialXBvalues_ ;
00321   double *SerialBvalues_ ;
00323   Teuchos::RCP<Epetra_MultiVector> SerialB_ ;
00324   Teuchos::RCP<Epetra_MultiVector> SerialX_ ;
00326   Teuchos::RCP<Epetra_MultiVector> SerialXextract_;
00327   Teuchos::RCP<Epetra_MultiVector> SerialBextract_;
00328 
00330   bool UseTranspose_;
00332   const Epetra_LinearProblem * Problem_;
00333 
00335   std::vector<int> ColIndicesV_;
00337   std::vector<double> RowValuesV_;
00339   Teuchos::RCP<Epetra_Import> ImportToSerial_;
00340   Teuchos::RCP<Epetra_Import> ImportRangeToSerial_;
00341   Teuchos::RCP<Epetra_Import> ImportDomainToSerial_;
00343   int MtxRedistTime_, MtxConvTime_, VecRedistTime_;
00344   int SymFactTime_, NumFactTime_, SolveTime_, OverheadTime_;
00345 
00346 };  // class Amesos_Klu  
00347 
00348 #endif /* AMESOS_KLU_H */
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines