Tpetra parallel linear algebra Version of the Day
Loading...
Searching...
No Matches
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 "KokkosKernels_ArithTraits.hpp"
18#include "Kokkos_Core.hpp"
19
20namespace Tpetra {
21namespace Details {
22
46template <class ScalarType, class DeviceType>
48 using val_type = typename KokkosKernels::ArithTraits<ScalarType>::val_type;
49 using mag_type = typename KokkosKernels::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>::host_mirror_type::device_type;
53
55 : foundInf(false)
56 , foundNan(false)
57 , foundZeroDiag(false)
58 , foundZeroRowNorm(false) {}
59
60 EquilibrationInfo(const std::size_t lclNumRows,
61 const std::size_t lclNumCols,
62 const bool assumeSymmetric_)
63 : rowNorms(Kokkos::View<mag_type*, device_type>("rowNorms", lclNumRows))
64 , rowDiagonalEntries(Kokkos::View<val_type*, device_type>("rowDiagonalEntries", lclNumRows))
65 , colNorms(Kokkos::View<mag_type*, device_type>("colNorms", lclNumCols))
66 , colDiagonalEntries(Kokkos::View<val_type*, device_type>("colDiagonalEntries",
67 assumeSymmetric_ ? std::size_t(0) : lclNumCols))
68 , rowScaledColNorms(Kokkos::View<mag_type*, device_type>("rowScaledColNorms",
69 assumeSymmetric_ ? std::size_t(0) : lclNumCols))
70 , assumeSymmetric(assumeSymmetric_)
71 , foundInf(false)
72 , foundNan(false)
73 , foundZeroDiag(false)
74 , foundZeroRowNorm(false) {}
75
76 EquilibrationInfo(const Kokkos::View<mag_type*, device_type>& rowNorms_,
77 const Kokkos::View<val_type*, device_type>& rowDiagonalEntries_,
78 const Kokkos::View<mag_type*, device_type>& colNorms_,
79 const Kokkos::View<val_type*, device_type>& colDiagonalEntries_,
80 const Kokkos::View<mag_type*, device_type>& rowScaledColNorms_,
81 const bool assumeSymmetric_,
82 const bool foundInf_,
83 const bool foundNan_,
84 const bool foundZeroDiag_,
85 const bool foundZeroRowNorm_)
86 : rowNorms(rowNorms_)
90 , rowScaledColNorms(rowScaledColNorms_)
91 , assumeSymmetric(assumeSymmetric_)
96
98 template <class SrcDeviceType>
99 void
101 using execution_space = typename device_type::execution_space;
102 // DEEP_COPY REVIEW - DEVICE-TO-DEVICE
103 Kokkos::deep_copy(execution_space(), rowNorms, src.rowNorms);
104 // DEEP_COPY REVIEW - DEVICE-TO-DEVICE
105 Kokkos::deep_copy(execution_space(), rowDiagonalEntries, src.rowDiagonalEntries);
106 // DEEP_COPY REVIEW - DEVICE-TO-DEVICE
107 Kokkos::deep_copy(execution_space(), colNorms, src.colNorms);
108 if (src.colDiagonalEntries.extent(0) == 0) {
110 Kokkos::View<val_type*, device_type>("colDiagonalEntries", 0);
111 } else {
112 // DEEP_COPY REVIEW - DEVICE-TO-DEVICE
113 Kokkos::deep_copy(execution_space(), colDiagonalEntries, src.colDiagonalEntries);
114 }
115 if (src.rowScaledColNorms.extent(0) == 0) {
117 Kokkos::View<mag_type*, device_type>("rowScaledColNorms", 0);
118 } else {
119 // DEEP_COPY REVIEW - DEVICE-TO-DEVICE
120 Kokkos::deep_copy(execution_space(), rowScaledColNorms, src.rowScaledColNorms);
121 }
122
123 assumeSymmetric = src.assumeSymmetric;
124 foundInf = src.foundInf;
125 foundNan = src.foundNan;
126 foundZeroDiag = src.foundZeroDiag;
127 foundZeroRowNorm = src.foundZeroRowNorm;
128 }
129
131 createMirrorView() {
132 auto rowNorms_h = Kokkos::create_mirror_view(rowNorms);
133 auto rowDiagonalEntries_h = Kokkos::create_mirror_view(rowDiagonalEntries);
134 auto colNorms_h = Kokkos::create_mirror_view(colNorms);
135 auto colDiagonalEntries_h = Kokkos::create_mirror_view(colDiagonalEntries);
136 auto rowScaledColNorms_h = Kokkos::create_mirror_view(rowScaledColNorms);
137
138 return HostMirror{rowNorms_h, rowDiagonalEntries_h, colNorms_h,
141 }
142
143 // We call a row a "diagonally dominant row" if the absolute value
144 // of the diagonal entry is >= the sum of the absolute values of the
145 // off-diagonal entries. The row norm is the sum of those two
146 // things, so this means diagAbsVal >= rowNorm - diagAbsVal. Ditto
147 // for a column.
148
150 Kokkos::View<mag_type*, device_type> rowNorms;
151
153 Kokkos::View<val_type*, device_type> rowDiagonalEntries;
154
160 Kokkos::View<mag_type*, device_type> colNorms;
161
165 Kokkos::View<val_type*, device_type> colDiagonalEntries;
166
177 Kokkos::View<mag_type*, device_type> rowScaledColNorms;
178
184
187
190
193
196};
197
198} // namespace Details
199} // namespace Tpetra
200
201#endif // TPETRA_DETAILS_EQUILIBRATIONINFO_HPP
Struct that holds views of the contents of a CrsMatrix.
Implementation details of Tpetra.
Namespace Tpetra contains the class and methods constituting the Tpetra library.
Struct storing results of Tpetra::computeRowAndColumnOneNorms.
Kokkos::View< mag_type *, device_type > rowNorms
One-norms of the matrix's rows, distributed via the row Map.
bool foundZeroRowNorm
At least one row of the matrix has a zero norm.
void assign(const EquilibrationInfo< ScalarType, SrcDeviceType > &src)
Deep-copy src into *this.
Kokkos::View< val_type *, device_type > colDiagonalEntries
Diagonal entries of the matrix, distributed via the column Map.
Kokkos::View< mag_type *, device_type > rowScaledColNorms
One-norms of the matrix's columns, after the matrix's rows have been scaled by rowNorms.
Kokkos::View< val_type *, device_type > rowDiagonalEntries
Diagonal entries of the matrix, distributed via the row Map.
bool foundNan
Found a NaN somewhere in the matrix.
Kokkos::View< mag_type *, device_type > colNorms
One-norms of the matrix's columns, distributed via the column Map.
bool assumeSymmetric
Whether to assume that the matrix is (globally) symmetric.
bool foundZeroDiag
Found a zero diagonal entry somewhere in the matrix.
bool foundInf
Found an Inf somewhere in the matrix.