51 template <
typename SparseStorageType>
54 : m_rows(0), m_cols(0), m_rowoffset(sparseStoragePtrVector.size() + 1, 0.0),
56 m_submatrix(sparseStoragePtrVector.size(), sparseStoragePtrVector)
58 for (
int i = 0; i < sparseStoragePtrVector.size(); i++)
60 const IndexType rows = sparseStoragePtrVector[i]->GetRows();
62 m_cols += sparseStoragePtrVector[i]->GetColumns();
67 template <
typename SparseStorageType>
70 : m_rows(src.m_rows), m_cols(src.m_cols), m_rowoffset(src.m_rowoffset),
71 m_mulCallsCounter(src.m_mulCallsCounter), m_submatrix(src.m_submatrix)
75 template <
typename SparseStorageType>
80 template <
typename SparseStorageType>
86 template <
typename SparseStorageType>
93 template <
typename SparseStorageType>
96 return m_submatrix[i]->GetRows();
100 template <
typename SparseStorageType>
103 return m_submatrix[i]->GetColumns();
106 template <
typename SparseStorageType>
110 return m_submatrix.size();
113 template <
typename SparseStorageType>
117 for (
int i = 0; i < m_submatrix.size(); i++)
119 nnz += m_submatrix[i]->GetNumNonZeroEntries();
125 template <
typename SparseStorageType>
129 return m_submatrix[i]->GetNumNonZeroEntries();
132 template <
typename SparseStorageType>
134 SparseStorageType>::GetFillInRatio(
int i)
const
139 template <
typename SparseStorageType>
141 SparseStorageType>::GetFillInRatio()
const
145 for (
int i = 0; i < m_submatrix.size(); i++)
147 stored += m_submatrix[i]->GetNumStoredDoubles();
153 template <
typename SparseStorageType>
154 typename boost::call_traits<
155 typename SparseStorageType::DataType>::const_reference
159 return m_submatrix[block]->GetValue(loc_row, loc_column);
162 template <
typename SparseStorageType>
163 typename boost::call_traits<
164 typename SparseStorageType::DataType>::const_reference
169 static DataType defaultReturnValue = 0;
171 signed int local_row = glob_row;
172 signed int local_col = glob_column;
174 while ((local_row >= m_submatrix[i]->GetRows()) && (local_col >= 0))
176 local_row -= m_submatrix[i]->GetRows();
177 local_col -= m_submatrix[i]->GetColumns();
182 return defaultReturnValue;
184 return m_submatrix[i]->GetValue(local_row, local_col);
187 template <
typename SparseStorageType>
191 for (
int i = 0; i < m_submatrix.size(); ++i)
193 m_submatrix[i]->Multiply(&in[m_rowoffset[i]], &out[m_rowoffset[i]]);
198 template <
typename SparseStorageType>
202 for (
int i = 0; i < m_submatrix.size(); ++i)
204 m_submatrix[i]->Multiply(&in[m_rowoffset[i]], &out[m_rowoffset[i]]);
209 template <
typename SparseStorageType>
213 m_submatrix[blockNum]->Multiply(in + m_rowoffset[blockNum],
214 out + m_rowoffset[blockNum]);
218 template <
typename SparseStorageType>
222 sizeof(
unsigned long) +
224 sizeof(
IndexType) * m_rowoffset.capacity() +
227 for (
int i = 0; i < m_submatrix.size(); i++)
229 bytes += m_submatrix[i]->GetMemoryUsage();
234 template <
typename SparseStorageType>
238 return m_submatrix[i]->GetMemoryUsage();
241 template <
typename SparseStorageType>
245 return m_mulCallsCounter;
248 template <
typename SparseStorageType>
250 SparseStorageType>::GetAvgRowDensity()
253 for (
int i = 0; i < m_submatrix.size(); i++)
255 avgRowDensity += (
DataType)m_submatrix[i]->GetNumNonZeroEntries() /
256 (
DataType)m_submatrix[i]->GetRows();
258 return avgRowDensity / m_submatrix.size();
261 template <
typename SparseStorageType>
266 (
DataType)m_submatrix[i]->GetRows();
269 template <
typename SparseStorageType>
273 for (
int i = 0; i < m_submatrix.size(); i++)
275 typename SparseStorageType::const_iterator entry =
276 m_submatrix[i]->begin();
277 for (; entry != m_submatrix[i]->end(); ++entry)
280 (std::max)(
static_cast<int>(bandwidth),
281 2 *
abs(
static_cast<int>(entry->first.first -
282 entry->first.second) +
289 template <
typename SparseStorageType>
293 typename SparseStorageType::const_iterator entry = m_submatrix[i]->begin();
294 for (; entry != m_submatrix[i]->end(); ++entry)
296 bandwidth = (std::max)(
297 static_cast<int>(bandwidth),
298 2 *
abs(
static_cast<int>(entry->first.first - entry->first.second) +
304 template <
typename SparseStorageType>
309 typename SparseStorageType::const_iterator entry = m_submatrix[i]->begin();
310 for (; entry != m_submatrix[i]->end(); entry++)
314 (*coo)[std::make_pair(loc_row, loc_col)] = entry->second;
319 template <
typename SparseStorageType>
325 for (
IndexType i = 0; i < m_submatrix.size(); i++)
327 typename SparseStorageType::const_iterator entry =
328 m_submatrix[i]->begin();
329 for (; entry != m_submatrix[i]->end(); entry++)
333 (*coo)[std::make_pair(loc_row + row_offset, loc_col + col_offset)] =
336 row_offset += m_submatrix[i]->GetRows();
337 col_offset += m_submatrix[i]->GetColumns();
349 template <
typename SparseStorageType>
353 const int matRows = m_submatrix[subMatrixIdx]->GetRows();
354 const int gridRows = matRows / blockSize + (matRows % blockSize > 0);
355 const int gridCols = gridRows;
357 std::vector<std::vector<int>> grid(gridRows);
358 for (
int row = 0; row < gridRows; row++)
360 grid[row].resize(gridCols, 0.0);
363 typename SparseStorageType::const_iterator entry =
364 m_submatrix[subMatrixIdx]->begin();
365 typename SparseStorageType::const_iterator stop =
366 m_submatrix[subMatrixIdx]->end();
367 for (; entry != stop; ++entry)
369 const IndexType row = entry->first.first;
370 const IndexType col = entry->first.second;
371 const int gridRow = row / blockSize;
372 const int gridCol = col / blockSize;
373 grid[gridRow][gridCol]++;
376 for (
int row = 0; row < gridRows; row++)
378 for (
int col = 0; col < gridCols; col++)
380 out << grid[row][col] <<
" ";
386 template <
typename SparseStorageType>
388 std::ostream &out,
const IndexType blockSize)
390 const int matRows = GetRows();
391 const int gridRows = matRows / blockSize + (matRows % blockSize > 0);
392 const int gridCols = gridRows;
394 std::vector<std::vector<int>> grid(gridRows);
395 for (
int row = 0; row < gridRows; row++)
397 grid[row].resize(gridCols, 0.0);
402 for (
int i = 0; i < m_submatrix.size(); i++)
404 typename SparseStorageType::const_iterator entry =
405 m_submatrix[i]->begin();
406 typename SparseStorageType::const_iterator stop = m_submatrix[i]->end();
407 for (; entry != stop; ++entry)
409 const IndexType row = entry->first.first + row_offset;
410 const IndexType col = entry->first.second + col_offset;
411 const int gridRow = row / blockSize;
412 const int gridCol = col / blockSize;
413 grid[gridRow][gridCol]++;
415 row_offset += m_submatrix[i]->GetRows();
416 col_offset += m_submatrix[i]->GetColumns();
419 for (
int row = 0; row < gridRows; row++)
421 for (
int col = 0; col < gridCols; col++)
423 out << grid[row][col] <<
" ";
435 template <
typename SparseStorageType>
443 blockSize = (std::min)(blockSize, m_submatrix[subMatrixIdx]->GetRows());
444 std::vector<std::vector<int>> grid(blockSize);
445 for (
int row = 0; row < blockSize; row++)
447 grid[row].resize(blockSize, 0.0);
450 typename SparseStorageType::const_iterator entry =
451 m_submatrix[subMatrixIdx]->begin();
452 typename SparseStorageType::const_iterator stop =
453 m_submatrix[subMatrixIdx]->end();
454 for (; entry != stop; ++entry)
456 const IndexType row = entry->first.first;
457 const IndexType col = entry->first.second;
459 if (blk_row != row / blockSize)
461 if (blk_col != col / blockSize)
463 grid[row % blockSize][col % blockSize]++;
466 for (
int row = 0; row < blockSize; row++)
468 for (
int col = 0; col < blockSize; col++)
470 out << grid[row][col] <<
" ";
476 template <
typename SparseStorageType>
481 blockSize = (std::min)(blockSize, GetRows());
482 std::vector<std::vector<int>> grid(blockSize);
483 for (
int row = 0; row < blockSize; row++)
485 grid[row].resize(blockSize, 0.0);
490 for (
int i = 0; i < m_submatrix.size(); i++)
492 typename SparseStorageType::const_iterator entry =
493 m_submatrix[i]->begin();
494 typename SparseStorageType::const_iterator stop = m_submatrix[i]->end();
495 for (; entry != stop; ++entry)
497 const IndexType row = entry->first.first + row_offset;
498 const IndexType col = entry->first.second + col_offset;
500 if (blk_row != row / blockSize)
502 if (blk_col != col / blockSize)
504 grid[row % blockSize][col % blockSize]++;
506 row_offset += m_submatrix[i]->GetRows();
507 col_offset += m_submatrix[i]->GetColumns();
510 for (
int row = 0; row < blockSize; row++)
512 for (
int col = 0; col < blockSize; col++)
514 out << grid[row][col] <<
" ";
SparseStorageType::DataType DataType
IndexType GetRows() const
COOMatTypeSharedPtr GetCooStorage()
boost::call_traits< DataType >::const_reference operator()(const IndexType row, const IndexType column) const
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)
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)