Amesos2 - Direct Sparse Solver Interfaces  Version of the Day
Amesos2_ShyLUBasker_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 
54 #ifndef AMESOS2_SHYLUBASKER_DECL_HPP
55 #define AMESOS2_SHYLUBASKER_DECL_HPP
56 
57 #include "Amesos2_SolverTraits.hpp"
58 #include "Amesos2_SolverCore.hpp"
59 #include "Amesos2_ShyLUBasker_FunctionMap.hpp"
60 
61 #include "shylubasker_decl.hpp"
62 #include "shylubasker_def.hpp"
63 #include "shylubasker_trilinos_decl.hpp"
64 
65 
66 namespace Amesos2 {
67 
75 template <class Matrix,class Vector>
76 class ShyLUBasker : public SolverCore<Amesos2::ShyLUBasker, Matrix, Vector>
77 {
78  friend class SolverCore<Amesos2::ShyLUBasker,Matrix,Vector>; // Give our base access
79  // to our private
80  // implementation funcs
81 public:
82 
84  static const char* name; // declaration. Initialization outside.
85 
86 
87  typedef ShyLUBasker<Matrix,Vector> type;
88 
89  typedef SolverCore<Amesos2::ShyLUBasker,Matrix,Vector> super_type;
90 
91  // Since typedef's are not inheritted, go grab them
92  typedef typename super_type::scalar_type scalar_type;
93  typedef typename super_type::local_ordinal_type local_ordinal_type;
94  typedef typename super_type::global_ordinal_type global_ordinal_type;
95  typedef typename super_type::global_size_type global_size_type;
96  typedef typename super_type::node_type node_type;
97 
98  typedef TypeMap<Amesos2::ShyLUBasker,scalar_type> type_map;
99  typedef typename type_map::type shylubasker_type;
100  typedef typename type_map::dtype shylubasker_dtype;
101 
102  typedef typename type_map::type slu_type;
103 
104  typedef FunctionMap<Amesos2::ShyLUBasker,shylubasker_type> function_map;
105 
106  typedef Matrix matrix_type;
107  typedef MatrixAdapter<matrix_type> matrix_adapter_type;
108 
109  typedef Kokkos::DefaultHostExecutionSpace HostExecSpaceType;
110 // typedef Kokkos::View<local_ordinal_type*, HostExecSpaceType> host_size_type_array;
111  typedef Kokkos::View<local_ordinal_type*, HostExecSpaceType> host_ordinal_type_array;
112  typedef Kokkos::View<shylubasker_type*, HostExecSpaceType> host_value_type_array;
113 
114 
115  ShyLUBasker( Teuchos::RCP<const Matrix> A,
116  Teuchos::RCP<Vector> X,
117  Teuchos::RCP<const Vector> B);
118  ~ShyLUBasker( );
119 
120 
121 private:
122 
127  bool single_proc_optimization() const;
128 
129 
135  int preOrdering_impl();
136 
137 
138  int symbolicFactorization_impl();
139 
140 
147 
148 
160  int solve_impl(const Teuchos::Ptr<MultiVecAdapter<Vector> > X,
161  const Teuchos::Ptr<const MultiVecAdapter<Vector> > B) const;
162 
163 
167  bool matrixShapeOK_impl() const;
168 
169 
170  void setParameters_impl(
171  const Teuchos::RCP<Teuchos::ParameterList> & parameterList );
172 
173 
180  Teuchos::RCP<const Teuchos::ParameterList> getValidParameters_impl() const;
181 
182 
191  bool loadA_impl(EPhase current_phase);
192 
193 
194  // Members
195  int num_threads;
196 
197  // The following Kokkos::View's are persisting storage for A's CCS arrays
199  host_value_type_array nzvals_view_;
201  host_ordinal_type_array rowind_view_;
203  host_ordinal_type_array colptr_view_;
204 
205 
206  bool is_contiguous_;
207 
208  typedef typename Kokkos::View<shylubasker_type**, Kokkos::LayoutLeft,
209  typename HostExecSpaceType::memory_space> host_solve_array_t;
210 
212  mutable host_solve_array_t xValues_;
213  int ldx_;
214 
216  mutable host_solve_array_t bValues_;
217  int ldb_;
218 
219  /*Handle for ShyLUBasker object*/
220 
221 #if defined( HAVE_AMESOS2_KOKKOS ) && defined( KOKKOS_ENABLE_OPENMP )
222  /*
223  typedef typename node_type::device_type kokkos_device;
224  typedef typename kokkos_device::execution_space kokkos_exe;
225  static_assert(std::is_same<kokkos_exe,Kokkos::OpenMP>::value,
226  "Kokkos node type not support by experimental ShyLUBasker Amesos2");
227  */
228  typedef Kokkos::OpenMP Exe_Space;
229  ::BaskerNS::BaskerTrilinosInterface<local_ordinal_type, shylubasker_dtype, Exe_Space> *ShyLUbasker;
230 #else
231  #pragma message("Amesos_ShyLUBasker_decl Error: ENABLED SHYLU_NODEBASKER BUT NOT KOKKOS or NOT OPENMP!")
232 #endif
233 
234 
235 }; // End class ShyLUBasker
236 
237 
238 // Specialize solver_traits struct for ShyLUBasker
239 // TODO
240 template <>
241 struct solver_traits<ShyLUBasker> {
242 #ifdef HAVE_TEUCHOS_COMPLEX
243 /*
244  typedef Meta::make_list4<float,
245  double,
246  std::complex<float>,
247  std::complex<double> > supported_scalars;
248 */
249  typedef Meta::make_list6<float,
250  double,
251  Kokkos::complex<float>,
252  Kokkos::complex<double>,
253  std::complex<float>,
254  std::complex<double> > supported_scalars;
255 #else
256  typedef Meta::make_list2<float, double> supported_scalars;
257 #endif
258 };
259 
260 template <typename Scalar, typename LocalOrdinal, typename ExecutionSpace>
261 struct solver_supports_matrix<ShyLUBasker,
262  KokkosSparse::CrsMatrix<Scalar, LocalOrdinal, ExecutionSpace>> {
263  static const bool value = true;
264 };
265 
266 } // end namespace Amesos2
267 
268 #endif // AMESOS2_SHYLUBASKER_DECL_HPP
Amesos2::SolverCore: A templated interface for interaction with third-party direct sparse solvers...
Definition: Amesos2_SolverCore_decl.hpp:105
int solve_impl(const Teuchos::Ptr< MultiVecAdapter< Vector > > X, const Teuchos::Ptr< const MultiVecAdapter< Vector > > B) const
ShyLUBasker specific solve.
Definition: Amesos2_ShyLUBasker_def.hpp:325
host_ordinal_type_array rowind_view_
Stores the location in Ai_ and Aval_ that starts row j.
Definition: Amesos2_ShyLUBasker_decl.hpp:201
host_value_type_array nzvals_view_
Stores the values of the nonzero entries for Umfpack.
Definition: Amesos2_ShyLUBasker_decl.hpp:199
Map types to solver-specific data-types and enums.
Definition: Amesos2_TypeMap.hpp:82
host_solve_array_t bValues_
Persisting 1D store for B.
Definition: Amesos2_ShyLUBasker_decl.hpp:216
Amesos2 interface to the Baker package.
Definition: Amesos2_ShyLUBasker_decl.hpp:76
Teuchos::RCP< const Teuchos::ParameterList > getValidParameters_impl() const
Definition: Amesos2_ShyLUBasker_def.hpp:526
int preOrdering_impl()
Performs pre-ordering on the matrix to increase efficiency.
Definition: Amesos2_ShyLUBasker_def.hpp:141
Provides traits about solvers.
Definition: Amesos2_SolverTraits.hpp:71
host_ordinal_type_array colptr_view_
Stores the row indices of the nonzero entries.
Definition: Amesos2_ShyLUBasker_decl.hpp:203
bool matrixShapeOK_impl() const
Determines whether the shape of the matrix is OK for this solver.
Definition: Amesos2_ShyLUBasker_def.hpp:400
bool loadA_impl(EPhase current_phase)
Reads matrix data into internal structures.
Definition: Amesos2_ShyLUBasker_def.hpp:591
A Matrix adapter interface for Amesos2.
Definition: Amesos2_MatrixAdapter_decl.hpp:76
std::string name() const override
Return the name of this solver.
Definition: Amesos2_SolverCore_def.hpp:759
int numericFactorization_impl()
ShyLUBasker specific numeric factorization.
Definition: Amesos2_ShyLUBasker_def.hpp:225
Passes functions to TPL functions based on type.
Definition: Amesos2_FunctionMap.hpp:76
host_solve_array_t xValues_
Persisting 1D store for X.
Definition: Amesos2_ShyLUBasker_decl.hpp:212
Provides access to interesting solver traits.
bool single_proc_optimization() const
can we optimize size_type and ordinal_type for straight pass through, also check that is_contiguous_ ...
Definition: Amesos2_ShyLUBasker_def.hpp:135