]> https://gitweb.dealii.org/ - dealii.git/commitdiff
new statistic functions
authorGuido Kanschat <dr.guido.kanschat@gmail.com>
Tue, 20 May 2003 09:03:56 +0000 (09:03 +0000)
committerGuido Kanschat <dr.guido.kanschat@gmail.com>
Tue, 20 May 2003 09:03:56 +0000 (09:03 +0000)
git-svn-id: https://svn.dealii.org/trunk@7660 0785d39b-7218-0410-832d-ea1e28bc413d

deal.II/lac/include/lac/block_sparse_matrix_ez.h
deal.II/lac/include/lac/sparse_matrix_ez.h
deal.II/lac/include/lac/sparse_matrix_ez.templates.h
deal.II/lac/source/sparse_matrix_ez.double.cc
deal.II/lac/source/sparse_matrix_ez.float.cc

index b5f3027e0bd8c6a761772e52f9cc632561dbb497..a3241e71b69cb8c85d164a83ed8169f9bc020bd8 100644 (file)
@@ -257,6 +257,18 @@ class BlockSparseMatrixEZ : public Subscriptor
                     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
@@ -496,4 +508,63 @@ BlockSparseMatrixEZ<Number>::Tvmult_add (
 }
 
 
+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
index e7d6ca9d64802014705c4b781ba945a4e7e5369e..1a7dfff8fc723bb6a182ecbca0849719a30234e3 100644 (file)
@@ -387,8 +387,9 @@ class SparseMatrixEZ : public Subscriptor
                                      * 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
@@ -398,7 +399,8 @@ class SparseMatrixEZ : public Subscriptor
     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
@@ -920,7 +922,26 @@ class SparseMatrixEZ : public Subscriptor
                                      */
     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
@@ -1561,5 +1582,34 @@ SparseMatrixEZ<number>::conjugate_add (const MATRIXA& A,
 }
 
 
+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     ---------------------------*/
index 85df27c60ce473d6c5975eef0af10b56f7f985bc..40aaac0fe1683f92d11bc800af491c28cf6a7d21 100644 (file)
@@ -68,7 +68,8 @@ void
 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();
 
@@ -76,8 +77,8 @@ SparseMatrixEZ<number>::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<n_rows;++i)
@@ -358,19 +359,23 @@ SparseMatrixEZ<number>::memory_consumption() const
 
 
 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;
     }
@@ -378,25 +383,18 @@ SparseMatrixEZ<number>::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<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;
     }
 }
 
index 99d7098f7c5d54169968c02cabe647ff2b326336..74cf27c8642164d2aefc80a08c183a20b2c2f268 100644 (file)
@@ -19,9 +19,6 @@
 #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
 
index 727164b37b0eb7f6f5d14007afd8b49e36811c5d..c4e92a7c96cdd3dd60f4d0e6762443ac45ad4c97 100644 (file)
@@ -18,8 +18,6 @@
 #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
 

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.