|
Amesos2 - Direct Sparse Solver Interfaces
Version of the Day
|
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 00303 super_type& setParameters( 00304 const Teuchos::RCP<Teuchos::ParameterList> & parameterList ); 00305 00306 00316 Teuchos::RCP<const Teuchos::ParameterList> getValidParameters() const; 00317 00318 00328 void setParameterList(const Teuchos::RCP<Teuchos::ParameterList> & parameterList) 00329 { 00330 setParameters(parameterList); 00331 } 00332 00333 00339 Teuchos::RCP<Teuchos::ParameterList> getNonconstParameterList() 00340 { 00341 return Teuchos::null; 00342 } 00343 00344 00350 Teuchos::RCP<Teuchos::ParameterList> unsetParameterList() 00351 { 00352 return Teuchos::null; 00353 } 00354 00355 00357 00358 00360 00361 00363 Teuchos::RCP<const Teuchos::Comm<int> > getComm() const 00364 { 00365 return matrixA_->getComm(); 00366 } 00367 00368 00370 inline Status& getStatus() const { return( status_ ); } 00371 00372 00374 00375 00377 std::string description() const; 00378 00379 00382 void describe(Teuchos::FancyOStream &out, 00383 const Teuchos::EVerbosityLevel verbLevel=Teuchos::Describable::verbLevel_default) const; 00384 00385 00402 void printTiming( 00403 Teuchos::FancyOStream &out, 00404 const Teuchos::EVerbosityLevel verbLevel) const; 00405 00406 00415 void getTiming(Teuchos::ParameterList& timingParameterList) const; 00416 00417 00425 std::string name() const; 00426 00427 private: 00428 00442 void loadA(EPhase current_phase); 00443 00444 protected: 00445 00452 void setNnzLU(size_t nnz){ status_.lu_nnz_ = nnz; } 00453 00455 Teuchos::RCP<const MatrixAdapter<Matrix> > matrixA_; 00456 00462 bool matrix_loaded_; 00463 00464 00466 Teuchos::RCP<Vector> multiVecX_; 00467 00473 Teuchos::RCP<const Vector> multiVecB_; 00474 00476 global_size_type globalNumRows_; 00477 00479 global_size_type globalNumCols_; 00480 00482 global_size_type globalNumNonZeros_; 00483 00485 global_size_type rowIndexBase_; 00486 00488 global_size_type columnIndexBase_; 00489 00490 00492 mutable Status status_; 00493 00495 Control control_; 00496 00498 mutable Timers timers_; 00499 00500 00501 /* Useful MPI vars */ 00502 00504 int rank_; 00505 00507 bool root_; 00508 00510 int nprocs_; 00511 00512 }; // End class Amesos2::SolverCore 00513 00514 00515 } // end namespace Amesos2 00516 00517 #endif // AMESOS2_SOLVERCORE_DECL_HPP
1.7.6.1