Public Member Functions | Static Public Member Functions | List of all members
PLMD::LoopUnroller< n > Class Template Reference

#include <LoopUnroller.h>

Public Member Functions

void _add (double *d, const double *a)
 
double _dot (const double *d, const double *v)
 
void _mul (double *d, const double s)
 
void _neg (double *d, const double *a)
 
void _sub (double *d, const double *a)
 
double _sum2 (const double *d)
 
void _zero (double *d)
 

Static Public Member Functions

static void _add (double *d, const double *v)
 Add v to d. More...
 
static double _dot (const double *d, const double *v)
 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; More...
 
static void _mul (double *d, const double s)
 Multiply d by s. More...
 
static void _neg (double *d, const double *v)
 Set d to -v. More...
 
static void _sub (double *d, const double *v)
 Subtract v from d. More...
 
static double _sum2 (const double *d)
 Squared modulo of d; Same as r=0.0; for(unsigned i=0;i<n;i++) r+=d[i]*d[i]; return r; More...
 
static void _zero (double *d)
 Set to zero. More...
 

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:

Here xxx is any of the methods of the class.

Member Function Documentation

◆ _add() [1/2]

void PLMD::LoopUnroller< 1 >::_add ( double *  d,
const double *  a 
)
inline

◆ _add() [2/2]

template<unsigned n>
void PLMD::LoopUnroller< n >::_add ( double *  d,
const double *  v 
)
static

Add v to d.

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

◆ _dot() [1/2]

template<unsigned n>
double PLMD::LoopUnroller< n >::_dot ( const double *  d,
const double *  v 
)
static

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;

◆ _dot() [2/2]

double PLMD::LoopUnroller< 1 >::_dot ( const double *  d,
const double *  v 
)
inline

◆ _mul() [1/2]

template<unsigned n>
void PLMD::LoopUnroller< n >::_mul ( double *  d,
const double  s 
)
static

Multiply d by s.

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

◆ _mul() [2/2]

void PLMD::LoopUnroller< 1 >::_mul ( double *  d,
const double  s 
)
inline

◆ _neg() [1/2]

void PLMD::LoopUnroller< 1 >::_neg ( double *  d,
const double *  a 
)
inline

◆ _neg() [2/2]

template<unsigned n>
void PLMD::LoopUnroller< n >::_neg ( double *  d,
const double *  v 
)
static

Set d to -v.

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

◆ _sub() [1/2]

void PLMD::LoopUnroller< 1 >::_sub ( double *  d,
const double *  a 
)
inline

◆ _sub() [2/2]

template<unsigned n>
void PLMD::LoopUnroller< n >::_sub ( double *  d,
const double *  v 
)
static

Subtract v from d.

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

◆ _sum2() [1/2]

template<unsigned n>
double PLMD::LoopUnroller< n >::_sum2 ( const double *  d)
static

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

◆ _sum2() [2/2]

double PLMD::LoopUnroller< 1 >::_sum2 ( const double *  d)
inline

◆ _zero() [1/2]

template<unsigned n>
void PLMD::LoopUnroller< n >::_zero ( double *  d)
static

Set to zero.

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

◆ _zero() [2/2]

void PLMD::LoopUnroller< 1 >::_zero ( double *  d)
inline

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