Ifpack2 Templated Preconditioning Package  Version 1.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
Ifpack2_Details_DenseSolver_decl.hpp
1 /*@HEADER
2 // ***********************************************************************
3 //
4 // Ifpack2: Templated Object-Oriented Algebraic Preconditioner Package
5 // Copyright (2009) Sandia Corporation
6 //
7 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
8 // license for use of this work by or on behalf of the U.S. Government.
9 //
10 // Redistribution and use in source and binary forms, with or without
11 // modification, are permitted provided that the following conditions are
12 // met:
13 //
14 // 1. Redistributions of source code must retain the above copyright
15 // notice, this list of conditions and the following disclaimer.
16 //
17 // 2. Redistributions in binary form must reproduce the above copyright
18 // notice, this list of conditions and the following disclaimer in the
19 // documentation and/or other materials provided with the distribution.
20 //
21 // 3. Neither the name of the Corporation nor the names of the
22 // contributors may be used to endorse or promote products derived from
23 // this software without specific prior written permission.
24 //
25 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
26 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
29 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
30 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
31 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
32 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 //
37 // Questions? Contact Michael A. Heroux (maherou@sandia.gov)
38 //
39 // ***********************************************************************
40 //@HEADER
41 */
42 
43 #ifndef IFPACK2_DETAILS_DENSESOLVER_DECL_HPP
44 #define IFPACK2_DETAILS_DENSESOLVER_DECL_HPP
45 
48 
49 #include "Ifpack2_ConfigDefs.hpp"
52 #include "Ifpack2_Details_LapackSupportsScalar.hpp"
53 #include "Tpetra_Import_fwd.hpp"
54 #include "Tpetra_Export_fwd.hpp"
56 #include <type_traits>
57 
58 namespace Ifpack2 {
59 namespace Details {
60 
73 template<class MatrixType,
74  const bool stub = ! LapackSupportsScalar<typename MatrixType::scalar_type>::value>
75 class DenseSolver :
76  public Ifpack2::Preconditioner<typename MatrixType::scalar_type,
77  typename MatrixType::local_ordinal_type,
78  typename MatrixType::global_ordinal_type,
79  typename MatrixType::node_type>,
80  virtual public Ifpack2::Details::CanChangeMatrix<Tpetra::RowMatrix<typename MatrixType::scalar_type,
81  typename MatrixType::local_ordinal_type,
82  typename MatrixType::global_ordinal_type,
83  typename MatrixType::node_type> >
84 {};
85 
87 template<class MatrixType>
88 class DenseSolver<MatrixType, false> :
89  public Ifpack2::Preconditioner<typename MatrixType::scalar_type,
90  typename MatrixType::local_ordinal_type,
91  typename MatrixType::global_ordinal_type,
92  typename MatrixType::node_type>,
93  virtual public Ifpack2::Details::CanChangeMatrix<Tpetra::RowMatrix<typename MatrixType::scalar_type,
94  typename MatrixType::local_ordinal_type,
95  typename MatrixType::global_ordinal_type,
96  typename MatrixType::node_type> >
97 {
98 public:
100 
101 
105  typedef MatrixType matrix_type;
106 
108  typedef typename MatrixType::scalar_type scalar_type;
109 
111  typedef typename MatrixType::local_ordinal_type local_ordinal_type;
112 
114  typedef typename MatrixType::global_ordinal_type global_ordinal_type;
115 
117  typedef typename MatrixType::node_type node_type;
118 
121 
123  typedef Tpetra::RowMatrix<scalar_type, local_ordinal_type, global_ordinal_type, node_type> row_matrix_type;
124 
125  static_assert(std::is_same<MatrixType, row_matrix_type>::value,
126  "Ifpack2::Details::DenseSolver: Please use MatrixType = Tpetra::RowMatrix.");
127 
128  typedef typename row_matrix_type::nonconst_global_inds_host_view_type nonconst_global_inds_host_view_type;
129  typedef typename row_matrix_type::nonconst_local_inds_host_view_type nonconst_local_inds_host_view_type;
130  typedef typename row_matrix_type::nonconst_values_host_view_type nonconst_values_host_view_type;
131 
132 
133 
135  typedef Tpetra::Map<local_ordinal_type, global_ordinal_type, node_type> map_type;
136 
138 
140 
145 
147  virtual ~DenseSolver ();
148 
150 
152 
153 
159 
165 
171  void
172  apply (const Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& X,
173  Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& Y,
177 
179 
181  void setParameters (const Teuchos::ParameterList& params);
182 
192  void initialize ();
193 
195  bool isInitialized () const;
196 
206  void compute ();
207 
209  bool isComputed () const;
210 
213 
216 
218  int getNumInitialize () const;
219 
221  int getNumCompute () const;
222 
224  int getNumApply() const;
225 
227  double getInitializeTime() const;
228 
230  double getComputeTime() const;
231 
233  double getApplyTime() const;
234 
236 
238 
240  std::string description () const;
241 
243  void
244  describe (Teuchos::FancyOStream &out,
245  const Teuchos::EVerbosityLevel verbLevel =
248 private:
249 
251  void
252  describeLocal (Teuchos::FancyOStream& out,
253  const Teuchos::EVerbosityLevel verbLevel) const;
254 
256  void reset ();
257 
265  static void
266  extract (Teuchos::SerialDenseMatrix<int, scalar_type>& A_local_dense,
267  const row_matrix_type& A_local);
268 
278  static void
280  const Teuchos::ArrayView<int>& ipiv);
281 
283  typedef Tpetra::MultiVector<scalar_type, local_ordinal_type,
285 
287  typedef Tpetra::Import<local_ordinal_type,
288  global_ordinal_type, node_type> import_type;
289 
291  typedef Tpetra::Export<local_ordinal_type,
292  global_ordinal_type, node_type> export_type;
293 
296 
305  void
306  applyImpl (const MV& X,
307  MV& Y,
308  const Teuchos::ETransp mode,
309  const scalar_type alpha,
310  const scalar_type beta) const;
311 
314 
317 
320 
322  Teuchos::Array<int> ipiv_;
323 
325  double initializeTime_;
326 
328  double computeTime_;
329 
331  mutable double applyTime_;
332 
334  int numInitialize_;
335 
337  int numCompute_;
338 
340  mutable int numApply_;
341 
343  bool isInitialized_;
344 
346  bool isComputed_;
347 };
348 
349 
351 template<class MatrixType>
352 class DenseSolver<MatrixType, true> :
353  public Ifpack2::Preconditioner<typename MatrixType::scalar_type,
354  typename MatrixType::local_ordinal_type,
355  typename MatrixType::global_ordinal_type,
356  typename MatrixType::node_type>,
357  virtual public Ifpack2::Details::CanChangeMatrix<Tpetra::RowMatrix<typename MatrixType::scalar_type,
358  typename MatrixType::local_ordinal_type,
359  typename MatrixType::global_ordinal_type,
360  typename MatrixType::node_type> >
361 {
362 public:
364 
365 
370  typedef MatrixType matrix_type;
371 
373  typedef typename MatrixType::scalar_type scalar_type;
374 
376  typedef typename MatrixType::local_ordinal_type local_ordinal_type;
377 
379  typedef typename MatrixType::global_ordinal_type global_ordinal_type;
380 
382  typedef typename MatrixType::node_type node_type;
383 
386 
388  typedef Tpetra::RowMatrix<scalar_type, local_ordinal_type, global_ordinal_type, node_type> row_matrix_type;
389 
391  typedef Tpetra::Map<local_ordinal_type, global_ordinal_type, node_type> map_type;
392 
394 
396 
401 
403  virtual ~DenseSolver ();
404 
406 
408 
414 
420 
426  void
427  apply (const Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& X,
428  Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& Y,
430  scalar_type alpha = Teuchos::ScalarTraits<scalar_type>::one(),
431  scalar_type beta = Teuchos::ScalarTraits<scalar_type>::zero()) const;
432 
434 
436  void setParameters (const Teuchos::ParameterList& params);
437 
447  void initialize ();
448 
450  bool isInitialized () const;
451 
461  void compute ();
462 
464  bool isComputed () const;
465 
468 
471 
473  int getNumInitialize () const;
474 
476  int getNumCompute () const;
477 
479  int getNumApply() const;
480 
482  double getInitializeTime() const;
483 
485  double getComputeTime() const;
486 
488  double getApplyTime() const;
489 
491 
493 
495  std::string description () const;
496 
498  void
499  describe (Teuchos::FancyOStream &out,
500  const Teuchos::EVerbosityLevel verbLevel =
503 private:
505  typedef Tpetra::MultiVector<scalar_type, local_ordinal_type,
506  global_ordinal_type, node_type> MV;
507 };
508 
509 } // namespace Details
510 } // namespace Ifpack2
511 
512 #endif // IFPACK2_DETAILS_DENSESOLVER_DECL_HPP
virtual Teuchos::RCP< const Tpetra::Map< MatrixType::local_ordinal_type, MatrixType::global_ordinal_type, MatrixType::node_type > > getDomainMap() const =0
The domain Map of this operator.
Mix-in interface for preconditioners that can change their matrix after construction.
Definition: Ifpack2_Details_CanChangeMatrix.hpp:93
Teuchos::ScalarTraits< scalar_type >::magnitudeType magnitude_type
The type of the absolute value (magnitude) of a scalar_type.
Definition: Ifpack2_Details_DenseSolver_decl.hpp:120
virtual Teuchos::RCP< const Tpetra::RowMatrix< MatrixType::scalar_type, MatrixType::local_ordinal_type, MatrixType::global_ordinal_type, MatrixType::node_type > > getMatrix() const =0
The input matrix given to the constructor.
Teuchos::ScalarTraits< MatrixType::scalar_type >::magnitudeType magnitude_type
The type of the magnitude (absolute value) of a matrix entry.
Definition: Ifpack2_Preconditioner.hpp:111
&quot;Preconditioner&quot; that uses LAPACK&#39;s dense LU.
Definition: Ifpack2_Details_DenseSolver_decl.hpp:75
virtual Teuchos::RCP< const Tpetra::Map< MatrixType::local_ordinal_type, MatrixType::global_ordinal_type, MatrixType::node_type > > getRangeMap() const =0
The range Map of this operator.
MatrixType::global_ordinal_type global_ordinal_type
The type of global indices in the input (global) matrix.
Definition: Ifpack2_Details_DenseSolver_decl.hpp:114
Interface for all Ifpack2 preconditioners.
Definition: Ifpack2_Preconditioner.hpp:107
MatrixType::node_type node_type
The Node type of the input (global) matrix.
Definition: Ifpack2_Details_DenseSolver_decl.hpp:117
MatrixType matrix_type
The first template parameter of this class.
Definition: Ifpack2_Details_DenseSolver_decl.hpp:105
Declaration of interface for preconditioners that can change their matrix after construction.
static const EVerbosityLevel verbLevel_default
virtual bool isComputed() const =0
True if the preconditioner has been successfully computed, else false.
MatrixType::local_ordinal_type local_ordinal_type
The type of local indices in the input (global) matrix.
Definition: Ifpack2_Details_DenseSolver_decl.hpp:111
virtual void setParameters(const Teuchos::ParameterList &List)=0
Set this preconditioner&#39;s parameters.
Tpetra::Map< local_ordinal_type, global_ordinal_type, node_type > map_type
Specialization of Tpetra::Map used by this class.
Definition: Ifpack2_Details_DenseSolver_decl.hpp:135
virtual void apply(const Tpetra::MultiVector< MatrixType::scalar_type, MatrixType::local_ordinal_type, MatrixType::global_ordinal_type, MatrixType::node_type > &X, Tpetra::MultiVector< MatrixType::scalar_type, MatrixType::local_ordinal_type, MatrixType::global_ordinal_type, MatrixType::node_type > &Y, Teuchos::ETransp mode=Teuchos::NO_TRANS, MatrixType::scalar_typealpha=Teuchos::ScalarTraits< MatrixType::scalar_type >::one(), MatrixType::scalar_typebeta=Teuchos::ScalarTraits< MatrixType::scalar_type >::zero()) const =0
Apply the preconditioner to X, putting the result in Y.
MatrixType::scalar_type scalar_type
The type of entries in the input (global) matrix.
Definition: Ifpack2_Details_DenseSolver_decl.hpp:108
Tpetra::RowMatrix< scalar_type, local_ordinal_type, global_ordinal_type, node_type > row_matrix_type
Specialization of Tpetra::RowMatrix used by this class.
Definition: Ifpack2_Details_DenseSolver_decl.hpp:123
virtual bool isInitialized() const =0
True if the preconditioner has been successfully initialized, else false.
virtual void setMatrix(const Teuchos::RCP< const Tpetra::RowMatrix< MatrixType::scalar_type, MatrixType::local_ordinal_type, MatrixType::global_ordinal_type, MatrixType::node_type > > &A)=0
Set the new matrix.