FIAS . Impressum . Privacy

how to pass/return Vc::Vector arguments to a function?

Matthias Kretz [please enable javascript to see the address]
Wed Nov 9 12:41:16 CET 2016


Hi Bert,

this is a good question, though with a simple answer. You only need to 
understand that a Vc::Vector is as much a low level type as all the builtin 
arithmetic types. So pass a Vc::Vector<T> the same way you would pass a T.

On the Linux calling convention this will pass the arguments via SSE/AVX/... 
registers, which, in most cases, is the most efficient variant.

Also on a general note, if you can, avoid reference or pointer arguments. 
Passing by value, creates a local copy and therefore helps the optimizer. 
References and pointers might alias to the same memory location, making the 
optimizers life hard and the resulting code more pessimistic.

BTW, is there significant data parallel work on the outer loop, too? In this 
case you might consider vectorising the outer loop.

Cheers,
  Matthias

On Dienstag, 8. November 2016 09:11:51 CET Tijskens Engelbert wrote:
> Dear all,
> I am working on a molecular dynamics code using Vc for vectorisation -
> obviously.
> the core of the problem is an outer loop (over all atoms), and
> an inner loop over all neighbours of the atom of the outer loop. The inner
> loop is vectorised (using Vc) and computes a force from a potential. The
> potential varies, depending on the nature of the problem, but the inner
> loop is always the same. I want to obtain a generic code for the outer and
> inner loop in which the potential can be passed in as a pointer to a
> (vectorised) function (or functor) or a template parameter for that
> function. how should i pass the vector arguments to a function? by  value?
>     inline
>     Vc::Vector<float,Abi>
>     lj_force_factor2
>       ( Vc::Vector<float,Abi> r2 // squared distance
>       ) {…}
> by  const value?
>     inline
>     Vc::Vector<float,Abi>
>     lj_force_factor2
>       ( Vc::Vector<float,Abi> r2 // squared distance
>       ) {…}
> by  reference?
>     inlined
>     Vc::Vector<float,Abi>
>     lj_force_factor2
>       ( Vc::Vector<float,Abi>& r2 // squared distance
>       ) {…}
> by  reference?
>     inlined
>     Vc::Vector<float,Abi>
>     lj_force_factor2
>       ( Vc::Vector<float,Abi> const& r2 // squared distance
>       ) {…}
> thanks for your advice in advance and kindest regards,
> 
> Dr [Engel]bert Tijskens
> HPC Analyst/Consultant
> 
> Flemish Supercomputer Center vscentrum.be<http://vscentrum.be>
> HPC core facility CalcUA uantwerp.be/calcua<http://uantwerp.be/calcua>
> Computational mathematics
> www.uantwerpen.be/en/rg/cma<http://www.uantwerpen.be/en/rg/cma>
 
> University of Antwerp
> Middelheimlaan1 G.309, B-2020 Antwerp, Belgium
> 
>[please enable javascript to see the address][please enable javascript to see the address]>
> ++32 3 265 3879
> 


-- 
──────────────────────────────────────────────────────────────────────────
 Dr. Matthias Kretz                                https://kretzfamily.de
 GSI Helmholtzzentrum für Schwerionenforschung             https://gsi.de
 SIMD easy and portable                     https://github.com/VcDevel/Vc
──────────────────────────────────────────────────────────────────────────



More information about the Vc mailing list
FIAS . Impressum . Privacy