Public Member Functions | Static Public Member Functions | List of all members
PLMD::GridBase::AcceleratorBase Class Referenceabstract

Auxiliary class for accelerating grid calculations. More...

#include <Grid.h>

Public Member Functions

virtual ~AcceleratorBase ()=default
 
virtual unsigned getDimension () const =0
 Can be used to check which value of dimension was used. More...
 
virtual GridBase::index_t getIndex (const GridBase &grid, const std::vector< unsigned > &nbin_, const unsigned *indices, std::size_t indices_size) const =0
 
virtual void getIndices (const std::vector< double > &min_, const std::vector< double > &dx_, const std::vector< double > &x, unsigned *rindex_data, std::size_t rindex_size) const =0
 
virtual void getIndices (const std::vector< unsigned > &nbin_, GridBase::index_t index, unsigned *indices, std::size_t indices_size) const =0
 
virtual std::vector< GridBase::index_tgetNeighbors (const GridBase &grid, const std::vector< unsigned > &nbin_, const std::vector< bool > &pbc_, const unsigned *indices, std::size_t indices_size, const std::vector< unsigned > &nneigh) const =0
 
virtual void getPoint (const std::vector< double > &min_, const std::vector< double > &dx_, const unsigned *indices, std::size_t indices_size, double *point, std::size_t point_size) const =0
 

Static Public Member Functions

static std::unique_ptr< AcceleratorBasecreate (unsigned dim)
 Creates an accelerator with proper dimension. More...
 

Detailed Description

Auxiliary class for accelerating grid calculations.

Many functions in the Grid class have loops running over the dimensions. These loops are always with a little number of iterations, so would likely benefit unrolling. Even better, if the compiler knew the dimension a priori it could remove the loops in most common cases (e.g. dimension=1 or 2).

To obtain this, I added this AcceleratorBase class. Specifically:

The trick works because we don't expect dimension to ever be very high. By restricting it to <=16, we can have a limited number of compiled instances. The compiler will choose at runtime which one should be used.

This class, as well as the derived classes, are expected to be empty. In other words, they only contain the pointer to a virtual table that the compiler will use to call the proper implementation variant, with the correct dimension.

Warning
Interface might change at any time. Do not use this outside of class GridBase and children.

Constructor & Destructor Documentation

◆ ~AcceleratorBase()

virtual PLMD::GridBase::AcceleratorBase::~AcceleratorBase ( )
virtualdefault

Member Function Documentation

◆ create()

std::unique_ptr< Grid::AcceleratorBase > AcceleratorBase::create ( unsigned  dim)
static

Creates an accelerator with proper dimension.

◆ getDimension()

virtual unsigned PLMD::GridBase::AcceleratorBase::getDimension ( ) const
pure virtual

Can be used to check which value of dimension was used.

◆ getIndex()

virtual GridBase::index_t PLMD::GridBase::AcceleratorBase::getIndex ( const GridBase grid,
const std::vector< unsigned > &  nbin_,
const unsigned *  indices,
std::size_t  indices_size 
) const
pure virtual

◆ getIndices() [1/2]

virtual void PLMD::GridBase::AcceleratorBase::getIndices ( const std::vector< double > &  min_,
const std::vector< double > &  dx_,
const std::vector< double > &  x,
unsigned *  rindex_data,
std::size_t  rindex_size 
) const
pure virtual

◆ getIndices() [2/2]

virtual void PLMD::GridBase::AcceleratorBase::getIndices ( const std::vector< unsigned > &  nbin_,
GridBase::index_t  index,
unsigned *  indices,
std::size_t  indices_size 
) const
pure virtual

◆ getNeighbors()

virtual std::vector<GridBase::index_t> PLMD::GridBase::AcceleratorBase::getNeighbors ( const GridBase grid,
const std::vector< unsigned > &  nbin_,
const std::vector< bool > &  pbc_,
const unsigned *  indices,
std::size_t  indices_size,
const std::vector< unsigned > &  nneigh 
) const
pure virtual

◆ getPoint()

virtual void PLMD::GridBase::AcceleratorBase::getPoint ( const std::vector< double > &  min_,
const std::vector< double > &  dx_,
const unsigned *  indices,
std::size_t  indices_size,
double *  point,
std::size_t  point_size 
) const
pure virtual

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