Nektar++
Public Types | Public Member Functions | Protected Attributes | List of all members
Nektar::NekSparseMatrix< SparseStorageType > Class Template Reference

#include <SparseMatrix.hpp>

Public Types

typedef SparseStorageType StorageType
 
typedef SparseStorageType::DataType DataType
 
typedef std::shared_ptr< SparseStorageType > SparseStorageSharedPtr
 
typedef Array< OneD, DataTypeDataVectorType
 
typedef Array< OneD, const DataTypeConstDataVectorType
 

Public Member Functions

 NekSparseMatrix (const SparseStorageSharedPtr &sparseStoragePtr)
 
 NekSparseMatrix (const NekSparseMatrix &src)
 
 ~NekSparseMatrix ()
 
IndexType GetRows () const
 
IndexType GetColumns () const
 
IndexType GetNumNonZeroEntries () const
 
const DataType GetFillInRatio () const
 
size_t GetMemoryFootprint () const
 
unsigned long GetMulCallsCounter () const
 
const DataType GetAvgRowDensity () const
 
IndexType GetBandwidth ()
 
COOMatTypeSharedPtr GetCooStorage ()
 
boost::call_traits< DataType >::const_reference operator() (const IndexType row, const IndexType column) const
 
SparseStorageType::const_iterator begin () const
 
SparseStorageType::const_iterator end () const
 
void Multiply (const DataVectorType &in, DataVectorType &out)
 
void Multiply (const DataType *in, DataType *out)
 
void writeSparsityPatternTo (std::ostream &out, IndexType blockSize=64)
 
void writeBlockSparsityPatternTo (std::ostream &out, const IndexType blk_row=0, const IndexType blk_col=0, IndexType blockSize=64)
 Complementary routine to the previous. It generates exact non-zero pattern of a given block matrix entry to *this object. E.g., for a 6x6 matrix defined as A(i,i):=i, A(i,j):=0, block size = 2 and blk_row=blk_col=2 it produces 2x2 matrix with 5 and 6 along the diagonal. More...
 

Protected Attributes

unsigned long m_mulCallsCounter
 
SparseStorageSharedPtr m_sparseStorage
 

Detailed Description

template<typename SparseStorageType>
class Nektar::NekSparseMatrix< SparseStorageType >

Definition at line 58 of file SparseMatrix.hpp.

Member Typedef Documentation

◆ ConstDataVectorType

template<typename SparseStorageType >
typedef Array<OneD, const DataType> Nektar::NekSparseMatrix< SparseStorageType >::ConstDataVectorType

Definition at line 65 of file SparseMatrix.hpp.

◆ DataType

template<typename SparseStorageType >
typedef SparseStorageType::DataType Nektar::NekSparseMatrix< SparseStorageType >::DataType

Definition at line 62 of file SparseMatrix.hpp.

◆ DataVectorType

template<typename SparseStorageType >
typedef Array<OneD, DataType> Nektar::NekSparseMatrix< SparseStorageType >::DataVectorType

Definition at line 64 of file SparseMatrix.hpp.

◆ SparseStorageSharedPtr

template<typename SparseStorageType >
typedef std::shared_ptr<SparseStorageType> Nektar::NekSparseMatrix< SparseStorageType >::SparseStorageSharedPtr

Definition at line 63 of file SparseMatrix.hpp.

◆ StorageType

template<typename SparseStorageType >
typedef SparseStorageType Nektar::NekSparseMatrix< SparseStorageType >::StorageType

Definition at line 61 of file SparseMatrix.hpp.

Constructor & Destructor Documentation

◆ NekSparseMatrix() [1/2]

template<typename SparseStorageType >
Nektar::NekSparseMatrix< SparseStorageType >::NekSparseMatrix ( const SparseStorageSharedPtr sparseStoragePtr)

Definition at line 55 of file SparseMatrix.cpp.

57  : m_mulCallsCounter(0), m_sparseStorage(sparseStoragePtr)
58 {
59 }
SparseStorageSharedPtr m_sparseStorage
unsigned long m_mulCallsCounter

◆ NekSparseMatrix() [2/2]

template<typename SparseStorageType >
Nektar::NekSparseMatrix< SparseStorageType >::NekSparseMatrix ( const NekSparseMatrix< SparseStorageType > &  src)

Definition at line 62 of file SparseMatrix.cpp.

63  : m_mulCallsCounter(src.m_mulCallsCounter),
64  m_sparseStorage(src.m_sparseStorage)
65 {
66 }

◆ ~NekSparseMatrix()

template<typename SparseStorageType >
Nektar::NekSparseMatrix< SparseStorageType >::~NekSparseMatrix

