Ifpack2 Templated Preconditioning Package  Version 1.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
Ifpack2_BlockTriDiContainer_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_BLOCKTRIDICONTAINER_DECL_HPP
44 #define IFPACK2_BLOCKTRIDICONTAINER_DECL_HPP
45 
48 
49 #include "Ifpack2_config.h"
50 #include "Ifpack2_Container.hpp"
51 #include "Tpetra_MultiVector.hpp"
52 #include "Tpetra_Map.hpp"
53 #include "Tpetra_RowMatrix.hpp"
54 #include "Tpetra_BlockCrsMatrix_decl.hpp"
55 #include <type_traits>
56 #include <string>
57 
58 namespace Ifpack2 {
59 
107 
111  namespace BlockTriDiContainerDetails {
115  struct ImplNotAvailTag {};
116  struct ImplSimdTag {};
117  struct ImplSacadoTag {};
118 
119  template<typename T> struct ImplTag { typedef ImplNotAvailTag type; };
120  template<> struct ImplTag<float> { typedef ImplSimdTag type; };
121  template<> struct ImplTag<double> { typedef ImplSimdTag type; };
122  template<> struct ImplTag<std::complex<float> > { typedef ImplSimdTag type; };
123  template<> struct ImplTag<std::complex<double> > { typedef ImplSimdTag type; };
124 
126  template<typename MatrixType> struct ImplObject;
127  }
128 
132  template <typename MatrixType,
135 
141  template <typename MatrixType>
142  class BlockTriDiContainer<MatrixType,BlockTriDiContainerDetails::ImplSimdTag>
143  : public Container<MatrixType> {
145 
146  private:
152  typedef MatrixType matrix_type;
153 
155  typedef typename MatrixType::scalar_type scalar_type;
157  typedef typename Kokkos::ArithTraits<scalar_type>::magnitudeType magnitude_type;
159  typedef typename Container<MatrixType>::local_ordinal_type local_ordinal_type;
161  typedef typename Container<MatrixType>::global_ordinal_type global_ordinal_type;
163  typedef typename Container<MatrixType>::node_type node_type;
164 
165  typedef typename Container<MatrixType>::mv_type mv_type;
166  typedef typename Container<MatrixType>::map_type map_type;
167  typedef typename Container<MatrixType>::vector_type vector_type;
168  typedef typename Container<MatrixType>::import_type import_type;
169 
170  typedef typename Container<MatrixType>::HostView host_view_type;
171  typedef typename Container<MatrixType>::ConstHostView const_host_view_type;
172  typedef host_view_type HostView;
173  typedef const_host_view_type ConstHostView;
174  //typedef Tpetra::MultiVector<local_scalar_type, local_ordinal_type, global_ordinal_type, node_type> local_mv_type;
175  //typedef typename Kokkos::View<local_scalar_type**, Kokkos::HostSpace> HostViewLocal;
176 
177  typedef Tpetra::CrsMatrix
178  <scalar_type,local_ordinal_type,global_ordinal_type,node_type> crs_matrix_type;
179  typedef Tpetra::BlockCrsMatrix
180  <scalar_type,local_ordinal_type,global_ordinal_type,node_type> block_crs_matrix_type;
181 
183 
190  typedef typename Container<MatrixType>::row_matrix_type row_matrix_type;
191 
192  static_assert (std::is_same<MatrixType, row_matrix_type>::value,
193  "Ifpack2::BlockTriDiContainer: MatrixType must be a Tpetra::RowMatrix specialization.");
195  public:
197 
198 
216  const Teuchos::RCP<const import_type>& importer,
217  bool pointIndexed);
218 
235  const int n_subparts_per_part = 1,
236  bool overlapCommAndComp = false,
237  bool useSequentialMethod = false,
238  const int block_size = -1);
239 
241  ~BlockTriDiContainer () override;
242 
243  struct ComputeParameters {
250  magnitude_type addRadiallyToDiagonal = Kokkos::ArithTraits<magnitude_type>::zero();
251  };
252 
254  struct ApplyParameters {
257  bool zeroStartingSolution = false;
259  scalar_type dampingFactor = Kokkos::ArithTraits<scalar_type>::one();
262  int maxNumSweeps = 1;
272  magnitude_type tolerance = Kokkos::ArithTraits<magnitude_type>::zero();
280  int checkToleranceEvery = 1;
281  };
282 
284 
286 
288  void setParameters(const Teuchos::ParameterList& List) override;
289 
290  void clearBlocks() override;
291 
293 
295 
297  void initialize () override;
298 
300  void compute () override;
301 
302  // \brief Compute <tt>Y := D^{-1} (X - R*Y)</tt>.
303  void applyInverseJacobi (const mv_type& X, mv_type& Y,
304  scalar_type dampingFactor,
305  bool zeroStartingSolution = false,
306  int numSweeps = 1) const override;
307 
309  ComputeParameters createDefaultComputeParameters () const;
310 
322  void compute (const ComputeParameters& input);
323 
325  ApplyParameters createDefaultApplyParameters () const;
326 
333  int applyInverseJacobi (const mv_type& X, mv_type& Y,
334  const ApplyParameters& input) const;
335 
339  const magnitude_type getNorms0 () const;
340 
343  const magnitude_type getNormsFinal () const;
344 
347  void
348  apply (const_host_view_type X,
349  host_view_type Y,
350  int blockIndex,
352  scalar_type alpha = Teuchos::ScalarTraits<scalar_type>::one(),
353  scalar_type beta = Teuchos::ScalarTraits<scalar_type>::zero()) const override;
354 
357  void
358  weightedApply (const_host_view_type X,
359  host_view_type Y,
360  const_host_view_type W,
361  int blockIndex,
363  scalar_type alpha = Teuchos::ScalarTraits<scalar_type>::one(),
364  scalar_type beta = Teuchos::ScalarTraits<scalar_type>::zero()) const override;
365 
367 
369 
373  std::ostream& print (std::ostream& os) const override;
374 
376 
378 
380  std::string description () const override;
381 
383  void
384  describe (Teuchos::FancyOStream &out,
385  const Teuchos::EVerbosityLevel verbLevel =
387 
389 
391  static std::string getName();
392 
393  private:
396 
397  // hide details of impl using ImplObj; finally I understand why AMB did that way.
399  int n_subparts_per_part_;
400 
401  // initialize distributed and local objects
402  void initInternal (const Teuchos::RCP<const row_matrix_type>& matrix,
403  const Teuchos::RCP<const import_type> &importer,
404  const bool overlapCommAndComp,
405  const bool useSeqMethod,
406  const int block_size = -1);
407 
408  void clearInternal();
409  };
410 
418  template <typename MatrixType>
419  class BlockTriDiContainer<MatrixType,BlockTriDiContainerDetails::ImplNotAvailTag>
420  : public Container<MatrixType> {
421  private:
422  typedef typename MatrixType::scalar_type scalar_type;
423  typedef typename Kokkos::ArithTraits<scalar_type>::magnitudeType magnitude_type;
424  typedef typename Container<MatrixType>::local_ordinal_type local_ordinal_type;
425  typedef typename Container<MatrixType>::global_ordinal_type global_ordinal_type;
426 
427  typedef typename Container<MatrixType>::mv_type mv_type;
428  typedef typename Container<MatrixType>::import_type import_type;
429 
430  typedef typename Container<MatrixType>::HostView host_view_type;
431  typedef typename Container<MatrixType>::ConstHostView const_host_view_type;
432  typedef typename Container<MatrixType>::row_matrix_type row_matrix_type;
433 
434  static_assert (std::is_same<MatrixType, row_matrix_type>::value,
435  "Ifpack2::BlockTriDiContainer: MatrixType must be a Tpetra::RowMatrix specialization.");
436  public:
437 
440  const Teuchos::RCP<const import_type>& importer,
441  bool pointIndexed)
442  : Container<MatrixType>(matrix, partitions, pointIndexed) {
443  TEUCHOS_TEST_FOR_EXCEPT_MSG(true, "Error: BlockTriDiContainer is not available for this scalar_type");
444  }
445 
446  void setParameters(const Teuchos::ParameterList& List) override {}
447  void clearBlocks() override {}
448 
449  void initialize () override {}
450  void compute () override {}
451  void applyInverseJacobi (const mv_type& X, mv_type& Y,
452  scalar_type dampingFactor,
453  bool zeroStartingSolution = false,
454  int numSweeps = 1) const override {}
455 
456  void
457  apply (const_host_view_type X,
458  host_view_type Y,
459  int blockIndex,
461  scalar_type alpha = Teuchos::ScalarTraits<scalar_type>::one(),
462  scalar_type beta = Teuchos::ScalarTraits<scalar_type>::zero()) const override {}
463 
464  void
465  weightedApply (const_host_view_type X,
466  host_view_type Y,
467  const_host_view_type W,
468  int blockIndex,
470  scalar_type alpha = Teuchos::ScalarTraits<scalar_type>::one(),
471  scalar_type beta = Teuchos::ScalarTraits<scalar_type>::zero()) const override {}
472 
473  std::ostream& print (std::ostream& os) const override {
474  return os << "Ifpack2::BlockTriDiContainer::ImplNotAvailTag";
475  }
476 
477  std::string description () const override {
478  return "Ifpack2::BlockTriDiContainer::ImplNotAvailTag";
479  }
480 
481  void
482  describe (Teuchos::FancyOStream &out,
483  const Teuchos::EVerbosityLevel verbLevel =
485  out << "Ifpack2::BlockTriDiContainer::ImplNotAvailTag";
486  }
487 
488  static std::string getName() {
489  return "Ifpack2::BlockTriDiContainer::ImplNotAvailTag";
490  }
491  };
492 
493 
494 } // namespace Ifpack2
495 
496 #endif // IFPACK2_BLOCKTRIDICONTAINER_DECL_HPP
Definition: Ifpack2_BlockTriDiContainer_decl.hpp:115
void compute() override
Extract the local diagonal blocks and prepare the solver.
Definition: Ifpack2_BlockTriDiContainer_decl.hpp:450
Store and solve local block tridiagonal linear problems.
Definition: Ifpack2_BlockTriDiContainer_decl.hpp:134
void initialize() override
Do all set-up operations that only require matrix structure.
Definition: Ifpack2_BlockTriDiContainer_decl.hpp:449
#define TEUCHOS_TEST_FOR_EXCEPT_MSG(throw_exception_test, msg)
forward declaration
Definition: Ifpack2_BlockTriDiContainer_decl.hpp:126
typename mv_type::dual_view_type::t_host HostView
Definition: Ifpack2_Container_decl.hpp:139
std::ostream & print(std::ostream &os) const override
Print basic information about the container to os.
Definition: Ifpack2_BlockTriDiContainer_decl.hpp:473
void setParameters(const Teuchos::ParameterList &List) override
Set parameters, if any.
Definition: Ifpack2_BlockTriDiContainer_decl.hpp:446
static const EVerbosityLevel verbLevel_default
Interface for creating and solving a set of local linear problems.
Definition: Ifpack2_Container_decl.hpp:112