]> https://gitweb.dealii.org/ - dealii-svn.git/commitdiff
Improve copying cached data.
authorbangerth <bangerth@0785d39b-7218-0410-832d-ea1e28bc413d>
Fri, 29 Aug 2008 02:16:16 +0000 (02:16 +0000)
committerbangerth <bangerth@0785d39b-7218-0410-832d-ea1e28bc413d>
Fri, 29 Aug 2008 02:16:16 +0000 (02:16 +0000)
git-svn-id: https://svn.dealii.org/trunk@16693 0785d39b-7218-0410-832d-ea1e28bc413d

deal.II/doc/news/changes.h
deal.II/lac/source/compressed_sparsity_pattern.cc

index ab6d9e7acb21b1e2d90a1f2f5522c4f58b8c33fc..18222d823153828bd7f4d0a88bb50cb3e20cb1fe 100644 (file)
@@ -244,6 +244,14 @@ inconvenience this causes.
 <h3>lac</h3>
 
 <ol>
+  <li>
+  <p>
+  Improved: The CompressedSparsityPattern can now elide some operations
+  upon entering entries that may have been added before already.
+  <br>
+  (Timo Heister, WB 2008/08/28)
+  </p>
+
   <li>
   <p>
   Fixed: There are now functions CompressedSparsityPattern::print and
index 44006ffcfcf93550b7555c7b91278932a736aa5e..c7bd346606f35c5a1202a239df632f178b7e0d59 100644 (file)
@@ -35,7 +35,7 @@ const unsigned int CompressedSparsityPattern::Line::cache_size;
 
 // Therefore, we require now, that the caller checks if this function
 // is necessary and only calls it, if it is actually used. Since it is
-// it called less often, it is removed from the inlined section.
+// called less often, it is removed from the inlined section.
 void
 CompressedSparsityPattern::Line::flush_cache () const
 {
@@ -136,44 +136,52 @@ CompressedSparsityPattern::Line::flush_cache () const
       }
 
                                        // then allocate new memory and merge
-                                       // arrays
-      std::vector<unsigned int> new_entries;
-      new_entries.reserve (n_new_entries);
-      unsigned int cache_position = 0;
-      unsigned int entry_position = 0;
-      while ((entry_position<entries.size()) && (cache_position<cache_entries))
-        if (entries[entry_position] < cache[cache_position])
-          {
-            new_entries.push_back (entries[entry_position]);
-            ++entry_position;
-          }
-        else if (entries[entry_position] == cache[cache_position])
-          {
-            new_entries.push_back (entries[entry_position]);
-            ++entry_position;
-            ++cache_position;
-          }
-        else
-          {
-            new_entries.push_back (cache[cache_position]);
-            ++cache_position;
-          }
-
-                                       // copy remaining elements from the
-                                       // array that we haven't finished. note
-                                       // that at most one of the following
-                                       // loops will run at all
-      for (; entry_position < entries.size(); ++entry_position)
-        new_entries.push_back (entries[entry_position]);
-      for (; cache_position < cache_entries; ++cache_position)
-        new_entries.push_back (cache[cache_position]);
+                                       // arrays, if there are any entries at
+                                       // all that need to be merged
+      Assert (n_new_entries >= entries.size(),
+             ExcInternalError());
+      if (n_new_entries > entries.size())
+       {
+         std::vector<unsigned int> new_entries;
+         new_entries.reserve (n_new_entries);
+         unsigned int cache_position = 0;
+         unsigned int entry_position = 0;
+         while ((entry_position<entries.size()) &&
+                (cache_position<cache_entries))
+           if (entries[entry_position] < cache[cache_position])
+             {
+               new_entries.push_back (entries[entry_position]);
+               ++entry_position;
+             }
+           else if (entries[entry_position] == cache[cache_position])
+             {
+               new_entries.push_back (entries[entry_position]);
+               ++entry_position;
+               ++cache_position;
+             }
+           else
+             {
+               new_entries.push_back (cache[cache_position]);
+               ++cache_position;
+             }
+
+                                          // copy remaining elements from the
+                                          // array that we haven't
+                                          // finished. note that at most one
+                                          // of the following loops will run
+                                          // at all
+         for (; entry_position < entries.size(); ++entry_position)
+           new_entries.push_back (entries[entry_position]);
+         for (; cache_position < cache_entries; ++cache_position)
+           new_entries.push_back (cache[cache_position]);
       
-      Assert (new_entries.size() == n_new_entries,
-              ExcInternalError());
+         Assert (new_entries.size() == n_new_entries,
+                 ExcInternalError());
 
-                                       // finally swap old and new array, and
-                                       // set cache size to zero
-      new_entries.swap (entries);
+                                          // finally swap old and new array,
+                                          // and set cache size to zero
+         new_entries.swap (entries);
+       }
     }
   
   cache_entries = 0;

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.