<html>
  <head>
    <meta content="text/html; charset=windows-1252"
      http-equiv="Content-Type">
  </head>
  <body text="#000000" bgcolor="#FFFFFF">
    <div class="moz-cite-prefix">On 2016-03-23 10:50, Erik Lindahl
      wrote:<br>
    </div>
    <blockquote
      cite="mid:EDA6437B-31AE-4DD5-AA88-C7293B99394A@gmail.com"
      type="cite">
      <meta http-equiv="Content-Type" content="text/html;
        charset=windows-1252">
      Hi,
      <div class=""><br class="">
      </div>
      <div class="">I haven’t followed the discussion in detail, but a
        long time ago I remember having simliar issues in the kernels
        when using a list[] of rvec[] (in plain-old-c, no c++) instead
        of extracting the pointer and handling the multiply-by-3
        manually. Could it be something similar here, e.g. that the
        compiler things it does not know enough about RVec rather than
        something going from with the outer list?</div>
    </blockquote>
    That would be my guess. The index used in the same loop comes from a
    vector as well and doesn't seem to affect performance.<br>
    <br>
    Berk<br>
    <blockquote
      cite="mid:EDA6437B-31AE-4DD5-AA88-C7293B99394A@gmail.com"
      type="cite">
      <div class=""><br class="">
      </div>
      <div class="">Cheers,</div>
      <div class=""><br class="">
      </div>
      <div class="">Erik</div>
      <div class=""><br class="">
      </div>
      <div class="">
        <div>
          <blockquote type="cite" class="">
            <div class="">On 23 Mar 2016, at 10:44, Berk Hess &lt;<a
                moz-do-not-send="true" href="mailto:hess@kth.se"
                class=""><a class="moz-txt-link-abbreviated" href="mailto:hess@kth.se">hess@kth.se</a></a>&gt; wrote:</div>
            <br class="Apple-interchange-newline">
            <div class="">
              <div text="#000000" bgcolor="#FFFFFF" class="">
                <div class="moz-cite-prefix">On 2016-03-23 10:42, Mark
                  Abraham wrote:<br class="">
                </div>
                <blockquote
cite="mid:CAMNuMAT8Wgv4ZroixK-JqNxvyYhpZzWNr7R8AK4rgetgFeEjrQ@mail.gmail.com"
                  type="cite" class="">
                  <div dir="ltr" class="">Hi,<br class="">
                    <br class="">
                    <div class="gmail_quote">
                      <div dir="ltr" class="">On Wed, Mar 23, 2016 at
                        9:44 AM Berk Hess &lt;<a moz-do-not-send="true"
                          class="moz-txt-link-abbreviated"
                          href="mailto:hess@kth.se">hess@kth.se</a>&gt;
                        wrote:<br class="">
                      </div>
                      <blockquote class="gmail_quote" style="margin:0 0
                        0 .8ex;border-left:1px #ccc
                        solid;padding-left:1ex">Hi,<br class="">
                        <br class="">
                        Luckily Szilard does thorough testing and
                        noticed a performance<br class="">
                        degradation in change set 25 of <a
                          moz-do-not-send="true"
                          href="https://gerrit.gromacs.org/#/c/5232/"
                          rel="noreferrer" target="_blank" class=""><a class="moz-txt-link-freetext" href="https://gerrit.gromacs.org/#/c/5232/">https://gerrit.gromacs.org/#/c/5232/</a></a>
                        The<br class="">
                        only signifcant change with respect to previous
                        sets is replacing C<br class="">
                        pointers by std::vector. I traced the
                        performance difference back to a<br class="">
                        single loop, which must have become several
                        factors slower to explain<br class="">
                        the time difference. I get the performance back
                        when replacing the<br class="">
                        vector by a pointer extracted with .data(), see
                        below. I looked at the<br class="">
                        assembly code from gcc 5.3.1 and the vector case
                        generated 200 extra<br class="">
                        instructions, which makes it difficult to see
                        what the actual difference<br class="">
                        is. The pointer case uses a lot of vmovss and
                        vaddss, which the vector<br class="">
                        one does much less, but this is only serial SIMD
                        instruction. I thought<br class="">
                        that [] in vector might does bounds checking,</blockquote>
                      <div class=""><br class="">
                      </div>
                      <div class="">Definitely not in release builds.</div>
                      <div class=""> </div>
                      <blockquote class="gmail_quote" style="margin:0 0
                        0 .8ex;border-left:1px #ccc
                        solid;padding-left:1ex"> but it seems it does
                        not.<br class="">
                        Can anyone explain why the vector case can be so
                        slow?</blockquote>
                      <blockquote class="gmail_quote" style="margin:0 0
                        0 .8ex;border-left:1px #ccc
                        solid;padding-left:1ex"> If this is a general
                        issue (with RVec or more?), we need to always
                        extra<br class="">
                        a pointer with .data() for use in all
                        inner-loops. This is pretty<br class="">
                        annoying and difficult to enforce.<br class="">
                        <br class="">
                        Cheers,<br class="">
                        <br class="">
                        Berk<br class="">
                        <br class="">
                                                const
                        std::vector&lt;RVec&gt; f_foreign =<br class="">
                        idt_foreign-&gt;force<br class="">
                      </blockquote>
                      <div class=""><br class="">
                      </div>
                      <div class="">This does a copy of the vector, and
                        doesn't seem to be in any version of this patch
                        in gerrit. Is this what you meant to write?</div>
                    </div>
                  </div>
                </blockquote>
                I tried this. But my original "vectorized" patch set
                took a pointer from idt_foreign and did not copy the
                vector, that gives the same, slow, performance.<br
                  class="">
                <br class="">
                Berk<br class="">
                <blockquote
