Loading...
Searching...
No Matches
PLMD::LoopUnroller< n > Class Template Reference

Utiliy class for loop unrolling. More...

#include <LoopUnroller.h>

Static Public Member Functions

template<typename T, typename TT>
static constexpr void _add (T *d, TT const *v) noexcept
 Add v to d.
 
template<typename T, typename TT>
static constexpr void _copy (T *d, TT const *v) noexcept
 copy the content o v into v Same as for(unsigned i=0;i<n;i++) d[i]=v[i];
 
template<typename T, typename TT>
static constexpr T _dot (T const *d, TT const *v) noexcept
 Dot product of d and v Same as r=0.0; for(unsigned i=0;i<n;i++) r+=d[i]*v[i]; return r;
 
template<typename T, typename TT>
static constexpr void _mul (T *d, TT const s) noexcept
 Multiply d by s.
 
template<typename T, typename TT>
static constexpr void _neg (T *d, TT const *v) noexcept
 Set d to -v.
 
template<typename T, typename TT>
static constexpr void _sub (T *d, TT const *v) noexcept
 Subtract v from d.
 
template<typename T>
static constexpr T _sum2 (T const *d) noexcept
 Squared modulo of d; Same as r=0.0; for(unsigned i=0;i<n;i++) r+=d[i]*d[i]; return r;
 
template<typename T>
static constexpr void _zero (T *d) noexcept
 Set to zero.
 

Detailed Description

template<unsigned n>
class PLMD::LoopUnroller< n >

Utiliy class for loop unrolling.

Many c++ compilers do not unroll small loops such as those used in the PLMD::Vector and PLMD::Tensor classes. This class provides methods to perform basic vector operations with unrolled loops. The methods work on double* so that they can be used in principles in other places of the code, but they are designed to be used in PLMD::Vector and PLMD::Tensor .

In case in the future we see that some compiler better optimize explicit loops, it should be easy to replace the methods here with loops. Alternatively, we could provide two paths using a cpp macro (e.g. __PLUMED_UNROLL_LOOPS or so).

All the methods for class LoopUnroller<n> act on n elements. Implementation is made using template metaprogramming, that is:

  • LoopUnroller<1>::xxx acts on the element [0] of the array.
  • LoopUnroller<n>::xxx calls LoopUnroller<n-1>::xxx then acts on element [n-1] of the array.

Here xxx is any of the methods of the class.

Member Function Documentation

◆ _add()

template<unsigned n>
template<typename T, typename TT>
void PLMD::LoopUnroller< n >::_add ( T * d,
TT const * v )
staticconstexprnoexcept

Add v to d.

Same as for(unsigned i=0;i<n;i++) d[i]+=v[i];

◆ _copy()

template<unsigned n>
template<typename T, typename TT>
void PLMD::LoopUnroller< n >::_copy ( T * d,
TT const * v )
staticconstexprnoexcept

copy the content o v into v Same as for(unsigned i=0;i<n;i++) d[i]=v[i];

◆ _dot()

template<unsigned n>
template<typename T, typename TT>
T PLMD::LoopUnroller< n >::_dot ( T const * d,
TT const * v )
staticconstexprnoexcept

Dot product of d and v Same as r=0.0; for(unsigned i=0;i<n;i++) r+=d[i]*v[i]; return r;

◆ _mul()

template<unsigned n>
template<typename T, typename TT>
void PLMD::LoopUnroller< n >::_mul ( T * d,
TT const s )
staticconstexprnoexcept

Multiply d by s.

Same as for(unsigned i=0;i<n;i++) d[i]*=s;

◆ _neg()

template<unsigned n>
template<typename T, typename TT>
void PLMD::LoopUnroller< n >::_neg ( T * d,
TT const * v )
staticconstexprnoexcept

Set d to -v.

Same as for(unsigned i=0;i<n;i++) d[i]=-v[i];

◆ _sub()

template<unsigned n>
template<typename T, typename TT>
void PLMD::LoopUnroller< n >::_sub ( T * d,
TT const * v )
staticconstexprnoexcept

Subtract v from d.

Same as for(unsigned i=0;i<n;i++) d[i]-=v[i];

◆ _sum2()

template<unsigned n>
template<typename T>
T PLMD::LoopUnroller< n >::_sum2 ( T const * d)
staticconstexprnoexcept

Squared modulo of d; Same as r=0.0; for(unsigned i=0;i<n;i++) r+=d[i]*d[i]; return r;

◆ _zero()

template<unsigned n>
template<typename T>
void PLMD::LoopUnroller< n >::_zero ( T * d)
staticconstexprnoexcept

Set to zero.

Same as for(unsigned i=0;i<n;i++) d[i]=0.0;


The documentation for this class was generated from the following file: