Amesos2 - Direct Sparse Solver Interfaces  Version of the Day
Amesos2_Umfpack_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 Sivasankaran Rajamanickam (srajama@sandia.gov)
39 //
40 // ***********************************************************************
41 //
42 // @HEADER
43 
44 #ifndef AMESOS2_UMFPACK_DECL_HPP
45 #define AMESOS2_UMFPACK_DECL_HPP
46 
47 #include "Amesos2_SolverTraits.hpp"
48 #include "Amesos2_SolverCore.hpp"
49 #include "Amesos2_Umfpack_FunctionMap.hpp"
50 
51 namespace Amesos2 {
52 
53 
61 template <class Matrix,
62  class Vector>
63 class Umfpack : public SolverCore<Amesos2::Umfpack, Matrix, Vector>
64 {
65  friend class SolverCore<Amesos2::Umfpack,Matrix,Vector>; // Give our base access
66  // to our private
67  // implementation funcs
68 public:
69 
71  static const char* name; // declaration. Initialization outside.
72 
73  typedef Umfpack<Matrix,Vector> type;
74  typedef SolverCore<Amesos2::Umfpack,Matrix,Vector> super_type;
75 
76  // Since typedef's are not inheritted, go grab them
77  typedef typename super_type::scalar_type scalar_type;
78  typedef typename super_type::local_ordinal_type local_ordinal_type;
79  typedef typename super_type::global_ordinal_type global_ordinal_type;
80  typedef typename super_type::global_size_type global_size_type;
81 
82  typedef TypeMap<Amesos2::Umfpack,scalar_type> type_map;
83 
84  /*
85  * The Umfpack interface will need two other typedef's, which are:
86  * - the umfpack type that corresponds to scalar_type and
87  * - the corresponding type to use for magnitude
88  */
89  typedef typename type_map::type umfpack_type;
90  typedef typename type_map::magnitude_type magnitude_type;
91 
92  typedef FunctionMap<Amesos2::Umfpack,umfpack_type> function_map;
93 
94  typedef Kokkos::DefaultHostExecutionSpace HostExecSpaceType;
95  typedef Kokkos::View<int*, HostExecSpaceType> host_size_type_array;
96  typedef Kokkos::View<int*, HostExecSpaceType> host_ordinal_type_array;
97  typedef Kokkos::View<umfpack_type*, HostExecSpaceType> host_value_type_array;
98 
100 
101 
108  Umfpack(Teuchos::RCP<const Matrix> A,
109  Teuchos::RCP<Vector> X,
110  Teuchos::RCP<const Vector> B);
111 
112 
114  ~Umfpack( );
115 
117 
119  std::string description() const;
120 
121 private:
122 
128  int preOrdering_impl();
129 
130 
139 
140 
147 
159  int solve_impl(const Teuchos::Ptr<MultiVecAdapter<Vector> > X,
160  const Teuchos::Ptr<const MultiVecAdapter<Vector> > B) const;
161 
162 
166  bool matrixShapeOK_impl() const;
167 
168 
171  void setParameters_impl(
172  const Teuchos::RCP<Teuchos::ParameterList> & parameterList );
173 
174 
181  Teuchos::RCP<const Teuchos::ParameterList> getValidParameters_impl() const;
182 
183 
192  bool loadA_impl(EPhase current_phase);
193 
194  // struct holds all data necessary to make a umfpack factorization or solve call
195  mutable struct UMFPACKData {
196  // Umfpack internal opaque object
197  void *Symbolic;
198  void *Numeric;
199 
200  // Info and Control state
201  double Info[UMFPACK_INFO];
202  double Control[UMFPACK_CONTROL];
203  } data_;
204 
205  // The following Kokkos::View's are persisting storage for A's CCS arrays
207  host_value_type_array nzvals_view_;
209  host_ordinal_type_array rowind_view_;
211  host_size_type_array colptr_view_;
212 
213  // The following Arrays are persisting storage arrays for X, and B
215  Teuchos::Array<umfpack_type> xvals_; int ldx_;
217  Teuchos::Array<umfpack_type> bvals_; int ldb_;
218 
219  bool is_contiguous_;
220 }; // End class Umfpack
221 
222 
223 // Specialize solver_traits struct for Umfpack
224 template <>
225 struct solver_traits<Umfpack> {
226 #ifdef HAVE_TEUCHOS_COMPLEX
227  typedef Meta::make_list4<float,
228  double,
229  std::complex<float>,
230  std::complex<double>
231  >supported_scalars;
232 #else
233  typedef Meta::make_list2<float,
234  double
235  >supported_scalars;
236 #endif
237 };
238 
239 } // end namespace Amesos2
240 
241 #endif // AMESOS2_UMFPACK_DECL_HPP
Amesos2::SolverCore: A templated interface for interaction with third-party direct sparse solvers...
Definition: Amesos2_SolverCore_decl.hpp:105
bool matrixShapeOK_impl() const
Determines whether the shape of the matrix is OK for this solver.
Definition: Amesos2_Umfpack_def.hpp:221
Teuchos::RCP< const Teuchos::ParameterList > getValidParameters_impl() const
Definition: Amesos2_Umfpack_def.hpp:248
int symbolicFactorization_impl()
Perform symbolic factorization of the matrix using Umfpack.
Definition: Amesos2_Umfpack_def.hpp:96
Map types to solver-specific data-types and enums.
Definition: Amesos2_TypeMap.hpp:82
int solve_impl(const Teuchos::Ptr< MultiVecAdapter< Vector > > X, const Teuchos::Ptr< const MultiVecAdapter< Vector > > B) const
Umfpack specific solve.
Definition: Amesos2_Umfpack_def.hpp:142
bool loadA_impl(EPhase current_phase)
Reads matrix data into internal structures.
Definition: Amesos2_Umfpack_def.hpp:266
Provides traits about solvers.
Definition: Amesos2_SolverTraits.hpp:71
int numericFactorization_impl()
Umfpack specific numeric factorization.
Definition: Amesos2_Umfpack_def.hpp:118
Teuchos::Array< umfpack_type > xvals_
Persisting 1D store for X.
Definition: Amesos2_Umfpack_decl.hpp:215
Amesos2 interface to the Umfpack package.
Definition: Amesos2_Umfpack_decl.hpp:63
host_size_type_array colptr_view_
Stores the row indices of the nonzero entries.
Definition: Amesos2_Umfpack_decl.hpp:211
int preOrdering_impl()
Performs pre-ordering on the matrix to increase efficiency.
Definition: Amesos2_Umfpack_def.hpp:88
std::string description() const
Returns a short description of this Solver.
Definition: Amesos2_Umfpack_def.hpp:79
std::string name() const override
Return the name of this solver.
Definition: Amesos2_SolverCore_def.hpp:759
host_ordinal_type_array rowind_view_
Stores the location in Ai_ and Aval_ that starts row j.
Definition: Amesos2_Umfpack_decl.hpp:209
Interface to Amesos2 solver objects.
Definition: Amesos2_Solver_decl.hpp:78
Passes functions to TPL functions based on type.
Definition: Amesos2_FunctionMap.hpp:76
Teuchos::Array< umfpack_type > bvals_
Persisting 1D store for B.
Definition: Amesos2_Umfpack_decl.hpp:217
Provides access to interesting solver traits.
host_value_type_array nzvals_view_
Stores the values of the nonzero entries for Umfpack.
Definition: Amesos2_Umfpack_decl.hpp:207