Nektar++
Classes | Public Types | Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
Nektar::StorageSmvBsr< T > Class Template Reference

#include <StorageSmvBsr.hpp>

Classes

class  const_iterator
 

Public Types

typedef T DataType
 
typedef Array< OneD, DataTypeDataVectorType
 
typedef Array< OneD, const DataTypeConstDataVectorType
 
typedef Array< OneD, IndexTypeIndexVectorType
 
typedef void(* MultiplyKernel) (const double *, const double *, double *)
 

Public Member Functions

 StorageSmvBsr (const IndexType blkRows, const IndexType blkCols, const IndexType blkDim, const BCOMatType &bcoMat, const MatrixStorage matType=eFULL)
 
 StorageSmvBsr (const StorageSmvBsr &src)
 
 ~StorageSmvBsr ()
 
IndexType GetRows () const
 
IndexType GetColumns () const
 
IndexType GetNumNonZeroEntries () const
 
IndexType GetNumStoredDoubles () const
 
IndexType GetBlkSize () const
 
DataType GetFillInRatio () const
 
size_t GetMemoryUsage () const
 
const_iterator begin () const
 
const_iterator end () const
 
const DataTypeGetValue (IndexType row, IndexType column) const
 
void Multiply (const DataType *in, DataType *out)
 
void Multiply (const DataVectorType &in, DataVectorType &out)
 
void MultiplyLight (const DataVectorType &in, DataVectorType &out)
 

Protected Member Functions

void processBcoInput (const IndexType blkRows, const IndexType blkDim, const BCOMatType &bcoMat)
 
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.9b routine CSR_VecMult_CAB_double() More...
 
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 from NIST Sparse Blas 0.9b routine BSR_VecMult_BAB_double() More...
 
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. More...
 
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. More...
 
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. More...
 

Protected Attributes

MultiplyKernel m_mvKernel
 
MatrixStorage m_matType
 
IndexType m_blkRows
 
IndexType m_blkCols
 
IndexType m_blkDim
 
IndexType m_bnnz
 
IndexType m_nnz
 
DataVectorType m_val
 
IndexVectorType m_indx
 
IndexVectorType m_pntr
 

Detailed Description

template<typename T>
class Nektar::StorageSmvBsr< T >

Definition at line 62 of file StorageSmvBsr.hpp.

Member Typedef Documentation

◆ ConstDataVectorType

template<typename T >
typedef Array<OneD, const DataType> Nektar::StorageSmvBsr< T >::ConstDataVectorType

Definition at line 68 of file StorageSmvBsr.hpp.

◆ DataType

template<typename T >
typedef T Nektar::StorageSmvBsr< T >::DataType

Definition at line 66 of file StorageSmvBsr.hpp.

◆ DataVectorType

template<typename T >
typedef Array<OneD, DataType> Nektar::StorageSmvBsr< T >::DataVectorType

Definition at line 67 of file StorageSmvBsr.hpp.

◆ IndexVectorType

template<typename T >
typedef Array<OneD, IndexType> Nektar::StorageSmvBsr< T >::IndexVectorType

Definition at line 69 of file StorageSmvBsr.hpp.

◆ MultiplyKernel

template<typename T >
typedef void(* Nektar::StorageSmvBsr< T >::MultiplyKernel) (const double *, const double *, double *)

Definition at line 71 of file StorageSmvBsr.hpp.

Constructor & Destructor Documentation

◆ StorageSmvBsr() [1/2]

template<typename DataType >
Nektar::StorageSmvBsr< DataType >::StorageSmvBsr ( const IndexType  blkRows,
const IndexType  blkCols,
const IndexType  blkDim,
const BCOMatType bcoMat,
const MatrixStorage  matType = eFULL 
)
Todo:
: - iterators over strictly lower-triangular part
  • number off-diagonal elements calculation
  • clear distinction between stored and factual nonzeros (row density)

Definition at line 206 of file StorageSmvBsr.cpp.

