50template <
typename SparseStorageType>
53 : m_rows(0), m_cols(0), m_rowoffset(sparseStoragePtrVector.size() + 1, 0.0),
55 m_submatrix(sparseStoragePtrVector.size(), sparseStoragePtrVector)
57 for (
int i = 0; i < sparseStoragePtrVector.size(); i++)
59 const IndexType rows = sparseStoragePtrVector[i]->GetRows();
61 m_cols += sparseStoragePtrVector[i]->GetColumns();
66template <
typename SparseStorageType>
69 : m_rows(src.m_rows), m_cols(src.m_cols), m_rowoffset(src.m_rowoffset),
70 m_mulCallsCounter(src.m_mulCallsCounter), m_submatrix(src.m_submatrix)
74template <
typename SparseStorageType>
79template <
typename SparseStorageType>
85template <
typename SparseStorageType>
92template <
typename SparseStorageType>
95 return m_submatrix[i]->GetRows();
99template <
typename SparseStorageType>
102 return m_submatrix[i]->GetColumns();
105template <
typename SparseStorageType>
109 return m_submatrix.size();
112template <
typename SparseStorageType>
116 for (
int i = 0; i < m_submatrix.size(); i++)
118 nnz += m_submatrix[i]->GetNumNonZeroEntries();
124template <
typename SparseStorageType>
128 return m_submatrix[i]->GetNumNonZeroEntries();
131template <
typename SparseStorageType>
133 SparseStorageType>::GetFillInRatio(
int i)
const
138template <
typename SparseStorageType>
140 SparseStorageType>::GetFillInRatio()
const
144 for (
int i = 0; i < m_submatrix.size(); i++)
146 stored += m_submatrix[i]->GetNumStoredDoubles();
152template <
typename SparseStorageType>
153typename boost::call_traits<
154 typename SparseStorageType::DataType>::const_reference
158 return m_submatrix[block]->GetValue(loc_row, loc_column);
161template <
typename SparseStorageType>
162typename boost::call_traits<
163 typename SparseStorageType::DataType>::const_reference
168 static DataType defaultReturnValue = 0;
170 signed int local_row = glob_row;
171 signed int local_col = glob_column;
173 while ((local_row >= m_submatrix[i]->GetRows()) && (local_col >= 0))
175 local_row -= m_submatrix[i]->GetRows();
176 local_col -= m_submatrix[i]->GetColumns();
181 return defaultReturnValue;
183 return m_submatrix[i]->GetValue(local_row, local_col);
186template <
typename SparseStorageType>
190 for (
int i = 0; i < m_submatrix.size(); ++i)
192 m_submatrix[i]->Multiply(&in[m_rowoffset[i]], &out[m_rowoffset[i]]);
197template <
typename SparseStorageType>
201 for (
int i = 0; i < m_submatrix.size(); ++i)
203 m_submatrix[i]->Multiply(&in[m_rowoffset[i]], &out[m_rowoffset[i]]);
208template <
typename SparseStorageType>
212 m_submatrix[blockNum]->Multiply(in + m_rowoffset[blockNum],
213 out + m_rowoffset[blockNum]);
217template <
typename SparseStorageType>
221 sizeof(
unsigned long) +
223 sizeof(
IndexType) * m_rowoffset.capacity() +
226 for (
int i = 0; i < m_submatrix.size(); i++)
228 bytes += m_submatrix[i]->GetMemoryUsage();
233template <
typename SparseStorageType>
237 return m_submatrix[i]->GetMemoryUsage();
240template <
typename SparseStorageType>
244 return m_mulCallsCounter;
247template <
typename SparseStorageType>
249 SparseStorageType>::GetAvgRowDensity()
252 for (
int i = 0; i < m_submatrix.size(); i++)
254 avgRowDensity += (
DataType)m_submatrix[i]->GetNumNonZeroEntries() /
255 (
DataType)m_submatrix[i]->GetRows();
257 return avgRowDensity / m_submatrix.size();
260template <
typename SparseStorageType>
265 (
DataType)m_submatrix[i]->GetRows();
268template <
typename SparseStorageType>
272 for (
int i = 0; i < m_submatrix.size(); i++)
274 typename SparseStorageType::const_iterator entry =
275 m_submatrix[i]->begin();
276 for (; entry != m_submatrix[i]->end(); ++entry)
279 (std::max)(
static_cast<int>(bandwidth),
280 2 *
abs(
static_cast<int>(entry->first.first -
281 entry->first.second) +
288template <
typename SparseStorageType>
292 typename SparseStorageType::const_iterator entry = m_submatrix[i]->begin();
293 for (; entry != m_submatrix[i]->end(); ++entry)
295 bandwidth = (std::max)(
296 static_cast<int>(bandwidth),
297 2 *
abs(
static_cast<int>(entry->first.first - entry->first.second) +
303template <
typename SparseStorageType>
308 typename SparseStorageType::const_iterator entry = m_submatrix[i]->begin();
309 for (; entry != m_submatrix[i]->end(); entry++)
313 (*coo)[std::make_pair(loc_row, loc_col)] = entry->second;
318template <
typename SparseStorageType>
324 for (
IndexType i = 0; i < m_submatrix.size(); i++)
326 typename SparseStorageType::const_iterator entry =
327 m_submatrix[i]->begin();
328 for (; entry != m_submatrix[i]->end(); entry++)
332 (*coo)[std::make_pair(loc_row + row_offset, loc_col + col_offset)] =
335 row_offset += m_submatrix[i]->GetRows();
336 col_offset += m_submatrix[i]->GetColumns();
348template <
typename SparseStorageType>
352 const int matRows = m_submatrix[subMatrixIdx]->GetRows();
353 const int gridRows = matRows / blockSize + (matRows % blockSize > 0);
354 const int gridCols = gridRows;
356 std::vector<std::vector<int>> grid(gridRows);
357 for (
int row = 0; row < gridRows; row++)
359 grid[row].resize(gridCols, 0.0);
362 typename SparseStorageType::const_iterator entry =
363 m_submatrix[subMatrixIdx]->begin();
364 typename SparseStorageType::const_iterator stop =
365 m_submatrix[subMatrixIdx]->end();
366 for (; entry != stop; ++entry)
368 const IndexType row = entry->first.first;
369 const IndexType col = entry->first.second;
370 const int gridRow = row / blockSize;
371 const int gridCol = col / blockSize;
372 grid[gridRow][gridCol]++;
375 for (
int row = 0; row < gridRows; row++)
377 for (
int col = 0; col < gridCols; col++)
379 out << grid[row][col] <<
" ";
385template <
typename SparseStorageType>
387 std::ostream &out,
const IndexType blockSize)
389 const int matRows = GetRows();
390 const int gridRows = matRows / blockSize + (matRows % blockSize > 0);
391 const int gridCols = gridRows;
393 std::vector<std::vector<int>> grid(gridRows);
394 for (
int row = 0; row < gridRows; row++)
396 grid[row].resize(gridCols, 0.0);
401 for (
int i = 0; i < m_submatrix.size(); i++)
403 typename SparseStorageType::const_iterator entry =
404 m_submatrix[i]->begin();
405 typename SparseStorageType::const_iterator stop = m_submatrix[i]->end();
406 for (; entry != stop; ++entry)
408 const IndexType row = entry->first.first + row_offset;
409 const IndexType col = entry->first.second + col_offset;
410 const int gridRow = row / blockSize;
411 const int gridCol = col / blockSize;
412 grid[gridRow][gridCol]++;
414 row_offset += m_submatrix[i]->GetRows();
415 col_offset += m_submatrix[i]->GetColumns();
418 for (
int row = 0; row < gridRows; row++)
420 for (
int col = 0; col < gridCols; col++)
422 out << grid[row][col] <<
" ";
434template <
typename SparseStorageType>
442 blockSize = (std::min)(blockSize, m_submatrix[subMatrixIdx]->GetRows());
443 std::vector<std::vector<int>> grid(blockSize);
444 for (
int row = 0; row < blockSize; row++)
446 grid[row].resize(blockSize, 0.0);
449 typename SparseStorageType::const_iterator entry =
450 m_submatrix[subMatrixIdx]->begin();
451 typename SparseStorageType::const_iterator stop =
452 m_submatrix[subMatrixIdx]->end();
453 for (; entry != stop; ++entry)
455 const IndexType row = entry->first.first;
456 const IndexType col = entry->first.second;
458 if (blk_row != row / blockSize)
460 if (blk_col != col / blockSize)
462 grid[row % blockSize][col % blockSize]++;
465 for (
int row = 0; row < blockSize; row++)
467 for (
int col = 0; col < blockSize; col++)
469 out << grid[row][col] <<
" ";
475template <
typename SparseStorageType>
480 blockSize = (std::min)(blockSize, GetRows());
481 std::vector<std::vector<int>> grid(blockSize);
482 for (
int row = 0; row < blockSize; row++)
484 grid[row].resize(blockSize, 0.0);
489 for (
int i = 0; i < m_submatrix.size(); i++)
491 typename SparseStorageType::const_iterator entry =
492 m_submatrix[i]->begin();
493 typename SparseStorageType::const_iterator stop = m_submatrix[i]->end();
494 for (; entry != stop; ++entry)
496 const IndexType row = entry->first.first + row_offset;
497 const IndexType col = entry->first.second + col_offset;
499 if (blk_row != row / blockSize)
501 if (blk_col != col / blockSize)
503 grid[row % blockSize][col % blockSize]++;
505 row_offset += m_submatrix[i]->GetRows();
506 col_offset += m_submatrix[i]->GetColumns();
509 for (
int row = 0; row < blockSize; row++)
511 for (
int col = 0; col < blockSize; col++)
513 out << grid[row][col] <<
" ";
SparseStorageType::DataType DataType
IndexType GetRows() const
COOMatTypeSharedPtr GetCooStorage()
IndexType GetNumberOfMatrixBlocks() const
std::shared_ptr< SparseStorageType > SparseStorageSharedPtr
void MultiplySubMatrix(const IndexType blockNum, DataType *in, DataType *out)
void writeSubmatrixBlockSparsityPatternTo(std::ostream &out, const IndexType subMatrixIdx, 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 en...
IndexType GetColumns() const
size_t GetMemoryFootprint()
unsigned long GetMulCallsCounter() const
~NekSparseDiagBlkMatrix()
void writeSubmatrixSparsityPatternTo(std::ostream &out, const IndexType subMatrixIdx, IndexType blockSize=64)
void writeSparsityPatternTo(std::ostream &out, IndexType blockSize=64)
DataType GetFillInRatio() const
void Multiply(const DataVectorType &in, DataVectorType &out)
void writeBlockSparsityPatternTo(std::ostream &out, const IndexType blk_row=0, const IndexType blk_col=0, IndexType blockSize=64)
IndexType GetNumNonZeroEntries()
NekSparseDiagBlkMatrix(const SparseStorageSharedPtrVector &sparseStoragePtrVector)
boost::call_traits< DataType >::const_reference operator()(const IndexType row, const IndexType column) const
The above copyright notice and this permission notice shall be included.
Array< OneD, IndexType > IndexVector
std::shared_ptr< COOMatType > COOMatTypeSharedPtr
std::map< CoordType, NekDouble > COOMatType
scalarT< T > abs(scalarT< T > in)