]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Improve order of multiplication/addition in perform_double_contraction which is perfo... 797/head
authorMartin Kronbichler <kronbichler@lnm.mw.tum.de>
Tue, 14 Apr 2015 13:31:34 +0000 (15:31 +0200)
committerMartin Kronbichler <kronbichler@lnm.mw.tum.de>
Tue, 14 Apr 2015 13:31:49 +0000 (15:31 +0200)
include/deal.II/base/symmetric_tensor.h

index e50518ea4e9724d559a8a647128a90fa1235e3df..4958cbf3c68870dd391776dff52d1a169df2cab9 100644 (file)
@@ -1184,11 +1184,14 @@ namespace internal
                 data[1] * sdata[1] +
                 2*data[2] * sdata[2]);
       default:
-        Number sum = Number();
+        // Start with the non-diagonal part to avoid some multiplications by
+        // 2.
+        Number sum = data[dim] * sdata[dim];
+        for (unsigned int d=dim+1; d<(dim*(dim+1)/2); ++d)
+          sum += data[d] * sdata[d];
+        sum *= 2.;
         for (unsigned int d=0; d<dim; ++d)
           sum += data[d] * sdata[d];
-        for (unsigned int d=dim; d<(dim*(dim+1)/2); ++d)
-          sum += 2 * data[d] * sdata[d];
         return sum;
       }
   }

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.