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 60 of file SparseMatrix.hpp.

Member Typedef Documentation

◆ ConstDataVectorType

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

Definition at line 68 of file SparseMatrix.hpp.

◆ DataType

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

Definition at line 65 of file SparseMatrix.hpp.

◆ DataVectorType

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

Definition at line 67 of file SparseMatrix.hpp.

◆ SparseStorageSharedPtr

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

Definition at line 66 of file SparseMatrix.hpp.

◆ StorageType

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

Definition at line 64 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.

55  :
57  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.

62  :
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 108 of file SparseMatrix.cpp.

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

◆ end()

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

Definition at line 114 of file SparseMatrix.cpp.

115  {
116  return m_sparseStorage->end();
117  }

◆ GetAvgRowDensity()

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

Definition at line 151 of file SparseMatrix.cpp.

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

◆ GetBandwidth()

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

Definition at line 158 of file SparseMatrix.cpp.

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

References tinysimd::abs().

◆ GetColumns()

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

Definition at line 81 of file SparseMatrix.cpp.

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

Referenced by Nektar::operator<<().

◆ GetCooStorage()

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

Definition at line 172 of file SparseMatrix.cpp.

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

◆ GetFillInRatio()

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

Definition at line 94 of file SparseMatrix.cpp.

95  {
96  return m_sparseStorage->GetFillInRatio();
97  }

◆ GetMemoryFootprint()

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

Definition at line 137 of file SparseMatrix.cpp.

138  {
139  return m_sparseStorage->GetMemoryUsage() +
140  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 87 of file SparseMatrix.cpp.

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

◆ GetRows()

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

Definition at line 75 of file SparseMatrix.cpp.

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

Referenced by Nektar::operator<<().

◆ Multiply() [1/2]

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

Definition at line 129 of file SparseMatrix.cpp.

131  {
132  m_sparseStorage->Multiply(in,out);
134  }

◆ Multiply() [2/2]

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

Definition at line 121 of file SparseMatrix.cpp.

123  {
124  m_sparseStorage->Multiply(in,out);
126  }

◆ 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 102 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 231 of file SparseMatrix.cpp.

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

◆ writeSparsityPatternTo()

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

Definition at line 192 of file SparseMatrix.cpp.

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

Member Data Documentation

◆ m_mulCallsCounter

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

Definition at line 105 of file SparseMatrix.hpp.

◆ m_sparseStorage

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

Definition at line 106 of file SparseMatrix.hpp.