From 7ea535c8fc0cd3378801720c11135fc2e487c2b4 Mon Sep 17 00:00:00 2001 From: guido Date: Tue, 20 May 2003 09:03:56 +0000 Subject: [PATCH] new statistic functions git-svn-id: https://svn.dealii.org/trunk@7660 0785d39b-7218-0410-832d-ea1e28bc413d --- .../lac/include/lac/block_sparse_matrix_ez.h | 71 +++++++++++++++++++ deal.II/lac/include/lac/sparse_matrix_ez.h | 58 +++++++++++++-- .../include/lac/sparse_matrix_ez.templates.h | 36 +++++----- deal.II/lac/source/sparse_matrix_ez.double.cc | 3 - deal.II/lac/source/sparse_matrix_ez.float.cc | 2 - 5 files changed, 142 insertions(+), 28 deletions(-) diff --git a/deal.II/lac/include/lac/block_sparse_matrix_ez.h b/deal.II/lac/include/lac/block_sparse_matrix_ez.h index b5f3027e0b..a3241e71b6 100644 --- a/deal.II/lac/include/lac/block_sparse_matrix_ez.h +++ b/deal.II/lac/include/lac/block_sparse_matrix_ez.h @@ -257,6 +257,18 @@ class BlockSparseMatrixEZ : public Subscriptor const BlockVector &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 + void print_statistics (STREAM& s, bool full = false); + private: /** * Object storing and managing @@ -496,4 +508,63 @@ BlockSparseMatrixEZ::Tvmult_add ( } +template +template +inline +void +BlockSparseMatrixEZ::print_statistics(STREAM& out, bool full) +{ + unsigned int used_total = 0; + unsigned int allocated_total = 0; + unsigned int reserved_total = 0; + std::vector used_by_line_total; + + unsigned int used; + unsigned int allocated; + unsigned int reserved; + std::vector used_by_line; + + for (unsigned int i=0;i 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& used_by_line, + const bool compute_by_line) const; + /** * Exception for applying * inverse-type operators to @@ -1561,5 +1582,34 @@ SparseMatrixEZ::conjugate_add (const MATRIXA& A, } +template +template +inline +void +SparseMatrixEZ::print_statistics(STREAM& out, bool full) +{ + unsigned int used; + unsigned int allocated; + unsigned int reserved; + std::vector 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 ---------------------------*/ diff --git a/deal.II/lac/include/lac/sparse_matrix_ez.templates.h b/deal.II/lac/include/lac/sparse_matrix_ez.templates.h index 85df27c60c..40aaac0fe1 100644 --- a/deal.II/lac/include/lac/sparse_matrix_ez.templates.h +++ b/deal.II/lac/include/lac/sparse_matrix_ez.templates.h @@ -68,7 +68,8 @@ void SparseMatrixEZ::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(); @@ -76,8 +77,8 @@ SparseMatrixEZ::reinit(const unsigned int n_rows, 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::memory_consumption() const template -template void -SparseMatrixEZ::print_statistics(STREAM& out, bool full) +SparseMatrixEZ::compute_statistics( + unsigned int& used, + unsigned int& allocated, + unsigned int& reserved, + std::vector& used_by_line, + const bool full) const { typename std::vector::const_iterator row = row_info.begin(); const typename std::vector::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; } @@ -378,25 +383,18 @@ SparseMatrixEZ::print_statistics(STREAM& out, bool full) // 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 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; } } diff --git a/deal.II/lac/source/sparse_matrix_ez.double.cc b/deal.II/lac/source/sparse_matrix_ez.double.cc index 99d7098f7c..74cf27c864 100644 --- a/deal.II/lac/source/sparse_matrix_ez.double.cc +++ b/deal.II/lac/source/sparse_matrix_ez.double.cc @@ -19,9 +19,6 @@ #define TYPEMAT double template class SparseMatrixEZ; -template void SparseMatrixEZ::print_statistics(std::ostream&, bool); -template void SparseMatrixEZ::print_statistics(LogStream&, bool); - #define TYPE2 float diff --git a/deal.II/lac/source/sparse_matrix_ez.float.cc b/deal.II/lac/source/sparse_matrix_ez.float.cc index 727164b37b..c4e92a7c96 100644 --- a/deal.II/lac/source/sparse_matrix_ez.float.cc +++ b/deal.II/lac/source/sparse_matrix_ez.float.cc @@ -18,8 +18,6 @@ #define TYPEMAT float template class SparseMatrixEZ; -template void SparseMatrixEZ::print_statistics(std::ostream&, bool); -template void SparseMatrixEZ::print_statistics(LogStream&, bool); #define TYPE2 float -- 2.39.5