Amesos2 - Direct Sparse Solver Interfaces  Version of the Day
Amesos2_STRUMPACK_decl.hpp
1 // @HEADER
2 //
3 // ***********************************************************************
4 //
5 // Amesos2: Templated Direct Sparse Solver Package
6 // Copyright 2011 Sandia Corporation
7 //
8 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
9 // the U.S. Government retains certain rights in this software.
10 //
11 // Redistribution and use in source and binary forms, with or without
12 // modification, are permitted provided that the following conditions are
13 // met:
14 //
15 // 1. Redistributions of source code must retain the above copyright
16 // notice, this list of conditions and the following disclaimer.
17 //
18 // 2. Redistributions in binary form must reproduce the above copyright
19 // notice, this list of conditions and the following disclaimer in the
20 // documentation and/or other materials provided with the distribution.
21 //
22 // 3. Neither the name of the Corporation nor the names of the
23 // contributors may be used to endorse or promote products derived from
24 // this software without specific prior written permission.
25 //
26 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
27 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
30 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
31 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
32 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
33 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
34 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
35 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
36 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37 //
38 // Questions? Contact Lisa Claus (lclaus@lbl.gov)
39 //
40 // ***********************************************************************
41 //
42 // @HEADER
43 
44 
45 #ifndef AMESOS2_STRUMPACK_DECL_HPP
46 #define AMESOS2_STRUMPACK_DECL_HPP
47 
48 #include "Amesos2_SolverTraits.hpp"
49 #include "Amesos2_SolverCore.hpp"
50 
51 #ifdef HAVE_MPI
52 #include "StrumpackSparseSolverMPIDist.hpp"
53 #else
54 #include "StrumpackSparseSolver.hpp"
55 #endif
56 
57 namespace Amesos2 {
58 
59 
69 template <class Matrix,
70  class Vector>
71 class STRUMPACK : public SolverCore<Amesos2::STRUMPACK, Matrix, Vector>
72 {
73  friend class SolverCore<Amesos2::STRUMPACK,Matrix,Vector>; // Give our base access
74  // to our private
75  // implementation funcs
76 public:
77 
79  static const char* name; // declaration. Initialization outside.
80 
81  typedef STRUMPACK<Matrix,Vector> type;
82  typedef SolverCore<Amesos2::STRUMPACK,Matrix,Vector> strum_type;
83 
84  typedef Matrix matrix_type;
85  typedef Vector vector_type;
86 
87  // Since typedef's are not inheritted, go grab them
88  typedef typename strum_type::scalar_type scalar_type;
89  typedef typename strum_type::local_ordinal_type local_ordinal_type;
90  typedef typename strum_type::global_ordinal_type global_ordinal_type;
91  typedef typename strum_type::global_size_type global_size_type;
92  typedef typename strum_type::node_type node_type;
93 
95 
96 
103  STRUMPACK(Teuchos::RCP<const Matrix> A,
104  Teuchos::RCP<Vector> X,
105  Teuchos::RCP<const Vector> B);
106 
107 
109  ~STRUMPACK( );
110 
112 
113 private:
114 
121  int preOrdering_impl();
122 
123 
132 
133 
140 
141 
153  int solve_impl(const Teuchos::Ptr<MultiVecAdapter<Vector> > X,
154  const Teuchos::Ptr<const MultiVecAdapter<Vector> > B) const;
155 
156 
162  bool matrixShapeOK_impl() const;
163 
164 
198  void setParameters_impl(
199  const Teuchos::RCP<Teuchos::ParameterList> & parameterList );
200 
201 
208  Teuchos::RCP<const Teuchos::ParameterList> getValidParameters_impl() const;
209 
210 
225  bool loadA_impl(EPhase current_phase);
226 
227 #ifdef HAVE_MPI
228  Teuchos::RCP<strumpack::StrumpackSparseSolverMPIDist<scalar_type,global_ordinal_type>> sp_;
229 #else
230  Teuchos::RCP<strumpack::StrumpackSparseSolver<scalar_type,global_ordinal_type>> sp_;
231 #endif
232 
233 
234  // The following Arrays are persisting storage arrays for A, X, and B
236  Teuchos::Array<scalar_type> nzvals_;
237  // /// Stores the row indices of the nonzero entries
238  Teuchos::Array<global_ordinal_type> colind_;
239  // /// Stores the location in \c Ai_ and Aval_ that starts row j
240  Teuchos::Array<global_ordinal_type> rowptr_;
241  // /// 1D store for B values
242  mutable Teuchos::Array<scalar_type> bvals_;
243  // /// 1D store for X values
244  mutable Teuchos::Array<scalar_type> xvals_;
245 
246 #ifdef HAVE_MPI
247  Teuchos::RCP<const Tpetra::Map<local_ordinal_type,
249  global_ordinal_type,
250  node_type> > strumpack_rowmap_;
251 #endif
252 }; // End class STRUMPACK
253 
254 
255 // Specialize the solver_traits template for STRUMPACK
256 template <>
257 struct solver_traits<STRUMPACK> {
258 #if defined(HAVE_TEUCHOS_COMPLEX) && !defined(__clang__)
259  typedef Meta::make_list4<float, double, std::complex<float>, std::complex<double>> supported_scalars;
260 #else
261  typedef Meta::make_list2<float, double> supported_scalars;
262 #endif
263 };
264 
265 } // end namespace Amesos2
266 
267 #endif // AMESOS2_STRUMPACK_DECL_HPP
Amesos2::SolverCore: A templated interface for interaction with third-party direct sparse solvers...
Definition: Amesos2_SolverCore_decl.hpp:105
Teuchos::Array< scalar_type > nzvals_
Stores the values of the nonzero entries for STRUMPACK.
Definition: Amesos2_STRUMPACK_decl.hpp:236
int preOrdering_impl()
Performs pre-ordering on the matrix to increase efficiency.
Definition: Amesos2_STRUMPACK_def.hpp:135
int solve_impl(const Teuchos::Ptr< MultiVecAdapter< Vector > > X, const Teuchos::Ptr< const MultiVecAdapter< Vector > > B) const
STRUMPACK specific solve.
Definition: Amesos2_STRUMPACK_def.hpp:202
void setParameters_impl(const Teuchos::RCP< Teuchos::ParameterList > &parameterList)
Definition: Amesos2_STRUMPACK_def.hpp:319
int symbolicFactorization_impl()
Perform symbolic factorization of the matrix using STRUMPACK.
Definition: Amesos2_STRUMPACK_def.hpp:155
Provides traits about solvers.
Definition: Amesos2_SolverTraits.hpp:71
Teuchos::RCP< const Teuchos::ParameterList > getValidParameters_impl() const
Definition: Amesos2_STRUMPACK_def.hpp:376
Definition: Amesos2_AbstractConcreteMatrixAdapter.hpp:48
bool loadA_impl(EPhase current_phase)
Reads matrix data into internal solver structures.
Definition: Amesos2_STRUMPACK_def.hpp:489
Interface to Amesos2 solver objects.
Definition: Amesos2_Solver_decl.hpp:78
std::string name() const
Return the name of this solver.
Definition: Amesos2_SolverCore_def.hpp:509
Amesos2 interface to STRUMPACK direct solver and preconditioner.
Definition: Amesos2_STRUMPACK_decl.hpp:71
Provides access to interesting solver traits.
bool matrixShapeOK_impl() const
Determines whether the shape of the matrix is OK for this solver.
Definition: Amesos2_STRUMPACK_def.hpp:301
int numericFactorization_impl()
STRUMPACK specific numeric factorization.
Definition: Amesos2_STRUMPACK_def.hpp:180