Amesos2 - Direct Sparse Solver Interfaces  Version of the Day
Amesos2_Cholmod_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 
00053 #ifndef AMESOS2_CHOLMOD_DECL_HPP
00054 #define AMESOS2_CHOLMOD_DECL_HPP
00055 
00056 #include "Amesos2_SolverTraits.hpp"
00057 #include "Amesos2_SolverCore.hpp"
00058 #include "Amesos2_Cholmod_FunctionMap.hpp"
00059 
00060 
00061 namespace Amesos2 {
00062 
00063 
00071 template <class Matrix,
00072           class Vector>
00073 class Cholmod : public SolverCore<Amesos2::Cholmod, Matrix, Vector>
00074 {
00075   friend class SolverCore<Amesos2::Cholmod,Matrix,Vector>; // Give our base access
00076                                                           // to our private
00077                                                           // implementation funcs
00078 public:
00079 
00081   static const char* name;      // declaration. Initialization outside.
00082 
00083   typedef Cholmod<Matrix,Vector>                                       type;
00084   typedef SolverCore<Amesos2::Cholmod,Matrix,Vector>             super_type;
00085 
00086   // Since typedef's are not inheritted, go grab them
00087   typedef typename super_type::scalar_type                    scalar_type;
00088   typedef typename super_type::local_ordinal_type      local_ordinal_type;
00089   typedef typename super_type::global_ordinal_type    global_ordinal_type;
00090   typedef typename super_type::global_size_type          global_size_type;
00091   typedef typename super_type::node_type                        node_type;
00092 
00093   typedef TypeMap<Amesos2::Cholmod,scalar_type>                    type_map;
00094 
00095   /*
00096    * The SuperLU interface will need two other typedef's, which are:
00097    * - the superlu type that corresponds to scalar_type and
00098    * - the corresponding type to use for magnitude
00099    */
00100   typedef typename type_map::type                                 chol_type;
00101   typedef typename type_map::magnitude_type                  magnitude_type;
00102 
00103   typedef FunctionMap<Amesos2::Cholmod,chol_type>              function_map;
00104 
00106 
00107 
00114   Cholmod(Teuchos::RCP<const Matrix> A,
00115           Teuchos::RCP<Vector>       X,
00116           Teuchos::RCP<const Vector> B);
00117 
00118 
00120   ~Cholmod( );
00121 
00123 
00124 private:
00125 
00129   int preOrdering_impl();
00130 
00131 
00139   int symbolicFactorization_impl();
00140 
00141 
00147   int numericFactorization_impl();
00148 
00149 
00161   int solve_impl(const Teuchos::Ptr<MultiVecAdapter<Vector> >       X,
00162                  const Teuchos::Ptr<const MultiVecAdapter<Vector> > B) const;
00163 
00164 
00168   bool matrixShapeOK_impl() const;
00169 
00170 
00198   void setParameters_impl(
00199     const Teuchos::RCP<Teuchos::ParameterList> & parameterList );
00200 
00201 
00208   Teuchos::RCP<const Teuchos::ParameterList> getValidParameters_impl() const;
00209 
00210 
00219   bool loadA_impl(EPhase current_phase);
00220 
00221 
00222   // struct holds all data necessary to make a superlu factorization or solve call
00223   mutable struct CholData {
00224     CHOL::cholmod_sparse A; 
00225     CHOL::cholmod_dense x, b;
00226     CHOL::cholmod_dense *Y, *E;
00227     CHOL::cholmod_factor *L;
00228     CHOL::cholmod_common c;
00229   } data_;
00230 
00231   // The following Arrays are persisting storage arrays for A, X, and B
00233   Teuchos::Array<chol_type> nzvals_;
00235   Teuchos::Array<int> rowind_;
00237   Teuchos::Array<int> colptr_;
00238 
00240   Teuchos::Array<chol_type> xvals_;  int ldx_;
00242   Teuchos::Array<chol_type> bvals_;  int ldb_;
00243 
00244   bool firstsolve;
00245   
00246   // Used as a hack around cholmod doing ordering and symfact together
00247   bool skip_symfact;
00248 
00249   Teuchos::RCP<const Tpetra::Map<local_ordinal_type,global_ordinal_type,node_type> > map;
00250 
00251 };                              // End class Cholmod
00252 
00253 
00254 /* Specialize solver_traits struct for Cholmod
00255  *
00256  * Based on the CHOLMOD documentation, the support for
00257  * single-precision complex numbers is unclear.  Much of the
00258  * discussion of complex types only makes explicit mention of 'double'
00259  * types.  So, be pessimistic for now and don't declare
00260  * single-precision complex support
00261  */
00262 template <>
00263 struct solver_traits<Cholmod> {
00264 #ifdef HAVE_TEUCHOS_COMPLEX
00265   typedef Meta::make_list4<float,
00266          double,
00267                            std::complex<double>,
00268                            CHOL::complex> supported_scalars;
00269 #else
00270   typedef Meta::make_list2<float, double> supported_scalars;
00271 #endif
00272 };
00273 
00274 } // end namespace Amesos2
00275 
00276 #endif  // AMESOS2_CHOLMOD_DECL_HPP