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 204 of file StorageSmvBsr.cpp.

209 : m_matType(matType), m_blkRows(blkRows), m_blkCols(blkCols),
210 m_blkDim(blkDim), m_bnnz(bcoMat.size()), m_nnz(0),
211 m_val(m_bnnz * blkDim * blkDim), m_indx(m_bnnz + 1), m_pntr(blkRows + 1)
212{
213 if (matType != Nektar::eFULL)
214 {
215 /// \todo: - iterators over strictly lower-triangular part
216 /// - number off-diagonal elements calculation
217 /// - clear distinction between stored and factual nonzeros
218 /// (row density)
219 std::cout << "matrix type not implemented" << std::endl;
220 throw 1;
221 }
222
223 processBcoInput(blkRows, blkDim, bcoMat);
224}
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 227 of file StorageSmvBsr.cpp.

228 : m_matType(src.m_matType), m_blkRows(src.m_blkRows),
229 m_blkCols(src.m_blkCols), m_blkDim(src.m_blkDim), m_bnnz(src.m_bnnz),
230 m_nnz(src.m_nnz), m_val(src.m_val), m_indx(src.m_indx), m_pntr(src.m_pntr)
231{
232}

◆ ~StorageSmvBsr()

Definition at line 234 of file StorageSmvBsr.cpp.

235{
236}

Member Function Documentation

◆ begin()

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

Definition at line 312 of file StorageSmvBsr.cpp.

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

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

◆ end()

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

Definition at line 318 of file StorageSmvBsr.cpp.

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

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

◆ GetBlkSize()

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

Definition at line 256 of file StorageSmvBsr.cpp.

257{
258 return m_blkDim;
259}

◆ GetColumns()

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

Definition at line 244 of file StorageSmvBsr.cpp.

245{
246 return m_blkCols * m_blkDim;
247}

◆ GetFillInRatio()

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

Definition at line 268 of file StorageSmvBsr.cpp.

◆ GetMemoryUsage()

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

Definition at line 274 of file StorageSmvBsr.cpp.

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

◆ GetNumNonZeroEntries()

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

Definition at line 250 of file StorageSmvBsr.cpp.

251{
252 return m_nnz;
253}

◆ GetNumStoredDoubles()

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

Definition at line 262 of file StorageSmvBsr.cpp.

263{
264 return m_bnnz * m_blkDim * m_blkDim;
265}

◆ GetRows()

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

Definition at line 238 of file StorageSmvBsr.cpp.

239{
240 return m_blkRows * m_blkDim;
241}

◆ GetValue()

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

Definition at line 284 of file StorageSmvBsr.cpp.

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

◆ Multiply() [1/2]

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

Definition at line 357 of file StorageSmvBsr.cpp.

358{
359 const double *b = &in[0];
360 double *c = &out[0];
361 const double *val = &m_val[0];
362 const int *bindx = (int *)&m_indx[0];
363 const int *bpntrb = (int *)&m_pntr[0];
364 const int *bpntre = (int *)&m_pntr[0] + 1;
365 const int mb = m_blkRows;
366
367 switch (m_blkDim)
368 {
369 case 1:
370 Multiply_1x1(mb, val, bindx, bpntrb, bpntre, b, c);
371 return;
372 case 2:
373 Multiply_2x2(mb, val, bindx, bpntrb, bpntre, b, c);
374 return;
375 default:
376 {
377 Multiply_generic(mb, val, bindx, bpntrb, bpntre, b, c);
378 return;
379 }
380 }
381}
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 329 of file StorageSmvBsr.cpp.

331{
332 const double *b = &in[0];
333 double *c = &out[0];
334 const double *val = &m_val[0];
335 const int *bindx = (int *)&m_indx[0];
336 const int *bpntrb = (int *)&m_pntr[0];
337 const int *bpntre = (int *)&m_pntr[0] + 1;
338 const int mb = m_blkRows;
339
340 switch (m_blkDim)
341 {
342 case 1:
343 Multiply_1x1(mb, val, bindx, bpntrb, bpntre, b, c);
344 return;
345 case 2:
346 Multiply_2x2(mb, val, bindx, bpntrb, bpntre, b, c);
347 return;
348 default:
349 {
350 Multiply_generic(mb, val, bindx, bpntrb, bpntre, b, c);
351 return;
352 }
353 }
354}

