50template <
typename DataType>
55 : m_matType(matType), m_iter(), m_begin(begin), m_end(end),
56 m_blkDim(blkDim), m_val(val), m_indx(indx), m_pntr(pntr)
81 std::cout <<
"const_iterator: 'begin' out stored values bounds"
94template <
typename DataType>
101 const IndexType block = storageIndex / elms;
102 const IndexType loc_offset = storageIndex % elms;
110 while (block >=
m_pntr[block_row + 1])
118 coord.first = block_row *
m_blkDim + loc_row;
119 coord.second = block_col *
m_blkDim + loc_col;
123template <
typename DataType>
131template <
typename DataType>
136template <
typename DataType>
145template <
typename DataType>
153template <
typename DataType>
160template <
typename DataType>
167template <
typename DataType>
174template <
typename DataType>
181template <
typename DataType>
184 while ((m_iter.storageindex + 1 <
m_val.
size()) &&
194 m_iter.nnzindex = m_end;
198 m_iter.second =
m_val[m_iter.storageindex];
200 CoordType c = storageIndexToFullCoord(m_iter.storageindex);
201 m_iter.first.first = c.first;
202 m_iter.first.second = c.second;
205template <
typename DataType>
221 std::cout <<
"matrix type not implemented" << std::endl;
228template <
typename DataType>
230 : m_matType(src.m_matType), m_blkRows(src.m_blkRows),
231 m_blkCols(src.m_blkCols), m_blkDim(src.m_blkDim), m_bnnz(src.m_bnnz),
232 m_nnz(src.m_nnz), m_val(src.m_val), m_indx(src.m_indx), m_pntr(src.m_pntr)
242 return m_blkRows * m_blkDim;
245template <
typename DataType>
248 return m_blkCols * m_blkDim;
251template <
typename DataType>
257template <
typename DataType>
263template <
typename DataType>
266 return m_bnnz * m_blkDim * m_blkDim;
269template <
typename DataType>
275template <
typename DataType>
278 return sizeof(
DataType) * m_val.capacity() +
285template <
typename DataType>
296 IndexType offset = m_pntr[brow] * m_blkDim * m_blkDim;
300 for (i = m_pntr[brow]; i < m_pntr[brow + 1]; i++)
302 if (bcol == m_indx[i])
304 return m_val[offset + lrow + lcol * m_blkDim];
306 offset += m_blkDim * m_blkDim;
309 return defaultReturnValue;
312template <
typename DataType>
316 return const_iterator(m_matType, 0, m_nnz, m_blkDim, m_val, m_indx, m_pntr);
319template <
typename DataType>
323 return const_iterator(m_matType, m_nnz, m_nnz, m_blkDim, m_val, m_indx,
330template <
typename DataType>
334 const double *b = &in[0];
336 const double *val = &m_val[0];
337 const int *bindx = (
int *)&m_indx[0];
338 const int *bpntrb = (
int *)&m_pntr[0];
339 const int *bpntre = (
int *)&m_pntr[0] + 1;
340 const int mb = m_blkRows;
345 Multiply_1x1(mb, val, bindx, bpntrb, bpntre, b, c);
348 Multiply_2x2(mb, val, bindx, bpntrb, bpntre, b, c);
352 Multiply_generic(mb, val, bindx, bpntrb, bpntre, b, c);
358template <
typename DataType>
361 const double *b = &in[0];
363 const double *val = &m_val[0];
364 const int *bindx = (
int *)&m_indx[0];
365 const int *bpntrb = (
int *)&m_pntr[0];
366 const int *bpntre = (
int *)&m_pntr[0] + 1;
367 const int mb = m_blkRows;
372 Multiply_1x1(mb, val, bindx, bpntrb, bpntre, b, c);
375 Multiply_2x2(mb, val, bindx, bpntrb, bpntre, b, c);
379 Multiply_generic(mb, val, bindx, bpntrb, bpntre, b, c);
387template <
typename DataType>
391 const double *b = &in[0];
393 const double *val = &m_val[0];
394 const int *bindx = (
int *)&m_indx[0];
395 const int *bpntrb = (
int *)&m_pntr[0];
396 const int *bpntre = (
int *)&m_pntr[0] + 1;
397 const int mb = m_blkRows;
402 Multiply_1x1(mb, val, bindx, bpntrb, bpntre, b, c);
405 Multiply_2x2(mb, val, bindx, bpntrb, bpntre, b, c);
409 Multiply_generic(mb, val, bindx, bpntrb, bpntre, b, c);
418template <
typename DataType>
420 const int *bindx,
const int *bpntrb,
421 const int *bpntre,
const double *b,
424 for (
int i = 0; i != mb; i++)
429 for (
int j = jb; j != je; j++)
431 t += b[bindx[j]] * (*val++);
440template <
typename DataType>
442 const int *bindx,
const int *bpntrb,
443 const int *bpntre,
const double *b,
448 const double *pval = val;
451 for (
int i = 0; i != mb; i++)
457 for (
int j = jb; j != je; j++)
459 int bs = bindx[j] * lb;
460 const double *pb = &b[bs];
462 pc[0] += pb[0] * pval[0] + pb[1] * pval[2];
463 pc[1] += pb[0] * pval[1] + pb[1] * pval[3];
471template <
typename DataType>
473 const int *bindx,
const int *bpntrb,
474 const int *bpntre,
const double *b,
479 const double *pval = val;
482 for (
int i = 0; i != mb; i++)
489 for (
int j = jb; j != je; j++)
491 int bs = bindx[j] * lb;
492 const double *pb = &b[bs];
494 pc[0] += pb[0] * pval[0] + pb[1] * pval[3] + pb[2] * pval[6];
495 pc[1] += pb[0] * pval[1] + pb[1] * pval[4] + pb[2] * pval[7];
496 pc[2] += pb[0] * pval[2] + pb[1] * pval[5] + pb[2] * pval[8];
504template <
typename DataType>
506 const int *bindx,
const int *bpntrb,
507 const int *bpntre,
const double *b,
512 const double *pval = val;
515 for (
int i = 0; i != mb; i++)
523 for (
int j = jb; j != je; j++)
525 int bs = bindx[j] * lb;
526 const double *pb = &b[bs];
528 pc[0] += pb[0] * pval[0] + pb[1] * pval[4] + pb[2] * pval[8] +
530 pc[1] += pb[0] * pval[1] + pb[1] * pval[5] + pb[2] * pval[9] +
532 pc[2] += pb[0] * pval[2] + pb[1] * pval[6] + pb[2] * pval[10] +
534 pc[3] += pb[0] * pval[3] + pb[1] * pval[7] + pb[2] * pval[11] +
543template <
typename DataType>
548 const double *b,
double *c)
550 const int lb = m_blkDim;
551 const double *pval = val;
552 const int mm = lb * lb;
554 for (
int i = 0; i != mb * lb; i++)
560 for (
int i = 0; i != mb; i++)
564 for (
int j = jb; j != je; j++)
566 Blas::Dgemv(
'N', lb, lb, 1.0, pval, lb, &b[bindx[j] * lb], 1, 1.0,
576template <
typename DataType>
587 std::vector<IndexType> tmp(blkRows + 1, 0);
591 for (entry = bcoMat.begin(); entry != bcoMat.end(); entry++)
593 rowcoord = (entry->first).first;
600 for (i = 0; i < blkRows; i++)
602 m_pntr[i + 1] = m_pntr[i] + tmp[i];
607 std::copy(&m_pntr[0], &m_pntr[0] + blkRows + 1, &tmp[0]);
610 for (entry = bcoMat.begin(); entry != bcoMat.end(); entry++)
612 rowcoord = (entry->first).first;
613 colcoord = (entry->first).second;
614 value = entry->second;
615 int blkSize = blkDim * blkDim;
617 for (i = 0; i < blkSize; i++)
619 m_val[blkSize * (tmp[rowcoord]) + i] = value[i];
626 m_indx[tmp[rowcoord]] = colcoord;
size_type size() const
Returns the array's size.
bool operator!=(const const_iterator &rhs)
CoordType storageIndexToFullCoord(IndexType storageIndex)
const DataVectorType & m_val
bool operator==(const const_iterator &rhs)
const_iterator(MatrixStorage matType, IndexType begin, IndexType end, IndexType blkDim, const DataVectorType &val, const IndexVectorType &indx, const IndexVectorType &pntr)
StorageSmvBsr(const IndexType blkRows, const IndexType blkCols, const IndexType blkDim, const BCOMatType &bcoMat, const MatrixStorage matType=eFULL)
const_iterator end() const
IndexType GetNumNonZeroEntries() const
void MultiplyLight(const DataVectorType &in, DataVectorType &out)
void processBcoInput(const IndexType blkRows, const IndexType blkDim, const BCOMatType &bcoMat)
DataType GetFillInRatio() const
size_t GetMemoryUsage() const
void Multiply(const DataType *in, DataType *out)
IndexType GetColumns() const
void Multiply_generic(const int mb, const double *val, const int *bindx, const int *bpntrb, const int *bpntre, const double *b, double *c)
Generic zero-based BSR multiply for higher matrix ranks.
void Multiply_1x1(const int mb, const double *val, const int *bindx, const int *bpntrb, const int *bpntre, const double *b, double *c)
Zero-based CSR multiply. Essentially this is slightly modified copy-paste from NIST Sparse Blas 0....
IndexType GetBlkSize() const
void Multiply_2x2(const int mb, const double *val, const int *bindx, const int *bpntrb, const int *bpntre, const double *b, double *c)
Zero-based BSR multiply unrolled for 2x2 blocks. Essentially this is slightly optimised copy-paste fr...
void Multiply_4x4(const int mb, const double *val, const int *bindx, const int *bpntrb, const int *bpntre, const double *b, double *c)
Zero-based BSR multiply unrolled for 4x4 blocks.
void Multiply_3x3(const int mb, const double *val, const int *bindx, const int *bpntrb, const int *bpntre, const double *b, double *c)
Zero-based BSR multiply unrolled for 3x3 blocks.
IndexType GetRows() const
const DataType & GetValue(IndexType row, IndexType column) const
const_iterator begin() const
IndexType GetNumStoredDoubles() const
static void Dgemv(const char &trans, const int &m, const int &n, const double &alpha, const double *a, const int &lda, const double *x, const int &incx, const double &beta, double *y, const int &incy)
BLAS level 2: Matrix vector multiply y = alpha A x plus beta y where A[m x n].
static const NekDouble kNekSparseNonZeroTol
std::map< CoordType, BCOEntryType > BCOMatType
std::pair< IndexType, IndexType > CoordType
BCOMatType::const_iterator BCOMatTypeConstIt
scalarT< T > abs(scalarT< T > in)