12#include <Kokkos_Core.hpp>
14#include "splines_linear_problem.hpp"
15#include "splines_linear_problem_2x2_blocks.hpp"
17namespace ddc::detail {
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36template <
class ExecSpace>
37class SplinesLinearProblem3x3Blocks :
public SplinesLinearProblem2x2Blocks<ExecSpace>
40 using typename SplinesLinearProblem2x2Blocks<ExecSpace>::MultiRHS;
41 using SplinesLinearProblem2x2Blocks<ExecSpace>::size;
42 using SplinesLinearProblem2x2Blocks<ExecSpace>::solve;
43 using SplinesLinearProblem2x2Blocks<ExecSpace>::m_top_left_block;
46 std::size_t m_top_size;
50
51
52
53
54
55
56 explicit SplinesLinearProblem3x3Blocks(
57 std::size_t
const mat_size,
58 std::size_t
const top_size,
59 std::unique_ptr<SplinesLinearProblem<ExecSpace>> center_block)
60 : SplinesLinearProblem2x2Blocks<ExecSpace>(mat_size, std::move(center_block))
61 , m_top_size(top_size)
67 void adjust_indices(std::size_t& i, std::size_t& j)
const
69 std::size_t
const nq = m_top_left_block->size();
73 }
else if (i < m_top_size + nq) {
79 }
else if (j < m_top_size + nq) {
85 double get_element(std::size_t i, std::size_t j)
const override
88 return SplinesLinearProblem2x2Blocks<ExecSpace>::get_element(i, j);
91 void set_element(std::size_t i, std::size_t j,
double const aij)
override
94 return SplinesLinearProblem2x2Blocks<ExecSpace>::set_element(i, j, aij);
99
100
101
102
103
104
105
106
107
108
109 void interchange_rows_from_3_to_2_blocks_rhs(MultiRHS
const b)
const
111 std::size_t
const nq = m_top_left_block->size();
113 MultiRHS
const b_top = Kokkos::
114 subview(b, std::pair<std::size_t, std::size_t> {0, m_top_size}, Kokkos::ALL);
115 MultiRHS
const b_bottom = Kokkos::
117 std::pair<std::size_t, std::size_t> {m_top_size + nq, size()},
120 MultiRHS
const b_top_dst = Kokkos::
122 std::pair<std::size_t, std::size_t> {m_top_size + nq, 2 * m_top_size + nq},
124 MultiRHS
const b_bottom_dst = Kokkos::
128 std::size_t> {2 * m_top_size + nq, m_top_size + size()},
131 if (b_bottom.extent(0) > b_top.extent(0)) {
133 MultiRHS
const buffer = Kokkos::create_mirror(ExecSpace(), b_bottom);
135 Kokkos::deep_copy(buffer, b_bottom);
136 Kokkos::deep_copy(b_bottom_dst, buffer);
138 Kokkos::deep_copy(b_bottom_dst, b_bottom);
140 Kokkos::deep_copy(b_top_dst, b_top);
144
145
146
147
148
149
150
151
152
153 void interchange_rows_from_2_to_3_blocks_rhs(MultiRHS
const b)
const
155 std::size_t
const nq = m_top_left_block->size();
157 MultiRHS
const b_top = Kokkos::
158 subview(b, std::pair<std::size_t, std::size_t> {0, m_top_size}, Kokkos::ALL);
159 MultiRHS
const b_bottom = Kokkos::
161 std::pair<std::size_t, std::size_t> {m_top_size + nq, size()},
164 MultiRHS
const b_top_src = Kokkos::
166 std::pair<std::size_t, std::size_t> {m_top_size + nq, 2 * m_top_size + nq},
168 MultiRHS
const b_bottom_src = Kokkos::
172 std::size_t> {2 * m_top_size + nq, m_top_size + size()},
175 Kokkos::deep_copy(b_top, b_top_src);
176 if (b_bottom.extent(0) > b_top.extent(0)) {
178 MultiRHS
const buffer = Kokkos::create_mirror(ExecSpace(), b_bottom);
180 Kokkos::deep_copy(buffer, b_bottom_src);
181 Kokkos::deep_copy(b_bottom, buffer);
183 Kokkos::deep_copy(b_bottom, b_bottom_src);
189
190
191
192
193
194
195
196
197
198 void solve(MultiRHS
const b,
bool const transpose)
const override
200 assert(b.extent(0) == size() + m_top_size);
202 interchange_rows_from_3_to_2_blocks_rhs(b);
203 SplinesLinearProblem2x2Blocks<ExecSpace>::
208 std::size_t> {m_top_size, m_top_size + size()},
211 interchange_rows_from_2_to_3_blocks_rhs(b);
215 std::size_t impl_required_number_of_rhs_rows()
const override
217 return size() + m_top_size;
The top-level namespace of DDC.