Tpetra parallel linear algebra  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Tpetra_Details_EquilibrationInfo.hpp
Go to the documentation of this file.
1 // @HEADER
2 // *****************************************************************************
3 // Tpetra: Templated Linear Algebra Services Package
4 //
5 // Copyright 2008 NTESS and the Tpetra contributors.
6 // SPDX-License-Identifier: BSD-3-Clause
7 // *****************************************************************************
8 // @HEADER
9 
10 #ifndef TPETRA_DETAILS_EQUILIBRATIONINFO_HPP
11 #define TPETRA_DETAILS_EQUILIBRATIONINFO_HPP
12 
15 
16 #include "TpetraCore_config.h"
17 #include "Kokkos_ArithTraits.hpp"
18 #include "Kokkos_Core.hpp"
19 
20 namespace Tpetra {
21 namespace Details {
22 
46 template<class ScalarType, class DeviceType>
48  using val_type = typename Kokkos::ArithTraits<ScalarType>::val_type;
49  using mag_type = typename Kokkos::ArithTraits<val_type>::mag_type;
50  using device_type = typename DeviceType::device_type;
51  using host_device_type = typename Kokkos::View<mag_type*, device_type>::HostMirror::device_type;
53 
55  foundInf (false),
56  foundNan (false),
57  foundZeroDiag (false),
58  foundZeroRowNorm (false)
59  {}
60 
61  EquilibrationInfo (const std::size_t lclNumRows,
62  const std::size_t lclNumCols,
63  const bool assumeSymmetric_) :
64  rowNorms (Kokkos::View<mag_type*, device_type> ("rowNorms", lclNumRows)),
65  rowDiagonalEntries (Kokkos::View<val_type*, device_type> ("rowDiagonalEntries", lclNumRows)),
66  colNorms (Kokkos::View<mag_type*, device_type> ("colNorms", lclNumCols)),
67  colDiagonalEntries (Kokkos::View<val_type*, device_type> ("colDiagonalEntries",
68  assumeSymmetric_ ?
69  std::size_t (0) :
70  lclNumCols)),
71  rowScaledColNorms (Kokkos::View<mag_type*, device_type> ("rowScaledColNorms",
72  assumeSymmetric_ ?
73  std::size_t (0) :
74  lclNumCols)),
75  assumeSymmetric (assumeSymmetric_),
76  foundInf (false),
77  foundNan (false),
78  foundZeroDiag (false),
79  foundZeroRowNorm (false)
80  {}
81 
82  EquilibrationInfo (const Kokkos::View<mag_type*, device_type>& rowNorms_,
83  const Kokkos::View<val_type*, device_type>& rowDiagonalEntries_,
84  const Kokkos::View<mag_type*, device_type>& colNorms_,
85  const Kokkos::View<val_type*, device_type>& colDiagonalEntries_,
86  const Kokkos::View<mag_type*, device_type>& rowScaledColNorms_,
87  const bool assumeSymmetric_,
88  const bool foundInf_,
89  const bool foundNan_,
90  const bool foundZeroDiag_,
91  const bool foundZeroRowNorm_) :
92  rowNorms (rowNorms_),
93  rowDiagonalEntries (rowDiagonalEntries_),
94  colNorms (colNorms_),
95  colDiagonalEntries (colDiagonalEntries_),
96  rowScaledColNorms (rowScaledColNorms_),
97  assumeSymmetric (assumeSymmetric_),
98  foundInf (foundInf_),
99  foundNan (foundNan_),
100  foundZeroDiag (foundZeroDiag_),
101  foundZeroRowNorm (foundZeroRowNorm_)
102  {}
103 
105  template<class SrcDeviceType>
106  void
108  {
109  using execution_space = typename device_type::execution_space;
110  // DEEP_COPY REVIEW - DEVICE-TO-DEVICE
111  Kokkos::deep_copy (execution_space(), rowNorms, src.rowNorms);
112  // DEEP_COPY REVIEW - DEVICE-TO-DEVICE
113  Kokkos::deep_copy (execution_space(), rowDiagonalEntries, src.rowDiagonalEntries);
114  // DEEP_COPY REVIEW - DEVICE-TO-DEVICE
115  Kokkos::deep_copy (execution_space(), colNorms, src.colNorms);
116  if (src.colDiagonalEntries.extent (0) == 0) {
118  Kokkos::View<val_type*, device_type> ("colDiagonalEntries", 0);
119  }
120  else {
121  // DEEP_COPY REVIEW - DEVICE-TO-DEVICE
122  Kokkos::deep_copy (execution_space(), colDiagonalEntries, src.colDiagonalEntries);
123  }
124  if (src.rowScaledColNorms.extent (0) == 0) {
126  Kokkos::View<mag_type*, device_type> ("rowScaledColNorms", 0);
127  }
128  else {
129  // DEEP_COPY REVIEW - DEVICE-TO-DEVICE
130  Kokkos::deep_copy (execution_space(), rowScaledColNorms, src.rowScaledColNorms);
131  }
132 
134  foundInf = src.foundInf;
135  foundNan = src.foundNan;
138  }
139 
141  createMirrorView ()
142  {
143  auto rowNorms_h = Kokkos::create_mirror_view (rowNorms);
144  auto rowDiagonalEntries_h = Kokkos::create_mirror_view (rowDiagonalEntries);
145  auto colNorms_h = Kokkos::create_mirror_view (colNorms);
146  auto colDiagonalEntries_h = Kokkos::create_mirror_view (colDiagonalEntries);
147  auto rowScaledColNorms_h = Kokkos::create_mirror_view (rowScaledColNorms);
148 
149  return HostMirror {rowNorms_h, rowDiagonalEntries_h, colNorms_h,
150  colDiagonalEntries_h, rowScaledColNorms_h, assumeSymmetric,
152  }
153 
154  // We call a row a "diagonally dominant row" if the absolute value
155  // of the diagonal entry is >= the sum of the absolute values of the
156  // off-diagonal entries. The row norm is the sum of those two
157  // things, so this means diagAbsVal >= rowNorm - diagAbsVal. Ditto
158  // for a column.
159 
161  Kokkos::View<mag_type*, device_type> rowNorms;
162 
164  Kokkos::View<val_type*, device_type> rowDiagonalEntries;
165 
171  Kokkos::View<mag_type*, device_type> colNorms;
172 
176  Kokkos::View<val_type*, device_type> colDiagonalEntries;
177 
188  Kokkos::View<mag_type*, device_type> rowScaledColNorms;
189 
195 
197  bool foundInf;
198 
200  bool foundNan;
201 
204 
207 };
208 
209 } // namespace Details
210 } // namespace Tpetra
211 
212 #endif // TPETRA_DETAILS_EQUILIBRATIONINFO_HPP
Kokkos::View< mag_type *, device_type > colNorms
One-norms of the matrix&#39;s columns, distributed via the column Map.
Kokkos::View< mag_type *, device_type > rowNorms
One-norms of the matrix&#39;s rows, distributed via the row Map.
bool foundZeroDiag
Found a zero diagonal entry somewhere in the matrix.
bool assumeSymmetric
Whether to assume that the matrix is (globally) symmetric.
Kokkos::View< val_type *, device_type > colDiagonalEntries
Diagonal entries of the matrix, distributed via the column Map.
Struct storing results of Tpetra::computeRowAndColumnOneNorms.
void deep_copy(MultiVector< DS, DL, DG, DN > &dst, const MultiVector< SS, SL, SG, SN > &src)
Copy the contents of the MultiVector src into dst.
Kokkos::View< val_type *, device_type > rowDiagonalEntries
Diagonal entries of the matrix, distributed via the row Map.
Kokkos::View< mag_type *, device_type > rowScaledColNorms
One-norms of the matrix&#39;s columns, after the matrix&#39;s rows have been scaled by rowNorms.
void assign(const EquilibrationInfo< ScalarType, SrcDeviceType > &src)
Deep-copy src into *this.
bool foundNan
Found a NaN somewhere in the matrix.
bool foundInf
Found an Inf somewhere in the matrix.
bool foundZeroRowNorm
At least one row of the matrix has a zero norm.