cite="mid:CAMNuMAT8Wgv4ZroixK-JqNxvyYhpZzWNr7R8AK4rgetgFeEjrQ@mail.gmail.com"
                  type="cite" class="">
                  <div dir="ltr" class="">
                    <div class="gmail_quote">
                      <div class=""><br class="">
                      </div>
                      <div class="">Mark</div>
                      <div class=""><br class="">
                      </div>
                      <blockquote class="gmail_quote" style="margin:0 0
                        0 .8ex;border-left:1px #ccc
                        solid;padding-left:1ex"> or<br class="">
                                                const RVec             
                         *f_foreign   =<br class="">
                        idt_foreign-&gt;force.data();<br class="">
                        <br class="">
                                                 int natom =
                        atomList-&gt;atom.size();<br class="">
                                                 for (int i = 0; i &lt;
                        natom; i++)<br class="">
                                                 {<br class="">
                                                     int ind =
                        atomList-&gt;atom[i];<br class="">
                                                     rvec_inc(f[ind],
                        f_foreign[ind]);<br class="">
                                                 }<br class="">
                        --<br class="">
                        Gromacs Developers mailing list<br class="">
                        <br class="">
                        * Please search the archive at <a
                          moz-do-not-send="true"
                          href="http://www.gromacs.org/Support/Mailing_Lists/GMX-developers_List"
                          rel="noreferrer" target="_blank" class=""><a class="moz-txt-link-freetext" href="http://www.gromacs.org/Support/Mailing_Lists/GMX-developers_List">http://www.gromacs.org/Support/Mailing_Lists/GMX-developers_List</a></a>
                        before posting!<br class="">
                        <br class="">
                        * Can't post? Read <a moz-do-not-send="true"
                          href="http://www.gromacs.org/Support/Mailing_Lists"
                          rel="noreferrer" target="_blank" class="">http://www.gromacs.org/Support/Mailing_Lists</a><br
                          class="">
                        <br class="">
                        * For (un)subscribe requests visit<br class="">
                        <a moz-do-not-send="true"
href="https://maillist.sys.kth.se/mailman/listinfo/gromacs.org_gmx-developers"
                          rel="noreferrer" target="_blank" class="">https://maillist.sys.kth.se/mailman/listinfo/gromacs.org_gmx-developers</a>
                        or send a mail to <a moz-do-not-send="true"
                          href="mailto:gmx-developers-request@gromacs.org"
                          target="_blank" class="">gmx-developers-request@gromacs.org</a>.<br
                          class="">
                      </blockquote>
                    </div>
                  </div>
                  <br class="">
                  <fieldset class="mimeAttachmentHeader"></fieldset>
                  <br class="">
                </blockquote>
                <br class="">
              </div>
              -- <br class="">
              Gromacs Developers mailing list<br class="">
              <br class="">
              * Please search the archive at <a moz-do-not-send="true"
href="http://www.gromacs.org/Support/Mailing_Lists/GMX-developers_List"
                class="">http://www.gromacs.org/Support/Mailing_Lists/GMX-developers_List</a>
              before posting!<br class="">
              <br class="">
              * Can't post? Read <a moz-do-not-send="true"
                href="http://www.gromacs.org/Support/Mailing_Lists"
                class="">http://www.gromacs.org/Support/Mailing_Lists</a><br
                class="">
              <br class="">
              * For (un)subscribe requests visit<br class="">
              <a moz-do-not-send="true"
href="https://maillist.sys.kth.se/mailman/listinfo/gromacs.org_gmx-developers"
                class="">https://maillist.sys.kth.se/mailman/listinfo/gromacs.org_gmx-developers</a>
              or send a mail to <a moz-do-not-send="true"
                href="mailto:gmx-developers-request@gromacs.org"
                class="">gmx-developers-request@gromacs.org</a>.</div>
          </blockquote>
        </div>
        <br class="">
      </div>
      <br>
      <fieldset class="mimeAttachmentHeader"></fieldset>
      <br>
    </blockquote>
    <br>
  </body>
</html>