|
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_t > | 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 =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 |
|
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:
- Any method in the Grid class that is a bottleneck in performance and has a loop can be moved to this auxiliary class.
- The method should be declared here as a pure virtual function of class AcceleratorBase. The implementation instead goes in class Accelerator
- Class Accelerator is derived from AcceleratorBase but depends on dimension as a template variable.
- The function AcceleratorBase::create takes case of constructing accelerators for each possible value of dimension.
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.