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//
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
58namespace Ifpack2 {
59
107
111 namespace BlockTriDiContainerDetails {
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,
133 typename ImplTagType = typename BlockTriDiContainerDetails::ImplTag<typename MatrixType::scalar_type>::type>
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::BlockCrsMatrix
178 <scalar_type,local_ordinal_type,global_ordinal_type,node_type> block_crs_matrix_type;
179
186 typedef typename Container<MatrixType>::row_matrix_type row_matrix_type;
187
188 static_assert (std::is_same<MatrixType, row_matrix_type>::value,
189 "Ifpack2::BlockTriDiContainer: MatrixType must be a Tpetra::RowMatrix specialization.");
191 public:
193
194
210 BlockTriDiContainer (const Teuchos::RCP<const row_matrix_type>& matrix,
211 const Teuchos::Array<Teuchos::Array<local_ordinal_type> >& partitions,
212 const Teuchos::RCP<const import_type>& importer,
213 bool pointIndexed);
214
229 BlockTriDiContainer (const Teuchos::RCP<const row_matrix_type>& matrix,
230 const Teuchos::Array<Teuchos::Array<local_ordinal_type> >& partitions,
231 bool overlapCommAndComp = false, bool useSequentialMethod = false);
232
234 ~BlockTriDiContainer () override;
235
236 struct ComputeParameters {
243 magnitude_type addRadiallyToDiagonal = Kokkos::ArithTraits<magnitude_type>::zero();
244 };
245
247 struct ApplyParameters {
250 bool zeroStartingSolution = false;
252 scalar_type dampingFactor = Kokkos::ArithTraits<scalar_type>::one();
255 int maxNumSweeps = 1;
265 magnitude_type tolerance = Kokkos::ArithTraits<magnitude_type>::zero();
273 int checkToleranceEvery = 1;
274 };
275
277
279
281 void setParameters(const Teuchos::ParameterList& List) override;
282
283 void clearBlocks() override;
284
286
288
290 void initialize () override;
291
293 void compute () override;
294
295 // \brief Compute <tt>Y := D^{-1} (X - R*Y)</tt>.
296 void applyInverseJacobi (const mv_type& X, mv_type& Y,
297 scalar_type dampingFactor,
298 bool zeroStartingSolution = false,
299 int numSweeps = 1) const override;
300
302 ComputeParameters createDefaultComputeParameters () const;
303
315 void compute (const ComputeParameters& input);
316
318 ApplyParameters createDefaultApplyParameters () const;
319
326 int applyInverseJacobi (const mv_type& X, mv_type& Y,
327 const ApplyParameters& input) const;
328
332 const magnitude_type getNorms0 () const;
333
336 const magnitude_type getNormsFinal () const;
337
340 void
341 apply (const_host_view_type X,
342 host_view_type Y,
343 int blockIndex,
344 Teuchos::ETransp mode = Teuchos::NO_TRANS,
345 scalar_type alpha = Teuchos::ScalarTraits<scalar_type>::one(),
346 scalar_type beta = Teuchos::ScalarTraits<scalar_type>::zero()) const override;
347
350 void
351 weightedApply (const_host_view_type X,
352 host_view_type Y,
353 const_host_view_type W,
354 int blockIndex,
355 Teuchos::ETransp mode = Teuchos::NO_TRANS,
356 scalar_type alpha = Teuchos::ScalarTraits<scalar_type>::one(),
357 scalar_type beta = Teuchos::ScalarTraits<scalar_type>::zero()) const override;
358
360
362
366 std::ostream& print (std::ostream& os) const override;
367
369
371
373 std::string description () const override;
374
376 void
377 describe (Teuchos::FancyOStream &out,
378 const Teuchos::EVerbosityLevel verbLevel =
379 Teuchos::Describable::verbLevel_default) const override;
380
382
384 static std::string getName();
385
386 private:
389
390 // hide details of impl using ImplObj; finally I understand why AMB did that way.
391 Teuchos::RCP<BlockTriDiContainerDetails::ImplObject<MatrixType> > impl_;
392
393 // initialize distributed and local objects
394 void initInternal (const Teuchos::RCP<const row_matrix_type>& matrix,
395 const Teuchos::Array<Teuchos::Array<local_ordinal_type> >& partitions,
396 const Teuchos::RCP<const import_type> &importer,
397 const bool overlapCommAndComp,
398 const bool useSeqMethod);
399
400 void clearInternal();
401 };
402
410 template <typename MatrixType>
411 class BlockTriDiContainer<MatrixType,BlockTriDiContainerDetails::ImplNotAvailTag>
412 : public Container<MatrixType> {
413 private:
414 typedef typename MatrixType::scalar_type scalar_type;
415 typedef typename Kokkos::ArithTraits<scalar_type>::magnitudeType magnitude_type;
416 typedef typename Container<MatrixType>::local_ordinal_type local_ordinal_type;
417 typedef typename Container<MatrixType>::global_ordinal_type global_ordinal_type;
418
419 typedef typename Container<MatrixType>::mv_type mv_type;
420 typedef typename Container<MatrixType>::import_type import_type;
421
422 typedef typename Container<MatrixType>::HostView host_view_type;
423 typedef typename Container<MatrixType>::ConstHostView const_host_view_type;
424 typedef typename Container<MatrixType>::row_matrix_type row_matrix_type;
425
426 static_assert (std::is_same<MatrixType, row_matrix_type>::value,
427 "Ifpack2::BlockTriDiContainer: MatrixType must be a Tpetra::RowMatrix specialization.");
428 public:
429
430 BlockTriDiContainer (const Teuchos::RCP<const row_matrix_type>& matrix,
431 const Teuchos::Array<Teuchos::Array<local_ordinal_type> >& partitions,
432 const Teuchos::RCP<const import_type>& importer,
433 bool pointIndexed)
434 : Container<MatrixType>(matrix, partitions, pointIndexed) {
435 TEUCHOS_TEST_FOR_EXCEPT_MSG(true, "Error: BlockTriDiContainer is not available for this scalar_type");
436 }
437
438 void setParameters(const Teuchos::ParameterList& List) override {}
439 void clearBlocks() override {}
440
441 void initialize () override {}
442 void compute () override {}
443 void applyInverseJacobi (const mv_type& X, mv_type& Y,
444 scalar_type dampingFactor,
445 bool zeroStartingSolution = false,
446 int numSweeps = 1) const override {}
447
448 void
449 apply (const_host_view_type X,
450 host_view_type Y,
451 int blockIndex,
452 Teuchos::ETransp mode = Teuchos::NO_TRANS,
453 scalar_type alpha = Teuchos::ScalarTraits<scalar_type>::one(),
454 scalar_type beta = Teuchos::ScalarTraits<scalar_type>::zero()) const override {}
455
456 void
457 weightedApply (const_host_view_type X,
458 host_view_type Y,
459 const_host_view_type W,
460 int blockIndex,
461 Teuchos::ETransp mode = Teuchos::NO_TRANS,
462 scalar_type alpha = Teuchos::ScalarTraits<scalar_type>::one(),
463 scalar_type beta = Teuchos::ScalarTraits<scalar_type>::zero()) const override {}
464
465 std::ostream& print (std::ostream& os) const override {
466 return os << "Ifpack2::BlockTriDiContainer::ImplNotAvailTag";
467 }
468
469 std::string description () const override {
470 return "Ifpack2::BlockTriDiContainer::ImplNotAvailTag";
471 }
472
473 void
474 describe (Teuchos::FancyOStream &out,
475 const Teuchos::EVerbosityLevel verbLevel =
476 Teuchos::Describable::verbLevel_default) const override {
477 out << "Ifpack2::BlockTriDiContainer::ImplNotAvailTag";
478 }
479
480 static std::string getName() {
481 return "Ifpack2::BlockTriDiContainer::ImplNotAvailTag";
482 }
483 };
484
485
486} // namespace Ifpack2
487
488#endif // IFPACK2_BLOCKTRIDICONTAINER_DECL_HPP
void setParameters(const Teuchos::ParameterList &List) override
Set parameters, if any.
Definition: Ifpack2_BlockTriDiContainer_decl.hpp:438
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:457
void compute() override
Extract the local diagonal blocks and prepare the solver.
Definition: Ifpack2_BlockTriDiContainer_decl.hpp:442
void initialize() override
Do all set-up operations that only require matrix structure.
Definition: Ifpack2_BlockTriDiContainer_decl.hpp:441
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:449
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:443
std::ostream & print(std::ostream &os) const override
Print basic information about the container to os.
Definition: Ifpack2_BlockTriDiContainer_decl.hpp:465
Store and solve local block tridiagonal linear problems.
Definition: Ifpack2_BlockTriDiContainer_decl.hpp:134
Interface for creating and solving a set of local linear problems.
Definition: Ifpack2_Container_decl.hpp:113
typename mv_type::dual_view_type::t_host HostView
Definition: Ifpack2_Container_decl.hpp:139
Preconditioners and smoothers for Tpetra sparse matrices.
Definition: Ifpack2_AdditiveSchwarz_decl.hpp:74
Definition: Ifpack2_BlockTriDiContainer_decl.hpp:115