Definition at line 69 of file SparseMatrix.cpp.

70 {
71 }

Member Function Documentation

◆ begin()

template<typename SparseStorageType >
SparseStorageType::const_iterator Nektar::NekSparseMatrix< SparseStorageType >::begin

Definition at line 109 of file SparseMatrix.cpp.

110 {
111  return m_sparseStorage->begin();
112 }

References Nektar::NekSparseMatrix< SparseStorageType >::begin().

Referenced by Nektar::NekSparseMatrix< SparseStorageType >::begin().

◆ end()

template<typename SparseStorageType >
SparseStorageType::const_iterator Nektar::NekSparseMatrix< SparseStorageType >::end

Definition at line 116 of file SparseMatrix.cpp.

117 {
118  return m_sparseStorage->end();
119 }

References Nektar::NekSparseMatrix< SparseStorageType >::end().

Referenced by Nektar::NekSparseMatrix< SparseStorageType >::end().

◆ GetAvgRowDensity()

template<typename SparseStorageType >
const SparseStorageType::DataType Nektar::NekSparseMatrix< SparseStorageType >::GetAvgRowDensity

Definition at line 152 of file SparseMatrix.cpp.

153 {
154  return (DataType)m_sparseStorage->GetNumNonZeroEntries() /
155  (DataType)m_sparseStorage->GetRows();
156 }
SparseStorageType::DataType DataType

References Nektar::NekSparseMatrix< SparseStorageType >::GetNumNonZeroEntries().

◆ GetBandwidth()

template<typename SparseStorageType >
IndexType Nektar::NekSparseMatrix< SparseStorageType >::GetBandwidth

Definition at line 159 of file SparseMatrix.cpp.

160 {
161  int bandwidth = 0;
162 
163  typename SparseStorageType::const_iterator entry = m_sparseStorage->begin();
164 
165  for (; entry != m_sparseStorage->end(); ++entry)
166  {
167  bandwidth = (std::max)(
168  bandwidth,
169  2 * std::abs((int)(entry->first.first - entry->first.second + 1)));
170  }
171  return bandwidth;
172 }
scalarT< T > abs(scalarT< T > in)
Definition: scalar.hpp:298

References tinysimd::abs().

◆ GetColumns()

template<typename SparseStorageType >
IndexType Nektar::NekSparseMatrix< SparseStorageType >::GetColumns

Definition at line 80 of file SparseMatrix.cpp.

81 {
82  return m_sparseStorage->GetColumns();
83 }

Referenced by Nektar::operator<<().

◆ GetCooStorage()

template<typename SparseStorageType >
COOMatTypeSharedPtr Nektar::NekSparseMatrix< SparseStorageType >::GetCooStorage

Definition at line 175 of file SparseMatrix.cpp.

176 {
177  COOMatTypeSharedPtr coo(new COOMatType());
178 
179  typename SparseStorageType::const_iterator entry = m_sparseStorage->begin();
180  for (; entry != m_sparseStorage->end(); entry++)
181  {
182  (*coo)[std::make_pair(entry->first.first, entry->first.second)] =
183  entry->second;
184  }
185  return coo;
186 }
std::shared_ptr< COOMatType > COOMatTypeSharedPtr
std::map< CoordType, NekDouble > COOMatType

◆ GetFillInRatio()

template<typename SparseStorageType >
const NekSparseMatrix< SparseStorageType >::DataType Nektar::NekSparseMatrix< SparseStorageType >::GetFillInRatio

◆ GetMemoryFootprint()

template<typename SparseStorageType >
size_t Nektar::NekSparseMatrix< SparseStorageType >::GetMemoryFootprint

Definition at line 138 of file SparseMatrix.cpp.

139 {
140  return m_sparseStorage->GetMemoryUsage() + sizeof(SparseStorageSharedPtr) +
141  sizeof(unsigned long); // mulCallsCounter
142 }
std::shared_ptr< SparseStorageType > SparseStorageSharedPtr

◆ GetMulCallsCounter()

template<typename SparseStorageType >
unsigned long Nektar::NekSparseMatrix< SparseStorageType >::GetMulCallsCounter

Definition at line 145 of file SparseMatrix.cpp.

146 {
147  return m_mulCallsCounter;
148 }

◆ GetNumNonZeroEntries()

template<typename SparseStorageType >
IndexType Nektar::NekSparseMatrix< SparseStorageType >::GetNumNonZeroEntries

Definition at line 86 of file SparseMatrix.cpp.

87 {
88  return m_sparseStorage->GetNumNonZeroEntries();
89 }

Referenced by Nektar::NekSparseMatrix< SparseStorageType >::GetAvgRowDensity().

