9#include <kernel/lafem/null_matrix.hpp>
10#include <kernel/lafem/sparse_matrix_bcsr.hpp>
11#include <kernel/lafem/sparse_matrix_csr.hpp>
12#include <kernel/lafem/saddle_point_matrix.hpp>
13#include <kernel/lafem/tuple_matrix.hpp>
16#include <cuda/std/utility>
36 template<
typename SystemMatrix_>
38 struct AmaVankaMatrixHelper;
40 struct AmaVankaMatrixHelper
43 typedef ... VankaMatrix;
45 static constexpr int num_blocks = 0;
68 static void fill_ptr_wrapper(
69 CSRTupleMatrixWrapper<typename SystemMatrix_::DataType, typename SystemMatrix_::IndexType, n_>& wrap,
70 const SystemMatrix_& matrix, Memory::Location mem_loc,
int row,
int col);
93 static void fill_column_info(
94 CSRTupleMatrixWrapper<typename SystemMatrix_::DataType, typename SystemMatrix_::IndexType, n_>& wrap,
95 const SystemMatrix_& matrix,
int row,
int col);
108 static bool compare(
const SystemMatrix_& matrix_a,
const SystemMatrix_& matrix_b);
120 template<
typename DT_,
typename IT_,
int n_>
121 struct CSRTupleMatrixWrapper
123 typedef DT_ DataType;
124 typedef IT_ IndexType;
125 static constexpr int n = n_;
126 Memory::TypedView<DataType> data_views[n_*n_];
127 Memory::TypedView<IndexType> col_views[n_*n_];
128 Memory::TypedView<IndexType> row_views[n_*n_];
135 DataType* data_arrays[n_*n_];
136 const IndexType* col_arrays[n_*n_];
137 const IndexType* row_arrays[n_*n_];
138 IndexType used_elements[n_*n_];
143 IndexType tensor_counts[n_+1];
146 int blocksizes[n_+1];
151 CUDA_HOST std::pair<IndexType, IndexType> get_tensor_size(Index i, Index j)
const
153 return std::make_pair(tensor_counts[i+std::min(i,
Index(1))], tensor_counts[j+1]);
156 CUDA_HOST std::pair<IndexType, IndexType> get_block_sizes(Index i, Index j)
const
158 return std::make_pair(blocksizes[i+std::min(i,
Index(1))], blocksizes[j+1]);
161 CUDA_HOST
Index get_all_rows_size()
const
163 Index val = tensor_counts[0];
164 for(
int i = 1; i < n_; ++i)
165 val += tensor_counts[i+1];
170 CSRTupleMatrixWrapper() =
default;
172 CSRTupleMatrixWrapper(CSRTupleMatrixWrapper&& other)
174 for(
int i = 0; i < n_*n_; ++i)
176 this->data_views[i] = std::forward<Memory::TypedView<DataType>>(
other.data_views[i]);
177 this->col_views[i] = std::forward<Memory::TypedView<IndexType>>(
other.col_views[i]);
178 this->row_views[i] = std::forward<Memory::TypedView<IndexType>>(
other.row_views[i]);
179 this->raw_data.data_arrays[i] =
other.raw_data.data_arrays[i];
180 this->raw_data.row_arrays[i] =
other.raw_data.row_arrays[i];
181 this->raw_data.col_arrays[i] =
other.raw_data.col_arrays[i];
182 this->raw_data.used_elements[i] =
other.raw_data.used_elements[i];
184 for(
int i = 0; i <= n_; ++i)
186 this->raw_data.tensor_counts[i] =
other.raw_data.tensor_counts[i];
187 this->raw_data.blocksizes[i] =
other.raw_data.blocksizes[i];
193 FEAT::String str(
"--------------------------\n\nMatrixWrapper: \n");
194 for(
int i = 0; i < n_; ++i)
196 for(
int j = 0; j < n_; ++j)
200 +
", " +
stringify(raw_data.tensor_counts[j+1]) +
"), Blocksize ("
205 str += String(
"\n--------------------------\n");
210 template<
typename DT_,
typename IT_,
int bh_,
int bw_>
211 struct AmaVankaMatrixHelper<LAFEM::NullMatrix<DT_, IT_, bh_, bw_>>
213 typedef LAFEM::SparseMatrixBCSR<DT_, IT_, bh_, bw_> VankaMatrix;
214 static constexpr int num_blocks = 1;
217 static void fill_ptr_wrapper(CSRTupleMatrixWrapper<DT_, IT_, n_>& wrap,
const LAFEM::NullMatrix<DT_, IT_, bh_, bw_>&, Memory::Location,
int row,
int col)
219 ASSERTM((n_ > row) && (n_ > col),
"MatrixWrapper is too small");
220 wrap.data_views[n_*row + col].release();
221 wrap.col_views[n_*row + col].release();
222 wrap.row_views[n_*row + col].release();
223 wrap.raw_data.data_arrays[n_*row + col] =
nullptr;
224 wrap.raw_data.col_arrays[n_*row + col] =
nullptr;
225 wrap.raw_data.row_arrays[n_*row + col] =
nullptr;
226 wrap.raw_data.used_elements[n_*row + col] = IT_(0);
230 static void fill_column_info(CSRTupleMatrixWrapper<DT_, IT_, n_>& wrap,
const LAFEM::NullMatrix<DT_, IT_, bh_, bw_>& matrix,
int row,
int col)
232 ASSERTM((n_ > row) && (n_ > col),
"MatrixWrapper is too small");
233 ASSERTM(row == 0,
"Row counter has to be zero");
239 wrap.raw_data.tensor_counts[0] = matrix.num_rows();
240 wrap.raw_data.blocksizes[0] = bh_;
242 wrap.raw_data.tensor_counts[col+1] = matrix.num_cols();
243 wrap.raw_data.blocksizes[col+1] = bw_;
246 static void fill_row_helper(
const LAFEM::NullMatrix<DT_, IT_, bh_, bw_>& matrix, Index* accum_row_idx, Index* accum_row_ctr,
int row_block,
int curr_row)
249 std::generate(accum_row_idx+curr_row, accum_row_idx+curr_row + matrix.num_rows_raw(), [n=0]()
mutable{return n++;});
251 std::fill(accum_row_ctr+curr_row, accum_row_ctr+curr_row + matrix.num_rows_raw(),
Index(row_block));
260 template<
typename DT_,
typename IT_>
261 struct AmaVankaMatrixHelper<LAFEM::SparseMatrixCSR<DT_, IT_>>
263 typedef LAFEM::SparseMatrixCSR<DT_, IT_> VankaMatrix;
264 static constexpr int num_blocks = 1;
267 static void fill_ptr_wrapper(CSRTupleMatrixWrapper<DT_, IT_, n_>& wrap,
const LAFEM::SparseMatrixCSR<DT_, IT_>& matrix, Memory::Location mem_loc,
int row,
int col)
269 ASSERTM((n_ > row) && (n_ > col),
"MatrixWrapper is too small");
270 wrap.data_views[n_*row + col] =
const_cast<LAFEM::SparseMatrixCSR<DT_, IT_>&
>(matrix).val_view_rw(mem_loc);
271 wrap.col_views[n_*row + col] = matrix.col_idx_view_r(mem_loc);
272 wrap.row_views[n_*row + col] = matrix.row_ptr_view_r(mem_loc);
273 wrap.raw_data.data_arrays[n_*row + col] = wrap.data_views[n_*row + col].get_w();
274 wrap.raw_data.col_arrays[n_*row + col] = wrap.col_views[n_*row + col].get_r();
275 wrap.raw_data.row_arrays[n_*row + col] = wrap.row_views[n_*row + col].get_r();
276 wrap.raw_data.used_elements[n_*row + col] = IT_(matrix.num_nzes());
280 static void fill_column_info(CSRTupleMatrixWrapper<DT_, IT_, n_>& wrap,
const LAFEM::SparseMatrixCSR<DT_, IT_>& matrix,
int row,
int col)
282 ASSERTM((n_ > row) && (n_ > col),
"MatrixWrapper is too small");
283 ASSERTM(row == 0,
"Row counter has to be zero");
289 wrap.raw_data.tensor_counts[0] = IT_(matrix.num_rows());
290 wrap.raw_data.blocksizes[0] = 1;
292 wrap.raw_data.tensor_counts[col+1] = IT_(matrix.num_cols());
293 wrap.raw_data.blocksizes[col+1] = 1;
296 static void fill_row_helper(
const LAFEM::SparseMatrixCSR<DT_, IT_>& matrix, Index* accum_row_idx, Index* accum_row_ctr,
int row_block,
int curr_row)
298 ASSERTM((accum_row_idx+curr_row + matrix.num_rows()) == std::find(accum_row_idx+curr_row, accum_row_idx+curr_row + matrix.num_rows(), ~
Index(0)),
"Row array was already written to");
299 ASSERTM((accum_row_ctr+curr_row + matrix.num_rows()) == std::find(accum_row_ctr+curr_row, accum_row_ctr+curr_row + matrix.num_rows(), ~
Index(0)),
"Row array was already written to");
301 std::generate(accum_row_idx+curr_row, accum_row_idx+curr_row + matrix.num_rows(), [n=0]()
mutable{return n++;});
303 std::fill(accum_row_ctr+curr_row, accum_row_ctr+curr_row + matrix.num_rows(),
Index(row_block));
315 template<
typename DT_,
typename IT_,
int bh_,
int bw_>
316 struct AmaVankaMatrixHelper<LAFEM::SparseMatrixBCSR<DT_, IT_, bh_, bw_>>
318 typedef LAFEM::SparseMatrixBCSR<DT_, IT_, bh_, bw_> VankaMatrix;
319 static constexpr int num_blocks = 1;
322 static void fill_ptr_wrapper(CSRTupleMatrixWrapper<DT_, IT_, n_>& wrap,
const LAFEM::SparseMatrixBCSR<DT_, IT_, bh_, bw_>& matrix, Memory::Location mem_loc,
int row,
int col)
324 ASSERTM((n_ > row) && (n_ > col),
"MatrixWrapper is too small");
325 wrap.data_views[n_*row + col] =
const_cast<LAFEM::SparseMatrixBCSR<DT_, IT_, bh_, bw_>&
>(matrix).val_view_raw_rw(mem_loc);
326 wrap.col_views[n_*row + col] = matrix.col_idx_view_r(mem_loc);
327 wrap.row_views[n_*row + col] = matrix.row_ptr_view_r(mem_loc);
328 wrap.raw_data.data_arrays[n_*row + col] = wrap.data_views[n_*row + col].get_w();
329 wrap.raw_data.col_arrays[n_*row + col] = wrap.col_views[n_*row + col].get_r();
330 wrap.raw_data.row_arrays[n_*row + col] = wrap.row_views[n_*row + col].get_r();
331 wrap.raw_data.used_elements[n_*row + col] = IT_(matrix.num_nzes());
335 static void fill_column_info(CSRTupleMatrixWrapper<DT_, IT_, n_>& wrap,
const LAFEM::SparseMatrixBCSR<DT_, IT_, bh_, bw_>& matrix,
int row,
int col)
337 ASSERTM((n_ > row) && (n_ > col),
"MatrixWrapper is too small");
338 ASSERTM(row == 0,
"Row counter has to be zero");
344 wrap.raw_data.tensor_counts[0] = IT_(matrix.num_rows());
345 wrap.raw_data.blocksizes[0] = bh_;
347 wrap.raw_data.tensor_counts[col+1] = IT_(matrix.num_cols());
348 wrap.raw_data.blocksizes[col+1] = bw_;
351 static void fill_row_helper(
const LAFEM::SparseMatrixBCSR<DT_, IT_, bh_, bw_>& matrix, Index* accum_row_idx, Index* accum_row_ctr,
int row_block,
int curr_row)
353 ASSERTM((accum_row_idx+curr_row + matrix.num_rows_raw()) == std::find(accum_row_idx+curr_row, accum_row_idx+curr_row + matrix.num_rows_raw(), ~
Index(0)),
"Row array was already written to");
354 ASSERTM((accum_row_ctr+curr_row + matrix.num_rows_raw()) == std::find(accum_row_ctr+curr_row, accum_row_ctr+curr_row + matrix.num_rows_raw(), ~
Index(0)),
"Row array was already written to");
356 std::generate(accum_row_idx+curr_row, accum_row_idx+curr_row + matrix.num_rows_raw(), [n=0]()
mutable{return n++;});
358 std::fill(accum_row_ctr+curr_row, accum_row_ctr+curr_row + matrix.num_rows_raw(),
Index(row_block));
370 template<
typename First_,
typename... Rest_>
371 struct AmaVankaMatrixHelper<LAFEM::TupleMatrixRow<First_, Rest_...>>
373 typedef LAFEM::TupleMatrixRow<
374 typename AmaVankaMatrixHelper<First_>::VankaMatrix,
375 typename AmaVankaMatrixHelper<Rest_>::VankaMatrix...> VankaMatrix;
377 typedef typename First_::DataType DataType;
378 typedef typename First_::IndexType IndexType;
380 static void fill_ptr_wrapper(CSRTupleMatrixWrapper<DataType, IndexType, n_>& wrap,
const LAFEM::TupleMatrixRow<First_, Rest_...>& matrix, Memory::Location mem_loc,
int row,
int col)
382 ASSERTM((n_ > row) && (n_ > col),
"MatrixWrapper is too small");
383 AmaVankaMatrixHelper<First_>::fill_ptr_wrapper(wrap, matrix.first(), mem_loc, row, col);
384 AmaVankaMatrixHelper<LAFEM::TupleMatrixRow<Rest_...>>::fill_ptr_wrapper(wrap, matrix.rest(), mem_loc, row, col+1);
388 static void fill_column_info(CSRTupleMatrixWrapper<DataType, IndexType, n_>& wrap,
const LAFEM::TupleMatrixRow<First_, Rest_...>& matrix,
int row,
int col)
390 ASSERTM((n_ > row) && (n_ > col),
"MatrixWrapper is too small");
391 ASSERTM(row == 0,
"Row counter has to be zero");
392 AmaVankaMatrixHelper<First_>::fill_column_info(wrap, matrix.first(), row, col);
393 AmaVankaMatrixHelper<LAFEM::TupleMatrixRow<Rest_...>>::fill_column_info(wrap, matrix.rest(), row, col+1);
396 static void fill_row_helper(
const LAFEM::TupleMatrixRow<First_, Rest_...>& matrix, Index* accum_row_idx, Index* accum_row_ctr,
int row_block,
int curr_row)
398 AmaVankaMatrixHelper<First_>::fill_row_helper(matrix.first(), accum_row_idx, accum_row_ctr, row_block, curr_row);
409 template<
typename First_>
410 struct AmaVankaMatrixHelper<LAFEM::TupleMatrixRow<First_>>
413 typedef LAFEM::TupleMatrixRow<typename AmaVankaMatrixHelper<First_>::VankaMatrix> VankaMatrix;
415 typedef typename First_::DataType DataType;
416 typedef typename First_::IndexType IndexType;
418 static void fill_ptr_wrapper(CSRTupleMatrixWrapper<DataType, IndexType, n_>& wrap,
const LAFEM::TupleMatrixRow<First_>& matrix, Memory::Location mem_loc,
int row,
int col)
420 ASSERTM((n_ > row) && (n_ > col),
"MatrixWrapper is too small");
421 AmaVankaMatrixHelper<First_>::fill_ptr_wrapper(wrap, matrix.first(), mem_loc, row, col);
425 static void fill_column_info(CSRTupleMatrixWrapper<DataType, IndexType, n_>& wrap,
const LAFEM::TupleMatrixRow<First_>& matrix,
int row,
int col)
427 ASSERTM((n_ > row) && (n_ > col),
"MatrixWrapper is too small");
428 ASSERTM(row == 0,
"Row counter has to be zero");
429 AmaVankaMatrixHelper<First_>::fill_column_info(wrap, matrix.first(), row, col);
432 static void fill_row_helper(
const LAFEM::TupleMatrixRow<First_>& matrix, Index* accum_row_idx, Index* accum_row_ctr,
int row_block,
int curr_row)
434 AmaVankaMatrixHelper<First_>::fill_row_helper(matrix.first(), accum_row_idx, accum_row_ctr, row_block, curr_row);
444 template<
typename FirstRow_,
typename... RestRows_>
445 struct AmaVankaMatrixHelper<LAFEM::TupleMatrix<FirstRow_, RestRows_...>>
447 typedef LAFEM::TupleMatrix<
448 typename AmaVankaMatrixHelper<FirstRow_>::VankaMatrix,
449 typename AmaVankaMatrixHelper<RestRows_>::VankaMatrix...> VankaMatrix;
450 static constexpr int num_blocks = VankaMatrix::num_col_blocks;
452 typedef typename FirstRow_::DataType DataType;
453 typedef typename FirstRow_::IndexType IndexType;
455 static void fill_ptr_wrapper(CSRTupleMatrixWrapper<DataType, IndexType, n_>& wrap,
const LAFEM::TupleMatrix<FirstRow_, RestRows_...>& matrix, Memory::Location mem_loc,
int row,
int col)
457 ASSERTM((n_ > row) && (n_ > col),
"MatrixWrapper is too small");
458 AmaVankaMatrixHelper<FirstRow_>::fill_ptr_wrapper(wrap, matrix.first(), mem_loc, row, col);
459 AmaVankaMatrixHelper<LAFEM::TupleMatrix<RestRows_...>>::fill_ptr_wrapper(wrap, matrix.rest(), mem_loc, row+1, col);
463 static void fill_column_info(CSRTupleMatrixWrapper<DataType, IndexType, n_>& wrap,
const LAFEM::TupleMatrix<FirstRow_, RestRows_...>& matrix,
int row,
int col)
465 ASSERTM((n_ > row) && (n_ > col),
"MatrixWrapper is too small");
466 ASSERTM(row == 0,
"Row counter has to be zero");
467 AmaVankaMatrixHelper<FirstRow_>::fill_column_info(wrap, matrix.first(), row, col);
470 static void fill_row_helper(
const LAFEM::TupleMatrix<FirstRow_, RestRows_...>& matrix, Index* accum_row_idx, Index* accum_row_ctr,
int row_block,
int curr_row)
472 AmaVankaMatrixHelper<FirstRow_>::fill_row_helper(matrix.first(), accum_row_idx, accum_row_ctr, row_block, curr_row);
473 AmaVankaMatrixHelper<LAFEM::TupleMatrix<RestRows_...>>::fill_row_helper(matrix.rest(), accum_row_idx, accum_row_ctr, row_block+1, curr_row+matrix.first().num_rows_raw());
484 template<
typename FirstRow_>
485 struct AmaVankaMatrixHelper<LAFEM::TupleMatrix<FirstRow_>>
487 typedef LAFEM::TupleMatrix<FirstRow_> MatrixType;
488 typedef LAFEM::TupleMatrix<typename AmaVankaMatrixHelper<FirstRow_>::VankaMatrix> VankaMatrix;
489 static constexpr int num_blocks = VankaMatrix::num_col_blocks;
491 typedef typename FirstRow_::DataType DataType;
492 typedef typename FirstRow_::IndexType IndexType;
494 static void fill_ptr_wrapper(CSRTupleMatrixWrapper<DataType, IndexType, n_>& wrap,
const LAFEM::TupleMatrix<FirstRow_>& matrix, Memory::Location mem_loc,
int row,
int col)
496 ASSERTM((n_ > row) && (n_ > col),
"MatrixWrapper is too small");
497 AmaVankaMatrixHelper<FirstRow_>::fill_ptr_wrapper(wrap, matrix.first(), mem_loc, row, col);
501 static void fill_column_info(CSRTupleMatrixWrapper<DataType, IndexType, n_>& wrap,
const LAFEM::TupleMatrix<FirstRow_>& matrix,
int row,
int col)
503 ASSERTM((n_ > row) && (n_ > col),
"MatrixWrapper is too small");
504 ASSERTM(row == 0,
"Row counter has to be zero");
505 AmaVankaMatrixHelper<FirstRow_>::fill_column_info(wrap, matrix.first(), row, col);
508 static void fill_row_helper(
const LAFEM::TupleMatrix<FirstRow_>& matrix, Index* accum_row_idx, Index* accum_row_ctr,
int row_block,
int curr_row)
510 AmaVankaMatrixHelper<FirstRow_>::fill_row_helper(matrix.first(), accum_row_idx, accum_row_ctr, row_block, curr_row);
520 template<
typename MatrixA_,
typename MatrixB_,
typename MatrixD_>
521 struct AmaVankaMatrixHelper<LAFEM::SaddlePointMatrix<MatrixA_, MatrixB_, MatrixD_>>
523 typedef typename MatrixA_::DataType DataType;
524 typedef typename MatrixA_::IndexType IndexType;
525 static constexpr int block_size = MatrixA_::block_width;
526 static constexpr int num_blocks = 2;
528 typedef LAFEM::TupleMatrix<
529 LAFEM::TupleMatrixRow<
530 LAFEM::SparseMatrixBCSR<DataType, IndexType, block_size, block_size>,
531 LAFEM::SparseMatrixBCSR<DataType, IndexType, block_size, 1>>,
532 LAFEM::TupleMatrixRow<
533 LAFEM::SparseMatrixBCSR<DataType, IndexType, 1, block_size>,
534 LAFEM::SparseMatrixBCSR<DataType, IndexType, 1, 1>>
538 static void fill_ptr_wrapper(CSRTupleMatrixWrapper<DataType, IndexType, n_>& wrap,
const LAFEM::SaddlePointMatrix<MatrixA_, MatrixB_, MatrixD_>& matrix, Memory::Location mem_loc,
int row,
int col)
540 ASSERTM((n_+1 > row) && (n_+1 > col),
"MatrixWrapper is too small");
541 AmaVankaMatrixHelper<MatrixA_>::fill_ptr_wrapper(wrap, matrix.template at<0,0>(), mem_loc, row, col);
542 AmaVankaMatrixHelper<MatrixB_>::fill_ptr_wrapper(wrap, matrix.template at<0,1>(), mem_loc, row, col+1);
543 AmaVankaMatrixHelper<MatrixD_>::fill_ptr_wrapper(wrap, matrix.template at<1,0>(), mem_loc, row+1, col);
544 AmaVankaMatrixHelper<LAFEM::NullMatrix<DataType, IndexType>>::fill_ptr_wrapper(wrap, LAFEM::NullMatrix<DataType, IndexType>(matrix.template at<1,0>().num_rows(), matrix.template at<0,1>().num_cols()), mem_loc, row+1, col+1);
548 static void fill_column_info(CSRTupleMatrixWrapper<DataType, IndexType, n_>& wrap,
const LAFEM::SaddlePointMatrix<MatrixA_, MatrixB_, MatrixD_>& matrix,
int row,
int col)
550 ASSERTM((n_+1 > row) && (n_+1 > col),
"MatrixWrapper is too small");
551 ASSERTM(row == 0,
"Row counter has to be zero");
552 AmaVankaMatrixHelper<MatrixA_>::fill_column_info(wrap, matrix.template at<0,0>(), row, col);
553 AmaVankaMatrixHelper<MatrixB_>::fill_column_info(wrap, matrix.template at<0,1>(), row, col+1);
556 static void fill_row_helper(
const LAFEM::SaddlePointMatrix<MatrixA_, MatrixB_, MatrixD_>& matrix, Index* accum_row_idx, Index* accum_row_ctr,
int row_block,
int curr_row)
558 AmaVankaMatrixHelper<MatrixA_>::fill_row_helper(matrix.template at<0,0>(), accum_row_idx, accum_row_ctr, row_block, curr_row);
559 AmaVankaMatrixHelper<MatrixD_>::fill_row_helper(matrix.template at<1,0>(), accum_row_idx, accum_row_ctr, row_block+1, curr_row + matrix.template at<0,0>().num_rows_raw());
573 template<
typename Matrix_>
574 CSRTupleMatrixWrapper<typename Matrix_::DataType, typename Matrix_::IndexType, Intern::AmaVankaMatrixHelper<Matrix_>::num_blocks>
577 CSRTupleMatrixWrapper<typename Matrix_::DataType, typename Matrix_::IndexType, Intern::AmaVankaMatrixHelper<Matrix_>::num_blocks>
579 AmaVankaMatrixHelper<Matrix_>::fill_ptr_wrapper(mat_wrapper, matrix, mem_loc, 0, 0);
580 AmaVankaMatrixHelper<Matrix_>::fill_column_info(mat_wrapper, matrix, 0, 0);
613 template<
typename Matrix_>
614 static void block_sizes(
const Matrix_& matrix, std::vector<Index>& sizes)
620 template<
typename DT_,
typename IT_>
621 static void block_sizes(
const LAFEM::SparseMatrixCSR<DT_, IT_>&, std::vector<Index>& sizes)
623 sizes.push_back(
Index(1));
627 template<
typename DT_,
typename IT_,
int bs_>
628 static void block_sizes(
const LAFEM::SparseMatrixBCSR<DT_, IT_, bs_, bs_>&, std::vector<Index>& sizes)
630 sizes.push_back(
Index(bs_));
634 template<
typename... Rows_>
635 static void block_sizes(
const LAFEM::TupleMatrix<Rows_...>& matrix, std::vector<Index>& sizes)
637 block_sizes_tpl<0>(matrix, sizes);
641 template<
int col_,
typename FirstRow_,
typename SecondRow_,
typename... RestRows_>
642 static void block_sizes_tpl(
const LAFEM::TupleMatrix<FirstRow_, SecondRow_, RestRows_...>& matrix, std::vector<Index>& sizes)
644 block_sizes(matrix.first().template at<col_>(), sizes);
645 block_sizes_tpl<col_+1>(matrix.rest(), sizes);
649 template<
int col_,
typename FirstRow_>
650 static void block_sizes_tpl(
const LAFEM::TupleMatrix<FirstRow_>& matrix, std::vector<Index>& sizes)
652 block_sizes(matrix.first().template at<col_>(), sizes);
666 template<
typename Matrix_>
667 static bool deduct_macro_dofs(
const Matrix_& DOXY(matrix), std::vector<Adjacency::Graph>& DOXY(macro_dofs))
688 template<
typename DT_,
typename IT_,
int bs_>
689 static bool deduct_macro_dofs(
690 const LAFEM::SaddlePointMatrix<
691 LAFEM::SparseMatrixBCSR<DT_, IT_, bs_, bs_>,
692 LAFEM::SparseMatrixBCSR<DT_, IT_, bs_, 1>,
693 LAFEM::SparseMatrixBCSR<DT_, IT_, 1, bs_>>& matrix,
694 std::vector<Adjacency::Graph>& macro_dofs)
696 typedef IT_ IndexType;
699 const Index num_dofs_p =
Index(matrix.block_d().num_rows());
702 const Memory::TypedView<IndexType> row_ptr_b = matrix.block_b().row_ptr_view_r();
703 const Memory::TypedView<IndexType> col_idx_b = matrix.block_b().col_idx_view_r();
704 const Memory::TypedView<IndexType> row_ptr_d = matrix.block_d().row_ptr_view_r();
705 const Memory::TypedView<IndexType> col_idx_d = matrix.block_d().col_idx_view_r();
708 std::map<IndexType, int> map_s;
709 std::vector<int> mask(std::size_t(num_dofs_p), 0);
710 std::vector<Index> p_ptr, p_idx;
711 p_ptr.push_back(
Index(0));
714 for(Index i(0); i < num_dofs_p; ++i)
724 for(IndexType kd = row_ptr_d[i]; kd < row_ptr_d[i+1]; ++kd)
727 const IndexType col_d = col_idx_d[kd];
730 for(IndexType kb = row_ptr_b[col_d]; kb < row_ptr_b[col_d+1]; ++kb)
733 const IndexType col_b = col_idx_b[kb];
736 auto ib = map_s.emplace(col_b, 1);
740 ++(ib.first->second);
747 for(
auto it = map_s.begin(); it != map_s.end(); ++it)
748 ideg = Math::max(ideg, it->second);
751 for(
auto it = map_s.begin(); it != map_s.end(); ++it)
753 if(ideg == it->second)
756 p_idx.push_back(
Index(it->first));
762 p_ptr.push_back(
Index(p_idx.size()));
768 const Index num_macros =
Index(p_ptr.size()-1u);
771 std::set<IndexType> set_v;
772 std::vector<Index> v_ptr, v_idx;
773 v_ptr.reserve(num_macros+1u);
774 v_ptr.push_back(
Index(0));
777 for(IndexType i(0); i < num_macros; ++i)
780 for(Index j = p_ptr[i]; j < p_ptr[i+1]; ++j)
783 const Index pix = p_idx[j];
786 for(IndexType k = row_ptr_d[pix]; k < row_ptr_d[pix+1]; ++k)
789 set_v.insert(col_idx_d[k]);
794 for(
auto it = set_v.begin(); it != set_v.end(); ++it)
796 v_idx.push_back(
Index(*it));
800 v_ptr.push_back(
Index(v_idx.size()));
807 macro_dofs.resize(std::size_t(2));
808 macro_dofs.front() = Adjacency::Graph(num_macros, matrix.block_b().num_rows(),
Index(v_idx.size()), v_ptr.data(), v_idx.data());
809 macro_dofs.back() = Adjacency::Graph(num_macros, matrix.block_d().num_rows(),
Index(p_idx.size()), p_ptr.data(), p_idx.data());
853 template<
typename Matrix_,
typename DT_>
854 static std::pair<Index,Index> gather(
const Matrix_& matrix,
855 DT_* local,
const Index stride,
const Index macro,
const std::vector<Adjacency::Graph>& macro_dofs,
856 const Index row_off,
const Index row_block,
const Index col_off,
const Index col_block)
862 template<
typename DT_,
typename IT_,
int bh_,
int bw_>
863 static std::pair<Index,Index> gather(
const LAFEM::NullMatrix<DT_, IT_, bh_, bw_>&,
864 DT_*,
const Index,
const Index macro,
const std::vector<Adjacency::Graph>& macro_dofs,
865 const Index,
const Index row_block,
const Index,
const Index col_block)
868 const Index* row_dom_ptr = macro_dofs.at(row_block).get_domain_ptr();
869 const Index* col_dom_ptr = macro_dofs.at(col_block).get_domain_ptr();
872 const Index num_rows = row_dom_ptr[macro+1] - row_dom_ptr[macro];
873 const Index num_cols = col_dom_ptr[macro+1] - col_dom_ptr[macro];
876 return std::make_pair(num_rows *
Index(bh_), num_cols *
Index(bw_));
880 template<
typename DT_,
typename IT_>
881 static std::pair<Index,Index> gather(
const LAFEM::SparseMatrixCSR<DT_, IT_>& matrix,
882 DT_* local,
const Index stride,
const Index macro,
const std::vector<Adjacency::Graph>& macro_dofs,
883 const Index row_off,
const Index row_block,
const Index col_off,
const Index col_block)
886 const Memory::TypedView<DT_> vals = matrix.val_view_r();
887 const Memory::TypedView<IT_> row_ptr = matrix.row_ptr_view_r();
888 const Memory::TypedView<IT_> col_idx = matrix.col_idx_view_r();
891 const Adjacency::Graph& row_dofs = macro_dofs.at(row_block);
892 const Adjacency::Graph& col_dofs = macro_dofs.at(col_block);
895 const Index* row_dom_ptr = row_dofs.get_domain_ptr();
896 const Index* col_dom_ptr = col_dofs.get_domain_ptr();
899 const Index num_rows = row_dom_ptr[macro+1] - row_dom_ptr[macro];
900 const Index num_cols = col_dom_ptr[macro+1] - col_dom_ptr[macro];
903 const Index* row_img_idx = &(row_dofs.get_image_idx()[row_dom_ptr[macro]]);
904 const Index* col_img_idx = &(col_dofs.get_image_idx()[col_dom_ptr[macro]]);
907 for(Index i(0); i < num_rows; ++i)
910 const Index irow = row_img_idx[i];
916 for(IT_ ai = row_ptr[irow]; ai < row_ptr[irow +
Index(1)]; ++ai)
922 while((j < num_cols) && (col_img_idx[j] < icol))
928 if((j < num_cols) && (col_img_idx[j] == icol))
931 local[(row_off + i) * stride + col_off + j] = vals[ai];
937 return std::make_pair(num_rows, num_cols);
941 template<
typename DT_,
typename IT_,
int bh_,
int bw_>
942 static std::pair<Index,Index> gather(
const LAFEM::SparseMatrixBCSR<DT_, IT_, bh_, bw_>& matrix,
943 DT_* local,
const Index stride,
const Index macro,
const std::vector<Adjacency::Graph>& macro_dofs,
944 const Index row_off,
const Index row_block,
const Index col_off,
const Index col_block)
947 const Memory::TypedView<Tiny::Matrix<DT_, bh_, bw_>> vals = matrix.val_view_r();
948 const Memory::TypedView<IT_> row_ptr = matrix.row_ptr_view_r();
949 const Memory::TypedView<IT_> col_idx = matrix.col_idx_view_r();
952 const Adjacency::Graph& row_dofs = macro_dofs.at(row_block);
953 const Adjacency::Graph& col_dofs = macro_dofs.at(col_block);
956 const Index* row_dom_ptr = row_dofs.get_domain_ptr();
957 const Index* col_dom_ptr = col_dofs.get_domain_ptr();
960 const Index num_rows = row_dom_ptr[macro+1] - row_dom_ptr[macro];
961 const Index num_cols = col_dom_ptr[macro+1] - col_dom_ptr[macro];
964 const Index* row_img_idx = &(row_dofs.get_image_idx()[row_dom_ptr[macro]]);
965 const Index* col_img_idx = &(col_dofs.get_image_idx()[col_dom_ptr[macro]]);
968 for(Index i(0); i < num_rows; ++i)
971 const Index irow = row_img_idx[i];
977 for(IT_ ai = row_ptr[irow]; ai < row_ptr[irow +
Index(1)]; ++ai)
983 while((j < num_cols) && (col_img_idx[j] < icol))
989 if((j < num_cols) && (col_img_idx[j] == icol))
992 const Tiny::Matrix<DT_, bh_, bw_>& mv = vals[ai];
995 for(
int ii(0); ii < bh_; ++ii)
1001 for(
int jj(0); jj < bw_; ++jj)
1003 local[lro + IT_(jj)] = mv[ii][jj];
1011 return std::make_pair(num_rows *
Index(bh_), num_cols *
Index(bw_));
1015 template<
typename DT_,
typename First_,
typename Second_,
typename... Rest_>
1016 static std::pair<Index,Index> gather(
const LAFEM::TupleMatrixRow<First_, Second_, Rest_...>& matrix,
1017 DT_* local,
const Index stride,
const Index macro,
const std::vector<Adjacency::Graph>& macro_dofs,
1018 const Index row_off,
const Index row_block,
const Index col_off,
const Index col_block)
1020 const std::pair<Index,Index> nrc_f = AmaVankaCore::gather(matrix.first(), local, stride, macro,
1021 macro_dofs, row_off, row_block, col_off, col_block);
1023 const std::pair<Index,Index> nrc_r = AmaVankaCore::gather(matrix.rest(), local, stride, macro,
1024 macro_dofs, row_off, row_block, col_off + nrc_f.second, col_block +
Index(1));
1026 XASSERTM(nrc_f.first == nrc_r.first,
"block row count mismatch");
1028 return std::make_pair(nrc_f.first, nrc_f.second + nrc_r.second);
1032 template<
typename DT_,
typename First_>
1033 static std::pair<Index,Index> gather(
const LAFEM::TupleMatrixRow<First_>& matrix,
1034 DT_* local,
const Index stride,
const Index macro,
const std::vector<Adjacency::Graph>& macro_dofs,
1035 const Index row_off,
const Index row_block,
const Index col_off,
const Index col_block)
1037 return AmaVankaCore::gather(matrix.first(), local, stride, macro,
1038 macro_dofs, row_off, row_block, col_off, col_block);
1042 template<
typename DT_,
typename FirstRow_,
typename SecondRow_,
typename... RestRows_>
1043 static std::pair<Index,Index> gather(
const LAFEM::TupleMatrix<FirstRow_, SecondRow_, RestRows_...>& matrix,
1044 DT_* local,
const Index stride,
const Index macro,
const std::vector<Adjacency::Graph>& macro_dofs,
1045 const Index row_off,
const Index row_block,
const Index col_off,
const Index col_block)
1047 const std::pair<Index,Index> nrc_f = AmaVankaCore::gather(matrix.first(), local, stride, macro,
1048 macro_dofs, row_off, row_block, col_off, col_block);
1050 const std::pair<Index,Index> nrc_r = AmaVankaCore::gather(matrix.rest(), local, stride, macro,
1051 macro_dofs, row_off + nrc_f.first, row_block +
Index(1), col_off, col_block);
1053 XASSERTM(nrc_f.second == nrc_r.second,
"block column count mismatch");
1055 return std::make_pair(nrc_f.first + nrc_r.first, nrc_f.second);
1059 template<
typename DT_,
typename FirstRow_>
1060 static std::pair<Index,Index> gather(
const LAFEM::TupleMatrix<FirstRow_>& matrix,
1061 DT_* local,
const Index stride,
const Index macro,
const std::vector<Adjacency::Graph>& macro_dofs,
1062 const Index row_off,
const Index row_block,
const Index col_off,
const Index col_block)
1064 return AmaVankaCore::gather(matrix.first(), local, stride, macro,
1065 macro_dofs, row_off, row_block, col_off, col_block);
1069 template<
typename DT_,
typename MatrixA_,
typename MatrixB_,
typename MatrixD_>
1070 static std::pair<Index,Index> gather(
const LAFEM::SaddlePointMatrix<MatrixA_, MatrixB_, MatrixD_>& matrix,
1071 DT_* local,
const Index stride,
const Index macro,
const std::vector<Adjacency::Graph>& macro_dofs,
1072 const Index row_off,
const Index row_block,
const Index col_off,
const Index col_block)
1075 const std::pair<Index,Index> nrc_a = AmaVankaCore::gather(matrix.block_a(), local, stride,
1076 macro, macro_dofs, row_off, row_block, col_off, col_block);
1079 const std::pair<Index,Index> nrc_b = AmaVankaCore::gather(matrix.block_b(), local, stride,
1080 macro, macro_dofs, row_off, row_block, col_off + nrc_a.second, col_block +
Index(1));
1083 const std::pair<Index,Index> nrc_d = AmaVankaCore::gather(matrix.block_d(), local, stride,
1084 macro, macro_dofs, row_off + nrc_a.first, row_block +
Index(1), col_off, col_block);
1086 XASSERTM(nrc_a.first == nrc_b.first,
"block row count mismatch");
1087 XASSERTM(nrc_a.second == nrc_d.second,
"block column count mismatch");
1089 return std::make_pair(nrc_a.first + nrc_d.first, nrc_a.second + nrc_b.second);
1117 template<
typename Matrix_>
1118 static void alloc(Matrix_& matrix,
1119 const std::vector<Adjacency::Graph>& dof_macros,
const std::vector<Adjacency::Graph>& macro_dofs,
1120 const Index row_block,
const Index col_block)
1126 template<
typename DT_,
typename IT_>
1127 static void alloc(LAFEM::SparseMatrixCSR<DT_, IT_>& matrix,
1128 const std::vector<Adjacency::Graph>& dof_macros,
const std::vector<Adjacency::Graph>& macro_dofs,
1129 const Index row_block,
const Index col_block)
1133 Adjacency::Graph graph(Adjacency::RenderType::injectify_sorted, dof_macros.at(row_block), macro_dofs.at(col_block));
1134 LAFEM::SparseMatrixCSR<DT_, IT_> matrix_main(graph);
1135 matrix.convert(matrix_main);
1139 template<
typename DT_,
typename IT_,
int bh_,
int bw_>
1140 static void alloc(LAFEM::SparseMatrixBCSR<DT_, IT_, bh_, bw_>& matrix,
1141 const std::vector<Adjacency::Graph>& dof_macros,
const std::vector<Adjacency::Graph>& macro_dofs,
1142 const Index row_block,
const Index col_block)
1146 Adjacency::Graph graph(Adjacency::RenderType::injectify_sorted, dof_macros.at(row_block), macro_dofs.at(col_block));
1147 matrix.convert(graph);
1151 template<
typename First_,
typename Second_,
typename... Rest_>
1152 static void alloc(LAFEM::TupleMatrixRow<First_, Second_, Rest_...>& matrix,
1153 const std::vector<Adjacency::Graph>& dof_macros,
const std::vector<Adjacency::Graph>& macro_dofs,
1154 const Index row_block,
const Index col_block)
1156 AmaVankaCore::alloc(matrix.first(), dof_macros, macro_dofs, row_block, col_block);
1157 AmaVankaCore::alloc(matrix.rest(), dof_macros, macro_dofs, row_block, col_block +
Index(1));
1161 template<
typename First_>
1162 static void alloc(LAFEM::TupleMatrixRow<First_>& matrix,
1163 const std::vector<Adjacency::Graph>& dof_macros,
const std::vector<Adjacency::Graph>& macro_dofs,
1164 const Index row_block,
const Index col_block)
1166 AmaVankaCore::alloc(matrix.first(), dof_macros, macro_dofs, row_block, col_block);
1170 template<
typename FirstRow_,
typename SecondRow_,
typename... RestRows_>
1171 static void alloc(LAFEM::TupleMatrix<FirstRow_, SecondRow_, RestRows_...>& matrix,
1172 const std::vector<Adjacency::Graph>& dof_macros,
const std::vector<Adjacency::Graph>& macro_dofs,
1173 const Index row_block,
const Index col_block)
1175 AmaVankaCore::alloc(matrix.first(), dof_macros, macro_dofs, row_block, col_block);
1176 AmaVankaCore::alloc(matrix.rest(), dof_macros, macro_dofs, row_block +
Index(1), col_block);
1180 template<
typename FirstRow_>
1181 static void alloc(LAFEM::TupleMatrix<FirstRow_>& matrix,
1182 const std::vector<Adjacency::Graph>& dof_macros,
const std::vector<Adjacency::Graph>& macro_dofs,
1183 const Index row_block,
const Index col_block)
1185 AmaVankaCore::alloc(matrix.first(), dof_macros, macro_dofs, row_block, col_block);
1231 template<
typename DT_,
typename Matrix_>
1232 static std::pair<Index,Index> scatter_add(Matrix_& matrix,
1233 const DT_* local,
const Index stride,
const Index macro,
const std::vector<Adjacency::Graph>& macro_dofs,
1234 const Index row_off,
const Index row_block,
const Index col_off,
const Index col_block)
1240 template<
typename DT_,
typename IT_>
1241 static std::pair<Index,Index> scatter_add(LAFEM::SparseMatrixCSR<DT_, IT_>& matrix,
1242 const DT_* local,
const Index stride,
const Index macro,
const std::vector<Adjacency::Graph>& macro_dofs,
1243 const Index row_off,
const Index row_block,
const Index col_off,
const Index col_block)
1246 Memory::TypedView<DT_> vals = matrix.val_view_rw();
1247 const Memory::TypedView<IT_> row_ptr = matrix.row_ptr_view_r();
1248 const Memory::TypedView<IT_> col_idx = matrix.col_idx_view_r();
1251 const Adjacency::Graph& row_dofs = macro_dofs.at(row_block);
1252 const Adjacency::Graph& col_dofs = macro_dofs.at(col_block);
1255 const Index* row_dom_ptr = row_dofs.get_domain_ptr();
1256 const Index* col_dom_ptr = col_dofs.get_domain_ptr();
1259 const Index num_rows = row_dom_ptr[macro+1] - row_dom_ptr[macro];
1260 const Index num_cols = col_dom_ptr[macro+1] - col_dom_ptr[macro];
1263 const Index* row_img_idx = &(row_dofs.get_image_idx()[row_dom_ptr[macro]]);
1264 const Index* col_img_idx = &(col_dofs.get_image_idx()[col_dom_ptr[macro]]);
1267 for(Index i(0); i < num_rows; ++i)
1270 const Index irow = row_img_idx[i];
1276 for(IT_ ai = row_ptr[irow]; ai < row_ptr[irow +
Index(1)]; ++ai)
1282 while((j < num_cols) && (col_img_idx[j] < icol))
1288 if((j < num_cols) && (col_img_idx[j] == icol))
1290 vals[ai] += local[(row_off + i) * stride + col_off + j];
1296 return std::make_pair(num_rows, num_cols);
1300 template<
typename DT_,
typename IT_,
int bh_,
int bw_>
1301 static std::pair<Index,Index> scatter_add(LAFEM::SparseMatrixBCSR<DT_, IT_, bh_, bw_>& matrix,
1302 const DT_* local,
const Index stride,
const Index macro,
const std::vector<Adjacency::Graph>& macro_dofs,
1303 const Index row_off,
const Index row_block,
const Index col_off,
const Index col_block)
1306 Memory::TypedView<Tiny::Matrix<DT_, bh_, bw_>> vals = matrix.val_view_rw();
1307 const Memory::TypedView<IT_> row_ptr = matrix.row_ptr_view_r();
1308 const Memory::TypedView<IT_> col_idx = matrix.col_idx_view_r();
1311 const Adjacency::Graph& row_dofs = macro_dofs.at(row_block);
1312 const Adjacency::Graph& col_dofs = macro_dofs.at(col_block);
1315 const Index* row_dom_ptr = row_dofs.get_domain_ptr();
1316 const Index* col_dom_ptr = col_dofs.get_domain_ptr();
1319 const Index num_rows = row_dom_ptr[macro+1] - row_dom_ptr[macro];
1320 const Index num_cols = col_dom_ptr[macro+1] - col_dom_ptr[macro];
1323 const Index* row_img_idx = &(row_dofs.get_image_idx()[row_dom_ptr[macro]]);
1324 const Index* col_img_idx = &(col_dofs.get_image_idx()[col_dom_ptr[macro]]);
1327 for(Index i(0); i < num_rows; ++i)
1330 const Index irow = row_img_idx[i];
1336 for(IT_ ai = row_ptr[irow]; ai < row_ptr[irow +
Index(1)]; ++ai)
1342 while((j < num_cols) && (col_img_idx[j] < icol))
1348 if((j < num_cols) && (col_img_idx[j] == icol))
1351 Tiny::Matrix<DT_, bh_, bw_>& mv = vals[ai];
1354 for(
int ii(0); ii < bh_; ++ii)
1360 for(
int jj(0); jj < bw_; ++jj)
1362 mv[ii][jj] += local[lro + IT_(jj)];
1370 return std::make_pair(num_rows *
Index(bh_), num_cols *
Index(bw_));
1374 template<
typename DT_,
typename First_,
typename Second_,
typename... Rest_>
1375 static std::pair<Index,Index> scatter_add(LAFEM::TupleMatrixRow<First_, Second_, Rest_...>& matrix,
1376 const DT_* local,
const Index stride,
const Index macro,
const std::vector<Adjacency::Graph>& macro_dofs,
1377 const Index row_off,
const Index row_block,
const Index col_off,
const Index col_block)
1379 const std::pair<Index,Index> nrc_f = AmaVankaCore::scatter_add(matrix.first(), local, stride, macro,
1380 macro_dofs, row_off, row_block, col_off, col_block);
1382 const std::pair<Index,Index> nrc_r = AmaVankaCore::scatter_add(matrix.rest(), local, stride, macro,
1383 macro_dofs, row_off, row_block, col_off + nrc_f.second, col_block +
Index(1));
1385 XASSERTM(nrc_f.first == nrc_r.first,
"block row count mismatch");
1387 return std::make_pair(nrc_f.first, nrc_f.second + nrc_r.second);
1391 template<
typename DT_,
typename First_>
1392 static std::pair<Index,Index> scatter_add(LAFEM::TupleMatrixRow<First_>& matrix,
1393 const DT_* local,
const Index stride,
const Index macro,
const std::vector<Adjacency::Graph>& macro_dofs,
1394 const Index row_off,
const Index row_block,
const Index col_off,
const Index col_block)
1396 return AmaVankaCore::scatter_add(matrix.first(), local, stride, macro,
1397 macro_dofs, row_off, row_block, col_off, col_block);
1401 template<
typename DT_,
typename FirstRow_,
typename SecondRow_,
typename... RestRows_>
1402 static std::pair<Index,Index> scatter_add(LAFEM::TupleMatrix<FirstRow_, SecondRow_, RestRows_...>& matrix,
1403 const DT_* local,
const Index stride,
const Index macro,
const std::vector<Adjacency::Graph>& macro_dofs,
1404 const Index row_off,
const Index row_block,
const Index col_off,
const Index col_block)
1406 const std::pair<Index,Index> nrc_f = AmaVankaCore::scatter_add(matrix.first(), local, stride,
1407 macro, macro_dofs, row_off, row_block, col_off, col_block);
1409 const std::pair<Index,Index> nrc_r = AmaVankaCore::scatter_add(matrix.rest(), local, stride,
1410 macro, macro_dofs, row_off + nrc_f.first, row_block +
Index(1), col_off, col_block);
1412 XASSERTM(nrc_f.second == nrc_r.second,
"block column count mismatch");
1414 return std::make_pair(nrc_f.first + nrc_r.first, nrc_f.second);
1418 template<
typename DT_,
typename FirstRow_>
1419 static std::pair<Index,Index> scatter_add(LAFEM::TupleMatrix<FirstRow_>& matrix,
1420 const DT_* local,
const Index stride,
const Index macro,
const std::vector<Adjacency::Graph>& macro_dofs,
1421 const Index row_off,
const Index row_block,
const Index col_off,
const Index col_block)
1423 return AmaVankaCore::scatter_add(matrix.first(), local, stride,
1424 macro, macro_dofs, row_off, row_block, col_off, col_block);
1452 template<
typename Matrix_>
1453 static void scale_rows(Matrix_& matrix,
const DT_ omega,
1454 const std::vector<Adjacency::Graph>& dof_macros,
const Index row_block,
const Index col_block)
1460 template<
typename DT_,
typename IT_>
1461 static void scale_rows(LAFEM::SparseMatrixCSR<DT_, IT_>& matrix,
const DT_ omega,
1462 const std::vector<Adjacency::Graph>& dof_macros,
const std::vector<int>& macro_mask,
const Index row_block,
const Index col_block)
1465 Memory::TypedView<DT_> vals = matrix.val_view_rw();
1466 const Memory::TypedView<IT_> row_ptr = matrix.row_ptr_view_r();
1467 const Memory::TypedView<IT_> col_idx = matrix.col_idx_view_r();
1470 const Adjacency::Graph& row_blocks = dof_macros.at(row_block);
1471 const Index num_rows = row_blocks.get_num_nodes_domain();
1472 XASSERT(matrix.num_rows() == num_rows);
1475 const Index* row_dom_ptr = row_blocks.get_domain_ptr();
1476 const Index* row_img_idx = row_blocks.get_image_idx();
1479 for(Index i(0); i < num_rows; ++i)
1481 XASSERT(row_dom_ptr[i] < row_dom_ptr[i+1]);
1485 if(macro_mask.empty())
1486 n = row_dom_ptr[i+1] - row_dom_ptr[i];
1489 for(Index j(row_dom_ptr[i]); j < row_dom_ptr[i+1]; ++j)
1490 n +=
Index(macro_mask[row_img_idx[j]]);
1495 const DT_ sc = omega / DT_(Math::max(n,
Index(1)));
1496 for(IT_ j(row_ptr[i]); j < row_ptr[i+1]; ++j)
1499 else if(row_block == col_block)
1501 for(IT_ j(row_ptr[i]); j < row_ptr[i+1]; ++j)
1503 vals[j] = DT_(col_idx[j] == i ? 1 : 0);
1510 template<
typename DT_,
typename IT_,
int bh_,
int bw_>
1511 static void scale_rows(LAFEM::SparseMatrixBCSR<DT_, IT_, bh_, bw_>& matrix,
const DT_ omega,
1512 const std::vector<Adjacency::Graph>& dof_macros,
const std::vector<int>& macro_mask,
const Index row_block,
const Index col_block)
1515 Memory::TypedView<Tiny::Matrix<DT_, bh_, bw_>> vals = matrix.val_view_rw();
1516 const Memory::TypedView<IT_> row_ptr = matrix.row_ptr_view_r();
1517 const Memory::TypedView<IT_> col_idx = matrix.col_idx_view_r();
1520 const Adjacency::Graph& row_blocks = dof_macros.at(row_block);
1521 const Index num_rows = row_blocks.get_num_nodes_domain();
1522 XASSERT(matrix.num_rows() == num_rows);
1525 const Index* row_dom_ptr = row_blocks.get_domain_ptr();
1526 const Index* row_img_idx = row_blocks.get_image_idx();
1529 for(Index i(0); i < num_rows; ++i)
1531 XASSERT(row_dom_ptr[i] < row_dom_ptr[i+1]);
1535 if(macro_mask.empty())
1536 n = row_dom_ptr[i+1] - row_dom_ptr[i];
1539 for(Index j(row_dom_ptr[i]); j < row_dom_ptr[i+1]; ++j)
1540 n +=
Index(macro_mask[row_img_idx[j]]);
1545 const DT_ sc = omega / DT_(n);
1546 for(IT_ j(row_ptr[i]); j < row_ptr[i+1]; ++j)
1549 else if(row_block == col_block)
1551 for(IT_ j(row_ptr[i]); j < row_ptr[i+1]; ++j)
1554 vals[j].set_identity();
1561 template<
typename DT_,
typename First_,
typename Second_,
typename... Rest_>
1562 static void scale_rows(LAFEM::TupleMatrixRow<First_, Second_, Rest_...>& matrix,
const DT_ omega,
1563 const std::vector<Adjacency::Graph>& dof_macros,
const std::vector<int>& macro_mask,
const Index row_block,
const Index col_block)
1565 AmaVankaCore::scale_rows(matrix.first(), omega, dof_macros, macro_mask, row_block, col_block);
1566 AmaVankaCore::scale_rows(matrix.rest(), omega, dof_macros, macro_mask, row_block, col_block +
Index(1));
1570 template<
typename DT_,
typename First_>
1571 static void scale_rows(LAFEM::TupleMatrixRow<First_>& matrix,
const DT_ omega,
1572 const std::vector<Adjacency::Graph>& dof_macros,
const std::vector<int>& macro_mask,
const Index row_block,
const Index col_block)
1574 AmaVankaCore::scale_rows(matrix.first(), omega, dof_macros, macro_mask, row_block, col_block);
1578 template<
typename DT_,
typename FirstRow_,
typename SecondRow_,
typename... RestRows_>
1579 static void scale_rows(LAFEM::TupleMatrix<FirstRow_, SecondRow_, RestRows_...>& matrix,
const DT_ omega,
1580 const std::vector<Adjacency::Graph>& dof_macros,
const std::vector<int>& macro_mask,
const Index row_block,
const Index col_block)
1582 AmaVankaCore::scale_rows(matrix.first(), omega, dof_macros, macro_mask, row_block, col_block);
1583 AmaVankaCore::scale_rows(matrix.rest(), omega, dof_macros, macro_mask, row_block +
Index(1), col_block);
1587 template<
typename DT_,
typename FirstRow_>
1588 static void scale_rows(LAFEM::TupleMatrix<FirstRow_>& matrix,
const DT_ omega,
1589 const std::vector<Adjacency::Graph>& dof_macros,
const std::vector<int>& macro_mask,
const Index row_block,
const Index col_block)
1591 AmaVankaCore::scale_rows(matrix.first(), omega, dof_macros, macro_mask, row_block, col_block);
1608 template<
typename Matrix_>
1609 static Index calc_stride(
const Matrix_& matrix,
const std::vector<Adjacency::Graph>& macro_dofs)
1611 const std::size_t num_graphs = macro_dofs.size();
1612 const Index num_macros = macro_dofs.front().get_num_nodes_domain();
1615 std::vector<Index> block_sizes;
1616 AmaVankaCore::block_sizes(matrix, block_sizes);
1618 XASSERT(num_graphs == block_sizes.size());
1622 for(Index imacro(0); imacro < num_macros; ++imacro)
1627 for(std::size_t igraph(0); igraph < num_graphs; ++igraph)
1629 count += macro_dofs.at(igraph).degree(imacro) * block_sizes.at(igraph);
1632 rtn = Math::max(rtn, count);
1648 struct VoxelAmaVankaCore
1650 template<
typename DT_,
typename IT_>
1651 CUDA_HOST_DEVICE
static void gather_loc_cell(DT_* local,
const DT_* vals,
const IT_* row_ptr,
const IT_* col_idx,
1652 const Index* row_img_idx,
const Index* col_img_idx,
const int bh_,
const int bw_,
const Index num_rows,
const Index num_cols,
1653 const Index stride,
const Index row_off,
const Index col_off)
1658 for(Index i(0); i < num_rows; ++i)
1661 const Index irow = row_img_idx[i];
1667 for(IT_ ai = row_ptr[irow]; ai < row_ptr[irow +
Index(1)]; ++ai)
1673 while((j < num_cols) && (col_img_idx[j] < icol))
1679 if((j < num_cols) && (col_img_idx[j] == icol))
1682 const DT_* mv = vals + ai*IT_(bw_)*IT_(bh_);
1684 for(
int ii(0); ii < bh_; ++ii)
1690 for(
int jj(0); jj < bw_; ++jj)
1692 local[lro + IT_(jj)] = mv[ii*bw_+jj];
1701 template<
typename DT_,
typename IT_,
int n_>
1702 CUDA_HOST
static std::pair<Index,Index> gather_loc(
const typename Intern::CSRTupleMatrixWrapper<DT_, IT_, n_>::RawData& mat_wrap,
1703 DT_* local,
const Index stride,
const Index macro,
const Adjacency::Graph** macro_dofs,
1704 const Index row_off,
const Index row_block,
const Index col_off,
const Index col_block)
1707 const Index cur_ind =
Index(n_)*row_block + col_block;
1708 const DT_* vals = mat_wrap.data_arrays[cur_ind];
1709 const IT_* row_ptr = mat_wrap.row_arrays[cur_ind];
1710 const IT_* col_idx = mat_wrap.col_arrays[cur_ind];
1711 const Adjacency::Graph& row_dofs = *macro_dofs[row_block];
1712 const Adjacency::Graph& col_dofs = *macro_dofs[col_block];
1715 const int bh_ = int(mat_wrap.get_block_sizes(row_block, col_block).first);
1716 const int bw_ = int(mat_wrap.get_block_sizes(row_block, col_block).second);
1719 const Index* row_dom_ptr = row_dofs.get_domain_ptr();
1720 const Index* col_dom_ptr = col_dofs.get_domain_ptr();
1723 const Index num_rows = row_dom_ptr[macro+1] - row_dom_ptr[macro];
1724 const Index num_cols = col_dom_ptr[macro+1] - col_dom_ptr[macro];
1727 const Index* row_img_idx = &(row_dofs.get_image_idx()[row_dom_ptr[macro]]);
1728 const Index* col_img_idx = &(col_dofs.get_image_idx()[col_dom_ptr[macro]]);
1730 gather_loc_cell(local, vals, row_ptr, col_idx, row_img_idx, col_img_idx, bh_, bw_, num_rows, num_cols,
1731 stride, row_off, col_off);
1734 return std::make_pair(num_rows *
Index(bh_), num_cols *
Index(bw_));
1737 template<
typename DT_,
typename IT_,
int n_>
1738 CUDA_HOST
static std::pair<Index,Index> gather_row(
const typename Intern::CSRTupleMatrixWrapper<DT_, IT_, n_>::RawData& mat_wrap,
1739 DT_* local,
const Index stride,
const Index macro,
const Adjacency::Graph** macro_dofs,
1740 const Index row_off,
const Index row_block,
const Index col_off,
const Index col_block)
1742 std::pair<Index, Index> nrc_r{0,0};
1744 for(
int l = 0; l < n_; ++l)
1746 std::pair<Index, Index> nrc_l = gather_loc<DT_,IT_,n_>(mat_wrap, local, stride, macro, macro_dofs, row_off, row_block, col_off+nrc_r.second, col_block+
Index(l));
1747 nrc_r.first = nrc_l.first;
1748 nrc_r.second += nrc_l.second;
1754 template<
typename DT_,
typename IT_,
int n_>
1755 CUDA_HOST
static std::pair<Index,Index> gather(
const typename Intern::CSRTupleMatrixWrapper<DT_, IT_, n_>::RawData& mat_wrap,
1756 DT_* local,
const Index stride,
const Index macro,
const Adjacency::Graph** macro_dofs,
1757 const Index row_off,
const Index row_block,
const Index col_off,
const Index col_block)
1759 std::pair<Index, Index> nrc_f{0,0};
1761 for(
int l = 0; l < n_; ++l)
1763 std::pair<Index, Index> nrc_r = gather_row<DT_,IT_,n_>(mat_wrap, local, stride, macro, macro_dofs, row_off+nrc_f.first, row_block+
Index(l), col_off, col_block);
1764 nrc_f.first += nrc_r.first;
1765 nrc_f.second = nrc_r.second;
1773 template<
typename DT_,
typename IT_,
int n_,
bool uniform_macros_>
1774 CUDA_HOST_DEVICE
static cuda::std::pair<Index,Index> gather_loc(
const typename Intern::CSRTupleMatrixWrapper<DT_, IT_, n_>::RawData& mat_wrap,
1775 DT_* local,
const Index stride,
const Index macro,
const Index** macro_dofs, Index* max_degrees_dofs,
1776 const Index row_off,
const Index row_block,
const Index col_off,
const Index col_block)
1779 const Index cur_ind =
Index(n_)*row_block + col_block;
1780 const DT_* vals = mat_wrap.data_arrays[cur_ind];
1781 const IT_* row_ptr = mat_wrap.row_arrays[cur_ind];
1782 const IT_* col_idx = mat_wrap.col_arrays[cur_ind];
1783 const Index* row_dofs = macro_dofs[row_block];
1784 const Index* col_dofs = macro_dofs[col_block];
1785 const Index degree_row = max_degrees_dofs[row_block] +
Index(!uniform_macros_);
1786 const Index degree_col = max_degrees_dofs[col_block] +
Index(!uniform_macros_);
1789 const int bh_ = int(mat_wrap.blocksizes[row_block+CudaMath::cuda_min(row_block,
Index(1))]);
1790 const int bw_ = int(mat_wrap.blocksizes[col_block+
Index(1)]);
1793 const Index* row_dom_ptr = row_dofs + degree_row*macro;
1794 const Index* col_dom_ptr = col_dofs + degree_col*macro;
1797 const Index num_rows = uniform_macros_ ? degree_row : row_dom_ptr[0];
1798 const Index num_cols = uniform_macros_ ? degree_col : col_dom_ptr[0];
1804 gather_loc_cell(local, vals, row_ptr, col_idx, row_dom_ptr +
Index(!uniform_macros_), col_dom_ptr +
Index(!uniform_macros_), bh_, bw_, num_rows, num_cols,
1805 stride, row_off, col_off);
1808 return cuda::std::make_pair(num_rows *
Index(bh_), num_cols *
Index(bw_));
1811 template<
typename DT_,
typename IT_,
int n_,
bool uniform_macros_>
1812 CUDA_HOST_DEVICE
static cuda::std::pair<Index,Index> gather_row(
const typename Intern::CSRTupleMatrixWrapper<DT_, IT_, n_>::RawData& mat_wrap,
1813 DT_* local,
const Index stride,
const Index macro,
const Index** macro_dofs, Index* max_degrees_dofs,
1814 const Index row_off,
const Index row_block,
const Index col_off,
const Index col_block)
1816 cuda::std::pair<Index, Index> nrc_r{0,0};
1818 for(
int l = 0; l < n_; ++l)
1820 cuda::std::pair<Index, Index> nrc_l = gather_loc<DT_, IT_, n_, uniform_macros_>(mat_wrap, local, stride, macro, macro_dofs, max_degrees_dofs, row_off, row_block, col_off+nrc_r.second, col_block+
Index(l));
1821 nrc_r.first = nrc_l.first;
1822 nrc_r.second += nrc_l.second;
1828 template<
typename DT_,
typename IT_,
int n_,
bool uniform_macros_>
1829 CUDA_HOST_DEVICE
static cuda::std::pair<Index,Index> gather(
const typename Intern::CSRTupleMatrixWrapper<DT_, IT_, n_>::RawData& mat_wrap,
1830 DT_* local,
const Index stride,
const Index macro,
const Index** macro_dofs, Index* max_degrees_dofs,
1831 const Index row_off,
const Index row_block,
const Index col_off,
const Index col_block)
1833 cuda::std::pair<Index, Index> nrc_f{0,0};
1835 for(
int l = 0; l < n_; ++l)
1837 cuda::std::pair<Index, Index> nrc_r = gather_row<DT_, IT_, n_, uniform_macros_>(mat_wrap, local, stride, macro, macro_dofs, max_degrees_dofs, row_off+nrc_f.first, row_block+
Index(l), col_off, col_block);
1838 nrc_f.first += nrc_r.first;
1839 nrc_f.second = nrc_r.second;
1846 template<
typename DT_,
typename IT_>
1847 CUDA_HOST_DEVICE
static void scatter_add_loc_cell(
const DT_* local, DT_* vals,
const IT_* row_ptr,
const IT_* col_idx,
1848 const Index* row_img_idx,
const Index* col_img_idx,
const int bh_,
const int bw_,
const Index num_rows,
const Index num_cols,
1849 const Index stride,
const Index row_off,
const Index col_off)
1853 for(Index i(0); i < num_rows; ++i)
1856 const Index irow = row_img_idx[i];
1862 for(IT_ ai = row_ptr[irow]; ai < row_ptr[irow +
Index(1)]; ++ai)
1868 while((j < num_cols) && (col_img_idx[j] < icol))
1874 if((j < num_cols) && (col_img_idx[j] == icol))
1877 DT_* mv = vals + ai*IT_(bh_)*IT_(bw_);
1879 for(
int ii(0); ii < bh_; ++ii)
1884 for(
int jj(0); jj < bw_; ++jj)
1886 mv[ii*bw_+jj] += local[lro + IT_(jj)];
1895 template<
typename DT_,
typename IT_,
int n_>
1896 CUDA_HOST
static std::pair<Index,Index> scatter_add_loc(
typename Intern::CSRTupleMatrixWrapper<DT_, IT_, n_>::RawData& mat_wrap,
1897 const DT_* local,
const Index stride,
const Index macro,
const Adjacency::Graph** macro_dofs,
1898 const Index row_off,
const Index row_block,
const Index col_off,
const Index col_block)
1901 const Index cur_ind =
Index(n_)*row_block + col_block;
1902 DT_* vals =
const_cast<DT_*
>(mat_wrap.data_arrays[cur_ind]);
1903 const IT_* row_ptr = mat_wrap.row_arrays[cur_ind];
1904 const IT_* col_idx = mat_wrap.col_arrays[cur_ind];
1905 const Adjacency::Graph& row_dofs = *macro_dofs[row_block];
1906 const Adjacency::Graph& col_dofs = *macro_dofs[col_block];
1909 const int bh_ = int(mat_wrap.get_block_sizes(row_block, col_block).first);
1910 const int bw_ = int(mat_wrap.get_block_sizes(row_block, col_block).second);
1913 const Index* row_dom_ptr = row_dofs.get_domain_ptr();
1914 const Index* col_dom_ptr = col_dofs.get_domain_ptr();
1917 const Index num_rows = row_dom_ptr[macro+1] - row_dom_ptr[macro];
1918 const Index num_cols = col_dom_ptr[macro+1] - col_dom_ptr[macro];
1921 const Index* row_img_idx = &(row_dofs.get_image_idx()[row_dom_ptr[macro]]);
1922 const Index* col_img_idx = &(col_dofs.get_image_idx()[col_dom_ptr[macro]]);
1924 scatter_add_loc_cell(local, vals, row_ptr, col_idx, row_img_idx, col_img_idx, bh_, bw_, num_rows, num_cols,
1925 stride, row_off, col_off);
1928 return std::make_pair(num_rows *
Index(bh_), num_cols *
Index(bw_));
1931 template<
typename DT_,
typename IT_,
int n_>
1932 CUDA_HOST
static std::pair<Index,Index> scatter_add_row(
typename Intern::CSRTupleMatrixWrapper<DT_, IT_, n_>::RawData& mat_wrap,
1933 const DT_* local,
const Index stride,
const Index macro,
const Adjacency::Graph** macro_dofs,
1934 const Index row_off,
const Index row_block,
const Index col_off,
const Index col_block)
1936 std::pair<Index, Index> nrc_r{0,0};
1938 for(
int l = 0; l < n_; ++l)
1940 std::pair<Index, Index> nrc_l = scatter_add_loc<DT_,IT_,n_>(mat_wrap, local, stride, macro, macro_dofs, row_off, row_block, col_off+nrc_r.second, col_block+
Index(l));
1941 nrc_r.first = nrc_l.first;
1942 nrc_r.second += nrc_l.second;
1948 template<
typename DT_,
typename IT_,
int n_>
1949 CUDA_HOST
static std::pair<Index,Index> scatter_add(
typename Intern::CSRTupleMatrixWrapper<DT_, IT_, n_>::RawData& mat_wrap,
1950 const DT_* local,
const Index stride,
const Index macro,
const Adjacency::Graph** macro_dofs,
1951 const Index row_off,
const Index row_block,
const Index col_off,
const Index col_block)
1953 std::pair<Index, Index> nrc_f{0,0};
1955 for(
int l = 0; l < n_; ++l)
1957 std::pair<Index, Index> nrc_r = scatter_add_row<DT_,IT_,n_>(mat_wrap, local, stride, macro, macro_dofs, row_off+nrc_f.first, row_block+
Index(l), col_off, col_block);
1958 nrc_f.first += nrc_r.first;
1959 nrc_f.second = nrc_f.second;
1967 template<
typename DT_,
typename IT_,
int n_,
bool uniform_macros_>
1968 CUDA_HOST_DEVICE
static cuda::std::pair<Index,Index> scatter_add_loc(
typename Intern::CSRTupleMatrixWrapper<DT_, IT_, n_>::RawData& mat_wrap,
1969 const DT_* local,
const Index stride,
const Index macro,
const Index** macro_dofs, Index* max_degrees_dofs,
1970 const Index row_off,
const Index row_block,
const Index col_off,
const Index col_block)
1973 const Index cur_ind =
Index(n_)*row_block + col_block;
1974 DT_* vals = mat_wrap.data_arrays[cur_ind];
1975 const IT_* row_ptr = mat_wrap.row_arrays[cur_ind];
1976 const IT_* col_idx = mat_wrap.col_arrays[cur_ind];
1977 const Index* row_dofs = macro_dofs[row_block];
1978 const Index* col_dofs = macro_dofs[col_block];
1979 const Index degree_row = max_degrees_dofs[row_block] +
Index(!uniform_macros_);
1980 const Index degree_col = max_degrees_dofs[col_block] +
Index(!uniform_macros_);
1983 const int bh_ = int(mat_wrap.blocksizes[row_block+CudaMath::cuda_min(row_block,
Index(1))]);
1984 const int bw_ = int(mat_wrap.blocksizes[col_block+
Index(1)]);
1987 const Index* row_dom_ptr = row_dofs + degree_row*macro;
1988 const Index* col_dom_ptr = col_dofs + degree_col*macro;
1991 const Index num_rows = uniform_macros_ ? degree_row : row_dom_ptr[0];
1992 const Index num_cols = uniform_macros_ ? degree_col : col_dom_ptr[0];
1998 scatter_add_loc_cell(local, vals, row_ptr, col_idx, row_dom_ptr +
Index(!uniform_macros_), col_dom_ptr +
Index(!uniform_macros_), bh_, bw_, num_rows, num_cols,
1999 stride, row_off, col_off);
2002 return cuda::std::make_pair(num_rows *
Index(bh_), num_cols *
Index(bw_));
2005 template<
typename DT_,
typename IT_,
int n_,
bool uniform_macros_>
2006 CUDA_HOST_DEVICE
static cuda::std::pair<Index,Index> scatter_add_row(
typename Intern::CSRTupleMatrixWrapper<DT_, IT_, n_>::RawData& mat_wrap,
2007 const DT_* local,
const Index stride,
const Index macro,
const Index** macro_dofs, Index* max_degrees_dofs,
2008 const Index row_off,
const Index row_block,
const Index col_off,
const Index col_block)
2010 cuda::std::pair<Index, Index> nrc_r{0,0};
2012 for(
int l = 0; l < n_; ++l)
2014 cuda::std::pair<Index, Index> nrc_l = scatter_add_loc<DT_, IT_, n_, uniform_macros_>(mat_wrap, local, stride, macro, macro_dofs, max_degrees_dofs, row_off, row_block, col_off+nrc_r.second, col_block+
Index(l));
2015 nrc_r.first = nrc_l.first;
2016 nrc_r.second += nrc_l.second;
2022 template<
typename DT_,
typename IT_,
int n_,
bool uniform_macros_>
2023 CUDA_HOST_DEVICE
static cuda::std::pair<Index,Index> scatter_add(
typename Intern::CSRTupleMatrixWrapper<DT_, IT_, n_>::RawData& mat_wrap,
2024 const DT_* local,
const Index stride,
const Index macro,
const Index** macro_dofs, Index* max_degrees_dofs,
2025 const Index row_off,
const Index row_block,
const Index col_off,
const Index col_block)
2027 cuda::std::pair<Index, Index> nrc_f{0,0};
2029 for(
int l = 0; l < n_; ++l)
2031 cuda::std::pair<Index, Index> nrc_r = scatter_add_row<DT_, IT_, n_, uniform_macros_>(mat_wrap, local, stride, macro, macro_dofs, max_degrees_dofs, row_off+nrc_f.first, row_block+
Index(l), col_off, col_block);
2032 nrc_f.first += nrc_r.first;
2033 nrc_f.second = nrc_f.second;
2040 template<
typename DT_,
typename IT_,
bool skip_singular_>
2041 CUDA_HOST
static void scale_row(DT_* vals, DT_ omega,
const IT_* row_ptr,
const IT_* col_idx,
const Index* row_dom_ptr,
const Index* row_img_idx,
2042 int hw,
int hb, Index cur_row,
const int* m_mask,
const bool meta_diag)
2044 ASSERT(row_dom_ptr[cur_row] < row_dom_ptr[cur_row+1]);
2047 if constexpr(skip_singular_)
2049 for(Index j = row_dom_ptr[cur_row]; j < row_dom_ptr[cur_row+1]; ++j)
2051 n +=
Index(m_mask[row_img_idx[j]]);
2056 n = row_dom_ptr[cur_row+1] - row_dom_ptr[cur_row];
2061 const DT_ sc = omega/ DT_(Math::max(n,
Index(1)));
2062 for(IT_ j = row_ptr[cur_row]; j < row_ptr[cur_row+1]; ++j)
2064 DT_* loc_val = vals + j*IT_(hw)*IT_(hb);
2065 for(
int ii = 0; ii < hw; ++ii)
2067 for(
int jj = 0; jj < hb; ++jj)
2069 loc_val[ii*hb+jj] *= sc;
2076 for(IT_ j = row_ptr[cur_row]; j < row_ptr[cur_row+1]; ++j)
2078 DT_* loc_val = vals + j*IT_(hw)*IT_(hb);
2079 const DT_ diag_val = DT_(col_idx[j] == cur_row ? 1 : 0);
2080 for(
int ii = 0; ii < hw; ++ii)
2082 for(
int jj = 0; jj < hb; ++jj)
2084 loc_val[ii*hb+jj] = DT_(0);
2088 for(
int ii = 0; ii < Math::min(hw, hb); ++ii)
2090 loc_val[ii*hb + ii] = diag_val;
2098 template<
typename DT_,
typename IT_,
bool skip_singular_>
2099 CUDA_HOST_DEVICE
static void scale_row(DT_* vals, DT_ omega,
const IT_* row_ptr,
const IT_* col_idx,
const Index* row_dom_ptr,
const Index row_number,
2100 int hw,
int hb, Index cur_row,
const int* m_mask,
bool meta_diag)
2104 if constexpr(skip_singular_)
2106 for(Index j = 0; j < row_number; ++j)
2108 n +=
Index(m_mask[row_dom_ptr[j]]);
2118 const DT_ sc = omega/ DT_(CudaMath::cuda_max(n,
Index(1)));
2119 for(IT_ j = row_ptr[cur_row]; j < row_ptr[cur_row+1]; ++j)
2121 DT_* loc_val = vals + j*hw*hb;
2122 for(
int ii = 0; ii < hw; ++ii)
2124 for(
int jj = 0; jj < hb; ++jj)
2126 loc_val[ii*hb+jj] *= sc;
2133 for(IT_ j = row_ptr[cur_row]; j < row_ptr[cur_row+1]; ++j)
2135 DT_* loc_val = vals + j*hw*hb;
2136 const DT_ diag_val = DT_(col_idx[j] == cur_row ? 1 : 0);
2137 for(
int ii = 0; ii < hw; ++ii)
2139 for(
int jj = 0; jj < hb; ++jj)
2141 loc_val[ii*hb+jj] = DT_(0);
2145 for(
int ii = 0; ii < CudaMath::cuda_min(hw, hb); ++ii)
2147 loc_val[ii*hb + ii] = diag_val;
#define ASSERT(expr)
Debug-Assertion macro definition.
#define ASSERTM(expr, msg)
Debug-Assertion macro definition with custom message.
#define XASSERT(expr)
Assertion macro definition.
#define XASSERTM(expr, msg)
Assertion macro definition with custom message.
String class implementation.
@ other
generic/other permutation strategy
Location
Memory location enumeration.
String stringify(const T_ &item)
Converts an item into a String.
std::uint64_t Index
Index data type.