]> https://gitweb.dealii.org/ - dealii-svn.git/commitdiff
Follow the documented advice of not looping over all elements of a matrix but do...
authorbangerth <bangerth@0785d39b-7218-0410-832d-ea1e28bc413d>
Tue, 12 Feb 2013 15:20:15 +0000 (15:20 +0000)
committerbangerth <bangerth@0785d39b-7218-0410-832d-ea1e28bc413d>
Tue, 12 Feb 2013 15:20:15 +0000 (15:20 +0000)
git-svn-id: https://svn.dealii.org/trunk@28325 0785d39b-7218-0410-832d-ea1e28bc413d

deal.II/source/lac/sparse_direct.cc

index 4da14da2ad00e7ed454272567b40919ff6b1266f..eb42a4d19e89fac0a8a02f0c303c39b429e8d99f 100644 (file)
@@ -1726,16 +1726,21 @@ factorize (const Matrix &matrix)
     // not yet written to
     std::vector<long int> row_pointers = Ap;
 
-    for (typename Matrix::const_iterator p=matrix.begin();
-         p!=matrix.end(); ++p)
+    // loop over the elements of the matrix row by row, as suggested
+    // in the documentation of the sparse matrix iterator class
+    for (unsigned int row = 0; row < matrix.n(); ++row)
       {
-        // write entry into the first
-        // free one for this row
-        Ai[row_pointers[p->row()]] = p->column();
-        Ax[row_pointers[p->row()]] = p->value();
+        for (typename Matrix::const_iterator p=matrix.begin(row);
+            p!=matrix.end(row); ++p)
+          {
+            // write entry into the first
+            // free one for this row
+            Ai[row_pointers[row]] = p->column();
+            Ax[row_pointers[row]] = p->value();
 
-        // then move pointer ahead
-        ++row_pointers[p->row()];
+            // then move pointer ahead
+            ++row_pointers[row];
+          }
       }
 
     // at the end, we should have
@@ -1955,15 +1960,20 @@ void SparseDirectMUMPS::initialize_matrix (const Matrix &matrix)
 
       unsigned int index = 0;
 
-      for (typename Matrix::const_iterator ptr = matrix.begin ();
-           ptr != matrix.end (); ++ptr)
-        if (std::abs (ptr->value ()) > 0.0)
-          {
-            a[index]   = ptr->value ();
-            irn[index] = ptr->row () + 1;
-            jcn[index] = ptr->column () + 1;
-            ++index;
-          }
+      // loop over the elements of the matrix row by row, as suggested
+      // in the documentation of the sparse matrix iterator class
+      for (unsigned int row = 0; row < matrix.n(); ++row)
+        {
+          for (typename Matrix::const_iterator ptr = matrix.begin (row);
+              ptr != matrix.end (row); ++ptr)
+            if (std::abs (ptr->value ()) > 0.0)
+              {
+                a[index]   = ptr->value ();
+                irn[index] = row + 1;
+                jcn[index] = ptr->column () + 1;
+                ++index;
+              }
+        }
 
       id.n   = n;
       id.nz  = nz;

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.