Amesos2 - Direct Sparse Solver Interfaces  Version of the Day
Amesos2_Basker_decl.hpp
Go to the documentation of this file.
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 Michael A. Heroux (maherou@sandia.gov)
39 //
40 // ***********************************************************************
41 //
42 // @HEADER
43 
53 #ifndef AMESOS2_BASKER_DECL_HPP
54 #define AMESOS2_BASKER_DECL_HPP
55 
56 #include "Amesos2_SolverTraits.hpp"
57 #include "Amesos2_SolverCore.hpp"
58 #include "Amesos2_Basker_FunctionMap.hpp"
59 
60 //Note: We got an error while being a class variable and mutable. Need to comeback and fix!!
61 
62 
63 namespace Amesos2 {
64 
72 template <class Matrix,class Vector>
73 class Basker : public SolverCore<Amesos2::Basker, Matrix, Vector>
74 {
75  friend class SolverCore<Amesos2::Basker,Matrix,Vector>; // Give our base access
76  // to our private
77  // implementation funcs
78 public:
79 
81  static const char* name; // declaration. Initialization outside.
82 
83 
84  typedef Amesos2::Basker<Matrix,Vector> type;
85 
86  typedef SolverCore<Amesos2::Basker,Matrix,Vector> super_type;
87 
88  // Since typedef's are not inheritted, go grab them
89  typedef typename super_type::scalar_type scalar_type;
90  typedef typename super_type::local_ordinal_type local_ordinal_type;
91  typedef typename super_type::global_ordinal_type global_ordinal_type;
92  typedef typename super_type::global_size_type global_size_type;
93  typedef typename super_type::node_type node_type;
94 
95  typedef TypeMap<Amesos2::Basker,scalar_type> type_map;
96 
97  typedef typename type_map::type basker_type;
98 
99  // TODO: Would like to change dtype to be a regular type, not static.
100  // Seems nothing was using dtype before anyways but Stokhos would break so
101  // will address that as a separate PR.
102  typedef decltype(type_map::dtype) basker_dtype;
103 
104  typedef FunctionMap<Amesos2::Basker,basker_type> function_map;
105 
106  typedef Matrix matrix_type;
107  typedef MatrixAdapter<matrix_type> matrix_adapter_type;
108 
109 
110  Basker( Teuchos::RCP<const Matrix> A,
111  Teuchos::RCP<Vector> X,
112  Teuchos::RCP<const Vector> B);
113  ~Basker( );
114 
115 
116 private:
117 
122  bool single_proc_optimization() const;
123 
129  int preOrdering_impl();
130 
131 
132  int symbolicFactorization_impl();
133 
134 
141 
142 
154  int solve_impl(const Teuchos::Ptr<MultiVecAdapter<Vector> > X,
155  const Teuchos::Ptr<const MultiVecAdapter<Vector> > B) const;
156 
157 
161  bool matrixShapeOK_impl() const;
162 
163 
164  void setParameters_impl(
165  const Teuchos::RCP<Teuchos::ParameterList> & parameterList );
166 
167 
174  Teuchos::RCP<const Teuchos::ParameterList> getValidParameters_impl() const;
175 
176 
185  bool loadA_impl(EPhase current_phase);
186 
187 
188  // Members
189  int num_threads;
190 
191  typedef Kokkos::DefaultHostExecutionSpace HostSpaceType;
192  typedef Kokkos::View<local_ordinal_type*, HostSpaceType> host_ordinal_type_array;
193 
194  typedef Kokkos::View<basker_type*, HostSpaceType> host_value_type_array;
195 
196  // The following Views are persisting storage arrays for A, X, and B
198  host_value_type_array host_nzvals_view_;
200  host_ordinal_type_array host_rows_view_;
202  host_ordinal_type_array host_col_ptr_view_;
203 
204  bool is_contiguous_;
205 
206  typedef typename Kokkos::View<basker_type**, Kokkos::LayoutLeft, HostSpaceType>
207  host_solve_array_t;
208 
210  mutable host_solve_array_t xValues_;
211  int ldx_;
212 
214  mutable host_solve_array_t bValues_;
215  int ldb_;
216 
217  /*Handle for Basker object*/
218  mutable ::BaskerClassicNS::BaskerClassic<local_ordinal_type,basker_dtype> basker;
219 
220 }; // End class Basker
221 
222 
223 // Specialize solver_traits struct for Basker
224 // TODO
225 template <>
226 struct solver_traits<Basker> {
227 #ifdef HAVE_TEUCHOS_COMPLEX
228  typedef Meta::make_list6<float,
229  double,
230  Kokkos::complex<float>,
231  Kokkos::complex<double>,
232  std::complex<float>,
233  std::complex<double> > supported_scalars;
234 #else
235  typedef Meta::make_list2<float, double> supported_scalars;
236 #endif
237 };
238 
239 template <typename Scalar, typename LocalOrdinal, typename ExecutionSpace>
240 struct solver_supports_matrix<Basker,
241  KokkosSparse::CrsMatrix<Scalar, LocalOrdinal, ExecutionSpace>> {
242  static const bool value = true;
243 };
244 
245 } // end namespace Amesos2
246 
247 #endif // AMESOS2_BASKER_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 host_col_ptr_view_
Stores the row indices of the nonzero entries.
Definition: Amesos2_Basker_decl.hpp:202
Map types to solver-specific data-types and enums.
Definition: Amesos2_TypeMap.hpp:82
bool loadA_impl(EPhase current_phase)
Reads matrix data into internal structures.
Definition: Amesos2_Basker_def.hpp:304
Teuchos::RCP< const Teuchos::ParameterList > getValidParameters_impl() const
Definition: Amesos2_Basker_def.hpp:284
std::string name() const
Return the name of this solver.
Definition: Amesos2_SolverCore_def.hpp:509
Provides traits about solvers.
Definition: Amesos2_SolverTraits.hpp:71
host_solve_array_t bValues_
Persisting 1D store for B.
Definition: Amesos2_Basker_decl.hpp:214
Amesos2 interface to the Baker package.
Definition: Amesos2_Basker_decl.hpp:73
bool single_proc_optimization() const
can we optimize size_type and ordinal_type for straight pass through,
Definition: Amesos2_Basker_def.hpp:85
A Matrix adapter interface for Amesos2.
Definition: Amesos2_MatrixAdapter_decl.hpp:76
bool matrixShapeOK_impl() const
Determines whether the shape of the matrix is OK for this solver.
Definition: Amesos2_Basker_def.hpp:258
host_solve_array_t xValues_
Persisting 1D store for X.
Definition: Amesos2_Basker_decl.hpp:210
Passes functions to TPL functions based on type.
Definition: Amesos2_FunctionMap.hpp:76
int preOrdering_impl()
Performs pre-ordering on the matrix to increase efficiency.
Definition: Amesos2_Basker_def.hpp:91
Provides access to interesting solver traits.
host_ordinal_type_array host_rows_view_
Stores the location in Ai_ and Aval_ that starts row j.
Definition: Amesos2_Basker_decl.hpp:200
int numericFactorization_impl()
Basker specific numeric factorization.
Definition: Amesos2_Basker_def.hpp:114
host_value_type_array host_nzvals_view_
Stores the values of the nonzero entries for CHOLMOD.
Definition: Amesos2_Basker_decl.hpp:198
int solve_impl(const Teuchos::Ptr< MultiVecAdapter< Vector > > X, const Teuchos::Ptr< const MultiVecAdapter< Vector > > B) const
Basker specific solve.
Definition: Amesos2_Basker_def.hpp:166