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();
182 return defaultReturnValue;
185 return m_submatrix[i]->GetValue(local_row, local_col);
188template <
typename SparseStorageType>
192 for (
int i = 0; i < m_submatrix.size(); ++i)
194 m_submatrix[i]->Multiply(&in[m_rowoffset[i]], &out[m_rowoffset[i]]);
199template <
typename SparseStorageType>
203 for (
int i = 0; i < m_submatrix.size(); ++i)
205 m_submatrix[i]->Multiply(&in[m_rowoffset[i]], &out[m_rowoffset[i]]);
210template <
typename SparseStorageType>
214 m_submatrix[blockNum]->Multiply(in + m_rowoffset[blockNum],
215 out + m_rowoffset[blockNum]);
219template <
typename SparseStorageType>
223 sizeof(
unsigned long) +
225 sizeof(
IndexType) * m_rowoffset.capacity() +
228 for (
int i = 0; i < m_submatrix.size(); i++)
230 bytes += m_submatrix[i]->GetMemoryUsage();
235template <
typename SparseStorageType>
239 return m_submatrix[i]->GetMemoryUsage();
242template <
typename SparseStorageType>
246 return m_mulCallsCounter;
249template <
typename SparseStorageType>
251 SparseStorageType>::GetAvgRowDensity()
254 for (
int i = 0; i < m_submatrix.size(); i++)
256 avgRowDensity += (
DataType)m_submatrix[i]->GetNumNonZeroEntries() /
257 (
DataType)m_submatrix[i]->GetRows();
259 return avgRowDensity / m_submatrix.size();
262template <
typename SparseStorageType>
267 (
DataType)m_submatrix[i]->GetRows();
270template <
typename SparseStorageType>
274 for (
int i = 0; i < m_submatrix.size(); i++)
276 typename SparseStorageType::const_iterator entry =
277 m_submatrix[i]->begin();
278 for (; entry != m_submatrix[i]->end(); ++entry)
281 (std::max)(
static_cast<int>(bandwidth),
282 2 *
abs(
static_cast<int>(entry->first.first -
283 entry->first.second) +
290template <
typename SparseStorageType>
294 typename SparseStorageType::const_iterator entry = m_submatrix[i]->begin();
295 for (; entry != m_submatrix[i]->end(); ++entry)
297 bandwidth = (std::max)(
298 static_cast<int>(bandwidth),
299 2 *
abs(
static_cast<int>(entry->first.first - entry->first.second) +
305template <
typename SparseStorageType>
310 typename SparseStorageType::const_iterator entry = m_submatrix[i]->begin();
311 for (; entry != m_submatrix[i]->end(); entry++)
315 (*coo)[std::make_pair(loc_row, loc_col)] = entry->second;
320template <
typename SparseStorageType>
326 for (
IndexType i = 0; i < m_submatrix.size(); i++)
328 typename SparseStorageType::const_iterator entry =
329 m_submatrix[i]->begin();
330 for (; entry != m_submatrix[i]->end(); entry++)
334 (*coo)[std::make_pair(loc_row + row_offset, loc_col + col_offset)] =
337 row_offset += m_submatrix[i]->GetRows();
338 col_offset += m_submatrix[i]->GetColumns();
350template <
typename SparseStorageType>
354 const int matRows = m_submatrix[subMatrixIdx]->GetRows();
355 const int gridRows = matRows / blockSize + (matRows % blockSize > 0);
356 const int gridCols = gridRows;
358 std::vector<std::vector<int>> grid(gridRows);
359 for (
int row = 0; row < gridRows; row++)
361 grid[row].resize(gridCols, 0.0);
364 typename SparseStorageType::const_iterator entry =
365 m_submatrix[subMatrixIdx]->begin();
366 typename SparseStorageType::const_iterator stop =
367 m_submatrix[subMatrixIdx]->end();
368 for (; entry != stop; ++entry)
370 const IndexType row = entry->first.first;
371 const IndexType col = entry->first.second;
372 const int gridRow = row / blockSize;
373 const int gridCol = col / blockSize;
374 grid[gridRow][gridCol]++;
377 for (
int row = 0; row < gridRows; row++)
379 for (
int col = 0; col < gridCols; col++)
381 out << grid[row][col] <<
" ";
387template <
typename SparseStorageType>
389 std::ostream &out,
const IndexType blockSize)
391 const int matRows = GetRows();
392 const int gridRows = matRows / blockSize + (matRows % blockSize > 0);
393 const int gridCols = gridRows;
395 std::vector<std::vector<int>> grid(gridRows);
396 for (
int row = 0; row < gridRows; row++)
398 grid[row].resize(gridCols, 0.0);
403 for (
int i = 0; i < m_submatrix.size(); i++)
405 typename SparseStorageType::const_iterator entry =
406 m_submatrix[i]->begin();
407 typename SparseStorageType::const_iterator stop = m_submatrix[i]->end();
408 for (; entry != stop; ++entry)
410 const IndexType row = entry->first.first + row_offset;
411 const IndexType col = entry->first.second + col_offset;
412 const int gridRow = row / blockSize;
413 const int gridCol = col / blockSize;
414 grid[gridRow][gridCol]++;
416 row_offset += m_submatrix[i]->GetRows();
417 col_offset += m_submatrix[i]->GetColumns();
420 for (
int row = 0; row < gridRows; row++)
422 for (
int col = 0; col < gridCols; col++)
424 out << grid[row][col] <<
" ";
436template <
typename SparseStorageType>
444 blockSize = (std::min)(blockSize, m_submatrix[subMatrixIdx]->GetRows());
445 std::vector<std::vector<int>> grid(blockSize);
446 for (
int row = 0; row < blockSize; row++)
448 grid[row].resize(blockSize, 0.0);
451 typename SparseStorageType::const_iterator entry =
452 m_submatrix[subMatrixIdx]->begin();
453 typename SparseStorageType::const_iterator stop =
454 m_submatrix[subMatrixIdx]->end();
455 for (; entry != stop; ++entry)
457 const IndexType row = entry->first.first;
458 const IndexType col = entry->first.second;
460 if (blk_row != row / blockSize)
464 if (blk_col != col / blockSize)
468 grid[row % blockSize][col % blockSize]++;
471 for (
int row = 0; row < blockSize; row++)
473 for (
int col = 0; col < blockSize; col++)
475 out << grid[row][col] <<
" ";
481template <
typename SparseStorageType>
486 blockSize = (std::min)(blockSize, GetRows());
487 std::vector<std::vector<int>> grid(blockSize);
488 for (
int row = 0; row < blockSize; row++)
490 grid[row].resize(blockSize, 0.0);
495 for (
int i = 0; i < m_submatrix.size(); i++)
497 typename SparseStorageType::const_iterator entry =
498 m_submatrix[i]->begin();
499 typename SparseStorageType::const_iterator stop = m_submatrix[i]->end();
500 for (; entry != stop; ++entry)
502 const IndexType row = entry->first.first + row_offset;
503 const IndexType col = entry->first.second + col_offset;
505 if (blk_row != row / blockSize)
509 if (blk_col != col / blockSize)
513 grid[row % blockSize][col % blockSize]++;
515 row_offset += m_submatrix[i]->GetRows();
516 col_offset += m_submatrix[i]->GetColumns();
519 for (
int row = 0; row < blockSize; row++)
521 for (
int col = 0; col < blockSize; col++)
523 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
Array< OneD, IndexType > IndexVector
std::shared_ptr< COOMatType > COOMatTypeSharedPtr
std::map< CoordType, NekDouble > COOMatType
scalarT< T > abs(scalarT< T > in)