52 template <
typename SparseStorageType>
55 : m_rows(0), m_cols(0), m_rowoffset(sparseStoragePtrVector.size() + 1, 0.0),
57 m_submatrix(sparseStoragePtrVector.size(), sparseStoragePtrVector)
59 for (
int i = 0; i < sparseStoragePtrVector.size(); i++)
61 const IndexType rows = sparseStoragePtrVector[i]->GetRows();
63 m_cols += sparseStoragePtrVector[i]->GetColumns();
68 template <
typename SparseStorageType>
71 : m_rows(src.m_rows), m_cols(src.m_cols), m_rowoffset(src.m_rowoffset),
72 m_mulCallsCounter(src.m_mulCallsCounter), m_submatrix(src.m_submatrix)
76 template <
typename SparseStorageType>
81 template <
typename SparseStorageType>
87 template <
typename SparseStorageType>
94 template <
typename SparseStorageType>
97 return m_submatrix[i]->GetRows();
101 template <
typename SparseStorageType>
104 return m_submatrix[i]->GetColumns();
107 template <
typename SparseStorageType>
111 return m_submatrix.size();
114 template <
typename SparseStorageType>
118 for (
int i = 0; i < m_submatrix.size(); i++)
120 nnz += m_submatrix[i]->GetNumNonZeroEntries();
126 template <
typename SparseStorageType>
130 return m_submatrix[i]->GetNumNonZeroEntries();
133 template <
typename SparseStorageType>
135 SparseStorageType>::GetFillInRatio(
int i)
const
140 template <
typename SparseStorageType>
142 SparseStorageType>::GetFillInRatio()
const
146 for (
int i = 0; i < m_submatrix.size(); i++)
148 stored += m_submatrix[i]->GetNumStoredDoubles();
154 template <
typename SparseStorageType>
155 typename boost::call_traits<
156 typename SparseStorageType::DataType>::const_reference
160 return m_submatrix[block]->GetValue(loc_row, loc_column);
163 template <
typename SparseStorageType>
164 typename boost::call_traits<
165 typename SparseStorageType::DataType>::const_reference
170 static DataType defaultReturnValue = 0;
172 signed int local_row = glob_row;
173 signed int local_col = glob_column;
175 while ((local_row >= m_submatrix[i]->GetRows()) && (local_col >= 0))
177 local_row -= m_submatrix[i]->GetRows();
178 local_col -= m_submatrix[i]->GetColumns();
183 return defaultReturnValue;
185 return m_submatrix[i]->GetValue(local_row, local_col);
188 template <
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]]);
199 template <
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]]);
210 template <
typename SparseStorageType>
214 m_submatrix[blockNum]->Multiply(in + m_rowoffset[blockNum],
215 out + m_rowoffset[blockNum]);
219 template <
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();
235 template <
typename SparseStorageType>
239 return m_submatrix[i]->GetMemoryUsage();
242 template <
typename SparseStorageType>
246 return m_mulCallsCounter;
249 template <
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();
262 template <
typename SparseStorageType>
267 (
DataType)m_submatrix[i]->GetRows();
270 template <
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) +
290 template <
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) +
305 template <
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;
320 template <
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();
350 template <
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] <<
" ";
387 template <
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] <<
" ";
436 template <
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)
462 if (blk_col != col / blockSize)
464 grid[row % blockSize][col % blockSize]++;
467 for (
int row = 0; row < blockSize; row++)
469 for (
int col = 0; col < blockSize; col++)
471 out << grid[row][col] <<
" ";
477 template <
typename SparseStorageType>
482 blockSize = (std::min)(blockSize, GetRows());
483 std::vector<std::vector<int>> grid(blockSize);
484 for (
int row = 0; row < blockSize; row++)
486 grid[row].resize(blockSize, 0.0);
491 for (
int i = 0; i < m_submatrix.size(); i++)
493 typename SparseStorageType::const_iterator entry =
494 m_submatrix[i]->begin();
495 typename SparseStorageType::const_iterator stop = m_submatrix[i]->end();
496 for (; entry != stop; ++entry)
498 const IndexType row = entry->first.first + row_offset;
499 const IndexType col = entry->first.second + col_offset;
501 if (blk_row != row / blockSize)
503 if (blk_col != col / blockSize)
505 grid[row % blockSize][col % blockSize]++;
507 row_offset += m_submatrix[i]->GetRows();
508 col_offset += m_submatrix[i]->GetColumns();
511 for (
int row = 0; row < blockSize; row++)
513 for (
int col = 0; col < blockSize; col++)
515 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)