const BlockVector<somenumber> &src) const;
+ /**
+ * Print statistics. If @p{full}
+ * is @p{true}, prints a
+ * histogram of all existing row
+ * lengths and allocated row
+ * lengths. Otherwise, just the
+ * relation of allocated and used
+ * entries is shown.
+ */
+ template <class STREAM>
+ void print_statistics (STREAM& s, bool full = false);
+
private:
/**
* Object storing and managing
}
+template <typename number>
+template <class STREAM>
+inline
+void
+BlockSparseMatrixEZ<number>::print_statistics(STREAM& out, bool full)
+{
+ unsigned int used_total = 0;
+ unsigned int allocated_total = 0;
+ unsigned int reserved_total = 0;
+ std::vector<unsigned int> used_by_line_total;
+
+ unsigned int used;
+ unsigned int allocated;
+ unsigned int reserved;
+ std::vector<unsigned int> used_by_line;
+
+ for (unsigned int i=0;i<n_block_rows();++i)
+ for (unsigned int j=0;j<n_block_cols();++j)
+ {
+ used_by_line.clear();
+ out << "block:\t" << i << '\t' << j << std::endl;
+ block(i,j).compute_statistics (used, allocated, reserved,
+ used_by_line, full);
+
+ out << "used:" << used << std::endl
+ << "allocated:" << allocated << std::endl
+ << "reserved:" << reserved << std::endl;
+
+ used_total += used;
+ allocated_total += allocated;
+ reserved_total += reserved;
+
+ if (full)
+ {
+ used_by_line_total.resize(used_by_line.size());
+ for (unsigned int i=0; i< used_by_line.size();++i)
+ if (used_by_line[i] != 0)
+ {
+ out << "row-entries\t" << i
+ << "\trows\t" << used_by_line[i]
+ << std::endl;
+ used_by_line_total[i] += used_by_line[i];
+ }
+ }
+ }
+ out << "Total" << std::endl
+ << "used:" << used_total << std::endl
+ << "allocated:" << allocated_total << std::endl
+ << "reserved:" << reserved_total << std::endl;
+ for (unsigned int i=0; i< used_by_line_total.size();++i)
+ if (used_by_line_total[i] != 0)
+ {
+ out << "row-entries\t" << i
+ << "\trows\t" << used_by_line_total[i]
+ << std::endl;
+ }
+}
+
+
#endif //__deal2__block_sparse_matrix_ez_h
* The matrix will have no
* entries at this point. The
* optional parameters
- * @p{default_row_length} and
- * @p{default_increment} allow
+ * @p{default_row_length},
+ * @p{default_increment} and
+ * @p{reserve} allow
* for preallocating
* memory. Providing these
* properly is essential for an
void reinit (const unsigned int n_rows,
const unsigned int n_columns,
unsigned int default_row_length = 0,
- unsigned int default_increment = 1);
+ unsigned int default_increment = 1,
+ unsigned int reserve = 0);
/**
* Release all memory and return
*/
template <class STREAM>
void print_statistics (STREAM& s, bool full = false);
-
+
+ /**
+ * Compute numbers of entries.
+ *
+ * In the first three arguments,
+ * this function returns the
+ * number of entries used,
+ * allocated and reserved by this
+ * matrix.
+ *
+ * If the final argument is true,
+ * the number of entries in each
+ * line is printed as well.
+ */
+ void compute_statistics (unsigned int& used,
+ unsigned int& allocated,
+ unsigned int& reserved,
+ std::vector<unsigned int>& used_by_line,
+ const bool compute_by_line) const;
+
/**
* Exception for applying
* inverse-type operators to
}
+template <typename number>
+template <class STREAM>
+inline
+void
+SparseMatrixEZ<number>::print_statistics(STREAM& out, bool full)
+{
+ unsigned int used;
+ unsigned int allocated;
+ unsigned int reserved;
+ std::vector<unsigned int> used_by_line;
+
+ compute_statistics (used, allocated, reserved, used_by_line, full);
+
+ out << "SparseMatrixEZ:used entries:" << used << std::endl
+ << "SparseMatrixEZ:allocated entries:" << allocated << std::endl
+ << "SparseMatrixEZ:reserved entries:" << reserved << std::endl;
+
+ if (full)
+ {
+ for (unsigned int i=0; i< used_by_line.size();++i)
+ if (used_by_line[i] != 0)
+ out << "SparseMatrixEZ:entries\t" << i
+ << "\trows\t" << used_by_line[i]
+ << std::endl;
+
+ }
+}
+
+
#endif
/*---------------------------- sparse_matrix.h ---------------------------*/
SparseMatrixEZ<number>::reinit(const unsigned int n_rows,
const unsigned int n_cols,
unsigned int default_row_length,
- unsigned int default_increment)
+ unsigned int default_increment,
+ unsigned int reserve)
{
clear();
n_columns = n_cols;
row_info.resize(n_rows);
-//TODO:[GK] allow for flexible memory reservation in later version
- data.reserve(default_row_length * n_rows + n_rows * increment);
+ if (reserve != 0)
+ data.reserve(reserve);
data.resize(default_row_length * n_rows);
for (unsigned int i=0;i<n_rows;++i)
template <typename number>
-template <class STREAM>
void
-SparseMatrixEZ<number>::print_statistics(STREAM& out, bool full)
+SparseMatrixEZ<number>::compute_statistics(
+ unsigned int& used,
+ unsigned int& allocated,
+ unsigned int& reserved,
+ std::vector<unsigned int>& used_by_line,
+ const bool full) const
{
typename std::vector<RowInfo>::const_iterator row = row_info.begin();
const typename std::vector<RowInfo>::const_iterator endrow = row_info.end();
// Add up entries actually used
- unsigned int entries_used = 0;
+ used = 0;
unsigned int max_length = 0;
for (; row != endrow ; ++ row)
{
- entries_used += row->length;
+ used += row->length;
if (max_length < row->length)
max_length = row->length;
}
// Number of entries allocated is
// position of last entry used
--row;
- unsigned int entries_alloc = row->start + row->length;
-
- out << "SparseMatrixEZ:used entries:" << entries_used << std::endl
- << "SparseMatrixEZ:alloc entries:" << entries_alloc << std::endl
- << "SparseMatrixEZ:reserved entries:" << data.capacity() << std::endl;
+ allocated = row->start + row->length;
+ reserved = data.capacity();
+
if (full)
{
- std::vector<unsigned int> length_used (max_length+1);
+ used_by_line.resize(max_length+1);
for (row = row_info.begin() ; row != endrow; ++row)
{
- ++length_used[row->length];
+ ++used_by_line[row->length];
}
- for (unsigned int i=0; i< length_used.size();++i)
- if (length_used[i] != 0)
- out << "SparseMatrixEZ:entries\t" << i
- << "\trows\t" << length_used[i]
- << std::endl;
}
}
#define TYPEMAT double
template class SparseMatrixEZ<TYPEMAT>;
-template void SparseMatrixEZ<TYPEMAT>::print_statistics(std::ostream&, bool);
-template void SparseMatrixEZ<TYPEMAT>::print_statistics(LogStream&, bool);
-
#define TYPE2 float
#define TYPEMAT float
template class SparseMatrixEZ<TYPEMAT>;
-template void SparseMatrixEZ<TYPEMAT>::print_statistics(std::ostream&, bool);
-template void SparseMatrixEZ<TYPEMAT>::print_statistics(LogStream&, bool);
#define TYPE2 float