10#ifndef IFPACK2_BLOCKCOMPUTERES_AND_SOLVE_DECL_HPP
11#define IFPACK2_BLOCKCOMPUTERES_AND_SOLVE_DECL_HPP
13#include <KokkosBatched_Util.hpp>
14#include <KokkosBatched_Vector.hpp>
15#include <Tpetra_BlockMultiVector.hpp>
16#include <Tpetra_BlockCrsMatrix_decl.hpp>
17#include "Ifpack2_BlockHelper.hpp"
18#include "Ifpack2_BlockHelper_ETI.hpp"
20namespace Ifpack2::BlockHelperDetails {
22template <
typename ExecSpace,
typename DiagOffsets,
typename Rowptrs,
24DiagOffsets findDiagOffsets(
const Rowptrs& rowptrs,
const Entries& entries,
25 size_t nrows,
int blocksize) {
26 DiagOffsets diag_offsets(do_not_initialize_tag(
"btdm.diag_offsets"), nrows);
28 Kokkos::parallel_reduce(
29 Kokkos::RangePolicy<ExecSpace>(0, nrows),
30 KOKKOS_LAMBDA(
size_t row,
int& err2) {
31 auto rowBegin = rowptrs(row);
32 auto rowEnd = rowptrs(row + 1);
33 for (
size_t j = rowBegin; j < rowEnd; j++) {
34 if (
size_t(entries(j)) == row) {
35 diag_offsets(row) = j * blocksize * blocksize;
42 TEUCHOS_TEST_FOR_EXCEPT_MSG(
43 err1,
"Ifpack2 BTD: at least one row has no diagonal entry");
47template <
typename MatrixType,
48 typename ImplTagType =
typename BlockTriDiContainerDetails::ImplTag<typename MatrixType::scalar_type>::type>
49struct ComputeResidualAndSolve;
51template <
typename MatrixType>
52struct ComputeResidualAndSolve<MatrixType, BlockTriDiContainerDetails::ImplSimdTag> {
53 using impl_type = BlockHelperDetails::ImplType<MatrixType>;
54 using node_device_type =
typename impl_type::node_device_type;
55 using execution_space =
typename impl_type::execution_space;
56 using memory_space =
typename impl_type::memory_space;
58 using local_ordinal_type =
typename impl_type::local_ordinal_type;
59 using size_type =
typename impl_type::size_type;
60 using impl_scalar_type =
typename impl_type::impl_scalar_type;
61 using magnitude_type =
typename impl_type::magnitude_type;
63 using local_ordinal_type_1d_view =
64 typename impl_type::local_ordinal_type_1d_view;
65 using size_type_1d_view =
typename impl_type::size_type_1d_view;
66 using tpetra_block_access_view_type =
67 typename impl_type::tpetra_block_access_view_type;
69 using impl_scalar_type_1d_view =
typename impl_type::impl_scalar_type_1d_view;
70 using impl_scalar_type_2d_view_tpetra =
71 typename impl_type::impl_scalar_type_2d_view_tpetra;
73 using btdm_scalar_type_3d_view =
typename impl_type::btdm_scalar_type_3d_view;
74 using btdm_scalar_type_4d_view =
typename impl_type::btdm_scalar_type_4d_view;
75 using i64_3d_view =
typename impl_type::i64_3d_view;
78 using member_type =
typename Kokkos::TeamPolicy<execution_space>::member_type;
80 ComputeResidualAndSolve(
const AmD<MatrixType>& amd_,
81 const btdm_scalar_type_3d_view& d_inv_,
82 const impl_scalar_type_1d_view& W_,
83 const local_ordinal_type& blocksize_requested_,
84 const impl_scalar_type& damping_factor_)
86 , blocksize_requested(blocksize_requested_)
89 , damping_factor(damping_factor_) {}
92 const Const<impl_scalar_type_2d_view_tpetra>& b_,
93 const impl_scalar_type_2d_view_tpetra& y_);
95 const Const<impl_scalar_type_2d_view_tpetra>& b_,
96 const impl_scalar_type_2d_view_tpetra& x_,
97 const impl_scalar_type_2d_view_tpetra& x_remote_,
98 const impl_scalar_type_2d_view_tpetra& y_);
100 const Const<impl_scalar_type_2d_view_tpetra>& b_,
101 const impl_scalar_type_2d_view_tpetra& x_,
102 const impl_scalar_type_2d_view_tpetra& y_);
104 const impl_scalar_type_2d_view_tpetra& x_,
105 const impl_scalar_type_2d_view_tpetra& x_remote_,
106 const impl_scalar_type_2d_view_tpetra& y_);
110 const AmD<MatrixType> amd;
113 const local_ordinal_type blocksize_requested;
116 const btdm_scalar_type_3d_view d_inv;
119 const impl_scalar_type_1d_view W;
121 impl_scalar_type damping_factor;
124template <
typename MatrixType>
125struct ComputeResidualAndSolve<MatrixType, BlockTriDiContainerDetails::ImplNotAvailTag> {
126 using impl_type = BlockHelperDetails::ImplType<MatrixType>;
127 using node_device_type =
typename impl_type::node_device_type;
128 using execution_space =
typename impl_type::execution_space;
129 using memory_space =
typename impl_type::memory_space;
131 using local_ordinal_type =
typename impl_type::local_ordinal_type;
132 using size_type =
typename impl_type::size_type;
133 using impl_scalar_type =
typename impl_type::impl_scalar_type;
134 using magnitude_type =
typename impl_type::magnitude_type;
136 using local_ordinal_type_1d_view =
137 typename impl_type::local_ordinal_type_1d_view;
138 using size_type_1d_view =
typename impl_type::size_type_1d_view;
139 using tpetra_block_access_view_type =
140 typename impl_type::tpetra_block_access_view_type;
142 using impl_scalar_type_1d_view =
typename impl_type::impl_scalar_type_1d_view;
143 using impl_scalar_type_2d_view_tpetra =
144 typename impl_type::impl_scalar_type_2d_view_tpetra;
146 using btdm_scalar_type_3d_view =
typename impl_type::btdm_scalar_type_3d_view;
147 using btdm_scalar_type_4d_view =
typename impl_type::btdm_scalar_type_4d_view;
148 using i64_3d_view =
typename impl_type::i64_3d_view;
151 using member_type =
typename Kokkos::TeamPolicy<execution_space>::member_type;
153 ComputeResidualAndSolve(
const AmD<MatrixType>& amd_,
154 const btdm_scalar_type_3d_view& d_inv_,
155 const impl_scalar_type_1d_view& W_,
156 const local_ordinal_type& blocksize_requested_,
157 const impl_scalar_type& damping_factor_)
159 , blocksize_requested(blocksize_requested_)
162 , damping_factor(damping_factor_) {
163 TEUCHOS_TEST_FOR_EXCEPT_MSG(
true,
"Error: BlockTriDiContainer and related classes are not available for this scalar_type");
167 const Const<impl_scalar_type_2d_view_tpetra>& b_,
168 const impl_scalar_type_2d_view_tpetra& y_) {}
169 void run_single_pass(
170 const Const<impl_scalar_type_2d_view_tpetra>& b_,
171 const impl_scalar_type_2d_view_tpetra& x_,
172 const impl_scalar_type_2d_view_tpetra& x_remote_,
173 const impl_scalar_type_2d_view_tpetra& y_) {}
175 const Const<impl_scalar_type_2d_view_tpetra>& b_,
176 const impl_scalar_type_2d_view_tpetra& x_,
177 const impl_scalar_type_2d_view_tpetra& y_) {}
179 const impl_scalar_type_2d_view_tpetra& x_,
180 const impl_scalar_type_2d_view_tpetra& x_remote_,
181 const impl_scalar_type_2d_view_tpetra& y_) {}
185 const AmD<MatrixType> amd;
188 const local_ordinal_type blocksize_requested;
191 const btdm_scalar_type_3d_view d_inv;
194 const impl_scalar_type_1d_view W;
196 impl_scalar_type damping_factor;