Ifpack2 Templated Preconditioning Package  Version 1.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
Ifpack2_DenseContainer_decl.hpp
Go to the documentation of this file.
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_DENSECONTAINER_DECL_HPP
44 #define IFPACK2_DENSECONTAINER_DECL_HPP
45 
48 
49 #include "Ifpack2_Container.hpp"
51 #include "Ifpack2_Details_LapackSupportsScalar.hpp"
52 #include "Tpetra_MultiVector.hpp"
53 #include "Tpetra_Map.hpp"
54 #include "Tpetra_RowMatrix.hpp"
56 #include "Tpetra_Experimental_BlockCrsMatrix_decl.hpp"
57 
58 namespace Ifpack2 {
59 
105 
106 template<class MatrixType, class LocalScalarType,
109 
110 template<class MatrixType, class LocalScalarType>
111 class DenseContainer<MatrixType, LocalScalarType, true> :
112  public Container<MatrixType> {
114 
115 private:
122  typedef MatrixType matrix_type;
124  typedef LocalScalarType local_scalar_type;
126  typedef typename Kokkos::Details::ArithTraits<local_scalar_type>::val_type local_impl_scalar_type;
127 
129  typedef typename Container<MatrixType>::scalar_type scalar_type;
131  typedef typename Container<MatrixType>::local_ordinal_type local_ordinal_type;
133  typedef typename Container<MatrixType>::global_ordinal_type global_ordinal_type;
135  typedef typename Container<MatrixType>::node_type node_type;
136 
137  typedef typename Container<MatrixType>::mv_type mv_type;
138  typedef Tpetra::MultiVector<local_scalar_type, local_ordinal_type, global_ordinal_type, node_type> local_mv_type;
139  typedef Tpetra::Vector<local_scalar_type, local_ordinal_type, global_ordinal_type, node_type> local_vector_type;
140  typedef typename Container<MatrixType>::map_type map_type;
141  typedef typename Container<MatrixType>::vector_type vector_type;
142  typedef typename Container<MatrixType>::partitioner_type partitioner_type;
143  typedef typename Container<MatrixType>::import_type import_type;
144 
145  typedef typename Container<MatrixType>::HostView HostView;
146  typedef typename local_mv_type::dual_view_type::t_host HostViewLocal;
147 
148  static_assert(std::is_same<MatrixType, Tpetra::RowMatrix<scalar_type, local_ordinal_type, global_ordinal_type, node_type>>::value,
149  "Ifpack2::DenseContainer: Please use MatrixType = Tpetra::RowMatrix.");
150 
159  typedef typename Container<MatrixType>::row_matrix_type row_matrix_type;
160 
161  typedef Tpetra::Experimental::BlockCrsMatrix<scalar_type, local_ordinal_type, global_ordinal_type, node_type> block_crs_matrix_type;
163 
164 public:
166 
167 
183  const Teuchos::RCP<const import_type>& importer,
184  int OverlapLevel,
185  scalar_type DampingFactor);
186 
188  const Teuchos::Array<local_ordinal_type>& localRows);
189 
191  virtual ~DenseContainer ();
192 
194 
196 
198  virtual bool isInitialized () const {
199  return IsInitialized_;
200  }
201 
203  virtual bool isComputed () const {
204  return IsComputed_;
205  }
206 
208  virtual void setParameters(const Teuchos::ParameterList& List);
209 
211 
213 
215  virtual void initialize ();
216 
218  virtual void compute ();
219 
221  virtual void
222  applyBlockCrs (HostView& X,
223  HostView& Y,
224  int blockIndex,
225  int stride,
227  scalar_type alpha = Teuchos::ScalarTraits<scalar_type>::one(),
228  scalar_type beta = Teuchos::ScalarTraits<scalar_type>::zero()) const;
229 
231  virtual void
232  apply (HostView& X,
233  HostView& Y,
234  int blockIndex,
235  int stride,
237  scalar_type alpha = Teuchos::ScalarTraits<scalar_type>::one(),
238  scalar_type beta = Teuchos::ScalarTraits<scalar_type>::zero()) const;
239 
241  virtual void
242  weightedApply (HostView& X,
243  HostView& Y,
244  HostView& W,
245  int blockIndex,
246  int stride,
248  scalar_type alpha = Teuchos::ScalarTraits<scalar_type>::one(),
249  scalar_type beta = Teuchos::ScalarTraits<scalar_type>::zero()) const;
250 
251  void clearBlocks();
252 
254 
256 
260  virtual std::ostream& print (std::ostream& os) const;
261 
263 
265 
267  virtual std::string description () const;
268 
270  virtual void
271  describe (Teuchos::FancyOStream &out,
272  const Teuchos::EVerbosityLevel verbLevel =
274 
276 
278  static std::string getName();
279 
280 private:
281 
283  DenseContainer (const DenseContainer<MatrixType, LocalScalarType>& rhs);
284 
286  void extractBlockCrs ();
287 
289  void extract ();
290 
294  void factor ();
295 
304  void
305  applyImpl (HostViewLocal& X,
306  HostViewLocal& Y,
307  int blockIndex,
308  int stride,
309  Teuchos::ETransp mode,
310  const local_scalar_type alpha,
311  const local_scalar_type beta) const;
312 
313  void
314  applyImplBlockCrs (HostViewLocal& X,
315  HostViewLocal& Y,
316  int blockIndex,
317  int stride,
318  Teuchos::ETransp mode,
319  const local_scalar_type alpha,
320  const local_scalar_type beta) const;
321 
323  std::vector<Teuchos::SerialDenseMatrix<int, local_scalar_type>> diagBlocks_;
324 
326  mutable std::vector<HostViewLocal> X_local;
327 
329  mutable std::vector<HostViewLocal> Y_local;
330 
332  Teuchos::Array<int> ipiv_;
333 
335  bool IsInitialized_;
336 
338  bool IsComputed_;
339 
341  bool hasBlockCrsMatrix_;
342 
344  local_scalar_type* scalars_;
345 
348 };
349 
350 template<class MatrixType, class LocalScalarType>
351 class DenseContainer<MatrixType, LocalScalarType, false> :
352  public Container<MatrixType> {
354 
355 private:
362  typedef MatrixType matrix_type;
364  typedef LocalScalarType local_scalar_type;
366  typedef typename Kokkos::Details::ArithTraits<local_scalar_type>::val_type local_impl_scalar_type;
367 
369  typedef typename Container<MatrixType>::scalar_type scalar_type;
371  typedef typename Container<MatrixType>::local_ordinal_type local_ordinal_type;
373  typedef typename Container<MatrixType>::global_ordinal_type global_ordinal_type;
375  typedef typename Container<MatrixType>::node_type node_type;
376 
377  typedef typename Container<MatrixType>::mv_type mv_type;
378  typedef Tpetra::MultiVector<local_scalar_type, local_ordinal_type, global_ordinal_type, node_type> local_mv_type;
379  typedef Tpetra::Vector<local_scalar_type, local_ordinal_type, global_ordinal_type, node_type> local_vector_type;
380  typedef typename Container<MatrixType>::map_type map_type;
381  typedef typename Container<MatrixType>::vector_type vector_type;
382  typedef typename Container<MatrixType>::partitioner_type partitioner_type;
383  typedef typename Container<MatrixType>::import_type import_type;
384 
385  typedef typename Container<MatrixType>::HostView HostView;
386  typedef typename local_mv_type::dual_view_type::t_host HostViewLocal;
387 
388  static_assert(std::is_same<MatrixType, Tpetra::RowMatrix<scalar_type, local_ordinal_type, global_ordinal_type, node_type>>::value,
389  "Ifpack2::DenseContainer: Please use MatrixType = Tpetra::RowMatrix.");
390 
399  typedef typename Container<MatrixType>::row_matrix_type row_matrix_type;
400 
401  typedef Tpetra::Experimental::BlockCrsMatrix<scalar_type, local_ordinal_type, global_ordinal_type, node_type> block_crs_matrix_type;
403 
404 public:
406 
407 
421  DenseContainer (const Teuchos::RCP<const row_matrix_type>& matrix,
423  const Teuchos::RCP<const import_type>& importer,
424  int OverlapLevel,
425  scalar_type DampingFactor);
426 
427  DenseContainer (const Teuchos::RCP<const row_matrix_type>& matrix,
428  const Teuchos::Array<local_ordinal_type>& localRows);
429 
431  virtual ~DenseContainer ();
432 
434 
436 
438  virtual bool isInitialized () const {
439  return IsInitialized_;
440  }
441 
443  virtual bool isComputed () const {
444  return IsComputed_;
445  }
446 
448  virtual void setParameters(const Teuchos::ParameterList& List);
449 
451 
453 
455  virtual void initialize ();
456 
458  virtual void compute ();
459 
461  virtual void
462  applyBlockCrs (HostView& X,
463  HostView& Y,
464  int blockIndex,
465  int stride,
467  scalar_type alpha = Teuchos::ScalarTraits<scalar_type>::one(),
468  scalar_type beta = Teuchos::ScalarTraits<scalar_type>::zero()) const;
469 
471  virtual void
472  apply (HostView& X,
473  HostView& Y,
474  int blockIndex,
475  int stride,
477  scalar_type alpha = Teuchos::ScalarTraits<scalar_type>::one(),
478  scalar_type beta = Teuchos::ScalarTraits<scalar_type>::zero()) const;
479 
481  virtual void
482  weightedApply (HostView& X,
483  HostView& Y,
484  HostView& W,
485  int blockIndex,
486  int stride,
488  scalar_type alpha = Teuchos::ScalarTraits<scalar_type>::one(),
489  scalar_type beta = Teuchos::ScalarTraits<scalar_type>::zero()) const;
490 
491  void clearBlocks();
492 
494 
496 
500  virtual std::ostream& print (std::ostream& os) const;
501 
503 
505 
507  virtual std::string description () const;
508 
510  virtual void
511  describe (Teuchos::FancyOStream &out,
512  const Teuchos::EVerbosityLevel verbLevel =
514 
516 
518  static std::string getName();
519 
520 private:
521 
523  DenseContainer (const DenseContainer<MatrixType, LocalScalarType>& rhs);
524 
526  void extractBlockCrs ();
527 
529  void extract ();
530 
534  void factor ();
535 
544  void
545  applyImpl (HostViewLocal& X,
546  HostViewLocal& Y,
547  int blockIndex,
548  int stride,
549  Teuchos::ETransp mode,
550  const local_scalar_type alpha,
551  const local_scalar_type beta) const;
552 
553  void
554  applyImplBlockCrs (HostViewLocal& X,
555  HostViewLocal& Y,
556  int blockIndex,
557  int stride,
558  Teuchos::ETransp mode,
559  const local_scalar_type alpha,
560  const local_scalar_type beta) const;
561 
563  std::vector<Teuchos::SerialDenseMatrix<int, local_scalar_type>> diagBlocks_;
564 
566  mutable std::vector<HostViewLocal> X_local;
567 
569  mutable std::vector<HostViewLocal> Y_local;
570 
572  Teuchos::Array<int> ipiv_;
573 
575  bool IsInitialized_;
576 
578  bool IsComputed_;
579 
581  bool hasBlockCrsMatrix_;
582 
584  local_scalar_type* scalars_;
585 
588 };
589 
590 } // namespace Ifpack2
591 
592 #endif // IFPACK2_DENSECONTAINER_DECL_HPP
Ifpack2::Container class declaration.
Declaration and definition of the Ifpack2::Details::MultiVectorLocalGatherScatter class...
Ifpack2::Partitioner:
Definition: Ifpack2_Partitioner.hpp:179
Store and solve a local dense linear problem.
Definition: Ifpack2_DenseContainer_decl.hpp:108
static const EVerbosityLevel verbLevel_default
Interface for creating and solving a local linear problem.
Definition: Ifpack2_Container.hpp:114
Type traits class that says whether Teuchos::LAPACK has a valid implementation for the given ScalarTy...
Definition: Ifpack2_Details_LapackSupportsScalar.hpp:17