211 : m_matType(matType), m_blkRows(blkRows), m_blkCols(blkCols),
212 m_blkDim(blkDim), m_bnnz(bcoMat.size()), m_nnz(0),
213 m_val(m_bnnz * blkDim * blkDim), m_indx(m_bnnz + 1), m_pntr(blkRows + 1)
214{
215 if (matType != Nektar::eFULL)
216 {
217 /// \todo: - iterators over strictly lower-triangular part
218 /// - number off-diagonal elements calculation
219 /// - clear distinction between stored and factual nonzeros
220 /// (row density)
221 std::cout << "matrix type not implemented" << std::endl;
222 throw 1;
223 }
224
225 processBcoInput(blkRows, blkDim, bcoMat);
226}
IndexVectorType m_indx
void processBcoInput(const IndexType blkRows, const IndexType blkDim, const BCOMatType &bcoMat)
IndexVectorType m_pntr

References Nektar::eFULL, and Nektar::StorageSmvBsr< T >::processBcoInput().

◆ StorageSmvBsr() [2/2]

template<typename DataType >
Nektar::StorageSmvBsr< DataType >::StorageSmvBsr ( const StorageSmvBsr< T > &  src)

Definition at line 229 of file StorageSmvBsr.cpp.

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)
233{
234}

◆ ~StorageSmvBsr()

Definition at line 236 of file StorageSmvBsr.cpp.

237{
238}

Member Function Documentation

◆ begin()

template<typename DataType >
StorageSmvBsr< DataType >::const_iterator Nektar::StorageSmvBsr< DataType >::begin

Definition at line 314 of file StorageSmvBsr.cpp.

315{
316 return const_iterator(m_matType, 0, m_nnz, m_blkDim, m_val, m_indx, m_pntr);
317}

Referenced by Nektar::StorageSmvBsr< T >::const_iterator::const_iterator().

◆ end()

template<typename DataType >
StorageSmvBsr< DataType >::const_iterator Nektar::StorageSmvBsr< DataType >::end

Definition at line 320 of file StorageSmvBsr.cpp.

322{
323 return const_iterator(m_matType, m_nnz, m_nnz, m_blkDim, m_val, m_indx,
324 m_pntr);
325}

Referenced by Nektar::StorageSmvBsr< T >::const_iterator::const_iterator().

◆ GetBlkSize()

template<typename DataType >
IndexType Nektar::StorageSmvBsr< DataType >::GetBlkSize

Definition at line 258 of file StorageSmvBsr.cpp.

259{
260 return m_blkDim;
261}

◆ GetColumns()

template<typename DataType >
IndexType Nektar::StorageSmvBsr< DataType >::GetColumns

Definition at line 246 of file StorageSmvBsr.cpp.

247{
248 return m_blkCols * m_blkDim;
249}

◆ GetFillInRatio()

template<typename DataType >
DataType Nektar::StorageSmvBsr< DataType >::GetFillInRatio

Definition at line 270 of file StorageSmvBsr.cpp.

◆ GetMemoryUsage()

template<typename DataType >
size_t Nektar::StorageSmvBsr< DataType >::GetMemoryUsage

Definition at line 276 of file StorageSmvBsr.cpp.

277{
278 return sizeof(DataType) * m_val.capacity() +
279 sizeof(IndexType) * m_indx.capacity() +
280 sizeof(IndexType) * m_pntr.capacity() +
281 sizeof(IndexType) * 5 + //< blkRows + blkCols + blkDim + nnz + bnnz
282 sizeof(MatrixStorage);
283}
size_type capacity() const
Returns the array's capacity.
unsigned int IndexType

◆ GetNumNonZeroEntries()

template<typename DataType >
IndexType Nektar::StorageSmvBsr< DataType >::GetNumNonZeroEntries

Definition at line 252 of file StorageSmvBsr.cpp.

253{
254 return m_nnz;
255}

◆ GetNumStoredDoubles()

template<typename DataType >
IndexType Nektar::StorageSmvBsr< DataType >::GetNumStoredDoubles

Definition at line 264 of file StorageSmvBsr.cpp.

265{
266 return m_bnnz * m_blkDim * m_blkDim;
267}

◆ GetRows()

template<typename DataType >
IndexType Nektar::StorageSmvBsr< DataType >::GetRows

Definition at line 240 of file StorageSmvBsr.cpp.

241{
242 return m_blkRows * m_blkDim;
243}

◆ GetValue()

template<typename DataType >
const DataType & Nektar::StorageSmvBsr< DataType >::GetValue ( IndexType  row,
IndexType  column 
) const

Definition at line 286 of file StorageSmvBsr.cpp.

