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 // Ifpack2: Templated Object-Oriented Algebraic Preconditioner Package
4 //
5 // Copyright 2009 NTESS and the Ifpack2 contributors.
6 // SPDX-License-Identifier: BSD-3-Clause
7 // *****************************************************************************
8 // @HEADER
9 
10 #ifndef IFPACK2_BLOCKTRIDICONTAINER_DECL_HPP
11 #define IFPACK2_BLOCKTRIDICONTAINER_DECL_HPP
12 
15 
16 #include "Ifpack2_config.h"
17 #include "Ifpack2_Container.hpp"
18 #include "Tpetra_MultiVector.hpp"
19 #include "Tpetra_Map.hpp"
20 #include "Tpetra_RowMatrix.hpp"
21 #include "Tpetra_BlockCrsMatrix_decl.hpp"
22 #include <type_traits>
23 #include <string>
24 
25 namespace Ifpack2 {
26 
74 
78 namespace BlockTriDiContainerDetails {
82 struct ImplNotAvailTag {};
83 struct ImplSimdTag {};
84 struct ImplSacadoTag {};
85 
86 template <typename T>
87 struct ImplTag { typedef ImplNotAvailTag type; };
88 template <>
89 struct ImplTag<float> { typedef ImplSimdTag type; };
90 template <>
91 struct ImplTag<double> { typedef ImplSimdTag type; };
92 template <>
93 struct ImplTag<std::complex<float> > { typedef ImplSimdTag type; };
94 template <>
95 struct ImplTag<std::complex<double> > { typedef ImplSimdTag type; };
96 
98 template <typename MatrixType>
99 struct ImplObject;
100 } // namespace BlockTriDiContainerDetails
101 
105 template <typename MatrixType,
108 
114 template <typename MatrixType>
115 class BlockTriDiContainer<MatrixType, BlockTriDiContainerDetails::ImplSimdTag>
116  : public Container<MatrixType> {
118 
119  private:
125  typedef MatrixType matrix_type;
126 
128  typedef typename MatrixType::scalar_type scalar_type;
130 #if KOKKOS_VERSION >= 40799
131  typedef typename KokkosKernels::ArithTraits<scalar_type>::magnitudeType magnitude_type;
132 #else
133  typedef typename Kokkos::ArithTraits<scalar_type>::magnitudeType magnitude_type;
134 #endif
135  typedef typename Container<MatrixType>::local_ordinal_type local_ordinal_type;
138  typedef typename Container<MatrixType>::global_ordinal_type global_ordinal_type;
140  typedef typename Container<MatrixType>::node_type node_type;
141 
142  typedef typename Container<MatrixType>::mv_type mv_type;
143  typedef typename Container<MatrixType>::map_type map_type;
144  typedef typename Container<MatrixType>::vector_type vector_type;
145  typedef typename Container<MatrixType>::import_type import_type;
146 
147  typedef typename Container<MatrixType>::HostView host_view_type;
148  typedef typename Container<MatrixType>::ConstHostView const_host_view_type;
149  typedef host_view_type HostView;
150  typedef const_host_view_type ConstHostView;
151  // typedef Tpetra::MultiVector<local_scalar_type, local_ordinal_type, global_ordinal_type, node_type> local_mv_type;
152  // typedef typename Kokkos::View<local_scalar_type**, Kokkos::HostSpace> HostViewLocal;
153 
154  typedef Tpetra::CrsMatrix<scalar_type, local_ordinal_type, global_ordinal_type, node_type> crs_matrix_type;
155  typedef Tpetra::BlockCrsMatrix<scalar_type, local_ordinal_type, global_ordinal_type, node_type> block_crs_matrix_type;
156 
158 
165  typedef typename Container<MatrixType>::row_matrix_type row_matrix_type;
166 
167  static_assert(std::is_same<MatrixType, row_matrix_type>::value,
168  "Ifpack2::BlockTriDiContainer: MatrixType must be a Tpetra::RowMatrix specialization.");
170  public:
172 
173 
191  const Teuchos::RCP<const import_type>& importer,
192  bool pointIndexed);
193 
210  const int n_subparts_per_part = 1,
211  bool overlapCommAndComp = false,
212  bool useSequentialMethod = false,
213  const int block_size = -1,
214  const bool explicitConversion = false);
215 
217  ~BlockTriDiContainer() override;
218 
219  struct ComputeParameters {
226 #if KOKKOS_VERSION >= 40799
227  magnitude_type addRadiallyToDiagonal = KokkosKernels::ArithTraits<magnitude_type>::zero();
228 #else
229  magnitude_type addRadiallyToDiagonal = Kokkos::ArithTraits<magnitude_type>::zero();
230 #endif
231  };
232 
234  struct ApplyParameters {
237  bool zeroStartingSolution = false;
239 #if KOKKOS_VERSION >= 40799
240  scalar_type dampingFactor = KokkosKernels::ArithTraits<scalar_type>::one();
241 #else
242  scalar_type dampingFactor = Kokkos::ArithTraits<scalar_type>::one();
243 #endif
244  int maxNumSweeps = 1;
256 #if KOKKOS_VERSION >= 40799
257  magnitude_type tolerance = KokkosKernels::ArithTraits<magnitude_type>::zero();
258 #else
259  magnitude_type tolerance = Kokkos::ArithTraits<magnitude_type>::zero();
260 #endif
261  int checkToleranceEvery = 1;
269  };
270 
272 
274 
276  void setParameters(const Teuchos::ParameterList& List) override;
277 
278  void clearBlocks() override;
279 
281 
283 
285  void initialize() override;
286 
288  void compute() override;
289 
290  // \brief Compute <tt>Y := D^{-1} (X - R*Y)</tt>.
291  void applyInverseJacobi(const mv_type& X, mv_type& Y,
292  scalar_type dampingFactor,
293  bool zeroStartingSolution = false,
294  int numSweeps = 1) const override;
295 
297  ComputeParameters createDefaultComputeParameters() const;
298 
310  void compute(const ComputeParameters& input);
311 
313  ApplyParameters createDefaultApplyParameters() const;
314 
321  int applyInverseJacobi(const mv_type& X, mv_type& Y,
322  const ApplyParameters& input) const;
323 
327  const magnitude_type getNorms0() const;
328 
331  const magnitude_type getNormsFinal() const;
332 
335  void
336  apply(const_host_view_type X,
337  host_view_type Y,
338  int blockIndex,
340  scalar_type alpha = Teuchos::ScalarTraits<scalar_type>::one(),
341  scalar_type beta = Teuchos::ScalarTraits<scalar_type>::zero()) const override;
342 
345  void
346  weightedApply(const_host_view_type X,
347  host_view_type Y,
348  const_host_view_type W,
349  int blockIndex,
351  scalar_type alpha = Teuchos::ScalarTraits<scalar_type>::one(),
352  scalar_type beta = Teuchos::ScalarTraits<scalar_type>::zero()) const override;
353 
355 
357 
361  std::ostream& print(std::ostream& os) const override;
362 
364 
366 
368  std::string description() const override;
369 
371  void
372  describe(Teuchos::FancyOStream& out,
373  const Teuchos::EVerbosityLevel verbLevel =
375 
377 
379  static std::string getName();
380 
381  private:
384 
385  // hide details of impl using ImplObj; finally I understand why AMB did that way.
387  int n_subparts_per_part_;
388  int block_size_ = -1;
389 
390  // initialize distributed and local objects
391  void initInternal(const Teuchos::RCP<const row_matrix_type>& matrix,
392  const Teuchos::RCP<const import_type>& importer,
393  const bool overlapCommAndComp,
394  const bool useSeqMethod,
395  const int block_size = -1,
396  const bool explicitConversion = false);
397 
398  void clearInternal();
399 
400  // Decide whether the fused block Jacobi path can and should be used.
401  bool shouldUseFusedBlockJacobi(
404  bool useSeqMethod);
405 };
406 
414 template <typename MatrixType>
415 class BlockTriDiContainer<MatrixType, BlockTriDiContainerDetails::ImplNotAvailTag>
416  : public Container<MatrixType> {
417  private:
418  typedef typename MatrixType::scalar_type scalar_type;
419 #if KOKKOS_VERSION >= 40799
420  typedef typename KokkosKernels::ArithTraits<scalar_type>::magnitudeType magnitude_type;
421 #else
422  typedef typename Kokkos::ArithTraits<scalar_type>::magnitudeType magnitude_type;
423 #endif
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 
437  public:
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 } // namespace Ifpack2
494 
495 #endif // IFPACK2_BLOCKTRIDICONTAINER_DECL_HPP
Definition: Ifpack2_BlockTriDiContainer_decl.hpp:82
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:107
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:99
typename mv_type::dual_view_type::t_host HostView
Definition: Ifpack2_Container_decl.hpp:109
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:79