51 template<
typename SparseStorageType>
54 sparseStoragePtrVector):
57 m_rowoffset(sparseStoragePtrVector.size()+1, 0.0),
59 m_submatrix(sparseStoragePtrVector.size(),sparseStoragePtrVector)
61 for (
int i = 0; i < sparseStoragePtrVector.size(); i++)
63 const IndexType rows = sparseStoragePtrVector[i]->GetRows();
65 m_cols += sparseStoragePtrVector[i]->GetColumns();
70 template<
typename SparseStorageType>
74 m_rowoffset(src.m_rowoffset),
75 m_mulCallsCounter(src.m_mulCallsCounter),
76 m_submatrix(src.m_submatrix)
80 template<
typename SparseStorageType>
85 template<
typename SparseStorageType>
91 template<
typename SparseStorageType>
98 template<
typename SparseStorageType>
101 return m_submatrix[i]->GetRows();
105 template<
typename SparseStorageType>
108 return m_submatrix[i]->GetColumns();
111 template<
typename SparseStorageType>
114 return m_submatrix.size();
117 template<
typename SparseStorageType>
121 for (
int i = 0; i < m_submatrix.size(); i++)
123 nnz += m_submatrix[i]->GetNumNonZeroEntries();
129 template<
typename SparseStorageType>
132 return m_submatrix[i]->GetNumNonZeroEntries();
135 template<
typename SparseStorageType>
138 return m_submatrix[i]->GetFillInRatio();
141 template<
typename SparseStorageType>
146 for (
int i = 0; i < m_submatrix.size(); i++)
148 stored += m_submatrix[i]->GetNumStoredDoubles();
149 nnz += m_submatrix[i]->GetNumNonZeroEntries();
155 template<
typename SparseStorageType>
158 return m_submatrix[block]->GetValue(loc_row, loc_column);
161 template<
typename SparseStorageType>
162 typename boost::call_traits<typename SparseStorageType::DataType>::const_reference
167 static DataType defaultReturnValue = 0;
169 signed int local_row = glob_row;
170 signed int local_col = glob_column;
172 while ((local_row >= m_submatrix[i]->GetRows()) &&
175 local_row -= m_submatrix[i]->
GetRows();
176 local_col -= m_submatrix[i]->GetColumns();
180 if (local_col < 0)
return defaultReturnValue;
182 return m_submatrix[i]->GetValue(local_row, local_col);
186 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>
215 m_submatrix[blockNum]->Multiply(in + m_rowoffset[blockNum], out + m_rowoffset[blockNum]);
219 template<
typename SparseStorageType>
224 sizeof(
unsigned long) +
226 sizeof(
IndexType)*m_rowoffset.capacity() +
229 for (
int i = 0; i < m_submatrix.size(); i++)
231 bytes += m_submatrix[i]->GetMemoryUsage();
236 template<
typename SparseStorageType>
239 return m_submatrix[i]->GetMemoryUsage();
242 template<
typename SparseStorageType>
245 return m_mulCallsCounter;
248 template<
typename SparseStorageType>
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();
260 template<
typename SparseStorageType>
263 return (
DataType) m_submatrix[i]->GetNumNonZeroEntries() /
264 (
DataType) m_submatrix[i]->GetRows();
267 template<
typename SparseStorageType>
271 for (
int i = 0; i < m_submatrix.size(); i++)
273 typename SparseStorageType::const_iterator entry = m_submatrix[i]->begin();
274 for (; entry != m_submatrix[i]->end(); ++entry)
276 bandwidth = (std::max)(
static_cast<int>(bandwidth),
277 2*
abs(
static_cast<int>(entry->first.first - entry->first.second)+1));
283 template<
typename SparseStorageType>
287 typename SparseStorageType::const_iterator entry = m_submatrix[i]->begin();
288 for (; entry != m_submatrix[i]->end(); ++entry)
290 bandwidth = (std::max)(
static_cast<int>(bandwidth),
291 2*
abs(
static_cast<int>(entry->first.first - entry->first.second)+1));
296 template<
typename SparseStorageType>
300 typename SparseStorageType::const_iterator entry = m_submatrix[i]->begin();
301 for (; entry != m_submatrix[i]->end(); entry++)
305 (*coo)[std::make_pair(loc_row, loc_col) ] = entry->second;
310 template<
typename SparseStorageType>
316 for (
IndexType i = 0; i < m_submatrix.size(); i++)
318 typename SparseStorageType::const_iterator entry = m_submatrix[i]->begin();
319 for (; entry != m_submatrix[i]->end(); entry++)
323 (*coo)[std::make_pair(loc_row + row_offset, loc_col + col_offset) ] = entry->second;
325 row_offset += m_submatrix[i]->GetRows();
326 col_offset += m_submatrix[i]->GetColumns();
338 template<
typename SparseStorageType>
344 const int matRows = m_submatrix[subMatrixIdx]->GetRows();
345 const int gridRows = matRows / blockSize + (matRows % blockSize > 0);
346 const int gridCols = gridRows;
348 std::vector< std::vector<int> > grid (gridRows);
349 for (
int row = 0; row < gridRows; row++)
351 grid[row].resize(gridCols,0.0);
354 typename SparseStorageType::const_iterator entry =
355 m_submatrix[subMatrixIdx]->begin();
356 typename SparseStorageType::const_iterator stop =
357 m_submatrix[subMatrixIdx]->end();
358 for (; entry != stop; ++entry)
360 const IndexType row = entry->first.first;
361 const IndexType col = entry->first.second;
362 const int gridRow = row / blockSize;
363 const int gridCol = col / blockSize;
364 grid[gridRow][gridCol]++;
367 for (
int row = 0; row < gridRows; row++)
369 for (
int col = 0; col < gridCols; col++)
371 out << grid[row][col] <<
" ";
377 template<
typename SparseStorageType>
382 const int matRows = GetRows();
383 const int gridRows = matRows / blockSize + (matRows % blockSize > 0);
384 const int gridCols = gridRows;
386 std::vector< std::vector<int> > grid (gridRows);
387 for (
int row = 0; row < gridRows; row++)
389 grid[row].resize(gridCols,0.0);
394 for (
int i = 0; i < m_submatrix.size(); i++)
396 typename SparseStorageType::const_iterator entry = m_submatrix[i]->begin();
397 typename SparseStorageType::const_iterator stop = m_submatrix[i]->end();
398 for (; entry != stop; ++entry)
400 const IndexType row = entry->first.first + row_offset;
401 const IndexType col = entry->first.second + col_offset;
402 const int gridRow = row / blockSize;
403 const int gridCol = col / blockSize;
404 grid[gridRow][gridCol]++;
406 row_offset += m_submatrix[i]->GetRows();
407 col_offset += m_submatrix[i]->GetColumns();
410 for (
int row = 0; row < gridRows; row++)
412 for (
int col = 0; col < gridCols; col++)
414 out << grid[row][col] <<
" ";
426 template<
typename SparseStorageType>
434 blockSize = (std::min)(blockSize, m_submatrix[subMatrixIdx]->GetRows());
435 std::vector< std::vector<int> > grid (blockSize);
436 for (
int row = 0; row < blockSize; row++)
438 grid[row].resize(blockSize,0.0);
441 typename SparseStorageType::const_iterator entry =
442 m_submatrix[subMatrixIdx]->begin();
443 typename SparseStorageType::const_iterator stop =
444 m_submatrix[subMatrixIdx]->end();
445 for (; entry != stop; ++entry)
447 const IndexType row = entry->first.first;
448 const IndexType col = entry->first.second;
450 if (blk_row != row / blockSize )
continue;
451 if (blk_col != col / blockSize )
continue;
452 grid[row % blockSize][col % blockSize]++;
455 for (
int row = 0; row < blockSize; row++)
457 for (
int col = 0; col < blockSize; col++)
459 out << grid[row][col] <<
" ";
465 template<
typename SparseStorageType>
472 blockSize = (std::min)(blockSize, GetRows());
473 std::vector< std::vector<int> > grid (blockSize);
474 for (
int row = 0; row < blockSize; row++)
476 grid[row].resize(blockSize,0.0);
481 for (
int i = 0; i < m_submatrix.size(); i++)
483 typename SparseStorageType::const_iterator entry =
484 m_submatrix[i]->begin();
485 typename SparseStorageType::const_iterator stop =
486 m_submatrix[i]->end();
487 for (; entry != stop; ++entry)
489 const IndexType row = entry->first.first + row_offset;
490 const IndexType col = entry->first.second + col_offset;
492 if (blk_row != row / blockSize )
continue;
493 if (blk_col != col / blockSize )
continue;
494 grid[row % blockSize][col % blockSize]++;
496 row_offset += m_submatrix[i]->GetRows();
497 col_offset += m_submatrix[i]->GetColumns();
500 for (
int row = 0; row < blockSize; row++)
502 for (
int col = 0; col < blockSize; col++)
504 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
DataType GetAvgRowDensity()
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)