From 5e25cd2314106f1d327e2938b72b5a5027389d4c Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Steffen=20M=C3=BCthing?= <muething@dune-project.org>
Date: Fri, 15 Nov 2013 19:00:51 +0100
Subject: [PATCH] [BCRSMatrix] Update maximum number of row entries in
 compress() on the fly

We iterate over all rows anyway, so avoid the additional loop.
---
 dune/istl/bcrsmatrix.hh | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)

diff --git a/dune/istl/bcrsmatrix.hh b/dune/istl/bcrsmatrix.hh
index b1743175f..30111c0a5 100644
--- a/dune/istl/bcrsmatrix.hh
+++ b/dune/istl/bcrsmatrix.hh
@@ -1239,6 +1239,7 @@ namespace Dune {
       //calculate statistics
       CompressionStatistics<size_type> stats;
       stats.overflow_total = overflow.size();
+      stats.maximum = 0;
 
       //get insertion iterators pointing to one before start (for later use of ++it)
       size_type* jiit = j.get();
@@ -1315,6 +1316,10 @@ namespace Dune {
           ++oit;
           r[i].setsize(r[i].getsize()+1);
         }
+
+        // update maximum row size
+        if (r[i].getsize()>stats.maximum)
+          stats.maximum = r[i].getsize();
       }
 
       // overflow area may be cleared
@@ -1326,12 +1331,6 @@ namespace Dune {
       stats.avg = (double) (nnz) / (double) n;
       stats.mem_ratio = (double) (nnz)/(double) allocationSize;
 
-      //determine maximum number of entries in a row
-      stats.maximum = 0;
-      for (size_type i=0; i<n; i++)
-        if (r[i].getsize()>stats.maximum)
-          stats.maximum = r[i].getsize();
-
       //matrix is now built
       ready = built;
 
-- 
GitLab