[gmx-developers] std::vector<Rvec> slowness

Berk Hess hess at kth.se
Wed Mar 23 09:44:21 CET 2016


Luckily Szilard does thorough testing and noticed a performance 
degradation in change set 25 of https://gerrit.gromacs.org/#/c/5232/ The 
only signifcant change with respect to previous sets is replacing C 
pointers by std::vector. I traced the performance difference back to a 
single loop, which must have become several factors slower to explain 
the time difference. I get the performance back when replacing the 
vector by a pointer extracted with .data(), see below. I looked at the 
assembly code from gcc 5.3.1 and the vector case generated 200 extra 
instructions, which makes it difficult to see what the actual difference 
is. The pointer case uses a lot of vmovss and vaddss, which the vector 
one does much less, but this is only serial SIMD instruction. I thought 
that [] in vector might does bounds checking, but it seems it does not.
Can anyone explain why the vector case can be so slow?
If this is a general issue (with RVec or more?), we need to always extra 
a pointer with .data() for use in all inner-loops. This is pretty 
annoying and difficult to enforce.



                        const std::vector<RVec> f_foreign = 
                        const RVec               *f_foreign   = 

                         int natom = atomList->atom.size();
                         for (int i = 0; i < natom; i++)
                             int ind = atomList->atom[i];
                             rvec_inc(f[ind], f_foreign[ind]);

More information about the gromacs.org_gmx-developers mailing list