◆ 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 417 of file StorageSmvBsr.cpp.

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

◆ 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 439 of file StorageSmvBsr.cpp.

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

◆ 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 470 of file StorageSmvBsr.cpp.

474{
475 const int lb = 3;
476
477 const double *pval = val;
478 double *pc = c;
479
480 for (int i = 0; i != mb; i++)
481 {
482 int jb = bpntrb[i];
483 int je = bpntre[i];
484 pc[0] = 0;
485 pc[1] = 0;
486 pc[2] = 0;
487 for (int j = jb; j != je; j++)
488 {
489 int bs = bindx[j] * lb;
490 const double *pb = &b[bs];
491
492 pc[0] += pb[0] * pval[0] + pb[1] * pval[3] + pb[2] * pval[6];
493 pc[1] += pb[0] * pval[1] + pb[1] * pval[4] + pb[2] * pval[7];
494 pc[2] += pb[0] * pval[2] + pb[1] * pval[5] + pb[2] * pval[8];
495 pval += 9;
496 }
497 pc += 3;
498 }
499}

◆ 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 503 of file StorageSmvBsr.cpp.

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

◆ 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 542 of file StorageSmvBsr.cpp.

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

References Blas::Dgemv().

◆ MultiplyLight()

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

Definition at line 386 of file StorageSmvBsr.cpp.

388{
389 const double *b = &in[0];
390 double *c = &out[0];
391 const double *val = &m_val[0];
392 const int *bindx = (int *)&m_indx[0];
393 const int *bpntrb = (int *)&m_pntr[0];
394 const int *bpntre = (int *)&m_pntr[0] + 1;
395 const int mb = m_blkRows;
396
397 switch (m_blkDim)
398 {
399 case 1:
400 Multiply_1x1(mb, val, bindx, bpntrb, bpntre, b, c);
401 return;
402 case 2:
403 Multiply_2x2(mb, val, bindx, bpntrb, bpntre, b, c);
404 return;
405 default:
406 {
407 Multiply_generic(mb, val, bindx, bpntrb, bpntre, b, c);
408 return;
409 }
410 }
411}

◆ processBcoInput()

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

Definition at line 573 of file StorageSmvBsr.cpp.

576{
577 IndexType i;
578 BCOMatTypeConstIt entry;
579 IndexType rowcoord;
580 IndexType colcoord;
581 BCOEntryType value;
582
583 std::vector<IndexType> tmp(blkRows + 1, 0);
584
585 // calculate the number of entries on each row
586 // and store the result in tmp
587 for (entry = bcoMat.begin(); entry != bcoMat.end(); entry++)
588 {
589 rowcoord = (entry->first).first;
590 tmp[rowcoord]++;
591 }
592 // Based upon this information, fill the array m_pntr
593 // which basically contains the offset of each row's
594 // first entry in the other arrays m_val and m_indx
595 m_pntr[0] = 0;
596 for (i = 0; i < blkRows; i++)
597 {
598 m_pntr[i + 1] = m_pntr[i] + tmp[i];
599 }
600
601 // Copy the values of m_pntr into tmp as this will be needed
602 // in the following step
603 std::copy(&m_pntr[0], &m_pntr[0] + blkRows + 1, &tmp[0]);
604
605 // Now, fill in index and value entries.
606 for (entry = bcoMat.begin(); entry != bcoMat.end(); entry++)
607 {
608 rowcoord = (entry->first).first;
609 colcoord = (entry->first).second;
610 value = entry->second;
611 int blkSize = blkDim * blkDim;
612
613 for (i = 0; i < blkSize; i++)
614 {
615 m_val[blkSize * (tmp[rowcoord]) + i] = value[i];
617 m_nnz++;
618 }
619
620 m_indx[tmp[rowcoord]] = colcoord;
621 tmp[rowcoord]++;
622 }
623}
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