<html>
  <head>
    <meta content="text/html; charset=windows-1252"
      http-equiv="Content-Type">
  </head>
  <body bgcolor="#FFFFFF" text="#000000">
    <div class="moz-cite-prefix">Le 04/24/2015 10:20 AM, Stéphane
      Mottelet a écrit :<br>
    </div>
    <blockquote cite="mid:5539FCC3.4000506@utc.fr" type="cite">
      <meta content="text/html; charset=windows-1252"
        http-equiv="Content-Type">
      <div class="moz-cite-prefix">Hello,<br>
        <br>
        Ok, I will try dynamic link since I want the project to stay
        into the Scilab world, but another alternative is Julia (<a
          moz-do-not-send="true" class="moz-txt-link-freetext"
          href="http://julialang.org/">http://julialang.org/</a>). I
        have made some tests this night and got a speedup of 25, the
        explanation is JIT compilation. Maybe will we have JIT
        compilation in Scilab 6 ?<br>
      </div>
    </blockquote>
    Hi Stéphane,<br>
    <br>
    JIT is not the only explanation for the speedup.<br>
    (I also did some scilab->julia conversion earlier this year to
    see how much we could gain).<br>
    It seems to me that your code is not particularly efficient for
    scilab, while it might be a bit less inefficient in julia.<br>
    For example:<br>
     - you are indexing a lot, which is not particularly fast in scilab.
    <br>
     - you are re-indexing several times:
    ...,v(17),v(104),v(149),...,v(17),v(104),v(149),... ->
    part_v=[v(17),v(104),v(149)] ; ...,part_v,...,part_v, could be
    faster.<br>
     - you might need to pre-allocate M1_v :
    M1_v=zeros(whatever_size_it_is) so that scilab won't have to
    re-allocate it while you make it grow by stacking scalar after
    scalar.<br>
     - more generally, it seems your code is highly redundant, couldn't
    you save some time by reusing some precalculated vector bit, like
    [v(17),v(104),v(149)] ?<br>
    <br>
    Hope it helps,<br>
    <br>
    Antoine<br>
    <blockquote cite="mid:5539FCC3.4000506@utc.fr" type="cite">
      <div class="moz-cite-prefix"> <br>
        Best regards,<br>
        <br>
        S.<br>
        <br>
        Le 24/04/2015 09:30, <a moz-do-not-send="true"
          class="moz-txt-link-abbreviated"
          href="mailto:aweeks@hidglobal.com">aweeks@hidglobal.com</a> a
        écrit :<br>
      </div>
      <blockquote
cite="mid:OF0ADF46E4.2C97D174-ON80257E31.002704B9-80257E31.0029358A@prox.com"
        type="cite"><font face="sans-serif" size="2">Hello Stephane,</font>
        <br>
        <br>
        <font face="sans-serif" size="2">We have a Scilab program which
          performs a  numerical integration on data points in
          3-dimensions - it has two nested loops.  When the number of
          data points was large this was slow so we implemented the
          calculation function in C and got a speed improvement of about
          24 times !</font> <br>
        <br>
        <font face="sans-serif" size="2">We also found three other
          improvements:</font> <br>
        <br>
        <font face="sans-serif" size="2">        using pointer
          arithmetic was faster than 'for' loops,</font> <br>
        <font face="sans-serif" size="2">        'pow(x, 2)' was faster
          than x*x,</font> <br>
        <font face="sans-serif" size="2">        handling the data as 3
          (N x 1) vectors was faster than using 1 (N x 3) matrix.</font>
        <br>
        <br>
        <font face="sans-serif" size="2">each of these giving something
          like a 3-4% improvement - small compared to x24 but still
          worth having.</font> <br>
        <br>
        <font face="sans-serif" size="2">If you don't mind tackling the
          dynamic linking it's probably worth the effort if you'll use
          this program a few times - good luck.</font> <br>
        <br>
        <font face="sans-serif" size="2">Adrian.</font> <br>
        <font face="sans-serif" size="2"><br>
        </font>
        <table>
          <tbody>
            <tr>
              <td><font color="#2f2f2f" face="Arial" size="2"><b>Adrian
                    Weeks </b></font><font color="#5f5f5f" face="Arial"
                  size="1"><br>
                  Development Engineer, Hardware Engineering EMEA<br>
                  Office: +44 (0)2920 528500 | Desk: +44 (0)2920 528523
                  | Fax: +44 (0)2920 520178</font><font color="blue"
                  face="Arial" size="1"><u><br>
                  </u></font><a moz-do-not-send="true"
                  href="mailto:aweeks@hidglobal.com"><font color="blue"
                    face="Arial" size="1"><u>aweeks@hidglobal.com</u></font></a><font
                  color="#5f5f5f" face="Arial" size="1"><br>
                </font> </td>
            </tr>
            <tr>
              <td><a moz-do-not-send="true"
                  href="http://www.hidglobal.com/"><img
                    src="cid:part4.03050006.06060805@laas.fr" alt="HID
                    Global Logo" height="48" width="312"></a> </td>
            </tr>
            <tr>
              <td><font color="#5f5f5f" face="Arial" size="1">Unit 3,
                  Cae Gwyrdd,<br>
                  Green meadow Springs,<br>
                  Cardiff, UK,<br>
                  CF15 7AB.</font><font color="blue" face="Arial"
                  size="1"><u><br>
                  </u></font><a moz-do-not-send="true"
                  href="http://www.hidglobal.com/"><font color="blue"
                    face="Arial" size="1"><u>www.hidglobal.com</u></font></a></td>
            </tr>
          </tbody>
        </table>
        <br>
        <br>
        <br>
        <br>
        <table width="100%">
          <tbody>
            <tr valign="top">
              <td><font color="#5f5f5f" face="sans-serif" size="1">From:</font>
              </td>
              <td><font face="sans-serif" size="1">Stéphane Mottelet <a
                    moz-do-not-send="true" class="moz-txt-link-rfc2396E"
                    href="mailto:stephane.mottelet@utc.fr"><stephane.mottelet@utc.fr></a></font>
              </td>
            </tr>
            <tr valign="top">
              <td><font color="#5f5f5f" face="sans-serif" size="1">To:</font>
              </td>
              <td><font face="sans-serif" size="1">"International users
                  mailing list for Scilab." <a moz-do-not-send="true"
                    class="moz-txt-link-rfc2396E"
                    href="mailto:users@lists.scilab.org"><users@lists.scilab.org></a></font>
              </td>
            </tr>
            <tr valign="top">
              <td><font color="#5f5f5f" face="sans-serif" size="1">Date:</font>
              </td>
              <td><font face="sans-serif" size="1">23/04/2015 22:52</font>
              </td>
            </tr>
            <tr valign="top">
              <td><font color="#5f5f5f" face="sans-serif" size="1">Subject:</font>
              </td>
              <td><font face="sans-serif" size="1">[Scilab-users] Ways
                  to speed up simple things in Scilab ?</font> </td>
            </tr>
            <tr valign="top">
              <td><font color="#5f5f5f" face="sans-serif" size="1">Sent
                  by:</font> </td>
              <td><font face="sans-serif" size="1">"users" <a
                    moz-do-not-send="true" class="moz-txt-link-rfc2396E"
                    href="mailto:users-bounces@lists.scilab.org"><users-bounces@lists.scilab.org></a></font></td>
            </tr>
          </tbody>
        </table>
        <br>
        <hr noshade="noshade"> <br>
        <br>
        <br>
        <tt><font size="2">Hello,<br>
            <br>
            I am currently working on a project where Scilab code is
            automatically <br>
            generated, and after many code optimization, the remaining
            bottleneck is <br>
            the time that Scilab spends to execute simple code like this
            (full <br>
            script (where the vector has 839 lines) with timings is
            attached) :<br>
            <br>
            M1_v=[v(17)<br>
            v(104)<br>
            v(149)<br>
            -(v(18)+v(63)+v(103))<br>
            -(v(18)+v(63)+v(103))<br>
            v(17)<br>
            ...<br>
            v(104)<br>
            v(149)<br>
            ]<br>
            <br>
            This kind of large vectors are the used to build a sparse
            matrix each <br>
            time the vector v changes, but with a constant sparsity
            pattern. <br>
            Actually, the time spent by Scilab in the statement<br>
            <br>
            M1=sparse(M1_ij,M1_v,[n1,n2])<br>
            <br>
            is negligible compared to the time spent to build f M1_v...<br>
            <br>
            I have also noticed that if you need to define such a matrix
            with more <br>
            that one column, the time elapsed is not linear with respect
            to the <br>
            number of columns: typically 4 times slower for 2 columns.
            In fact the <br>
            statement<br>
            <br>
            v=[1 1<br>
            ...<br>
            1000 1000]<br>
            <br>
            is even two times slower than<br>
            <br>
            v1=[1<br>
            ...<br>
            1000];<br>
            v2=[1<br>
            ....<br>
            1000];<br>
            v=[v1 v2];<br>
            <br>
            So my question to users who have the experience of dynamic
            link of user <br>
            code : do you think that using dynamic link of compiled
            generated C code <br>
            could improve the timings ?<br>
            <br>
            In advance, thanks for your help !<br>
            <br>
            S.<br>
            <br>
            <br>
            [attachment "test.sce" deleted by Adrian Weeks/CWL/EU/ITG]
            _______________________________________________<br>
            users mailing list<br>
            <a moz-do-not-send="true" class="moz-txt-link-abbreviated"
              href="mailto:users@lists.scilab.org">users@lists.scilab.org</a><br>
          </font></tt><a moz-do-not-send="true"
          href="http://lists.scilab.org/mailman/listinfo/users"><tt><font
              size="2">http://lists.scilab.org/mailman/listinfo/users</font></tt></a><tt><font
            size="2"><br>
          </font></tt> <br>
        <br>
        <br>
        <fieldset class="mimeAttachmentHeader"></fieldset>
        <br>
        <pre wrap="">_______________________________________________
users mailing list
<a moz-do-not-send="true" class="moz-txt-link-abbreviated" href="mailto:users@lists.scilab.org">users@lists.scilab.org</a>
<a moz-do-not-send="true" class="moz-txt-link-freetext" href="http://lists.scilab.org/mailman/listinfo/users">http://lists.scilab.org/mailman/listinfo/users</a>
</pre>
      </blockquote>
      <br>
      <br>
      <pre class="moz-signature" cols="72">-- 
Département de Génie Informatique
EA 4297 Transformations Intégrées de la Matière Renouvelable
Université de Technologie de Compiègne -  CS 60319
60203 Compiègne cedex</pre>
      <br>
      <fieldset class="mimeAttachmentHeader"></fieldset>
      <br>
      <pre wrap="">_______________________________________________
users mailing list
<a class="moz-txt-link-abbreviated" href="mailto:users@lists.scilab.org">users@lists.scilab.org</a>
<a class="moz-txt-link-freetext" href="http://lists.scilab.org/mailman/listinfo/users">http://lists.scilab.org/mailman/listinfo/users</a>
</pre>
    </blockquote>
  </body>
</html>