288{
289 IndexType brow = grow / m_blkDim;
290 IndexType bcol = gcolumn / m_blkDim;
291 IndexType lrow = grow % m_blkDim;
292 IndexType lcol = gcolumn % m_blkDim;
293
294 // rewind to the first entry of the first
295 // block in the current block row
296 IndexType offset = m_pntr[brow] * m_blkDim * m_blkDim;
297
298 IndexType i;
299 static DataType defaultReturnValue;
300 for (i = m_pntr[brow]; i < m_pntr[brow + 1]; i++)
301 {
302 if (bcol == m_indx[i])
303 {
304 return m_val[offset + lrow + lcol * m_blkDim];
305 }
306 offset += m_blkDim * m_blkDim;
307 }
308
309 return defaultReturnValue;
310}

◆ Multiply() [1/2]

template<typename DataType >
void Nektar::StorageSmvBsr< DataType >::Multiply ( const DataType in,
DataType out 
)

Definition at line 359 of file StorageSmvBsr.cpp.

360{
361 const double *b = &in[0];
362 double *c = &out[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;
368
369 switch (m_blkDim)
370 {
371 case 1:
372 Multiply_1x1(mb, val, bindx, bpntrb, bpntre, b, c);
373 return;
374 case 2:
375 Multiply_2x2(mb, val, bindx, bpntrb, bpntre, b, c);
376 return;
377 default:
378 {
379 Multiply_generic(mb, val, bindx, bpntrb, bpntre, b, c);
380 return;
381 }
382 }
383}
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....
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...

◆ Multiply() [2/2]

template<typename DataType >
void Nektar::StorageSmvBsr< DataType >::Multiply ( const DataVectorType in,
DataVectorType out 
)

Definition at line 331 of file StorageSmvBsr.cpp.

333{
334 const double *b = &in[0];
335 double *c = &out[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;
341
342 switch (m_blkDim)
343 {
344 case 1:
345 Multiply_1x1(mb, val, bindx, bpntrb, bpntre, b, c);
346 return;
347 case 2:
348 Multiply_2x2(mb, val, bindx, bpntrb, bpntre, b, c);
349 return;
350 default:
351 {
352 Multiply_generic(mb, val, bindx, bpntrb, bpntre, b, c);
353 return;
354 }
355 }
356}

◆ Multiply_1x1()

template<typename DataType >
void Nektar::StorageSmvBsr< DataType >::Multiply_1x1 ( const int  mb,
const double *  val,
const int *  bindx,
const int *  bpntrb,
const int *  bpntre,
const double *  b,
double *  c 
)
protected

Zero-based CSR multiply. Essentially this is slightly modified copy-paste from NIST Sparse Blas 0.9b routine CSR_VecMult_CAB_double()

Definition at line 419 of file StorageSmvBsr.cpp.

423{
424 for (int i = 0; i != mb; i++)
425 {
426 double t = 0;
427 int jb = bpntrb[i];
428 int je = bpntre[i];
429 for (int j = jb; j != je; j++)
430 {
431 t += b[bindx[j]] * (*val++);
432 }
433 c[i] = t;
434 }
435}

◆ Multiply_2x2()

template<typename DataType >
void Nektar::StorageSmvBsr< DataType >::Multiply_2x2 ( const int  mb,
const double *  val,
const int *  bindx,
const int *  bpntrb,
const int *  bpntre,
const double *  b,
double *  c 
)
protected

Zero-based BSR multiply unrolled for 2x2 blocks. Essentially this is slightly optimised copy-paste from NIST Sparse Blas 0.9b routine BSR_VecMult_BAB_double()

Definition at line 441 of file StorageSmvBsr.cpp.

445{
446 const int lb = 2;
447
448 const double *pval = val;
449 double *pc = c;
450
451 for (int i = 0; i != mb; i++)
452 {
453 int jb = bpntrb[i];
454 int je = bpntre[i];
455 pc[0] = 0;
456 pc[1] = 0;
457 for (int j = jb; j != je; j++)
458 {
459 int bs = bindx[j] * lb;
460 const double *pb = &b[bs];
461
462 pc[0] += pb[0] * pval[0] + pb[1] * pval[2];
463 pc[1] += pb[0] * pval[1] + pb[1] * pval[3];
464 pval += 4;
465 }
466 pc += 2;
467 }
468}

◆ Multiply_3x3()

template<typename DataType >
void Nektar::StorageSmvBsr< DataType >::Multiply_3x3 ( const int  mb,
const double *  val,
const int *  bindx,
const int *  bpntrb,
const int *  bpntre,
const double *  b,
double *  c 
)
protected

Zero-based BSR multiply unrolled for 3x3 blocks.

Definition at line 472 of file StorageSmvBsr.cpp.

476{
477 const int lb = 3;
478
479 const double *pval = val;
480 double *pc = c;
481
482 for (int i = 0; i != mb; i++)
483 {
484 int jb = bpntrb[i];
485 int je = bpntre[i];
486 pc[0] = 0;
487 pc[1] = 0;
488 pc[2] = 0;
489 for (int j = jb; j != je; j++)
490 {
491 int bs = bindx[j] * lb;
492 const double *pb = &b[bs];
493
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];
497 pval += 9;
498 }
499 pc += 3;
500 }
501}

◆ Multiply_4x4()

template<typename DataType >
void Nektar::StorageSmvBsr< DataType >::Multiply_4x4 ( const int  mb,
const double *  val,
const int *  bindx,
const int *  bpntrb,
const int *  bpntre,
const double *  b,
double *  c 
)
protected

Zero-based BSR multiply unrolled for 4x4 blocks.

Definition at line 505 of file StorageSmvBsr.cpp.

509{
510 const int lb = 4;
511
512 const double *pval = val;
513 double *pc = c;
514
515 for (int i = 0; i != mb; i++)
516 {
517 int jb = bpntrb[i];
518 int je = bpntre[i];
519 pc[0] = 0;
520 pc[1] = 0;
521 pc[2] = 0;
522 pc[3] = 0;
523 for (int j = jb; j != je; j++)
524 {
525 int bs = bindx[j] * lb;
526 const double *pb = &b[bs];
527
528 pc[0] += pb[0] * pval[0] + pb[1] * pval[4] + pb[2] * pval[8] +
529 pb[3] * pval[12];
530 pc[1] += pb[0] * pval[1] + pb[1] * pval[5] + pb[2] * pval[9] +
531 pb[3] * pval[13];
532 pc[2] += pb[0] * pval[2] + pb[1] * pval[6] + pb[2] * pval[10] +
533 pb[3] * pval[14];
534 pc[3] += pb[0] * pval[3] + pb[1] * pval[7] + pb[2] * pval[11] +
535 pb[3] * pval[15];
536 pval += 16;
537 }
538 pc += 4;
539 }
540}

◆ Multiply_generic()

template<typename DataType >
void Nektar::StorageSmvBsr< DataType >::Multiply_generic ( const int  mb,
const double *  val,
const int *  bindx,
const int *  bpntrb,
const int *  bpntre,
const double *  b,
double *  c 
)
protected

Generic zero-based BSR multiply for higher matrix ranks.

Definition at line 544 of file StorageSmvBsr.cpp.

549{
550 const int lb = m_blkDim;
551 const double *pval = val;
552 const int mm = lb * lb;
553 double *pc = c;
554 for (int i = 0; i != mb * lb; i++)
555 {
556 *pc++ = 0;
557 }
558
559 pc = c;
560 for (int i = 0; i != mb; i++)
561 {
562 int jb = bpntrb[i];
563 int je = bpntre[i];
564 for (int j = jb; j != je; j++)
565 {
566 Blas::Dgemv('N', lb, lb, 1.0, pval, lb, &b[bindx[j] * lb], 1, 1.0,
567 pc, 1);
568 pval += mm;
569 }
570 pc += lb;
571 }
572}
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].
Definition: Blas.hpp:211

