Amesos2 - Direct Sparse Solver Interfaces  Version of the Day
Amesos2_KLU2_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_KLU2_DECL_HPP
00053 #define AMESOS2_KLU2_DECL_HPP
00054 
00055 #include "Amesos2_SolverTraits.hpp"
00056 #include "Amesos2_SolverCore.hpp"
00057 #include "Amesos2_KLU2_FunctionMap.hpp"
00058 
00059 
00060 namespace Amesos2 {
00061 
00062 
00070 template <class Matrix,
00071           class Vector>
00072 class KLU2 : public SolverCore<Amesos2::KLU2, Matrix, Vector>
00073 {
00074   friend class SolverCore<Amesos2::KLU2,Matrix,Vector>; // Give our base access
00075                                                           // to our private
00076                                                           // implementation funcs
00077 public:
00078 
00080   static const char* name;      // declaration. Initialization outside.
00081 
00082   typedef KLU2<Matrix,Vector>                                       type;
00083   typedef SolverCore<Amesos2::KLU2,Matrix,Vector>             super_type;
00084 
00085   // Since typedef's are not inheritted, go grab them
00086   typedef typename super_type::scalar_type                      scalar_type;
00087   typedef typename super_type::local_ordinal_type        local_ordinal_type;
00088   typedef typename super_type::global_ordinal_type      global_ordinal_type;
00089   typedef typename super_type::global_size_type            global_size_type;
00090 
00091   typedef TypeMap<Amesos2::KLU2,scalar_type>                    type_map;
00092 
00093   /*
00094    * The KLU2 interface will need two other typedef's, which are:
00095    * - the KLU2 type that corresponds to scalar_type and
00096    * - the corresponding type to use for magnitude
00097    */
00098   typedef typename type_map::type                                  slu_type;
00099   typedef typename type_map::magnitude_type                  magnitude_type;
00100 
00101   typedef FunctionMap<Amesos2::KLU2,slu_type>               function_map;
00102 
00104 
00105 
00112   KLU2(Teuchos::RCP<const Matrix> A,
00113           Teuchos::RCP<Vector>       X,
00114           Teuchos::RCP<const Vector> B);
00115 
00116 
00118   ~KLU2( );
00119 
00121 
00122 private:
00123 
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   // struct holds all data necessary for KLU2 factorization or solve call
00222   mutable struct KLU2Data {
00223       ::KLU2::klu_symbolic<scalar_type, local_ordinal_type> *symbolic_;
00224       ::KLU2::klu_numeric<scalar_type, local_ordinal_type> *numeric_;
00225       ::KLU2::klu_common<scalar_type, local_ordinal_type> common_;
00226   } data_ ;
00227 
00228   // The following Arrays are persisting storage arrays for A, X, and B
00230   Teuchos::Array<slu_type> nzvals_;
00232   Teuchos::Array<local_ordinal_type> rowind_;
00234   Teuchos::Array<local_ordinal_type> colptr_;
00235 
00237   Teuchos::Array<slu_type> xvals_;  local_ordinal_type ldx_;
00239   Teuchos::Array<slu_type> bvals_;  local_ordinal_type ldb_;
00240 
00241 };                              // End class KLU2
00242 
00243 
00244 // Specialize solver_traits struct for KLU2
00245 // TODO
00246 //template <>
00247 //struct solver_traits<KLU2> {
00248 //#ifdef HAVE_TEUCHOS_COMPLEX
00249   //typedef Meta::make_list6<float,
00250                            //double,
00251                            //std::complex<float>,
00252                            //std::complex<double>,
00253                            //SLU::C::complex,
00254                            //SLU::Z::doublecomplex> supported_scalars;
00255 //#else
00256   //typedef Meta::make_list2<float, double> supported_scalars;
00257 //#endif
00258 //};
00259 
00260 } // end namespace Amesos2
00261 
00262 #endif  // AMESOS2_KLU2_DECL_HPP