Amesos2 - Direct Sparse Solver Interfaces Version of the Day
Amesos2_SolverCore_decl.hpp
Go to the documentation of this file.
00001 // @HEADER
00002 //
00003 // ***********************************************************************
00004 //
00005 //           Amesos2: Templated Direct Sparse Solver Package 
00006 //                  Copyright 2011 Sandia Corporation
00007 //
00008 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
00009 // the U.S. Government retains certain rights in this software.
00010 //
00011 // Redistribution and use in source and binary forms, with or without
00012 // modification, are permitted provided that the following conditions are
00013 // met:
00014 //
00015 // 1. Redistributions of source code must retain the above copyright
00016 // notice, this list of conditions and the following disclaimer.
00017 //
00018 // 2. Redistributions in binary form must reproduce the above copyright
00019 // notice, this list of conditions and the following disclaimer in the
00020 // documentation and/or other materials provided with the distribution.
00021 //
00022 // 3. Neither the name of the Corporation nor the names of the
00023 // contributors may be used to endorse or promote products derived from
00024 // this software without specific prior written permission.
00025 //
00026 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
00027 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00028 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
00029 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
00030 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
00031 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00032 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00033 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
00034 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
00035 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00036 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00037 //
00038 // Questions? Contact Michael A. Heroux (maherou@sandia.gov)
00039 //
00040 // ***********************************************************************
00041 //
00042 // @HEADER
00043 
00052 #ifndef AMESOS2_SOLVERCORE_DECL_HPP
00053 #define AMESOS2_SOLVERCORE_DECL_HPP
00054 
00055 #include <string>
00056 
00057 #include <Teuchos_RCP.hpp>
00058 #include <Teuchos_ParameterList.hpp>
00059 
00060 #include "Amesos2_Solver.hpp"
00061 #include "Amesos2_MatrixTraits.hpp"
00062 #include "Amesos2_MatrixAdapter_decl.hpp"
00063 #include "Amesos2_MultiVecAdapter_decl.hpp"
00064 #include "Amesos2_TypeDecl.hpp"
00065 
00066 #include "Amesos2_Control.hpp"
00067 #include "Amesos2_Status.hpp"
00068 #include "Amesos2_Timers.hpp"
00069 
00070 namespace Amesos2 {
00071 
00072 
00073   /* This is the base class to be used in a *statically* polymorphic
00074    * way. E.g. for the Superlu solver:
00075    *
00076    * In Amesos2_Superlu.hpp:
00077    * class Superlu : SolverCore<Superlu> { ... }
00078    *
00079    * Each concrete solver will implement several private sub-functions
00080    * that will be called within the common code for each function.
00081    */
00082 
00102   template <template <class,class> class ConcreteSolver,
00103       class Matrix,
00104       class Vector >
00105   class SolverCore : public Amesos2::Solver<Matrix,Vector>
00106   {
00107   public:
00108 
00109     // Grant public access to contained types
00110     typedef SolverCore<ConcreteSolver,Matrix,Vector>                       type;
00111     typedef Solver<Matrix,Vector>                                    super_type;
00112     typedef ConcreteSolver<Matrix,Vector>                           solver_type;
00113     typedef Matrix                                                  matrix_type;
00114     typedef Vector                                                  vector_type;
00115     typedef typename MatrixAdapter<matrix_type>::scalar_t           scalar_type;
00116     typedef typename MatrixAdapter<matrix_type>::local_ordinal_t    local_ordinal_type;
00117     typedef typename MatrixAdapter<matrix_type>::global_ordinal_t   global_ordinal_type;
00118     typedef typename MatrixAdapter<matrix_type>::global_size_t      global_size_type;
00119     typedef typename MatrixAdapter<matrix_type>::node_t             node_type;
00120 
00121 
00123 
00124 
00135     SolverCore( Teuchos::RCP<const Matrix> A,
00136     Teuchos::RCP<Vector>       X,
00137     Teuchos::RCP<const Vector> B );
00138 
00139 
00141     ~SolverCore( );
00142 
00143 
00145     SolverCore(const solver_type& rhs);
00146 
00147 
00149     super_type& operator=(const solver_type* rhs);
00150 
00152 
00154 
00155 
00167     super_type& preOrdering();
00168 
00169 
00187     super_type& symbolicFactorization();
00188 
00189 
00213     super_type& numericFactorization();
00214 
00215 
00235     void solve();
00236 
00237 
00238     void solve(const Teuchos::Ptr<Vector> X, const Teuchos::Ptr<const Vector> B) const;
00239 
00240 
00241     void solve(Vector* X, const Vector* B) const;
00242   
00243 
00245 
00246 
00256     bool matrixShapeOK();
00257 
00258     void setA( const Teuchos::RCP<const Matrix> a, EPhase keep_phase = CLEAN );
00259 
00260     void setA( const Matrix* a, EPhase keep_phase = CLEAN ){ setA(Teuchos::rcp(a), keep_phase); }
00261 
00262     void setX(const Teuchos::RCP<Vector> x){ multiVecX_ = x; }
00263 
00264     void setX(Vector* x){ multiVecX_ = Teuchos::rcp(x); }
00265   
00266     const Teuchos::RCP<Vector> getX(){ return( multiVecX_ ); }
00267 
00268     Vector* getXRaw(){ return multiVecX_.getRawPtr(); }
00269 
00270     void setB(const Teuchos::RCP<const Vector> b){ multiVecB_ = b; }
00271 
00272     void setB(const Vector* b){ multiVecB_ = Teuchos::rcp(b); }
00273 
00274     const Teuchos::RCP<const Vector> getB(){ return( multiVecB_ ); }
00275 
00276     const Vector* getBRaw(){ return multiVecB_.getRawPtr(); }
00277 
00278 
00280 
00281 
00300     super_type& setParameters(
00301             const Teuchos::RCP<Teuchos::ParameterList> & parameterList );
00302 
00303 
00313     Teuchos::RCP<const Teuchos::ParameterList> getValidParameters() const;
00314 
00315 
00325     void setParameterList(const Teuchos::RCP<Teuchos::ParameterList> & parameterList)
00326     {
00327       setParameters(parameterList);
00328     }
00329 
00330 
00336     Teuchos::RCP<Teuchos::ParameterList> getNonconstParameterList()
00337     {
00338       return Teuchos::null;
00339     }
00340 
00341 
00347     Teuchos::RCP<Teuchos::ParameterList> unsetParameterList()
00348     {
00349       return Teuchos::null;
00350     }
00351 
00352 
00354 
00355 
00357 
00358 
00360     Teuchos::RCP<const Teuchos::Comm<int> > getComm() const
00361     {
00362       return matrixA_->getComm();
00363     }
00364 
00365   
00367     inline Status& getStatus() const { return( status_ ); }
00368 
00369 
00371 
00372 
00374     std::string description() const;
00375 
00376 
00379     void describe(Teuchos::FancyOStream &out,
00380       const Teuchos::EVerbosityLevel verbLevel=Teuchos::Describable::verbLevel_default) const;
00381 
00382 
00399     void printTiming(
00400          Teuchos::FancyOStream &out,
00401          const Teuchos::EVerbosityLevel verbLevel) const;
00402 
00403 
00412     void getTiming(Teuchos::ParameterList& timingParameterList) const;
00413 
00414 
00422     std::string name() const;
00423 
00424   private:
00425 
00439     void loadA(EPhase current_phase);
00440 
00441   protected:
00442 
00449     void setNnzLU(size_t nnz){ status_.lu_nnz_ = nnz; }
00450 
00452     Teuchos::RCP<const MatrixAdapter<Matrix> > matrixA_;
00453 
00459     bool matrix_loaded_;
00460 
00461 
00463     Teuchos::RCP<Vector> multiVecX_;
00464 
00470     Teuchos::RCP<const Vector> multiVecB_;
00471 
00473     global_size_type globalNumRows_;
00474 
00476     global_size_type globalNumCols_;
00477 
00479     global_size_type globalNumNonZeros_;
00480 
00482     global_size_type rowIndexBase_;
00483 
00485     global_size_type columnIndexBase_;
00486 
00487 
00489     mutable Status status_;
00490 
00492     Control control_;
00493 
00495     mutable Timers timers_;
00496 
00497 
00498     /* Useful MPI vars */
00499 
00501     int rank_;
00502 
00504     bool root_;
00505 
00507     int nprocs_;
00508 
00509   };        // End class Amesos2::SolverCore
00510 
00511 
00512 } // end namespace Amesos2
00513 
00514 #endif  // AMESOS2_SOLVERCORE_DECL_HPP