<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div>Dumb question:  wouldn&#39;t smart pointers (C++11 std::shared_ptr be an intermediate solution between std::vector and old-school manual allocation?  (Not passing judgement on whether we should use std::vector&lt;Rvec&gt; but thinking about the options here).</div><div><br></div><div>Best,</div><div>--Peter</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Date: Wed, 23 Mar 2016 13:18:52 +0000<br>
From: Mark Abraham &lt;<a href="mailto:mark.j.abraham@gmail.com">mark.j.abraham@gmail.com</a>&gt;<br>
To: <a href="mailto:gmx-developers@gromacs.org">gmx-developers@gromacs.org</a><br>
Subject: Re: [gmx-developers] std::vector&lt;Rvec&gt; slowness<br>
Message-ID:<br>
        &lt;<a href="mailto:CAMNuMAT4GftoMf8t5uzB5o9E%2BCxFG2HEdi-JvbCDqukjXooY6w@mail.gmail.com">CAMNuMAT4GftoMf8t5uzB5o9E+CxFG2HEdi-JvbCDqukjXooY6w@mail.gmail.com</a>&gt;<br>
Content-Type: text/plain; charset=&quot;utf-8&quot;<br>
<br>
Hi,<br>
<br>
On Wed, Mar 23, 2016 at 1:56 PM Berk Hess &lt;<a href="mailto:hess@kth.se">hess@kth.se</a>&gt; wrote:<br>
<br>
&gt; Hi,<br>
&gt;<br>
&gt; It&#39;s impractical and bad for performance to go from AoS to SoA.<br>
&gt;<br>
<br>
Sure, but that&#39;s what we do every MD step on typical CPUs. We do DD<br>
communication on XYZXYZXYZXYZ and then transpose them to XXXXYYYYZZZZ to<br>
use in short-ranged kernels. If we did DD communication on<br>
XXXXX....YYYYY..... ZZZZZZ.... then we still have gather-scatter overhead,<br>
but we don&#39;t have transposition in the mix.<br>
<br>
The question is now if we can fix this issue or if we should always try to<br>
&gt; use .data() in inner-loops<br>
&gt;<br>
<br>
I think you&#39;re missing my point... we&#39;ve always done a cast from rvec * to<br>
real * to pass to inner loops. :-) Using data() is a similar idea - hence<br>
my suggestion of as_real_array(theVectorOfRVecs).<br>
<br>
or if we should completely avoid std::vector&lt;RVec&gt; in performance sensitive<br>
&gt; code and use good old C pointers with nasty manual allocation.<br>
&gt;<br>
<br>
Allocation is irrelevant to how one uses it. One must have a real * to be<br>
sure the compiler isn&#39;t confused. To get that from a vector, we use data().<br>
Whether the allocation of the memory is managed by std::vector or snew is<br>
immaterial.<br>
<br>
Mark<br></blockquote></div></div></div>