octave-bug-tracker
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Octave-bug-tracker] [bug #54005] kron performance affected by octave_qu


From: Rik
Subject: [Octave-bug-tracker] [bug #54005] kron performance affected by octave_quit() calls
Date: Tue, 19 Jun 2018 16:51:41 -0400 (EDT)
User-agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:55.0) Gecko/20100101 Firefox/55.0

Follow-up Comment #4, bug #54005 (project octave):

I'm not saying we shouldn't do this, but I am seeing only modest improvement
when moving octave_quit() up one level.

First, I rewrote the test script to have pre-computed vectors.  The only thing
that we want in the tic/toc loop is the test of kron itself, not the actual
construction of new vectors each time using ones().  The result is shown here,
and attached.


N = 10;
nel = 10_000;

rowvec = ones (nel, 1);
colvec = ones (1, nel);

ver = version
hg_id = __octave_config_info__.hg_id

tic()
for i = 1 : N
  a = kron (rowvec, rowvec);
end
toc()

tic()
for i = 1 : N
  a = kron (colvec, colvec);
end
toc()


Results were:


ver = 5.0.0
hg_id = hg-id-disabled
Elapsed time is 4.4956 seconds.
Elapsed time is 5.72668 seconds.


I then moved octave_quit out of the innermost loop.  I don't think it is
necessary to call it that frequently.


diff -r b7db401e1a99 libinterp/corefcn/kron.cc
--- a/libinterp/corefcn/kron.cc Tue Jun 19 09:18:44 2018 -0700
+++ b/libinterp/corefcn/kron.cc Tue Jun 19 13:40:26 2018 -0700
@@ -65,12 +65,15 @@ kron (const MArray<R>& a, const MArray<T
 
   for (octave_idx_type ja = 0; ja < nca; ja++)
     for (octave_idx_type jb = 0; jb < ncb; jb++)
-      for (octave_idx_type ia = 0; ia < nra; ia++)
-        {
-          octave_quit ();
-          mx_inline_mul (nrb, cv, a(ia, ja), b.data () + nrb*jb);
-          cv += nrb;
-        }
+      {
+        octave_quit ();
+        for (octave_idx_type ia = 0; ia < nra; ia++)
+          {
+       //     octave_quit ();
+            mx_inline_mul (nrb, cv, a(ia, ja), b.data () + nrb*jb);
+            cv += nrb;
+          }
+      }
 
   return c;
 }
@@ -90,12 +93,15 @@ kron (const MDiagArray2<R>& a, const MAr
   MArray<T> c (dim_vector (nra*nrb, nca*ncb), T ());
 
   for (octave_idx_type ja = 0; ja < dla; ja++)
-    for (octave_idx_type jb = 0; jb < ncb; jb++)
-      {
-        octave_quit ();
-        mx_inline_mul (nrb, &c.xelem (ja*nrb, ja*ncb + jb), a.dgelem (ja),
-                       b.data () + nrb*jb);
-      }
+    {
+      octave_quit ();
+      for (octave_idx_type jb = 0; jb < ncb; jb++)
+        {
+      //    octave_quit ();
+          mx_inline_mul (nrb, &c.xelem (ja*nrb, ja*ncb + jb), a.dgelem (ja),
+                         b.data () + nrb*jb);
+        }
+    }
 
   return c;
 }


And the result was


ver = 5.0.0
hg_id = hg-id-disabled
Elapsed time is 4.44244 seconds.
Elapsed time is 5.30063 seconds.


The reduction in execution time for column vectors was about 7%.

Marco is correct that we don't want to move octave_quit() completely outside
the loops or we would disable Ctrl+C interruption.  Is 7% worth it?




    _______________________________________________________

Reply to this item at:

  <http://savannah.gnu.org/bugs/?54005>

_______________________________________________
  Message sent via Savannah
  https://savannah.gnu.org/




reply via email to

[Prev in Thread] Current Thread [Next in Thread]