11#include <kernel/lafem/forward.hpp>
12#include <kernel/lafem/container.hpp>
13#include <kernel/lafem/dense_vector.hpp>
14#include <kernel/lafem/sparse_layout.hpp>
15#include <kernel/lafem/arch/scale.hpp>
16#include <kernel/lafem/arch/axpy.hpp>
17#include <kernel/lafem/arch/apply.hpp>
18#include <kernel/lafem/arch/lumping.hpp>
19#include <kernel/lafem/arch/norm.hpp>
20#include <kernel/lafem/arch/scale_row_col.hpp>
21#include <kernel/lafem/arch/row_norm.hpp>
22#include <kernel/lafem/arch/diagonal.hpp>
23#include <kernel/adjacency/graph.hpp>
24#include <kernel/util/tiny_algebra.hpp>
25#include <kernel/util/statistics.hpp>
26#include <kernel/util/time_stamp.hpp>
39 template<
typename DT_,
typename IT_,
int size_>
40 struct BCSRVectorHelper
42 static_assert(size_ > 1,
"invalid block size");
43 typedef DenseVectorBlocked<DT_, IT_, size_> VectorType;
46 template<
typename DT_,
typename IT_>
47 struct BCSRVectorHelper<DT_, IT_, 1>
49 typedef DenseVector< DT_, IT_> VectorType;
52 template<
typename DT_,
int BlockHeight_,
int BlockW
idth_, Perspective perspective_>
53 struct BCSRPerspectiveHelper
55 typedef Tiny::Matrix<DT_, BlockHeight_, BlockWidth_>
Type;
58 template<
typename DT_,
int BlockHeight_,
int BlockW
idth_>
59 struct BCSRPerspectiveHelper<DT_, BlockHeight_, BlockWidth_,
Perspective::
pod>
89 template <
typename DT_,
typename IT_,
int BlockHeight_,
int BlockW
idth_>
92 static_assert(BlockHeight_ > 0,
"invalid block size");
93 static_assert(BlockWidth_ > 0,
"invalid block size");
114 template <
typename DT2_ = DT_,
typename IT2_ = IT_>
118 template <
typename DataType2_,
typename IndexType2_>
122 typedef typename Intern::BCSRVectorHelper<DT_, IT_, BlockHeight_>::VectorType
VectorTypeL;
124 typedef typename Intern::BCSRVectorHelper<DT_, IT_, BlockWidth_>::VectorType
VectorTypeR;
126 static constexpr bool is_global =
false;
127 static constexpr bool is_local =
true;
140 typedef DT_ DataType;
141 typedef IT_ IndexType;
160 _num_rows(matrix.
rows()),
168 _col_ptr =
new IT_[_num_cols];
170 for(
Index i(0); i < _num_cols; ++i)
172 _col_ptr[i] = _deadcode;
179 if(_col_ptr !=
nullptr)
185 template<
typename LocalMatrix_,
typename RowMapping_,
typename ColMapping_>
186 void operator()(
const LocalMatrix_& loc_mat,
const RowMapping_& row_map,
187 const ColMapping_& col_map, DT_ alpha = DT_(1))
190 for(
int i(0); i < row_map.get_num_local_dofs(); ++i)
193 const Index ix = row_map.get_index(i);
196 for(IT_ k(_row_ptr[ix]); k < _row_ptr[ix + 1]; ++k)
198 _col_ptr[_col_idx[k]] = k;
202 for(
int j(0); j < col_map.get_num_local_dofs(); ++j)
205 const Index jx = col_map.get_index(j);
208 ASSERTM(_col_ptr[jx] != _deadcode,
"invalid column index");
211 _data[_col_ptr[jx]] += alpha * loc_mat[i][j];
218 for(IT_ k(_row_ptr[ix]); k < _row_ptr[ix + 1]; ++k)
220 _col_ptr[_col_idx[k]] = _deadcode;
244 Index & _used_elements()
276 Container<DT_, IT_> (rows_in * columns_in)
295 Container<DT_, IT_> (rows_in * columns_in)
303 this->
_indices.push_back(MemoryPool::template allocate_memory<IT_>(_used_elements()));
306 this->
_indices.push_back(MemoryPool::template allocate_memory<IT_>(_rows() + 1));
309 this->
_elements.push_back(MemoryPool::template allocate_memory<DT_>(used_elements<Perspective::pod>()));
310 this->
_elements_size.push_back(used_elements<Perspective::pod>());
324 this->
_indices.assign(layout_in._indices.begin(), layout_in._indices.end());
325 this->
_indices_size.assign(layout_in._indices_size.begin(), layout_in._indices_size.end());
326 this->
_scalar_index.assign(layout_in._scalar_index.begin(), layout_in._scalar_index.end());
331 this->
_elements.push_back(MemoryPool::template allocate_memory<DT_>(used_elements<Perspective::pod>()));
332 this->
_elements_size.push_back(used_elements<Perspective::pod>());
346 const Index num_rows = graph.get_num_nodes_domain();
349 IT_ * prow_ptr(this->
row_ptr());
350 IT_ * pcol_idx(this->
col_ind());
352 FEAT_PRAGMA_OMP(parallel
for)
353 for(
Index i = 0; i <= num_rows; ++i)
354 prow_ptr[i] = IT_(dom_ptr[i]);
356 FEAT_PRAGMA_OMP(parallel
for)
357 for(
Index i = 0; i < num_nnze; ++i)
358 pcol_idx[i] = IT_(img_idx[i]);
403 Container<DT_, IT_>(rows_in * columns_in)
411 XASSERTM(val_in.
size() % (BlockHeight_ * BlockWidth_) == 0,
"input values size is not a multiple of container blocksize!");
437 template <
typename DT2_ = DT_,
typename IT2_ = IT_>
441 deserialize<DT2_, IT2_>(input);
465 this->
move(std::forward<SparseMatrixBCSR>(other));
481 t.
clone(*
this, clone_mode);
493 template<
typename DT2_,
typename IT2_>
506 template <
typename DT2_,
typename IT2_>
512 template <
typename DT2_,
typename IT2_>
521 std::vector<IndexType> tmp_row_ptr(n_rows+1u);
522 std::vector<IndexType> tmp_col_ptr;
525 const IT2_* _crs_row = other.row_ptr();
526 const IT2_* _crs_col = other.col_ind();
527 const DT2_ * _crs_val = other.val();
530 tmp_col_ptr.reserve(other.used_elements());
533 std::set<IndexType> tmp_uni_col;
536 for(
Index b_row = 0; b_row < n_rows; ++b_row)
540 for(IT2_ idx = _crs_row[l_row]; idx < _crs_row[l_row+1]; ++idx)
545 tmp_row_ptr[b_row+1] =
IndexType(tmp_uni_col.size()) + tmp_row_ptr[b_row];
546 std::for_each(tmp_uni_col.begin(), tmp_uni_col.end(), [&](
const auto& ele){tmp_col_ptr.push_back(ele);});
553 Index elements_size = tmp_col_ptr.size();
565 this->
_indices.push_back(MemoryPool::template allocate_memory<IT_>(_used_elements()));
568 this->
_indices.push_back(MemoryPool::template allocate_memory<IT_>(_rows() + 1));
571 this->
_elements.push_back(MemoryPool::template allocate_memory<DT_>(used_elements<Perspective::pod>()));
572 this->
_elements_size.push_back(used_elements<Perspective::pod>());
578 std::copy(tmp_row_ptr.begin(), tmp_row_ptr.end(),
row_ptr);
579 std::copy(tmp_col_ptr.begin(), tmp_col_ptr.end(), col);
596 FEAT_PRAGMA_OMP(parallel
for)
597 for(
Index b_row =
Index(0); b_row < n_rows; ++b_row)
650 this->
_indices.assign(layout_in._indices.begin(), layout_in._indices.end());
651 this->
_indices_size.assign(layout_in._indices_size.begin(), layout_in._indices_size.end());
652 this->
_scalar_index.assign(layout_in._scalar_index.begin(), layout_in._scalar_index.end());
657 this->
_elements.push_back(MemoryPool::template allocate_memory<DT_>(used_elements<Perspective::pod>()));
658 this->
_elements_size.push_back(used_elements<Perspective::pod>());
670 template <
typename DT2_ = DT_,
typename IT2_ = IT_>
686 template <
typename DT2_ = DT_,
typename IT2_ = IT_>
700 std::ios_base::openmode bin = std::ifstream::in | std::ifstream::binary;
702 bin = std::ifstream::in;
703 std::ifstream file(filename.c_str(), bin);
704 if (! file.is_open())
705 XABORTM(
"Unable to open Matrix file " + filename);
728 XABORTM(
"Filemode not supported!");
884 std::ios_base::openmode bin = std::ofstream::out | std::ofstream::binary;
886 bin = std::ofstream::out;
888 char* buff =
nullptr;
894 file.open(filename.c_str(), bin);
896 XABORTM(
"Unable to open Matrix file " + filename);
918 file <<
"%%MatrixMarket matrix coordinate real general\n";
919 file << this->
template rows<Perspective::pod>() <<
" " << this->
template columns<Perspective::pod>() <<
" " << this->
template used_elements<Perspective::pod>() <<
"\n";
921 for (
Index row(0) ; row <
rows() ; ++row)
923 const IT_ end(this->
row_ptr()[row + 1]);
924 for (IT_ i(this->
row_ptr()[row]) ; i < end ; ++i)
926 auto block = this->
val()[i];
927 for (
int y(0) ; y < BlockHeight_ ; ++y)
929 for (
int x(0) ; x < BlockWidth_ ; ++x)
931 file << ((int)row * BlockHeight_) + y + 1 <<
" " << ((int)this->
col_ind()[i] * BlockWidth_) + x + 1 <<
" " <<
stringify_fp_sci(block[y][x]) <<
"\n";
939 XABORTM(
"Filemode not supported!");
956 MemoryPool::synchronize();
962 return this->val<Perspective::native>()[i];
987 template <Perspective perspective_ = Perspective::native>
1002 template <Perspective perspective_ = Perspective::native>
1017 template <Perspective perspective_ = Perspective::native>
1033 if (this->
size() == 0)
1043 if (this->
size() == 0)
1057 template <Perspective perspective_ = Perspective::native>
1058 auto val() const -> const typename Intern::BCSRPerspectiveHelper<DT_, BlockHeight_, BlockWidth_, perspective_>::Type *
1060 if (this->
size() == 0)
1063 return (
const typename Intern::BCSRPerspectiveHelper<DT_, BlockHeight_, BlockWidth_, perspective_>::Type *)(this->
_elements.at(0));
1068 template <Perspective perspective_ = Perspective::native>
1069 auto val() ->
typename Intern::BCSRPerspectiveHelper<DT_, BlockHeight_, BlockWidth_, perspective_>::Type *
1071 if (this->
size() == 0)
1074 return (
typename Intern::BCSRPerspectiveHelper<DT_, BlockHeight_, BlockWidth_, perspective_>::Type *)(this->
_elements.at(0));
1107 return "SparseMatrixBCSR";
1118 this->_copy_content(x, full);
1134 const DT_ alpha = DT_(1))
1136 XASSERTM(x.
rows() == this->rows(),
"Matrix rows do not match!");
1137 XASSERTM(x.
columns() == this->columns(),
"Matrix columns do not match!");
1143 Arch::Axpy::value(this->
template val<Perspective::pod>(),
1145 x.template val<Perspective::pod>(),
1149 Statistics::add_time_axpy(ts_stop.
elapsed(ts_start));
1160 XASSERTM(x.
rows() == this->rows(),
"Row count does not match!");
1161 XASSERTM(x.
columns() == this->columns(),
"Column count does not match!");
1166 Arch::Scale::value(this->
template val<Perspective::pod>(), x.template val<Perspective::pod>(), alpha, this->
used_elements<
Perspective::pod>());
1168 Statistics::add_time_axpy(ts_stop.
elapsed(ts_start));
1180 DT_ result = Arch::Norm2::value(this->
template val<Perspective::pod>(),
1181 this->used_elements<Perspective::pod>());
1183 Statistics::add_time_reduction(ts_stop.
elapsed(ts_start));
1195 XASSERTM(row_norms.size() == this->rows(),
"Matrix/Vector dimension mismatch");
1200 Arch::RowNorm::bcsr_norm2(row_norms.template elements<Perspective::pod>(),
1201 this->template val<Perspective::pod>(),
1205 Statistics::add_time_reduction(ts_stop.
elapsed(ts_start));
1216 XASSERTM(row_norms.size() == this->rows(),
"Matrix/Vector dimension mismatch");
1221 Arch::RowNorm::bcsr_norm2sqr(row_norms.template elements<Perspective::pod>(),
1222 this->template val<Perspective::pod>(),
1226 Statistics::add_time_reduction(ts_stop.
elapsed(ts_start));
1250 XASSERTM(row_norms.size() == this->rows(),
"Matrix/Vector dimension mismatch");
1251 XASSERTM(scal.size() == this->columns(),
"Matrix/scalings dimension mismatch");
1256 Arch::RowNorm::bcsr_scaled_norm2sqr(row_norms.template elements<Perspective::pod>(),
1257 scal.template elements<Perspective::pod>(), this->template val<Perspective::pod>(),
1261 Statistics::add_time_reduction(ts_stop.
elapsed(ts_start));
1273 Index max_abs_index = Arch::MaxAbsIndex::value(this->
template val<Perspective::pod>(), this->
template used_elements<Perspective::pod>());
1274 ASSERT(max_abs_index < this->
template used_elements<Perspective::pod>());
1276 MemoryPool::template copy<DT_>(&result, this->
template val<Perspective::pod>() + max_abs_index, 1);
1280 Statistics::add_time_reduction(ts_stop.
elapsed(ts_start));
1294 Index min_abs_index = Arch::MinAbsIndex::value(this->
template val<Perspective::pod>(), this->
template used_elements<Perspective::pod>());
1295 ASSERT(min_abs_index < this->
template used_elements<Perspective::pod>());
1297 MemoryPool::template copy<DT_>(&result, this->
template val<Perspective::pod>() + min_abs_index, 1);
1301 Statistics::add_time_reduction(ts_stop.
elapsed(ts_start));
1315 Index max_index = Arch::MaxIndex::value(this->
template val<Perspective::pod>(), this->
template used_elements<Perspective::pod>());
1316 ASSERT(max_index < this->
template used_elements<Perspective::pod>());
1318 MemoryPool::template copy<DT_>(&result, this->
template val<Perspective::pod>() + max_index, 1);
1321 Statistics::add_time_reduction(ts_stop.
elapsed(ts_start));
1335 Index min_index = Arch::MinIndex::value(this->
template val<Perspective::pod>(), this->
template used_elements<Perspective::pod>());
1336 ASSERT(min_index < this->
template used_elements<Perspective::pod>());
1338 MemoryPool::template copy<DT_>(&result, this->
template val<Perspective::pod>() + min_index, 1);
1341 Statistics::add_time_reduction(ts_stop.
elapsed(ts_start));
1357 DataType max_rel_diff = Arch::MaxRelDiff::value(this->
template val<Perspective::pod>(), x.template val<Perspective::pod>(), this->template used_elements<Perspective::pod>());
1360 Statistics::add_time_reduction(ts_stop.
elapsed(ts_start));
1377 if(this->
size() == 0 && x.
size() == 0 && this->get_elements().size() == 0 && this->get_indices().size() == 0 && x.
get_elements().size() == 0 && x.
get_indices().size() == 0)
1391 col_ind_a =
const_cast<IT_*
>(this->
col_ind());
1392 row_ptr_a =
const_cast<IT_*
>(this->
row_ptr());
1393 col_ind_b =
const_cast<IT_*
>(x.
col_ind());
1394 row_ptr_b =
const_cast<IT_*
>(x.
row_ptr());
1399 if (col_ind_a[i] != col_ind_b[i])
1407 for (
Index i(0) ; i < this->
rows() + 1; ++i)
1409 if (row_ptr_a[i] != row_ptr_b[i])
1452 const IT_ * ptxcol_ind(x.
col_ind());
1453 const IT_ * ptxrow_ptr(x.
row_ptr());
1454 const typename XType::ValueType * ptxval(x.
val());
1460 IT_ * ptcol_ind(tcol_ind.
elements());
1462 IT_ * ptrow_ptr(trow_ptr.
elements());
1466 for (
Index i(0); i < txused_elements; ++i)
1468 ++ptrow_ptr[ptxcol_ind[i] + 1];
1471 for (
Index i(1); i < txcolumns - 1; ++i)
1473 ptrow_ptr[i + 1] += ptrow_ptr[i];
1476 for (
Index i(0); i < txrows; ++i)
1478 for (IT_ k(ptxrow_ptr[i]); k < ptxrow_ptr[i+1]; ++k)
1480 const IT_ l(ptxcol_ind[k]);
1481 const IT_ j(ptrow_ptr[l]);
1483 ptcol_ind[j] = IT_(i);
1488 for (
Index i(txcolumns); i > 0; --i)
1490 ptrow_ptr[i] = ptrow_ptr[i - 1];
1505 XASSERTM(x.
rows() == this->rows(),
"Row count does not match!");
1506 XASSERTM(x.
columns() == this->columns(),
"Column count does not match!");
1508 XASSERTM(s.
size() == this->rows(),
"Vector size does not match!");
1513 Arch::ScaleRows::template bcsr<BlockHeight_, BlockWidth_>(this->val<Perspective::pod>(), x.template val<Perspective::pod>(),
1514 this->
col_ind(), this->row_ptr(), s.template elements<Perspective::pod>(), this->rows(), this->columns(), this->
used_elements());
1517 Statistics::add_time_axpy(ts_stop.
elapsed(ts_start));
1522 XASSERTM(x.
rows() == this->rows(),
"Row count does not match!");
1523 XASSERTM(x.
columns() == this->columns(),
"Column count does not match!");
1525 XASSERTM(s.
size() == this->columns(),
"Vector size does not match!");
1530 Arch::ScaleCols::template bcsr<BlockHeight_, BlockWidth_>(this->val<Perspective::pod>(), x.template val<Perspective::pod>(),
1531 this->
col_ind(), this->row_ptr(), s.template elements<Perspective::pod>(), this->rows(), this->columns(), this->
used_elements());
1534 Statistics::add_time_axpy(ts_stop.
elapsed(ts_start));
1551 FEAT_KERNEL_MARKER_START(
"BCSR-apply");
1559 XASSERTM(r.template elements<Perspective::pod>() != x.template elements<Perspective::pod>(),
"Vector x and r must not share the same memory!");
1562 Arch::Apply::template bcsr<BlockHeight_, BlockWidth_>(
1564 this->row_ptr(), this->rows(), this->columns(), this->used_elements());
1566 FEAT_KERNEL_MARKER_STOP(
"BCSR-apply");
1568 Statistics::add_time_reduction(ts_stop.
elapsed(ts_start));
1585 FEAT_KERNEL_MARKER_START(
"BCSR-apply");
1593 XASSERTM(r.template elements<Perspective::pod>() != x.template elements<Perspective::pod>(),
"Vector x and r must not share the same memory!");
1596 Arch::Apply::template bcsr_transposed<BlockHeight_, BlockWidth_>(
1598 this->row_ptr(), this->rows(), this->columns(), this->used_elements());
1600 FEAT_KERNEL_MARKER_STOP(
"BCSR-apply");
1602 Statistics::add_time_reduction(ts_stop.
elapsed(ts_start));
1615 XASSERTM(r.
size() == this->rows(),
"Vector size of r does not match!");
1620 FEAT_KERNEL_MARKER_START(
"BCSR-apply");
1627 XASSERTM(r.template elements<Perspective::pod>() != x.template elements<Perspective::pod>(),
"Vector x and r must not share the same memory!");
1631 Arch::Apply::template bcsr<BlockHeight_, BlockWidth_>(
1632 r.template elements<Perspective::pod>(), DT_(1), x.
elements(), DT_(0), r.template elements<Perspective::pod>(), this->template val<Perspective::pod>(), this->col_ind(),
1633 this->row_ptr(), this->rows(), this->columns(), this->
used_elements());
1635 FEAT_KERNEL_MARKER_STOP(
"BCSR-apply");
1637 Statistics::add_time_blas2(ts_stop.
elapsed(ts_start));
1651 XASSERTM(r.
size() == this->columns(),
"Vector size of r does not match!");
1656 FEAT_KERNEL_MARKER_START(
"BCSR-apply");
1663 XASSERTM(r.template elements<Perspective::pod>() != x.template elements<Perspective::pod>(),
"Vector x and r must not share the same memory!");
1667 Arch::Apply::template bcsr_transposed<BlockHeight_, BlockWidth_>(
1668 r.template elements<Perspective::pod>(), DT_(1), x.
elements(), DT_(0), r.template elements<Perspective::pod>(), this->template val<Perspective::pod>(), this->col_ind(),
1669 this->row_ptr(), this->rows(), this->columns(), this->
used_elements());
1671 FEAT_KERNEL_MARKER_STOP(
"BCSR-apply");
1673 Statistics::add_time_blas2(ts_stop.
elapsed(ts_start));
1687 XASSERTM(x.
size() == this->columns(),
"Vector size of x does not match!");
1691 FEAT_KERNEL_MARKER_START(
"BCSR-apply");
1698 XASSERTM(r.template elements<Perspective::pod>() != x.template elements<Perspective::pod>(),
"Vector x and r must not share the same memory!");
1702 Arch::Apply::template bcsr<BlockHeight_, BlockWidth_>(
1703 r.
elements(), DT_(1), x.template elements<Perspective::pod>(), DT_(0), r.
elements(), this->template val<Perspective::pod>(), this->col_ind(),
1704 this->row_ptr(), this->rows(), this->columns(), this->used_elements());
1706 FEAT_KERNEL_MARKER_STOP(
"BCSR-apply");
1708 Statistics::add_time_blas2(ts_stop.
elapsed(ts_start));
1722 XASSERTM(x.
size() == this->rows(),
"Vector size of x does not match!");
1726 FEAT_KERNEL_MARKER_START(
"BCSR-apply");
1733 XASSERTM(r.template elements<Perspective::pod>() != x.template elements<Perspective::pod>(),
"Vector x and r must not share the same memory!");
1737 Arch::Apply::template bcsr_transposed<BlockHeight_, BlockWidth_>(
1738 r.
elements(), DT_(1), x.template elements<Perspective::pod>(), DT_(0), r.
elements(), this->template val<Perspective::pod>(), this->col_ind(),
1739 this->row_ptr(), this->rows(), this->columns(), this->used_elements());
1741 FEAT_KERNEL_MARKER_STOP(
"BCSR-apply");
1743 Statistics::add_time_blas2(ts_stop.
elapsed(ts_start));
1756 XASSERTM(r.
size() == this->rows(),
"Vector size of r does not match!");
1757 XASSERTM(x.
size() == this->columns(),
"Vector size of x does not match!");
1761 FEAT_KERNEL_MARKER_START(
"BCSR-apply");
1768 XASSERTM(r.template elements<Perspective::pod>() != x.template elements<Perspective::pod>(),
"Vector x and r must not share the same memory!");
1772 Arch::Apply::template bcsr<BlockHeight_, BlockWidth_>(
1773 r.template elements<Perspective::pod>(), DT_(1), x.template elements<Perspective::pod>(), DT_(0), r.template elements<Perspective::pod>(), this->template val<Perspective::pod>(),
1774 this->col_ind(), this->row_ptr(), this->rows(), this->columns(), this->
used_elements());
1776 FEAT_KERNEL_MARKER_STOP(
"BCSR-apply");
1778 Statistics::add_time_blas2(ts_stop.
elapsed(ts_start));
1791 XASSERTM(r.
size() == this->columns(),
"Vector size of r does not match!");
1792 XASSERTM(x.
size() == this->rows(),
"Vector size of x does not match!");
1796 FEAT_KERNEL_MARKER_START(
"BCSR-apply");
1803 XASSERTM(r.template elements<Perspective::pod>() != x.template elements<Perspective::pod>(),
"Vector x and r must not share the same memory!");
1807 Arch::Apply::template bcsr_transposed<BlockHeight_, BlockWidth_>(
1808 r.template elements<Perspective::pod>(), DT_(1), x.template elements<Perspective::pod>(), DT_(0), r.template elements<Perspective::pod>(), this->template val<Perspective::pod>(),
1809 this->col_ind(), this->row_ptr(), this->rows(), this->columns(), this->
used_elements());
1811 FEAT_KERNEL_MARKER_STOP(
"BCSR-apply");
1813 Statistics::add_time_blas2(ts_stop.
elapsed(ts_start));
1831 const DT_ alpha = DT_(1))
const
1839 FEAT_KERNEL_MARKER_START(
"BCSR-apply");
1847 XASSERTM(r.template elements<Perspective::pod>() != x.template elements<Perspective::pod>(),
"Vector x and r must not share the same memory!");
1849 Statistics::add_flops( (this->used_elements<Perspective::pod>() + this->rows<Perspective::pod>()) * 2 );
1851 Arch::Apply::template bcsr<BlockHeight_, BlockWidth_>(
1853 this->row_ptr(), this->rows(), this->columns(), this->used_elements());
1855 FEAT_KERNEL_MARKER_STOP(
"BCSR-apply");
1857 Statistics::add_time_blas2(ts_stop.
elapsed(ts_start));
1875 const DT_ alpha = DT_(1))
const
1883 FEAT_KERNEL_MARKER_START(
"BCSR-apply");
1891 XASSERTM(r.template elements<Perspective::pod>() != x.template elements<Perspective::pod>(),
"Vector x and r must not share the same memory!");
1893 Statistics::add_flops( (this->used_elements<Perspective::pod>() + this->rows<Perspective::pod>()) * 2 );
1895 Arch::Apply::template bcsr_transposed<BlockHeight_, BlockWidth_>(
1897 this->row_ptr(), this->rows(), this->columns(), this->used_elements());
1899 FEAT_KERNEL_MARKER_STOP(
"BCSR-apply");
1901 Statistics::add_time_blas2(ts_stop.
elapsed(ts_start));
1919 const DT_ alpha = DT_(1))
const
1921 XASSERTM(r.
size() == this->rows(),
"Vector size of r does not match!");
1923 XASSERTM(y.
size() == this->rows(),
"Vector size of y does not match!");
1927 FEAT_KERNEL_MARKER_START(
"BCSR-apply");
1935 XASSERTM(r.template elements<Perspective::pod>() != x.template elements<Perspective::pod>(),
"Vector x and r must not share the same memory!");
1937 Statistics::add_flops( (this->used_elements<Perspective::pod>() + this->rows<Perspective::pod>()) * 2 );
1938 Arch::Apply::template bcsr<BlockHeight_, BlockWidth_>(
1939 r.template elements<Perspective::pod>(), alpha, x.
elements(), DT_(1), y.template elements<Perspective::pod>(), this->template val<Perspective::pod>(), this->col_ind(),
1940 this->row_ptr(), this->rows(), this->columns(), this->
used_elements());
1942 FEAT_KERNEL_MARKER_STOP(
"BCSR-apply");
1944 Statistics::add_time_blas2(ts_stop.
elapsed(ts_start));
1962 const DT_ alpha = DT_(1))
const
1964 XASSERTM(r.
size() == this->columns(),
"Vector size of r does not match!");
1966 XASSERTM(y.
size() == this->columns(),
"Vector size of y does not match!");
1970 FEAT_KERNEL_MARKER_START(
"BCSR-apply");
1978 XASSERTM(r.template elements<Perspective::pod>() != x.template elements<Perspective::pod>(),
"Vector x and r must not share the same memory!");
1980 Statistics::add_flops((this->used_elements<Perspective::pod>() + this->rows<Perspective::pod>()) * 2);
1981 Arch::Apply::template bcsr_transposed<BlockHeight_, BlockWidth_>(
1982 r.template elements<Perspective::pod>(), alpha, x.
elements(), DT_(1), y.template elements<Perspective::pod>(), this->template val<Perspective::pod>(), this->col_ind(),
1983 this->row_ptr(), this->rows(), this->columns(), this->
used_elements());
1985 FEAT_KERNEL_MARKER_STOP(
"BCSR-apply");
1987 Statistics::add_time_blas2(ts_stop.
elapsed(ts_start));
2005 const DT_ alpha = DT_(1))
const
2008 XASSERTM(x.
size() == this->columns(),
"Vector size of x does not match!");
2013 FEAT_KERNEL_MARKER_START(
"BCSR-apply");
2021 XASSERTM(r.template elements<Perspective::pod>() != x.template elements<Perspective::pod>(),
"Vector x and r must not share the same memory!");
2023 Statistics::add_flops( (this->used_elements<Perspective::pod>() + this->rows<Perspective::pod>()) * 2 );
2024 Arch::Apply::template bcsr<BlockHeight_, BlockWidth_>(
2025 r.
elements(), alpha, x.template elements<Perspective::pod>(), DT_(1), y.
elements(), this->template val<Perspective::pod>(), this->col_ind(),
2026 this->row_ptr(), this->rows(), this->columns(), this->used_elements());
2028 FEAT_KERNEL_MARKER_STOP(
"BCSR-apply");
2030 Statistics::add_time_blas2(ts_stop.
elapsed(ts_start));
2048 const DT_ alpha = DT_(1))
const
2051 XASSERTM(x.
size() == this->rows(),
"Vector size of x does not match!");
2056 FEAT_KERNEL_MARKER_START(
"BCSR-apply");
2064 XASSERTM(r.template elements<Perspective::pod>() != x.template elements<Perspective::pod>(),
"Vector x and r must not share the same memory!");
2066 Statistics::add_flops( (this->used_elements<Perspective::pod>() + this->rows<Perspective::pod>()) * 2 );
2067 Arch::Apply::template bcsr_transposed<BlockHeight_, BlockWidth_>(
2068 r.
elements(), alpha, x.template elements<Perspective::pod>(), DT_(1), y.
elements(), this->template val<Perspective::pod>(), this->col_ind(),
2069 this->row_ptr(), this->rows(), this->columns(), this->used_elements());
2071 FEAT_KERNEL_MARKER_STOP(
"BCSR-apply");
2073 Statistics::add_time_blas2(ts_stop.
elapsed(ts_start));
2091 const DT_ alpha = DT_(1))
const
2093 XASSERTM(r.
size() == this->rows(),
"Vector size of r does not match!");
2094 XASSERTM(x.
size() == this->columns(),
"Vector size of x does not match!");
2095 XASSERTM(y.
size() == this->rows(),
"Vector size of y does not match!");
2099 FEAT_KERNEL_MARKER_START(
"BCSR-apply");
2107 XASSERTM(r.template elements<Perspective::pod>() != x.template elements<Perspective::pod>(),
"Vector x and r must not share the same memory!");
2109 Statistics::add_flops( (this->used_elements<Perspective::pod>() + this->rows<Perspective::pod>()) * 2 );
2110 Arch::Apply::template bcsr<BlockHeight_, BlockWidth_>(
2111 r.template elements<Perspective::pod>(), alpha, x.template elements<Perspective::pod>(), DT_(1), y.template elements<Perspective::pod>(), this->template val<Perspective::pod>(),
2112 this->col_ind(), this->row_ptr(), this->rows(), this->columns(), this->
used_elements());
2114 FEAT_KERNEL_MARKER_STOP(
"BCSR-apply");
2116 Statistics::add_time_blas2(ts_stop.
elapsed(ts_start));
2134 const DT_ alpha = DT_(1))
const
2136 XASSERTM(r.
size() == this->columns(),
"Vector size of r does not match!");
2137 XASSERTM(x.
size() == this->rows(),
"Vector size of x does not match!");
2138 XASSERTM(y.
size() == this->columns(),
"Vector size of y does not match!");
2142 FEAT_KERNEL_MARKER_START(
"BCSR-apply");
2150 XASSERTM(r.template elements<Perspective::pod>() != x.template elements<Perspective::pod>(),
"Vector x and r must not share the same memory!");
2152 Statistics::add_flops( (this->used_elements<Perspective::pod>() + this->rows<Perspective::pod>()) * 2 );
2153 Arch::Apply::template bcsr_transposed<BlockHeight_, BlockWidth_>(
2154 r.template elements<Perspective::pod>(), alpha, x.template elements<Perspective::pod>(), DT_(1), y.template elements<Perspective::pod>(), this->template val<Perspective::pod>(),
2155 this->col_ind(), this->row_ptr(), this->rows(), this->columns(), this->
used_elements());
2157 FEAT_KERNEL_MARKER_STOP(
"BCSR-apply");
2159 Statistics::add_time_blas2(ts_stop.
elapsed(ts_start));
2177 const DT_ alpha = DT_(1))
const
2179 XASSERTM(r.
size() == this->rows(),
"Vector size of r does not match!");
2180 XASSERTM(x.
size() == this->columns(),
"Vector size of x does not match!");
2185 FEAT_KERNEL_MARKER_START(
"BCSR-apply");
2193 XASSERTM(r.template elements<Perspective::pod>() != x.template elements<Perspective::pod>(),
"Vector x and r must not share the same memory!");
2195 Statistics::add_flops( (this->used_elements<Perspective::pod>() + this->rows<Perspective::pod>()) * 2 );
2196 Arch::Apply::template bcsr<BlockHeight_, BlockWidth_>(
2197 r.template elements<Perspective::pod>(), alpha, x.template elements<Perspective::pod>(), DT_(1), y.template elements<Perspective::pod>(), this->template val<Perspective::pod>(),
2198 this->col_ind(), this->row_ptr(), this->rows(), this->columns(), this->
used_elements());
2200 FEAT_KERNEL_MARKER_STOP(
"BCSR-apply");
2202 Statistics::add_time_blas2(ts_stop.
elapsed(ts_start));
2220 const DT_ alpha = DT_(1))
const
2222 XASSERTM(r.
size() == this->columns(),
"Vector size of r does not match!");
2223 XASSERTM(x.
size() == this->rows(),
"Vector size of x does not match!");
2228 FEAT_KERNEL_MARKER_START(
"BCSR-apply");
2236 XASSERTM(r.template elements<Perspective::pod>() != x.template elements<Perspective::pod>(),
"Vector x and r must not share the same memory!");
2238 Statistics::add_flops( (this->used_elements<Perspective::pod>() + this->rows<Perspective::pod>()) * 2 );
2239 Arch::Apply::template bcsr_transposed<BlockHeight_, BlockWidth_>(
2240 r.template elements<Perspective::pod>(), alpha, x.template elements<Perspective::pod>(), DT_(1), y.template elements<Perspective::pod>(), this->template val<Perspective::pod>(),
2241 this->col_ind(), this->row_ptr(), this->rows(), this->columns(), this->
used_elements());
2243 FEAT_KERNEL_MARKER_STOP(
"BCSR-apply");
2245 Statistics::add_time_blas2(ts_stop.
elapsed(ts_start));
2284 const DT_ alpha = DT_(1),
2285 const bool allow_incomplete =
false)
2288 XASSERT(BlockHeight_ == BlockWidth_);
2296 const ValueType* data_d = d.
val();
2299 const IT_* row_ptr_x = this->
row_ptr();
2300 const IT_* col_idx_x = this->
col_ind();
2301 const IT_* row_ptr_d = d.
row_ptr();
2302 const IT_* col_idx_d = d.
col_ind();
2303 const IT_* row_ptr_a = a.
row_ptr();
2304 const IT_* col_idx_a = a.
col_ind();
2305 const IT_* row_ptr_b = b.
row_ptr();
2306 const IT_* col_idx_b = b.
col_ind();
2309 for(IT_ i(0); i < IT_(this->
rows()); ++i)
2312 for(IT_ ik(row_ptr_d[i]); ik < row_ptr_d[i+1]; ++ik)
2315 const IT_ k = col_idx_d[ik];
2318 for(IT_ kl(row_ptr_a[k]); kl < row_ptr_a[k+1]; ++kl)
2321 const IT_ l = col_idx_a[kl];
2332 IT_ ij = row_ptr_x[i];
2333 IT_ lj = row_ptr_b[l];
2334 while(lj < row_ptr_b[l+1])
2336 if(ij >= row_ptr_x[i+1])
2341 if(allow_incomplete)
2344 XABORTM(
"Incomplete output matrix structure");
2346 else if(col_idx_x[ij] == col_idx_b[lj])
2355 else if(col_idx_x[ij] < col_idx_b[lj])
2366 if(allow_incomplete)
2369 XABORTM(
"Incomplete output matrix structure");
2410 const DT_ alpha = DT_(1),
2411 const bool allow_incomplete =
false)
2414 XASSERT(BlockHeight_ == BlockWidth_);
2422 const DT_* data_d = d.
val();
2424 const DT_* data_b = b.
val();
2425 const IT_* row_ptr_x = this->
row_ptr();
2426 const IT_* col_idx_x = this->
col_ind();
2427 const IT_* row_ptr_d = d.
row_ptr();
2428 const IT_* col_idx_d = d.
col_ind();
2429 const IT_* row_ptr_a = a.
row_ptr();
2430 const IT_* col_idx_a = a.
col_ind();
2431 const IT_* row_ptr_b = b.
row_ptr();
2432 const IT_* col_idx_b = b.
col_ind();
2435 for(IT_ i(0); i < IT_(this->
rows()); ++i)
2438 for(IT_ ik(row_ptr_d[i]); ik < row_ptr_d[i+1]; ++ik)
2441 const IT_ k = col_idx_d[ik];
2444 for(IT_ kl(row_ptr_a[k]); kl < row_ptr_a[k+1]; ++kl)
2447 const IT_ l = col_idx_a[kl];
2450 ValueType omega = (alpha * data_d[ik]) * data_a[kl];
2456 IT_ ij = row_ptr_x[i];
2457 IT_ lj = row_ptr_b[l];
2458 while(lj < row_ptr_b[l+1])
2460 if(ij >= row_ptr_x[i+1])
2465 if(allow_incomplete)
2468 XABORTM(
"Incomplete output matrix structure");
2470 else if(col_idx_x[ij] == col_idx_b[lj])
2477 else if(col_idx_x[ij] < col_idx_b[lj])
2488 if(allow_incomplete)
2491 XABORTM(
"Incomplete output matrix structure");
2503 XASSERTM(lump.size() ==
rows(),
"lump vector size does not match matrix row count!");
2505 Arch::Lumping::bcsr(
2506 lump.template elements<Perspective::pod>(),
2507 this->template val<Perspective::pod>(),
2539 XASSERTM(diag.size() ==
rows(),
"diag size does not match matrix row count!");
2545 typename VectorTypeL::ValueType t(0);
2548 ValueType m = this->
template val<LAFEM::Perspective::native>()[index];
2549 for (
int i(0) ; i < BlockHeight_ ; ++i)
2591 XASSERTM(diag_indices.
size() ==
rows(),
"diag size does not match matrix row count!");
2606 return diag_indices;
2612 if (perm_row.
size() == 0 && perm_col.
size() == 0)
2615 XASSERTM(perm_row.
size() == this->rows(),
"Container rows does not match permutation size");
2616 XASSERTM(perm_col.
size() == this->columns(),
"Container columns does not match permutation size");
2619 IT_ * temp_row_ptr =
new IT_[
rows() + 1];
2628 temp_row_ptr[0] = 0;
2629 for (
Index row(0) ; row < this->
rows() ; ++row)
2634 for (
Index i(new_start), j(this->
row_ptr()[perm_pos[row]]) ; i < new_start + row_size ; ++i, ++j)
2636 temp_col_ind[i] = this->
col_ind()[j];
2637 temp_val[i] = this->
val()[j];
2640 new_start += row_size;
2641 temp_row_ptr[row+1] = (IT_)new_start;
2649 ::memcpy(this->
row_ptr(), temp_row_ptr, (
rows() + 1) *
sizeof(IT_));
2653 this->
col_ind()[i] = (IT_)perm_pos[temp_col_ind[i]];
2656 delete[] temp_row_ptr;
2657 delete[] temp_col_ind;
2663 for (
Index row(0) ; row <
rows() ; ++row)
2667 for (
Index i(1), j ; i < row_size ; ++i)
2669 swap_key = this->
col_ind()[i + offset];
2670 swap_val = this->
val()[i + offset];
2672 while (j > 0 && this->
col_ind()[j - 1 + offset] > swap_key)
2675 this->
val()[j + offset] = this->
val()[j - 1 + offset];
2678 this->
col_ind()[j + offset] = swap_key;
2679 this->
val()[j + offset] = swap_val;
2727 const DT_ alpha = DT_(1))
const
2731 static constexpr IT_ bhd = IT_(BHD_);
2737 const auto& b(*
this);
2747 DT_* data_v = v.template elements<LAFEM::Perspective::pod>();
2748 const DT_* data_d = d.template val<LAFEM::Perspective::pod>();
2749 const DT_* data_a = a.template elements<LAFEM::Perspective::pod>();
2750 const DT_* data_b = b.template val<LAFEM::Perspective::pod>();
2751 const IT_* row_ptr_d = d.
row_ptr();
2752 const IT_* col_idx_d = d.
col_ind();
2753 const IT_* row_ptr_b = b.
row_ptr();
2754 const IT_* col_idx_b = b.
col_ind();
2757 for(IT_ row(0); row < IT_(v.
size()); ++row)
2760 for(IT_ pos_d(row_ptr_d[row]); pos_d < row_ptr_d[row+1]; ++pos_d)
2763 const IT_ col_d(col_idx_d[pos_d]);
2766 typename MatrixD::ValueType omega(0);
2767 for(IT_ i(0); i < bhd; ++i)
2769 for(IT_ j(0); j < bwd; ++j)
2771 omega[int(i)][int(j)] = alpha * data_d[bhd*bwd*pos_d + bwd*i + j] * data_a[bwd*col_d + j];
2777 IT_ pos_b(row_ptr_b[col_d]);
2778 while(pos_b < row_ptr_b[col_d+1])
2780 if(col_idx_b[pos_b] == row)
2783 for(IT_ i(0); i < bhd; ++i)
2785 for(IT_ j(0); j < bh; ++j)
2787 data_v[bhd*row + i] += omega[int(i)][int(j)]*data_b[bh*bw*pos_b + bw*j + i];
2809 for (
int k(0) ; k < BlockHeight_ ; ++k)
2814 for (
int l(0) ; l < BlockWidth_ ; ++l)
2815 lhs <<
" " <<
stringify(b(i, j).v[k][l]);
2833 VectorTypeR create_vector_r()
const
2839 Index get_length_of_line(
const Index row)
const
2841 const auto * prow_ptr(this->
row_ptr());
2842 const auto trow = row /
Index(BlockHeight_);
2843 return Index(prow_ptr[trow + 1] - prow_ptr[trow]) *
Index(BlockWidth_);
2847 void set_line(
const Index row, DT_ *
const pval_set, IT_ *
const pcol_set,
2848 const Index col_start,
const Index stride = 1)
const
2850 const auto * prow_ptr(this->
row_ptr());
2851 const auto * pcol_ind(this->
col_ind());
2852 const auto * pval(this->
val());
2854 const auto trow = int(row) / BlockHeight_;
2855 const auto lrow = int(row) - trow * BlockHeight_;
2858 const Index end((
Index(prow_ptr[trow + 1] - prow_ptr[trow])));
2859 for (
Index i(0); i < end; ++i)
2861 for (
Index ti(0); ti <
Index(BlockWidth_); ++ti)
2863 pval_set[(i *
Index(BlockWidth_) + ti) * stride] = pval[start + i](lrow,
int(ti));
2864 pcol_set[(i *
Index(BlockWidth_) + ti) * stride] = pcol_ind[start + i] * IT_(BlockWidth_) + IT_(ti) + IT_(col_start);
2869 void set_line_reverse(
const Index row,
const DT_ *
const pval_set,
const Index stride = 1)
2871 const auto * prow_ptr(this->
row_ptr());
2872 auto * pval(this->
val());
2874 const auto trow = int(row) / BlockHeight_;
2875 const auto lrow = int(row) - trow * BlockHeight_;
2878 const Index end((
Index(prow_ptr[trow + 1] - prow_ptr[trow])));
2879 for (
Index i(0); i < end; ++i)
2881 for (
Index ti(0); ti <
Index(BlockWidth_); ++ti)
2883 pval[start + i](lrow, int(ti)) = pval_set[(i *
Index(BlockWidth_) + ti) * stride];
2908 XASSERTM(domain_node <
rows(),
"Domain node index out of range");
2915 XASSERTM(domain_node <
rows(),
"Domain node index out of range");
#define ASSERT(expr)
Debug-Assertion macro definition.
#define XABORTM(msg)
Abortion macro definition with custom message.
#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.
Adjacency Graph implementation.
Index * get_domain_ptr()
Returns the domain pointer array.
Index * get_image_idx()
Returns the image node index array.
Index get_num_indices() const
Returns the total number indices.
Index size() const
returns the size of the permutation
Index * get_perm_pos()
returns the permute-position array
Permutation inverse() const
Computes the inverse permutation.
const std::vector< IT_ * > & get_indices() const
Returns a list of all Index arrays.
std::vector< DT_ * > _elements
List of pointers to all datatype dependent arrays.
Index used_elements() const
Returns the number of effective stored elements.
const std::vector< DT_ * > & get_elements() const
Returns a list of all data arrays.
std::vector< Index > _elements_size
List of corresponding datatype array sizes.
Index size() const
Returns the containers size.
void assign(const Container< DT2_, IT2_ > &other)
Assignment operation.
std::vector< IT_ * > _indices
List of pointers to all IT_ dependent arrays.
void clone(const Container &other, CloneMode clone_mode=CloneMode::Weak)
Clone operation.
void move(Container &&other)
Assignment move operation.
virtual void clear()
Free all allocated arrays.
std::vector< Index > _indices_size
List of corresponding IT_ array sizes.
void format(DT_ value=DT_(0))
Reset all elements of the container to a given value or zero if missing.
std::vector< Index > _scalar_index
List of scalars with datatype index.
Blocked Dense data vector class template.
void convert(const DenseVectorBlocked< DT2_, IT2_, BlockSize_ > &other)
Conversion method.
void copy(const DenseVectorBlocked &x, bool full=false)
Performs .
Index size() const
The number of elements.
Dense data vector class template.
DT_ * elements()
Get a pointer to the data array.
void copy(const VT_ &a)
Performs .
Config class for serialize parameter.
Layout scheme for sparse matrix containers.
Scatter-Axpy operation for SparseMatrixBCSR.
CSR based blocked sparse matrix.
void apply_transposed(DenseVectorBlocked< DT_, IT_, BlockWidth_ > &r, const DenseVectorBlocked< DT_, IT_, BlockHeight_ > &x, const DenseVector< DT_, IT_ > &y, const DT_ alpha=DT_(1)) const
Calculate .
const IT_ * ImageIterator
ImageIterator typedef for Adjactor interface implementation.
SparseMatrixBCSR(FileMode mode, const String &filename)
Constructor.
IT_ const * col_ind() const
Retrieve column indices array.
ImageIterator image_end(Index domain_node) const
SparseMatrixBCSR(Index rows_in, Index columns_in)
Constructor.
void apply_transposed(DenseVectorBlocked< DT_, IT_, BlockWidth_ > &r, const DenseVectorBlocked< DT_, IT_, BlockHeight_ > &x) const
Calculate .
void row_norm2(VectorTypeL &row_norms) const
Computes the 2-norm for every row.
SparseMatrixBCSR(SparseMatrixBCSR &&other)
Move Constructor.
DT_ min_abs_element() const
Retrieve the absolute minimum value of this matrix.
void copy(const SparseMatrixBCSR &x, bool full=false)
Performs .
DT_ min_element() const
Retrieve the minimum value of this matrix.
void row_norm2sqr(VectorTypeL &row_norms, const VectorTypeR &scal) const
Computes the square of the 2-norm for every row, where every row is scaled by a vector.
Intern::BCSRVectorHelper< DT_, IT_, BlockHeight_ >::VectorType VectorTypeL
Compatible L-vector type.
void permute(Adjacency::Permutation &perm_row, Adjacency::Permutation &perm_col)
Permutate matrix rows and columns according to the given Permutations.
void apply(DenseVectorBlocked< DT_, IT_, BlockHeight_ > &r, const DenseVector< DT_, IT_ > &x, const DenseVectorBlocked< DT_, IT_, BlockHeight_ > &y, const DT_ alpha=DT_(1)) const
Calculate .
SparseMatrixBCSR(std::vector< char > input)
Constructor.
IT_ IndexType
Our indextype.
static constexpr SparseLayoutId layout_id
Our used layout type.
void apply(DenseVector< DT_, IT_ > &r, const DenseVector< DT_, IT_ > &x, const DenseVector< DT_, IT_ > &y, const DT_ alpha=DT_(1)) const
Calculate .
void axpy(const SparseMatrixBCSR &x, const DT_ alpha=DT_(1))
Calculate .
void row_norm2sqr(VectorTypeL &row_norms) const
Computes the square of the 2-norm for every row.
void convert(const SparseMatrixBCSR< DT2_, IT2_, BlockHeight_, BlockWidth_ > &other)
Conversion method.
void clone(const SparseMatrixBCSR< DT2_, IT2_, BlockHeight_, BlockWidth_ > &other, CloneMode clone_mode=CloneMode::Weak)
Clone operation.
ValueType operator()(Index row, Index col) const
Retrieve specific matrix element.
Index rows() const
Retrieve matrix row count.
DenseVector< IT_, IT_ > extract_diag_indices() const
extract main diagonal vector from matrix
friend std::ostream & operator<<(std::ostream &lhs, const SparseMatrixBCSR &b)
SparseMatrixBCSR streaming operator.
VectorTypeL extract_diag() const
extract main diagonal vector from matrix
SparseMatrixBCSR(Index rows_in, Index columns_in, Index used_elements_in)
Constructor.
void write_out(FileMode mode, const String &filename) const
Write out matrix to file.
void apply(DenseVector< DT_, IT_ > &r, const DenseVectorBlocked< DT_, IT_, BlockWidth_ > &x) const
Calculate .
static constexpr int BlockHeight
Our block height.
SparseMatrixBCSR(const Index rows_in, const Index columns_in, DenseVector< IT_, IT_ > &col_ind_in, DenseVector< DT_, IT_ > &val_in, DenseVector< IT_, IT_ > &row_ptr_in)
Constructor.
void apply_transposed(DenseVectorBlocked< DT_, IT_, BlockWidth_ > &r, const DenseVector< DT_, IT_ > &x) const
Calculate .
SparseMatrixBCSR(const SparseLayout< IT_, layout_id > &layout_in)
Constructor.
Intern::BCSRVectorHelper< DT_, IT_, BlockWidth_ >::VectorType VectorTypeR
Compatible R-vector type.
bool same_layout(const SparseMatrixBCSR &x) const
Checks if the structural layout of this matrix matches that of another matrix. This excludes comparis...
void extract_diag_indices(DenseVector< IT_, IT_ > &diag_indices) const
extract main diagonal vector from matrix
void apply_transposed(DenseVectorBlocked< DT_, IT_, BlockWidth_ > &r, const DenseVectorBlocked< DT_, IT_, BlockHeight_ > &x, const DenseVectorBlocked< DT_, IT_, BlockWidth_ > &y, const DT_ alpha=DT_(1)) const
Calculate .
static String name()
Returns a descriptive string.
IT_ * col_ind()
Retrieve column indices array.
void apply(DenseVector< DT_, IT_ > &r, const DenseVector< DT_, IT_ > &x) const
Calculate .
DT_ norm_frobenius() const
Calculates the Frobenius norm of this matrix.
IT_ * row_ptr()
Retrieve row start index array.
void add_double_mat_product(const LAFEM::SparseMatrixBCSR< DT_, IT_, BlockHeight_, BlockWidth_ > &d, const LAFEM::SparseMatrixBCSR< DT_, IT_, BlockHeight_, BlockWidth_ > &a, const LAFEM::SparseMatrixBCSR< DT_, IT_, BlockHeight_, BlockWidth_ > &b, const DT_ alpha=DT_(1), const bool allow_incomplete=false)
Adds a double-matrix product onto this matrix.
void write_out(FileMode mode, std::ostream &file) const
Write out matrix to file.
void convert(const Adjacency::Graph &graph)
Conversion method.
void lump_rows(VectorTypeL &lump) const
void apply(DenseVectorBlocked< DT_, IT_, BlockHeight_ > &r, const DenseVectorBlocked< DT_, IT_, BlockWidth_ > &x, const DenseVector< DT_, IT_ > &y, const DT_ alpha=DT_(1)) const
Calculate .
VectorTypeL lump_rows() const
Returns the lumped rows vector.
static constexpr int BlockWidth
Our block width.
Index columns() const
Retrieve matrix column count.
void apply(DenseVectorBlocked< DT_, IT_, BlockHeight_ > &r, const DenseVector< DT_, IT_ > &x) const
Calculate .
SparseMatrixBCSR clone(CloneMode clone_mode=CloneMode::Weak) const
Clone operation.
void apply(DenseVectorBlocked< DT_, IT_, BlockHeight_ > &r, const DenseVectorBlocked< DT_, IT_, BlockWidth_ > &x) const
Calculate .
SparseLayout< IT_, layout_id > layout() const
Retrieve convenient sparse matrix layout object.
Index used_elements() const
Retrieve non zero element count.
void add_double_mat_product(const LAFEM::SparseMatrixCSR< DT_, IT_ > &d, const LAFEM::SparseMatrixBCSR< DT_, IT_, BlockHeight_, BlockWidth_ > &a, const LAFEM::SparseMatrixCSR< DT_, IT_ > &b, const DT_ alpha=DT_(1), const bool allow_incomplete=false)
Adds a double-matrix product onto this matrix.
void add_trace_double_mat_mult(typename LAFEM::SparseMatrixBCSR< DT_, IT_, BHD_, BlockHeight >::VectorTypeL &v, const LAFEM::SparseMatrixBCSR< DT_, IT_, BHD_, BlockHeight > &d, const LAFEM::DenseVectorBlocked< DT_, IT_, BlockHeight > &a, const DT_ alpha=DT_(1)) const
Adds the trace of a double matrix multiplikation to a vector.
void read_from(FileMode mode, std::istream &file)
Read in matrix from stream.
DT_ max_element() const
Retrieve the maximum value of this matrix.
SparseMatrixBCSR< DT_, IT_, BlockWidth_, BlockHeight_ > transpose() const
Calculate .
void apply_transposed(DenseVector< DT_, IT_ > &r, const DenseVector< DT_, IT_ > &x, const DenseVector< DT_, IT_ > &y, const DT_ alpha=DT_(1)) const
Calculate .
void apply(DenseVector< DT_, IT_ > &r, const DenseVectorBlocked< DT_, IT_, BlockWidth_ > &x, const DenseVector< DT_, IT_ > &y, const DT_ alpha=DT_(1)) const
Calculate .
void extract_diag(VectorTypeL &diag) const
extract main diagonal vector from matrix
DT_ max_abs_element() const
Retrieve the absolute maximum value of this matrix.
ImageIterator image_begin(Index domain_node) const
DT_ max_rel_diff(const SparseMatrixBCSR &x) const
Retrieve the maximum relative difference of this matrix and another one y.max_rel_diff(x) returns .
void apply_transposed(DenseVector< DT_, IT_ > &r, const DenseVectorBlocked< DT_, IT_, BlockHeight_ > &x, const DenseVector< DT_, IT_ > &y, const DT_ alpha=DT_(1)) const
Calculate .
void deserialize(std::vector< char > input)
Deserialization of complete container entity.
void apply_transposed(DenseVector< DT_, IT_ > &r, const DenseVector< DT_, IT_ > &x) const
Calculate .
void scale_rows(const SparseMatrixBCSR &x, const DenseVectorBlocked< DT_, IT_, BlockHeight_ > &s)
Calculate .
void read_from(FileMode mode, const String &filename)
Read in matrix from file.
DT_ DataType
Our datatype.
SparseMatrixBCSR()
Constructor.
SparseMatrixBCSR & operator=(SparseMatrixBCSR &&other)
Move operator.
void extract_diag(VectorTypeL &diag, DenseVector< IT_, IT_ > &diag_indices) const
extract main diagonal vector from matrix
void scale(const SparseMatrixBCSR &x, const DT_ alpha)
Calculate .
Index get_num_nodes_domain() const
IT_ const * row_ptr() const
Retrieve row start index array.
void apply_transposed(DenseVectorBlocked< DT_, IT_, BlockWidth_ > &r, const DenseVector< DT_, IT_ > &x, const DenseVectorBlocked< DT_, IT_, BlockWidth_ > &y, const DT_ alpha=DT_(1)) const
Calculate .
std::vector< char > serialize(const LAFEM::SerialConfig &config=SerialConfig()) const
Serialization of complete container entity.
void apply_transposed(DenseVector< DT_, IT_ > &r, const DenseVectorBlocked< DT_, IT_, BlockHeight_ > &x) const
Calculate .
Tiny::Matrix< DataType, BlockHeight, BlockWidth > ValueType
Value type, meaning the type of each block.
auto val() const -> const typename Intern::BCSRPerspectiveHelper< DT_, BlockHeight_, BlockWidth_, perspective_ >::Type *
Retrieve non zero element array.
void apply(DenseVectorBlocked< DT_, IT_, BlockHeight_ > &r, const DenseVectorBlocked< DT_, IT_, BlockWidth_ > &x, const DenseVectorBlocked< DT_, IT_, BlockHeight_ > &y, const DT_ alpha=DT_(1)) const
Calculate .
Index get_num_nodes_image() const
auto val() -> typename Intern::BCSRPerspectiveHelper< DT_, BlockHeight_, BlockWidth_, perspective_ >::Type *
void transpose(const SparseMatrixBCSR< DT_, IT_, BlockWidth_, BlockHeight_ > &x)
Calculate .
SparseMatrixBCSR(FileMode mode, std::istream &file)
Constructor.
SparseMatrixBCSR(const Adjacency::Graph &graph)
Constructor.
IT_ * col_ind()
Retrieve column indices array.
DT_ * val()
Retrieve non zero element array.
Index rows() const
Retrieve matrix row count.
Index columns() const
Retrieve matrix column count.
IT_ * row_ptr()
Retrieve row start index array.
static void release_memory(void *address)
release memory or decrease reference counter
static void increase_memory(void *address)
increase memory counter
static void add_flops(Index flops)
Add an amount of flops to the global flop counter.
String class implementation.
double elapsed(const TimeStamp &before) const
Calculates the time elapsed between two time stamps.
Tiny Matrix class template.
CUDA_HOST_DEVICE Matrix & set_mat_mat_mult(const Matrix< T_, m_, la_, sma_, sna_ > &a, const Matrix< T_, lb_, n_, smb_, snb_ > &b)
Sets this matrix to the algebraic matrix-product of two other matrices.
CUDA_HOST_DEVICE Matrix & set_transpose(const Matrix< T_, n_, m_, sma_, sna_ > &a)
Sets this matrix to the transpose of another matrix.
constexpr std::size_t FileOutStreamBufferSize
OutStreamBufferSize.
T_ abs(T_ x)
Returns the absolute value.
Type
bitmask for zfp header
CUDA_HOST_DEVICE void axpy(T_ &y, const T_ &x, const T_ &alpha)
Performs an AXPY of two scalars.
String stringify(const T_ &item)
Converts an item into a String.
String stringify_fp_sci(DataType_ value, int precision=0, int width=0, bool sign=false)
Prints a floating point value to a string in scientific notation.
std::uint64_t Index
Index data type.