Ifpack2 Templated Preconditioning Package Version 1.0
Loading...
Searching...
No Matches
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 "Ifpack2_BlockHelper_ETI.hpp"
23#include <type_traits>
24#include <string>
25
26namespace Ifpack2 {
27
75
79template <typename MatrixType,
80 typename ImplTagType = typename BlockTriDiContainerDetails::ImplTag<typename MatrixType::scalar_type>::type>
82
88template <typename MatrixType>
89class BlockTriDiContainer<MatrixType, BlockTriDiContainerDetails::ImplSimdTag>
90 : public Container<MatrixType> {
92
93 private:
99 typedef MatrixType matrix_type;
100
102 typedef typename MatrixType::scalar_type scalar_type;
104 typedef typename KokkosKernels::ArithTraits<scalar_type>::magnitudeType magnitude_type;
106 typedef typename Container<MatrixType>::local_ordinal_type local_ordinal_type;
108 typedef typename Container<MatrixType>::global_ordinal_type global_ordinal_type;
110 typedef typename Container<MatrixType>::node_type node_type;
111
112 typedef typename Container<MatrixType>::mv_type mv_type;
113 typedef typename Container<MatrixType>::map_type map_type;
114 typedef typename Container<MatrixType>::vector_type vector_type;
115 typedef typename Container<MatrixType>::import_type import_type;
116
117 typedef typename Container<MatrixType>::HostView host_view_type;
118 typedef typename Container<MatrixType>::ConstHostView const_host_view_type;
119 typedef host_view_type HostView;
120 typedef const_host_view_type ConstHostView;
121 // typedef Tpetra::MultiVector<local_scalar_type, local_ordinal_type, global_ordinal_type, node_type> local_mv_type;
122 // typedef typename Kokkos::View<local_scalar_type**, Kokkos::HostSpace> HostViewLocal;
123
124 typedef Tpetra::CrsMatrix<scalar_type, local_ordinal_type, global_ordinal_type, node_type> crs_matrix_type;
125 typedef Tpetra::BlockCrsMatrix<scalar_type, local_ordinal_type, global_ordinal_type, node_type> block_crs_matrix_type;
126
127 const Teuchos::Array<Teuchos::Array<local_ordinal_type> > partitions_;
128
135 typedef typename Container<MatrixType>::row_matrix_type row_matrix_type;
136
137 static_assert(std::is_same<MatrixType, row_matrix_type>::value,
138 "Ifpack2::BlockTriDiContainer: MatrixType must be a Tpetra::RowMatrix specialization.");
140 public:
142
143
164 BlockTriDiContainer(const Teuchos::RCP<const row_matrix_type>& matrix,
165 const Teuchos::Array<Teuchos::Array<local_ordinal_type> >& partitions,
166 const Teuchos::RCP<const import_type>& importer,
167 bool pointIndexed);
168
188 BlockTriDiContainer(const Teuchos::RCP<const row_matrix_type>& matrix,
189 const Teuchos::Array<Teuchos::Array<local_ordinal_type> >& partitions,
190 const int n_subparts_per_part = 1,
191 bool overlapCommAndComp = false,
192 bool useSequentialMethod = false,
193 const int block_size = -1,
194 const bool explicitConversion = false);
195
197 ~BlockTriDiContainer() override;
198
199 struct ComputeParameters {
206 magnitude_type addRadiallyToDiagonal = KokkosKernels::ArithTraits<magnitude_type>::zero();
207 };
208
210 struct ApplyParameters {
213 bool zeroStartingSolution = false;
215 scalar_type dampingFactor = KokkosKernels::ArithTraits<scalar_type>::one();
218 int maxNumSweeps = 1;
228 magnitude_type tolerance = KokkosKernels::ArithTraits<magnitude_type>::zero();
236 int checkToleranceEvery = 1;
237 };
238
240
242
244 void setParameters(const Teuchos::ParameterList& List) override;
245
246 void clearBlocks() override;
247
249
251
253 void initialize() override;
254
256 void compute() override;
257
258 // \brief Compute <tt>Y := D^{-1} (X - R*Y)</tt>.
259 void applyInverseJacobi(const mv_type& X, mv_type& Y,
260 scalar_type dampingFactor,
261 bool zeroStartingSolution = false,
262 int numSweeps = 1) const override;
263
265 ComputeParameters createDefaultComputeParameters() const;
266
280 void compute(const ComputeParameters& input);
281
283 ApplyParameters createDefaultApplyParameters() const;
284
291 int applyInverseJacobi(const mv_type& X, mv_type& Y,
292 const ApplyParameters& input) const;
293
297 const magnitude_type getNorms0() const;
298
301 const magnitude_type getNormsFinal() const;
302
305 void
306 apply(const_host_view_type X,
307 host_view_type Y,
308 int blockIndex,
309 Teuchos::ETransp mode = Teuchos::NO_TRANS,
310 scalar_type alpha = Teuchos::ScalarTraits<scalar_type>::one(),
311 scalar_type beta = Teuchos::ScalarTraits<scalar_type>::zero()) const override;
312
315 void
316 weightedApply(const_host_view_type X,
317 host_view_type Y,
318 const_host_view_type W,
319 int blockIndex,
320 Teuchos::ETransp mode = Teuchos::NO_TRANS,
321 scalar_type alpha = Teuchos::ScalarTraits<scalar_type>::one(),
322 scalar_type beta = Teuchos::ScalarTraits<scalar_type>::zero()) const override;
323
325
327
331 std::ostream& print(std::ostream& os) const override;
332
334
336
338 std::string description() const override;
339
341 void
342 describe(Teuchos::FancyOStream& out,
343 const Teuchos::EVerbosityLevel verbLevel =
344 Teuchos::Describable::verbLevel_default) const override;
345
347
349 static std::string getName();
350
351 private:
354
355 // hide details of impl using ImplObj; finally I understand why AMB did that way.
356 Teuchos::RCP<BlockTriDiContainerDetails::ImplObject<MatrixType> > impl_;
357 int n_subparts_per_part_;
358 int block_size_ = -1;
359
360 // initialize distributed and local objects
361 void initInternal(const Teuchos::RCP<const row_matrix_type>& matrix,
362 const Teuchos::RCP<const import_type>& importer,
363 const bool overlapCommAndComp,
364 const bool useSeqMethod,
365 const int block_size = -1,
366 const bool explicitConversion = false);
367
368 void clearInternal();
369
370 // Decide whether the fused block Jacobi path can and should be used.
371 bool shouldUseFusedBlockJacobi(
372 const Teuchos::RCP<const row_matrix_type>& matrix,
373 const Teuchos::Array<Teuchos::Array<local_ordinal_type> >& partitions,
374 bool useSeqMethod);
375};
376
384template <typename MatrixType>
385class BlockTriDiContainer<MatrixType, BlockTriDiContainerDetails::ImplNotAvailTag>
386 : public Container<MatrixType> {
387 private:
388 typedef typename MatrixType::scalar_type scalar_type;
389 typedef typename KokkosKernels::ArithTraits<scalar_type>::magnitudeType magnitude_type;
390 typedef typename Container<MatrixType>::local_ordinal_type local_ordinal_type;
391 typedef typename Container<MatrixType>::global_ordinal_type global_ordinal_type;
392
393 typedef typename Container<MatrixType>::mv_type mv_type;
394 typedef typename Container<MatrixType>::import_type import_type;
395
396 typedef typename Container<MatrixType>::HostView host_view_type;
397 typedef typename Container<MatrixType>::ConstHostView const_host_view_type;
398 typedef typename Container<MatrixType>::row_matrix_type row_matrix_type;
399
400 static_assert(std::is_same<MatrixType, row_matrix_type>::value,
401 "Ifpack2::BlockTriDiContainer: MatrixType must be a Tpetra::RowMatrix specialization.");
402
403 public:
404 BlockTriDiContainer(const Teuchos::RCP<const row_matrix_type>& matrix,
405 const Teuchos::Array<Teuchos::Array<local_ordinal_type> >& partitions,
406 const Teuchos::RCP<const import_type>& importer,
407 bool pointIndexed)
408 : Container<MatrixType>(matrix, partitions, pointIndexed) {
409 TEUCHOS_TEST_FOR_EXCEPT_MSG(true, "Error: BlockTriDiContainer is not available for this scalar_type");
410 }
411
412 void setParameters(const Teuchos::ParameterList& List) override {}
413 void clearBlocks() override {}
414
415 void initialize() override {}
416 void compute() override {}
417 void applyInverseJacobi(const mv_type& X, mv_type& Y,
418 scalar_type dampingFactor,
419 bool zeroStartingSolution = false,
420 int numSweeps = 1) const override {}
421
422 void
423 apply(const_host_view_type X,
424 host_view_type Y,
425 int blockIndex,
426 Teuchos::ETransp mode = Teuchos::NO_TRANS,
427 scalar_type alpha = Teuchos::ScalarTraits<scalar_type>::one(),
428 scalar_type beta = Teuchos::ScalarTraits<scalar_type>::zero()) const override {}
429
430 void
431 weightedApply(const_host_view_type X,
432 host_view_type Y,
433 const_host_view_type W,
434 int blockIndex,
435 Teuchos::ETransp mode = Teuchos::NO_TRANS,
436 scalar_type alpha = Teuchos::ScalarTraits<scalar_type>::one(),
437 scalar_type beta = Teuchos::ScalarTraits<scalar_type>::zero()) const override {}
438
439 std::ostream& print(std::ostream& os) const override {
440 return os << "Ifpack2::BlockTriDiContainer::ImplNotAvailTag";
441 }
442
443 std::string description() const override {
444 return "Ifpack2::BlockTriDiContainer::ImplNotAvailTag";
445 }
446
447 void
448 describe(Teuchos::FancyOStream& out,
449 const Teuchos::EVerbosityLevel verbLevel =
450 Teuchos::Describable::verbLevel_default) const override {
451 out << "Ifpack2::BlockTriDiContainer::ImplNotAvailTag";
452 }
453
454 static std::string getName() {
455 return "Ifpack2::BlockTriDiContainer::ImplNotAvailTag";
456 }
457};
458
459} // namespace Ifpack2
460
461#endif // IFPACK2_BLOCKTRIDICONTAINER_DECL_HPP
void setParameters(const Teuchos::ParameterList &List) override
Set parameters, if any.
Definition Ifpack2_BlockTriDiContainer_decl.hpp:412
void weightedApply(const_host_view_type X, host_view_type Y, const_host_view_type W, int blockIndex, Teuchos::ETransp mode=Teuchos::NO_TRANS, scalar_type alpha=Teuchos::ScalarTraits< scalar_type >::one(), scalar_type beta=Teuchos::ScalarTraits< scalar_type >::zero()) const override
Compute Y := alpha * diag(D) * M^{-1} (diag(D) * X) + beta*Y.
Definition Ifpack2_BlockTriDiContainer_decl.hpp:431
void compute() override
Extract the local diagonal blocks and prepare the solver.
Definition Ifpack2_BlockTriDiContainer_decl.hpp:416
void initialize() override
Do all set-up operations that only require matrix structure.
Definition Ifpack2_BlockTriDiContainer_decl.hpp:415
void apply(const_host_view_type X, host_view_type Y, int blockIndex, Teuchos::ETransp mode=Teuchos::NO_TRANS, scalar_type alpha=Teuchos::ScalarTraits< scalar_type >::one(), scalar_type beta=Teuchos::ScalarTraits< scalar_type >::zero()) const override
Compute Y := alpha * M^{-1} X + beta*Y.
Definition Ifpack2_BlockTriDiContainer_decl.hpp:423
void applyInverseJacobi(const mv_type &X, mv_type &Y, scalar_type dampingFactor, bool zeroStartingSolution=false, int numSweeps=1) const override
Compute Y := (1 - a) Y + a D^{-1} (X - R*Y).
Definition Ifpack2_BlockTriDiContainer_decl.hpp:417
std::ostream & print(std::ostream &os) const override
Print basic information about the container to os.
Definition Ifpack2_BlockTriDiContainer_decl.hpp:439
Store and solve local block tridiagonal linear problems.
Definition Ifpack2_BlockTriDiContainer_decl.hpp:81
Interface for creating and solving a set of local linear problems.
Definition Ifpack2_Container_decl.hpp:79
typename mv_type::dual_view_type::t_host HostView
Definition Ifpack2_Container_decl.hpp:105
Preconditioners and smoothers for Tpetra sparse matrices.
Definition Ifpack2_AdditiveSchwarz_decl.hpp:40