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 
94  typedef Kokkos::DefaultHostExecutionSpace HostExecSpaceType;
95  typedef Kokkos::View<global_ordinal_type*, HostExecSpaceType> host_ordinal_type_array;
96  typedef Kokkos::View<scalar_type*, HostExecSpaceType> host_value_type_array;
97 
99 
100 
107  STRUMPACK(Teuchos::RCP<const Matrix> A,
108  Teuchos::RCP<Vector> X,
109  Teuchos::RCP<const Vector> B);
110 
111 
113  ~STRUMPACK( );
114 
116 
117 private:
118 
125  int preOrdering_impl();
126 
127 
136 
137 
144 
145 
157  int solve_impl(const Teuchos::Ptr<MultiVecAdapter<Vector> > X,
158  const Teuchos::Ptr<const MultiVecAdapter<Vector> > B) const;
159 
160 
166  bool matrixShapeOK_impl() const;
167 
168 
202  void setParameters_impl(
203  const Teuchos::RCP<Teuchos::ParameterList> & parameterList );
204 
205 
212  Teuchos::RCP<const Teuchos::ParameterList> getValidParameters_impl() const;
213 
214 
229  bool loadA_impl(EPhase current_phase);
230 
231 #ifdef HAVE_MPI
232  Teuchos::RCP<strumpack::StrumpackSparseSolverMPIDist<scalar_type,global_ordinal_type>> sp_;
233 #else
234  Teuchos::RCP<strumpack::StrumpackSparseSolver<scalar_type,global_ordinal_type>> sp_;
235 #endif
236 
237 
238  // The following Arrays are persisting storage arrays for A, X, and B
240  host_value_type_array nzvals_view_;
242  host_ordinal_type_array colind_view_;
244  host_ordinal_type_array rowptr_view_;
245  // /// 1D store for B values
246  mutable Teuchos::Array<scalar_type> bvals_;
247  // /// 1D store for X values
248  mutable Teuchos::Array<scalar_type> xvals_;
249 
250 #ifdef HAVE_MPI
251  Teuchos::RCP<const Tpetra::Map<local_ordinal_type,
253  global_ordinal_type,
254  node_type> > strumpack_rowmap_;
255 #endif
256 }; // End class STRUMPACK
257 
258 
259 // Specialize the solver_traits template for STRUMPACK
260 template <>
261 struct solver_traits<STRUMPACK> {
262 #if defined(HAVE_TEUCHOS_COMPLEX) && !defined(__clang__)
263  typedef Meta::make_list4<float, double, std::complex<float>, std::complex<double>> supported_scalars;
264 #else
265  typedef Meta::make_list2<float, double> supported_scalars;
266 #endif
267 };
268 
269 } // end namespace Amesos2
270 
271 #endif // AMESOS2_STRUMPACK_DECL_HPP
Amesos2::SolverCore: A templated interface for interaction with third-party direct sparse solvers...
Definition: Amesos2_SolverCore_decl.hpp:105
host_ordinal_type_array colind_view_
Stores the row indices of the nonzero entries.
Definition: Amesos2_STRUMPACK_decl.hpp:242
int preOrdering_impl()
Performs pre-ordering on the matrix to increase efficiency.
Definition: Amesos2_STRUMPACK_def.hpp:136
void setParameters_impl(const Teuchos::RCP< Teuchos::ParameterList > &parameterList)
Definition: Amesos2_STRUMPACK_def.hpp:320
int symbolicFactorization_impl()
Perform symbolic factorization of the matrix using STRUMPACK.
Definition: Amesos2_STRUMPACK_def.hpp:156
bool matrixShapeOK_impl() const
Determines whether the shape of the matrix is OK for this solver.
Definition: Amesos2_STRUMPACK_def.hpp:302
Provides traits about solvers.
Definition: Amesos2_SolverTraits.hpp:71
host_ordinal_type_array rowptr_view_
Stores the location in Ai_ and Aval_ that starts row j.
Definition: Amesos2_STRUMPACK_decl.hpp:244
host_value_type_array nzvals_view_
Stores the values of the nonzero entries for STRUMPACK.
Definition: Amesos2_STRUMPACK_decl.hpp:240
bool loadA_impl(EPhase current_phase)
Reads matrix data into internal solver structures.
Definition: Amesos2_STRUMPACK_def.hpp:490
std::string name() const override
Return the name of this solver.
Definition: Amesos2_SolverCore_def.hpp:759
Interface to Amesos2 solver objects.
Definition: Amesos2_Solver_decl.hpp:78
Amesos2 interface to STRUMPACK direct solver and preconditioner.
Definition: Amesos2_STRUMPACK_decl.hpp:71
Provides access to interesting solver traits.
Teuchos::RCP< const Teuchos::ParameterList > getValidParameters_impl() const
Definition: Amesos2_STRUMPACK_def.hpp:377
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:203
int numericFactorization_impl()
STRUMPACK specific numeric factorization.
Definition: Amesos2_STRUMPACK_def.hpp:181