|
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 00053 #ifndef AMESOS2_SUPERLU_DECL_HPP 00054 #define AMESOS2_SUPERLU_DECL_HPP 00055 00056 #include "Amesos2_SolverTraits.hpp" 00057 #include "Amesos2_SolverCore.hpp" 00058 #include "Amesos2_Superlu_FunctionMap.hpp" 00059 00060 00061 namespace Amesos2 { 00062 00063 00071 template <class Matrix, 00072 class Vector> 00073 class Superlu : public SolverCore<Amesos2::Superlu, Matrix, Vector> 00074 { 00075 friend class SolverCore<Amesos2::Superlu,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 Superlu<Matrix,Vector> type; 00084 typedef SolverCore<Amesos2::Superlu,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 00092 typedef TypeMap<Amesos2::Superlu,scalar_type> type_map; 00093 00094 /* 00095 * The SuperLU interface will need two other typedef's, which are: 00096 * - the superlu type that corresponds to scalar_type and 00097 * - the corresponding type to use for magnitude 00098 */ 00099 typedef typename type_map::type slu_type; 00100 typedef typename type_map::magnitude_type magnitude_type; 00101 00102 typedef FunctionMap<Amesos2::Superlu,slu_type> function_map; 00103 00105 00106 00113 Superlu(Teuchos::RCP<const Matrix> A, 00114 Teuchos::RCP<Vector> X, 00115 Teuchos::RCP<const Vector> B); 00116 00117 00119 ~Superlu( ); 00120 00122 00124 std::string description() const; 00125 00126 private: 00127 00133 int preOrdering_impl(); 00134 00135 00143 int symbolicFactorization_impl(); 00144 00145 00151 int numericFactorization_impl(); 00152 00153 00165 int solve_impl(const Teuchos::Ptr<MultiVecAdapter<Vector> > X, 00166 const Teuchos::Ptr<const MultiVecAdapter<Vector> > B) const; 00167 00168 00172 bool matrixShapeOK_impl() const; 00173 00174 00208 void setParameters_impl( 00209 const Teuchos::RCP<Teuchos::ParameterList> & parameterList ); 00210 00211 00218 Teuchos::RCP<const Teuchos::ParameterList> getValidParameters_impl() const; 00219 00220 00229 bool loadA_impl(EPhase current_phase); 00230 00231 00232 // struct holds all data necessary to make a superlu factorization or solve call 00233 mutable struct SLUData { 00234 SLU::SuperMatrix A, B, X, L, U; // matrix A in NCformat 00235 SLU::SuperMatrix AC; // permuted matrix A in NCPformat 00236 00237 SLU::superlu_options_t options; 00238 SLU::mem_usage_t mem_usage; 00239 SLU::SuperLUStat_t stat; 00240 00241 Teuchos::Array<magnitude_type> berr; 00242 Teuchos::Array<magnitude_type> ferr; 00243 Teuchos::Array<int> perm_r; 00244 Teuchos::Array<int> perm_c; 00245 Teuchos::Array<int> etree; 00246 Teuchos::Array<magnitude_type> R; 00247 Teuchos::Array<magnitude_type> C; 00248 00249 char equed; 00250 bool rowequ, colequ; // flags what type of equilibration 00251 // has been performed 00252 00253 int relax; 00254 int panel_size; 00255 } data_; 00256 00257 // The following Arrays are persisting storage arrays for A, X, and B 00259 Teuchos::Array<slu_type> nzvals_; 00261 Teuchos::Array<int> rowind_; 00263 Teuchos::Array<int> colptr_; 00264 00266 Teuchos::Array<slu_type> xvals_; int ldx_; 00268 Teuchos::Array<slu_type> bvals_; int ldb_; 00269 00270 /* Note: In the above, must use "Amesos2::Superlu" rather than 00271 * "Superlu" because otherwise the compiler references the 00272 * specialized type of the class, and not the templated type that is 00273 * required for Amesos2::TypeMap 00274 */ 00275 00276 /* SuperLU can accept input in either compressed-row or 00277 * compressed-column storage. We will store and pass matrices in 00278 * *compressed-column* format. 00279 */ 00280 00281 /* 00282 * Internal flag that is used for the numericFactorization_impl 00283 * routine. If true, then the superlu gstrf routine should have 00284 * SamePattern_SameRowPerm in its options. Otherwise, it should 00285 * factor from scratch. 00286 * 00287 * This is somewhat of a kludge to get around the fact that the 00288 * superlu routines all expect something different from the options 00289 * struct. The big issue is that we don't want gstrf doing the 00290 * symbolic factorization if it doesn't need to. On the other hand, 00291 * we can't leave options.Fact set to SamePattern_SameRowPerm 00292 * because the solver driver needs it to be set at FACTORED. But 00293 * having it set at FACTORED upon re-entrance into 00294 * numericFactorization prompts gstrf to redo the symbolic 00295 * factorization. 00296 */ 00297 bool same_symbolic_; 00298 bool ILU_Flag_; 00299 00300 }; // End class Superlu 00301 00302 00303 // Specialize solver_traits struct for SuperLU 00304 template <> 00305 struct solver_traits<Superlu> { 00306 #ifdef HAVE_TEUCHOS_COMPLEX 00307 typedef Meta::make_list6<float, 00308 double, 00309 std::complex<float>, 00310 std::complex<double>, 00311 SLU::C::complex, 00312 SLU::Z::doublecomplex> supported_scalars; 00313 #else 00314 typedef Meta::make_list2<float, double> supported_scalars; 00315 #endif 00316 }; 00317 00318 } // end namespace Amesos2 00319 00320 #endif // AMESOS2_SUPERLU_DECL_HPP
1.7.6.1