References Blas::Dgemv().

◆ MultiplyLight()

template<typename DataType >
void Nektar::StorageSmvBsr< DataType >::MultiplyLight ( const DataVectorType in,
DataVectorType out 
)

Definition at line 388 of file StorageSmvBsr.cpp.

390{
391 const double *b = &in[0];
392 double *c = &out[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;
398
399 switch (m_blkDim)
400 {
401 case 1:
402 Multiply_1x1(mb, val, bindx, bpntrb, bpntre, b, c);
403 return;
404 case 2:
405 Multiply_2x2(mb, val, bindx, bpntrb, bpntre, b, c);
406 return;
407 default:
408 {
409 Multiply_generic(mb, val, bindx, bpntrb, bpntre, b, c);
410 return;
411 }
412 }
413}

◆ processBcoInput()

template<typename DataType >
void Nektar::StorageSmvBsr< DataType >::processBcoInput ( const IndexType  blkRows,
const IndexType  blkDim,
const BCOMatType bcoMat 
)
protected

Definition at line 577 of file StorageSmvBsr.cpp.

580{
581 IndexType i;
582 BCOMatTypeConstIt entry;
583 IndexType rowcoord;
584 IndexType colcoord;
585 BCOEntryType value;
586
587 std::vector<IndexType> tmp(blkRows + 1, 0);
588
589 // calculate the number of entries on each row
590 // and store the result in tmp
591 for (entry = bcoMat.begin(); entry != bcoMat.end(); entry++)
592 {
593 rowcoord = (entry->first).first;
594 tmp[rowcoord]++;
595 }
596 // Based upon this information, fill the array m_pntr
597 // which basically contains the offset of each row's
598 // first entry in the other arrays m_val and m_indx
599 m_pntr[0] = 0;
600 for (i = 0; i < blkRows; i++)
601 {
602 m_pntr[i + 1] = m_pntr[i] + tmp[i];
603 }
604
605 // Copy the values of m_pntr into tmp as this will be needed
606 // in the following step
607 std::copy(&m_pntr[0], &m_pntr[0] + blkRows + 1, &tmp[0]);
608
609 // Now, fill in index and value entries.
610 for (entry = bcoMat.begin(); entry != bcoMat.end(); entry++)
611 {
612 rowcoord = (entry->first).first;
613 colcoord = (entry->first).second;
614 value = entry->second;
615 int blkSize = blkDim * blkDim;
616
617 for (i = 0; i < blkSize; i++)
618 {
619 m_val[blkSize * (tmp[rowcoord]) + i] = value[i];
621 {
622 m_nnz++;
623 }
624 }
625
626 m_indx[tmp[rowcoord]] = colcoord;
627 tmp[rowcoord]++;
628 }
629}
def copy(self)
Definition: pycml.py:2663
static const NekDouble kNekSparseNonZeroTol
Array< OneD, NekDouble > BCOEntryType
BCOMatType::const_iterator BCOMatTypeConstIt
scalarT< T > abs(scalarT< T > in)
Definition: scalar.hpp:298

References tinysimd::abs(), CellMLToNektar.pycml::copy(), and Nektar::NekConstants::kNekSparseNonZeroTol.

Referenced by Nektar::StorageSmvBsr< T >::StorageSmvBsr().

Member Data Documentation

◆ m_blkCols

template<typename T >
IndexType Nektar::StorageSmvBsr< T >::m_blkCols
protected

Definition at line 181 of file StorageSmvBsr.hpp.

◆ m_blkDim

template<typename T >
IndexType Nektar::StorageSmvBsr< T >::m_blkDim
protected

◆ m_blkRows

template<typename T >
IndexType Nektar::StorageSmvBsr< T >::m_blkRows
protected

Definition at line 180 of file StorageSmvBsr.hpp.

◆ m_bnnz

template<typename T >
IndexType Nektar::StorageSmvBsr< T >::m_bnnz
protected

Definition at line 184 of file StorageSmvBsr.hpp.

◆ m_indx

template<typename T >
IndexVectorType Nektar::StorageSmvBsr< T >::m_indx
protected

◆ m_matType

template<typename T >
MatrixStorage Nektar::StorageSmvBsr< T >::m_matType
protected

Definition at line 178 of file StorageSmvBsr.hpp.

◆ m_mvKernel

template<typename T >
MultiplyKernel Nektar::StorageSmvBsr< T >::m_mvKernel
protected

Definition at line 176 of file StorageSmvBsr.hpp.

◆ m_nnz

template<typename T >
IndexType Nektar::StorageSmvBsr< T >::m_nnz
protected

Definition at line 185 of file StorageSmvBsr.hpp.

◆ m_pntr

template<typename T >
IndexVectorType Nektar::StorageSmvBsr< T >::m_pntr
protected

◆ m_val

template<typename T >
DataVectorType Nektar::StorageSmvBsr< T >::m_val
protected