◆ GetRows()

template<typename SparseStorageType >
IndexType Nektar::NekSparseMatrix< SparseStorageType >::GetRows

Definition at line 74 of file SparseMatrix.cpp.

75 {
76  return m_sparseStorage->GetRows();
77 }

Referenced by Nektar::operator<<().

◆ Multiply() [1/2]

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

Definition at line 130 of file SparseMatrix.cpp.

132 {
133  m_sparseStorage->Multiply(in, out);
135 }

◆ Multiply() [2/2]

template<typename SparseStorageType >
void Nektar::NekSparseMatrix< SparseStorageType >::Multiply ( const DataVectorType in,
DataVectorType out 
)

Definition at line 122 of file SparseMatrix.cpp.

124 {
125  m_sparseStorage->Multiply(in, out);
127 }

◆ operator()()

template<typename SparseStorageType >
boost::call_traits< typename SparseStorageType::DataType >::const_reference Nektar::NekSparseMatrix< SparseStorageType >::operator() ( const IndexType  row,
const IndexType  column 
) const

Definition at line 101 of file SparseMatrix.cpp.

103 {
104  return m_sparseStorage->GetValue(row, column);
105 }

◆ writeBlockSparsityPatternTo()

template<typename SparseStorageType >
void Nektar::NekSparseMatrix< SparseStorageType >::writeBlockSparsityPatternTo ( std::ostream &  out,
const IndexType  blk_row = 0,
const IndexType  blk_col = 0,
IndexType  blockSize = 64 
)

Complementary routine to the previous. It generates exact non-zero pattern of a given block matrix entry to *this object. E.g., for a 6x6 matrix defined as A(i,i):=i, A(i,j):=0, block size = 2 and blk_row=blk_col=2 it produces 2x2 matrix with 5 and 6 along the diagonal.

Definition at line 236 of file SparseMatrix.cpp.

239 {
240  blockSize = (std::min)(blockSize, m_sparseStorage->GetRows());
241  std::vector<std::vector<int>> grid(blockSize);
242  for (int row = 0; row < blockSize; row++)
243  {
244  grid[row].resize(blockSize, 0);
245  }
246 
247  typename SparseStorageType::const_iterator entry = m_sparseStorage->begin();
248  for (; entry != m_sparseStorage->end(); entry++)
249  {
250  const IndexType row = entry->first.first;
251  const IndexType col = entry->first.second;
252 
253  if (blk_row != row / blockSize)
254  continue;
255  if (blk_col != col / blockSize)
256  continue;
257  grid[row % blockSize][col % blockSize]++;
258  }
259 
260  for (int row = 0; row < blockSize; row++)
261  {
262  for (int col = 0; col < blockSize; col++)
263  {
264  out << grid[row][col] << " ";
265  }
266  out << std::endl;
267  }
268 }
unsigned int IndexType

◆ writeSparsityPatternTo()

template<typename SparseStorageType >
void Nektar::NekSparseMatrix< SparseStorageType >::writeSparsityPatternTo ( std::ostream &  out,
IndexType  blockSize = 64 
)

Definition at line 196 of file SparseMatrix.cpp.

198 {
199  const int matRows = m_sparseStorage->GetRows();
200  const int gridRows = matRows / blockSize + (matRows % blockSize > 0);
201  const int gridCols = gridRows;
202 
203  std::vector<std::vector<int>> grid(gridRows);
204  for (int row = 0; row < gridRows; row++)
205  {
206  grid[row].resize(gridCols, 0);
207  }
208 
209  typename SparseStorageType::const_iterator entry = m_sparseStorage->begin();
210  for (; entry != m_sparseStorage->end(); entry++)
211  {
212  const IndexType row = entry->first.first;
213  const IndexType col = entry->first.second;
214  const int gridRow = row / blockSize;
215  const int gridCol = col / blockSize;
216  grid[gridRow][gridCol]++;
217  }
218 
219  for (int row = 0; row < gridRows; row++)
220  {
221  for (int col = 0; col < gridCols; col++)
222  {
223  out << grid[row][col] << " ";
224  }
225  out << std::endl;
226  }
227 }

Member Data Documentation

◆ m_mulCallsCounter

template<typename SparseStorageType >
unsigned long Nektar::NekSparseMatrix< SparseStorageType >::m_mulCallsCounter
protected

Definition at line 100 of file SparseMatrix.hpp.

◆ m_sparseStorage

template<typename SparseStorageType >
SparseStorageSharedPtr Nektar::NekSparseMatrix< SparseStorageType >::m_sparseStorage
protected

Definition at line 101 of file SparseMatrix.hpp.