Ifpack2 Templated Preconditioning Package  Version 1.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
Ifpack2_TriDiContainer_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_TRIDICONTAINER_DECL_HPP
43 #define IFPACK2_TRIDICONTAINER_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 #include <type_traits>
57 #include <string>
58 
59 namespace Ifpack2 {
60 
105 template<class MatrixType, class LocalScalarType,
108 
109 template<class MatrixType, class LocalScalarType>
110 class TriDiContainer<MatrixType, LocalScalarType, true> :
111  public Container<MatrixType> {
113 
114 private:
120  typedef MatrixType matrix_type;
122  typedef LocalScalarType local_scalar_type;
123 
125  typedef typename Container<MatrixType>::scalar_type scalar_type;
127  typedef typename Container<MatrixType>::local_ordinal_type local_ordinal_type;
129  typedef typename Container<MatrixType>::global_ordinal_type global_ordinal_type;
131  typedef typename Container<MatrixType>::node_type node_type;
132 
133  typedef typename Container<MatrixType>::mv_type mv_type;
134  typedef typename Container<MatrixType>::map_type map_type;
135  typedef typename Container<MatrixType>::vector_type vector_type;
136  typedef typename Container<MatrixType>::partitioner_type partitioner_type;
137  typedef typename Container<MatrixType>::import_type import_type;
138 
139  typedef typename Container<MatrixType>::HostView HostView;
140  typedef Tpetra::MultiVector<local_scalar_type, local_ordinal_type, global_ordinal_type, node_type> local_mv_type;
141  typedef typename Kokkos::View<local_scalar_type**, Kokkos::HostSpace> HostViewLocal;
142 
143  static_assert (std::is_same<MatrixType, Tpetra::RowMatrix<scalar_type, local_ordinal_type, global_ordinal_type, node_type>>::value,
144  "Ifpack2::TriDiContainer: MatrixType must be a Tpetra::RowMatrix specialization.");
145 
154  typedef typename Container<MatrixType>::row_matrix_type row_matrix_type;
156 public:
158 
159 
175  const Teuchos::RCP<const import_type>& importer,
176  int OverlapLevel,
177  scalar_type DampingFactor);
178 
180  const Teuchos::Array<local_ordinal_type>& localRows);
181 
183  virtual ~TriDiContainer ();
184 
186 
188 
190  virtual bool isInitialized() const;
191 
193  virtual bool isComputed() const;
194 
196  virtual void setParameters(const Teuchos::ParameterList& List);
197 
199 
201 
203  virtual void initialize ();
204 
206  virtual void compute ();
207 
208  void clearBlocks();
209 
211  virtual void
212  apply (HostView& X,
213  HostView& Y,
214  int blockIndex,
215  int stride,
217  scalar_type alpha = Teuchos::ScalarTraits<scalar_type>::one(),
218  scalar_type beta = Teuchos::ScalarTraits<scalar_type>::zero()) const;
219 
220  void applyImpl (HostViewLocal& X,
221  HostViewLocal& Y,
222  int blockIndex,
223  int stride,
224  Teuchos::ETransp mode,
225  local_scalar_type alpha,
226  local_scalar_type beta) const;
227 
229  virtual void
230  weightedApply (HostView& X,
231  HostView& Y,
232  HostView& W,
233  int blockIndex,
234  int stride,
236  scalar_type alpha = Teuchos::ScalarTraits<scalar_type>::one(),
237  scalar_type beta = Teuchos::ScalarTraits<scalar_type>::zero()) const;
238 
240 
242 
246  virtual std::ostream& print (std::ostream& os) const;
247 
249 
251 
253  virtual std::string description () const;
254 
256  virtual void
257  describe (Teuchos::FancyOStream &out,
258  const Teuchos::EVerbosityLevel verbLevel =
260 
262 
264  static std::string getName();
265 private:
268 
270  void extract ();
271 
275  void factor ();
276 
278  std::vector<Teuchos::SerialTriDiMatrix<int, local_scalar_type>> diagBlocks_;
279 
281  mutable std::vector<HostViewLocal> X_local;
282 
284  mutable std::vector<HostViewLocal> Y_local;
285 
287  Teuchos::Array<int> ipiv_;
288 
290  bool IsInitialized_;
291 
293  bool IsComputed_;
294 
296  local_scalar_type* scalars_;
297 
299  Teuchos::Array<int> scalarOffsets_;
300 };
301 
302 template<class MatrixType, class LocalScalarType>
303 class TriDiContainer<MatrixType, LocalScalarType, false> :
304  public Container<MatrixType> {
306 
307 private:
313  typedef MatrixType matrix_type;
315  typedef LocalScalarType local_scalar_type;
316 
318  typedef typename Container<MatrixType>::scalar_type scalar_type;
320  typedef typename Container<MatrixType>::local_ordinal_type local_ordinal_type;
322  typedef typename Container<MatrixType>::global_ordinal_type global_ordinal_type;
324  typedef typename Container<MatrixType>::node_type node_type;
325 
326  typedef typename Container<MatrixType>::mv_type mv_type;
327  typedef typename Container<MatrixType>::map_type map_type;
328  typedef typename Container<MatrixType>::vector_type vector_type;
329  typedef typename Container<MatrixType>::partitioner_type partitioner_type;
330  typedef typename Container<MatrixType>::import_type import_type;
331 
332  typedef typename Container<MatrixType>::HostView HostView;
333  typedef Tpetra::MultiVector<local_scalar_type, local_ordinal_type, global_ordinal_type, node_type> local_mv_type;
334  typedef typename Kokkos::View<local_scalar_type**, Kokkos::HostSpace> HostViewLocal;
335 
336  static_assert (std::is_same<MatrixType, Tpetra::RowMatrix<scalar_type, local_ordinal_type, global_ordinal_type, node_type>>::value,
337  "Ifpack2::TriDiContainer: MatrixType must be a Tpetra::RowMatrix specialization.");
338 
347  typedef typename Container<MatrixType>::row_matrix_type row_matrix_type;
349 public:
351 
352 
368  const Teuchos::RCP<const import_type>& importer,
369  int OverlapLevel,
370  scalar_type DampingFactor);
371 
373  const Teuchos::Array<local_ordinal_type>& localRows);
374 
376  virtual ~TriDiContainer ();
377 
379 
381 
383  virtual bool isInitialized() const;
384 
386  virtual bool isComputed() const;
387 
389  virtual void setParameters(const Teuchos::ParameterList& List);
390 
392 
394 
396  virtual void initialize ();
397 
399  virtual void compute ();
400 
401  void clearBlocks();
402 
404  virtual void
405  apply (HostView& X,
406  HostView& Y,
407  int blockIndex,
408  int stride,
410  scalar_type alpha = Teuchos::ScalarTraits<scalar_type>::one(),
411  scalar_type beta = Teuchos::ScalarTraits<scalar_type>::zero()) const;
412 
413  void applyImpl (HostViewLocal& X,
414  HostViewLocal& Y,
415  int blockIndex,
416  int stride,
417  Teuchos::ETransp mode,
418  local_scalar_type alpha,
419  local_scalar_type beta) const;
420 
422  virtual void
423  weightedApply (HostView& X,
424  HostView& Y,
425  HostView& W,
426  int blockIndex,
427  int stride,
429  scalar_type alpha = Teuchos::ScalarTraits<scalar_type>::one(),
430  scalar_type beta = Teuchos::ScalarTraits<scalar_type>::zero()) const;
431 
433 
435 
439  virtual std::ostream& print (std::ostream& os) const;
440 
442 
444 
446  virtual std::string description () const;
447 
449  virtual void
450  describe (Teuchos::FancyOStream &out,
451  const Teuchos::EVerbosityLevel verbLevel =
453 
455 
457  static std::string getName();
458 private:
461 
463  void extract ();
464 
468  void factor ();
469 
471  std::vector<Teuchos::SerialTriDiMatrix<int, local_scalar_type>> diagBlocks_;
472 
474  mutable std::vector<HostViewLocal> X_local;
475 
477  mutable std::vector<HostViewLocal> Y_local;
478 
480  Teuchos::Array<int> ipiv_;
481 
483  bool IsInitialized_;
484 
486  bool IsComputed_;
487 
489  local_scalar_type* scalars_;
490 
492  Teuchos::Array<int> scalarOffsets_;
493 };
494 
495 }// namespace Ifpack2
496 
497 #endif // IFPACK2_TRIDICONTAINER_DECL_HPP
Store and solve a local TriDi linear problem.
Definition: Ifpack2_TriDiContainer_decl.hpp:107
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