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

Member Typedef Documentation

◆ ConstDataVectorType

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

Definition at line 64 of file SparseMatrix.hpp.

◆ DataType

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

Definition at line 61 of file SparseMatrix.hpp.

◆ DataVectorType

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

Definition at line 63 of file SparseMatrix.hpp.

◆ SparseStorageSharedPtr

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

Definition at line 62 of file SparseMatrix.hpp.

◆ StorageType

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

Definition at line 60 of file SparseMatrix.hpp.

Constructor & Destructor Documentation

◆ NekSparseMatrix() [1/2]

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

Definition at line 54 of file SparseMatrix.cpp.

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

◆ NekSparseMatrix() [2/2]

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

Definition at line 61 of file SparseMatrix.cpp.

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

◆ ~NekSparseMatrix()

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

Definition at line 68 of file SparseMatrix.cpp.

69{
70}

Member Function Documentation

◆ begin()

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

◆ end()

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

◆ 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

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

◆ 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)(
167 bandwidth,
168 2 * std::abs((int)(entry->first.first - entry->first.second + 1)));
169 }
170 return bandwidth;
171}
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 79 of file SparseMatrix.cpp.

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

Referenced by Nektar::operator<<().

◆ GetCooStorage()

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

Definition at line 174 of file SparseMatrix.cpp.

175{
177
178 typename SparseStorageType::const_iterator entry = m_sparseStorage->begin();
179 for (; entry != m_sparseStorage->end(); entry++)
180 {
181 (*coo)[std::make_pair(entry->first.first, entry->first.second)] =
182 entry->second;
183 }
184 return coo;
185}
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 137 of file SparseMatrix.cpp.

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

◆ GetMulCallsCounter()

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

Definition at line 144 of file SparseMatrix.cpp.

145{
146 return m_mulCallsCounter;
147}

◆ GetNumNonZeroEntries()

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

Definition at line 85 of file SparseMatrix.cpp.

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

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

◆ GetRows()

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

Definition at line 73 of file SparseMatrix.cpp.

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

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< typenameSparseStorageType::DataType >::const_reference Nektar::NekSparseMatrix< SparseStorageType >::operator() ( const IndexType  row,
const IndexType  column 
) const

Definition at line 100 of file SparseMatrix.cpp.

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

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

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

◆ writeSparsityPatternTo()

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

Definition at line 195 of file SparseMatrix.cpp.

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

Member Data Documentation

◆ m_mulCallsCounter

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

Definition at line 99 of file SparseMatrix.hpp.

◆ m_sparseStorage

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

Definition at line 100 of file SparseMatrix.hpp.