Ifpack2 Templated Preconditioning Package  Version 1.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
Ifpack2_BandedContainer_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 #ifndef IFPACK2_BANDEDCONTAINER_DECL_HPP
43 #define IFPACK2_BANDEDCONTAINER_DECL_HPP
44 
47 
48 #include "Ifpack2_Container.hpp"
50 #include "Ifpack2_Details_LapackSupportsScalar.hpp"
51 #include "Tpetra_MultiVector.hpp"
52 #include "Tpetra_Map.hpp"
53 #include "Tpetra_RowMatrix.hpp"
56 
57 namespace Ifpack2 {
58 
104 template<class MatrixType,
105  class LocalScalarType,
108 
109 template<class MatrixType, class LocalScalarType>
110 class BandedContainer<MatrixType, LocalScalarType, true> :
111  public Container<MatrixType> {
113 
114 private:
121  typedef MatrixType matrix_type;
123  typedef LocalScalarType local_scalar_type;
125  typedef typename Kokkos::Details::ArithTraits<local_scalar_type>::val_type local_impl_scalar_type;
126 
128  typedef typename Container<MatrixType>::scalar_type scalar_type;
130  typedef typename Container<MatrixType>::local_ordinal_type local_ordinal_type;
132  typedef typename Container<MatrixType>::global_ordinal_type global_ordinal_type;
134  typedef typename Container<MatrixType>::node_type node_type;
135 
136  typedef typename Container<MatrixType>::mv_type mv_type;
137  typedef typename Container<MatrixType>::map_type map_type;
138  typedef Tpetra::MultiVector<local_scalar_type, local_ordinal_type, global_ordinal_type, node_type> local_mv_type;
139  typedef typename Container<MatrixType>::vector_type vector_type;
140  typedef typename Container<MatrixType>::partitioner_type partitioner_type;
141  typedef typename Container<MatrixType>::import_type import_type;
142 
143  typedef typename Container<MatrixType>::HostView HostView;
144  typedef typename local_mv_type::dual_view_type::t_host HostViewLocal;
145 
146  static_assert(std::is_same<MatrixType,
147  Tpetra::RowMatrix<scalar_type, local_ordinal_type, global_ordinal_type, node_type> >::value,
148  "Ifpack2::BandedContainer: Please use MatrixType = Tpetra::RowMatrix.");
149 
158  typedef typename Container<MatrixType>::row_matrix_type row_matrix_type;
159 
161 public:
163 
164 
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 ~BandedContainer ();
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 
220  void clearBlocks();
221 
223  virtual void
224  apply (HostView& X,
225  HostView& Y,
226  int blockIndex,
227  int stride,
229  scalar_type alpha = Teuchos::ScalarTraits<scalar_type>::one(),
230  scalar_type beta = Teuchos::ScalarTraits<scalar_type>::zero()) const;
231 
233  virtual void
234  weightedApply (HostView& X,
235  HostView& Y,
236  HostView& D,
237  int blockIndex,
238  int stride,
240  scalar_type alpha = Teuchos::ScalarTraits<scalar_type>::one(),
241  scalar_type beta = Teuchos::ScalarTraits<scalar_type>::zero()) const;
242 
244 
246 
250  virtual std::ostream& print (std::ostream& os) const;
251 
253 
255 
257  virtual std::string description () const;
258 
260  virtual void
261  describe (Teuchos::FancyOStream &out,
262  const Teuchos::EVerbosityLevel verbLevel =
264 
266 
268  static std::string getName();
269 
270 private:
272  BandedContainer (const BandedContainer<MatrixType, LocalScalarType>& rhs);
273 
275  void extract ();
276 
280  void factor ();
281 
290  void
291  applyImpl (HostViewLocal& X,
292  HostViewLocal& Y,
293  int blockIndex,
294  int stride,
295  Teuchos::ETransp mode,
296  const local_scalar_type alpha,
297  const local_scalar_type beta) const;
298 
300  std::vector<Teuchos::SerialBandDenseMatrix<int, local_scalar_type> > diagBlocks_;
301 
303  mutable std::vector<HostViewLocal> X_local;
304 
306  mutable std::vector<HostViewLocal> Y_local;
307 
309  Teuchos::Array<int> ipiv_;
310 
312  bool IsInitialized_;
313 
315  bool IsComputed_;
316 
317  Teuchos::Array<local_ordinal_type> kl_; //< number of subdiagonals
318  Teuchos::Array<local_ordinal_type> ku_; //< number of superdiagonals
319 
321  local_scalar_type* scalars_;
322 
324  Teuchos::Array<local_ordinal_type> scalarOffsets_;
325 };
326 
327 template<class MatrixType, class LocalScalarType>
328 class BandedContainer<MatrixType, LocalScalarType, false> :
329  public Container<MatrixType> {
331 
332 private:
339  typedef MatrixType matrix_type;
341  typedef LocalScalarType local_scalar_type;
343  typedef typename Kokkos::Details::ArithTraits<local_scalar_type>::val_type local_impl_scalar_type;
344 
346  typedef typename Container<MatrixType>::scalar_type scalar_type;
348  typedef typename Container<MatrixType>::local_ordinal_type local_ordinal_type;
350  typedef typename Container<MatrixType>::global_ordinal_type global_ordinal_type;
352  typedef typename Container<MatrixType>::node_type node_type;
353 
354  typedef typename Container<MatrixType>::mv_type mv_type;
355  typedef typename Container<MatrixType>::map_type map_type;
356  typedef Tpetra::MultiVector<local_scalar_type, local_ordinal_type, global_ordinal_type, node_type> local_mv_type;
357  typedef typename Container<MatrixType>::vector_type vector_type;
358  typedef typename Container<MatrixType>::partitioner_type partitioner_type;
359  typedef typename Container<MatrixType>::import_type import_type;
360 
361  typedef typename Container<MatrixType>::HostView HostView;
362  typedef typename local_mv_type::dual_view_type::t_host HostViewLocal;
363 
364  static_assert(std::is_same<MatrixType,
365  Tpetra::RowMatrix<scalar_type, local_ordinal_type, global_ordinal_type, node_type> >::value,
366  "Ifpack2::BandedContainer: Please use MatrixType = Tpetra::RowMatrix.");
367 
376  typedef typename Container<MatrixType>::row_matrix_type row_matrix_type;
377 
379 public:
381 
382 
399  BandedContainer (const Teuchos::RCP<const row_matrix_type>& matrix,
401  const Teuchos::RCP<const import_type>& importer,
402  int OverlapLevel,
403  scalar_type DampingFactor);
404 
405  BandedContainer (const Teuchos::RCP<const row_matrix_type>& matrix,
406  const Teuchos::Array<local_ordinal_type>& localRows);
407 
409  virtual ~BandedContainer ();
410 
412 
414 
416  virtual bool isInitialized () const {
417  return IsInitialized_;
418  }
419 
421  virtual bool isComputed () const {
422  return IsComputed_;
423  }
424 
426  virtual void setParameters (const Teuchos::ParameterList& List);
427 
429 
431 
433  virtual void initialize ();
434 
436  virtual void compute ();
437 
438  void clearBlocks();
439 
441  virtual void
442  apply (HostView& X,
443  HostView& Y,
444  int blockIndex,
445  int stride,
447  scalar_type alpha = Teuchos::ScalarTraits<scalar_type>::one(),
448  scalar_type beta = Teuchos::ScalarTraits<scalar_type>::zero()) const;
449 
451  virtual void
452  weightedApply (HostView& X,
453  HostView& Y,
454  HostView& D,
455  int blockIndex,
456  int stride,
458  scalar_type alpha = Teuchos::ScalarTraits<scalar_type>::one(),
459  scalar_type beta = Teuchos::ScalarTraits<scalar_type>::zero()) const;
460 
462 
464 
468  virtual std::ostream& print (std::ostream& os) const;
469 
471 
473 
475  virtual std::string description () const;
476 
478  virtual void
479  describe (Teuchos::FancyOStream &out,
480  const Teuchos::EVerbosityLevel verbLevel =
482 
484 
486  static std::string getName();
487 
488 private:
490  BandedContainer (const BandedContainer<MatrixType, LocalScalarType>& rhs);
491 
493  void extract ();
494 
498  void factor ();
499 
508  void
509  applyImpl (HostViewLocal& X,
510  HostViewLocal& Y,
511  int blockIndex,
512  int stride,
513  Teuchos::ETransp mode,
514  const local_scalar_type alpha,
515  const local_scalar_type beta) const;
516 
518  std::vector<Teuchos::SerialBandDenseMatrix<int, local_scalar_type> > diagBlocks_;
519 
521  mutable std::vector<HostViewLocal> X_local;
522 
524  mutable std::vector<HostViewLocal> Y_local;
525 
527  Teuchos::Array<int> ipiv_;
528 
530  bool IsInitialized_;
531 
533  bool IsComputed_;
534 
535  Teuchos::Array<local_ordinal_type> kl_; //< number of subdiagonals
536  Teuchos::Array<local_ordinal_type> ku_; //< number of superdiagonals
537 
539  local_scalar_type* scalars_;
540 
542  Teuchos::Array<local_ordinal_type> scalarOffsets_;
543 };
544 
545 }// namespace Ifpack2
546 
547 #endif // IFPACK2_BANDEDCONTAINER_DECL_HPP
Ifpack2::Container class declaration.
Declaration and definition of the Ifpack2::Details::MultiVectorLocalGatherScatter class...
Ifpack2::Partitioner:
Definition: Ifpack2_Partitioner.hpp:179
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
Store and solve a local Banded linear problem.
Definition: Ifpack2_BandedContainer_decl.hpp:107