ESPResSo
Extensible Simulation Package for Research on Soft Matter Systems
Loading...
Searching...
No Matches
TuningAlgorithm Class Referenceabstract

Tuning algorithm for P3M. More...

#include <TuningAlgorithm.hpp>

+ Inheritance diagram for TuningAlgorithm:
+ Collaboration diagram for TuningAlgorithm:

Classes

struct  Parameters
 

Public Member Functions

 TuningAlgorithm (System::System &system, double prefactor, int timings)
 
virtual ~TuningAlgorithm ()=default
 
virtual P3MParametersget_params ()=0
 Get the P3M parameters.
 
virtual void on_solver_change () const =0
 Re-initialize the currently active solver.
 
virtual TuningAlgorithm::Parameters get_time ()=0
 Tuning loop entry point.
 
virtual void setup_logger (bool verbose)=0
 Configure the logger.
 
virtual void determine_mesh_limits ()=0
 Determine a sensible range for the mesh.
 
void determine_r_cut_limits ()
 Determine a sensible range for the real-space cutoff.
 
void determine_cao_limits (int initial_cao)
 Determine a sensible range for the charge assignment order.
 
virtual std::tuple< double, double, double, double > calculate_accuracy (Utils::Vector3i const &mesh, int cao, double r_cut_iL) const =0
 Get the minimal error for this combination of parameters.
 
virtual std::optional< std::string > layer_correction_veto_r_cut (double r_cut) const =0
 Veto real-space cutoffs larger than the layer correction gap.
 
virtual std::optional< std::string > fft_decomposition_veto (Utils::Vector3i const &) const
 Veto FFT decomposition in non-cubic boxes.
 
void commit (Utils::Vector3i const &mesh, int cao, double r_cut_iL, double alpha_L)
 Write tuned parameters to the P3M parameter struct.
 
void tune ()
 

Protected Member Functions

auto get_n_trials ()
 
void increment_n_trials ()
 
void reset_n_trials ()
 
double get_m_time (Utils::Vector3i const &mesh, int &tuned_cao, double &tuned_r_cut_iL, double &tuned_alpha_L, double &tuned_accuracy)
 Get the optimal alpha and the corresponding computation time for a fixed mesh.
 
double get_mc_time (Utils::Vector3i const &mesh, int cao, double &tuned_r_cut_iL, double &tuned_alpha_L, double &tuned_accuracy)
 Get the optimal alpha and the corresponding computation time for a fixed mesh and cao.
 

Protected Attributes

System::Systemm_system
 
double m_prefactor
 
std::unique_ptr< TuningLoggerm_logger = nullptr
 
int cao_min = -1
 
int cao_max = -1
 
int cao_best = -1
 
double m_r_cut_iL_min = -1.
 
double m_r_cut_iL_max = -1.
 

Static Protected Attributes

static auto constexpr time_granularity = 2.
 Granularity of the time measurement (milliseconds).
 
static auto constexpr max_n_consecutive_trials = 20
 Maximal number of consecutive trials that don't improve runtime.
 
static auto constexpr time_sentinel = std::numeric_limits<double>::max()
 Value for invalid time measurements.
 

Detailed Description

Tuning algorithm for P3M.

The algorithm basically determines the mesh, cao and then the real-space cutoff, in this order.

For each mesh, the optimal cao for the previous mesh is re-used as an initial guess, and the algorithm checks whether increasing or decreasing it leads to a better solution. This is efficient, since the optimal cao only changes little with the meshes in general.

The real-space cutoff for a given mesh and cao is determined via a bisection on the error estimate, which determines where the error estimate equals the required accuracy. Therefore the smallest possible, i.e. fastest real-space cutoff is determined.

Both the search over mesh and cao stop to search in a specific direction once the computation time is significantly higher than the currently known optimum.

Definition at line 64 of file TuningAlgorithm.hpp.

Constructor & Destructor Documentation

◆ TuningAlgorithm()

TuningAlgorithm::TuningAlgorithm ( System::System system,
double  prefactor,
int  timings 
)
inline

Definition at line 94 of file TuningAlgorithm.hpp.

◆ ~TuningAlgorithm()

virtual TuningAlgorithm::~TuningAlgorithm ( )
virtualdefault

Member Function Documentation

◆ calculate_accuracy()

virtual std::tuple< double, double, double, double > TuningAlgorithm::calculate_accuracy ( Utils::Vector3i const &  mesh,
int  cao,
double  r_cut_iL 
) const
pure virtual

Get the minimal error for this combination of parameters.

The real-space error is tuned such that it contributes half of the total error, and then the k-space error is calculated. If an optimal alpha is not found, the value 0.1 is used as fallback.

Parameters
[in]meshnumber of mesh points per coordinate direction (>0), in real space.
[in]caocharge assignment order ([0,7]).
[in]r_cut_iLcutoff radius for real space electrostatics (>0), rescaled to r_cut_iL = r_cut * box_l_i.
Returns
Error magnitude, real-space error, k-space error,

Ewald splitting parameter (0.

Implemented in CoulombTuningAlgorithm< FloatType, Architecture >, and DipolarTuningAlgorithm< FloatType, Architecture >.

Referenced by get_mc_time().

◆ commit()

void TuningAlgorithm::commit ( Utils::Vector3i const &  mesh,
int  cao,
double  r_cut_iL,
double  alpha_L 
)

Write tuned parameters to the P3M parameter struct.

Definition at line 90 of file TuningAlgorithm.cpp.

References System::System::box_geo, get_params(), and m_system.

Referenced by get_mc_time(), and tune().

◆ determine_cao_limits()

void TuningAlgorithm::determine_cao_limits ( int  initial_cao)

Determine a sensible range for the charge assignment order.

Definition at line 77 of file TuningAlgorithm.cpp.

References P3MParameters::cao, cao_best, cao_max, cao_min, get_params(), and m_logger.

Referenced by CoulombP3MImpl< FloatType, Architecture >::tune(), and DipolarP3MImpl< FloatType, Architecture >::tune().

◆ determine_mesh_limits()

virtual void TuningAlgorithm::determine_mesh_limits ( )
pure virtual

◆ determine_r_cut_limits()

void TuningAlgorithm::determine_r_cut_limits ( )

◆ fft_decomposition_veto()

virtual std::optional< std::string > TuningAlgorithm::fft_decomposition_veto ( Utils::Vector3i const &  ) const
inlinevirtual

Veto FFT decomposition in non-cubic boxes.

Reimplemented in CoulombTuningAlgorithm< FloatType, Architecture >.

Definition at line 152 of file TuningAlgorithm.hpp.

Referenced by get_mc_time().

◆ get_m_time()

double TuningAlgorithm::get_m_time ( Utils::Vector3i const &  mesh,
int &  tuned_cao,
double &  tuned_r_cut_iL,
double &  tuned_alpha_L,
double &  tuned_accuracy 
)
protected

Get the optimal alpha and the corresponding computation time for a fixed mesh.

_cao should contain an initial guess, which is then adapted by stepping up and down.

Parameters
[in]meshnumber of mesh points per coordinate direction (>0), in real space.
[in,out]tuned_caoinitial guess for the

charge assignment order ([0,7]).

Parameters
[out]tuned_r_cut_iLcutoff radius for real space electrostatics (>0), rescaled to r_cut_iL = r_cut * box_l_i.
[out]tuned_alpha_LEwald splitting parameter (0.
[out]tuned_accuracyaccuracy of the actual parameter set.
Returns
The integration time in case of success, otherwise -P3M_TUNE_CAO_TOO_LARGE

Definition at line 223 of file TuningAlgorithm.cpp.

References cao_max, cao_min, get_mc_time(), P3M_TUNE_CAO_TOO_LARGE, and time_granularity.

Referenced by DipolarTuningAlgorithm< FloatType, Architecture >::get_time().

◆ get_mc_time()

double TuningAlgorithm::get_mc_time ( Utils::Vector3i const &  mesh,
int  cao,
double &  tuned_r_cut_iL,
double &  tuned_alpha_L,
double &  tuned_accuracy 
)
protected

Get the optimal alpha and the corresponding computation time for a fixed mesh and cao.

The tuned_r_cut_iL is determined via a simple bisection.

Parameters
[in]meshnumber of mesh points per coordinate direction (>0), in real space.
[in]caocharge assignment order ([0,7]).
[in,out]tuned_r_cut_iLcutoff radius for real space electrostatics (>0), rescaled to r_cut_iL = r_cut * box_l_i.
[in,out]tuned_alpha_LEwald splitting parameter (0.
[in,out]tuned_accuracyaccuracy of the actual parameter set.
Returns
The integration time in case of success, otherwise -P3M_TUNE_ACCURACY_TOO_LARGE, -P3M_TUNE_FFT_MESH_SIZE, -P3M_TUNE_CAO_TOO_LARGE, or -P3M_TUNE_ELC_GAP_SIZE

Definition at line 118 of file TuningAlgorithm.cpp.

References P3MParameters::accuracy, benchmark_integration_step(), System::System::box_geo, calculate_accuracy(), System::System::cell_structure, commit(), fft_decomposition_veto(), get_params(), Utils::hadamard_division(), increment_n_trials(), layer_correction_veto_r_cut(), System::System::local_geo, m_logger, m_r_cut_iL_max, m_r_cut_iL_min, m_system, on_solver_change(), P3M_RCUT_PREC, P3M_TUNE_ACCURACY_TOO_LARGE, P3M_TUNE_CAO_TOO_LARGE, P3M_TUNE_ELC_GAP_SIZE, and P3M_TUNE_FFT_MESH_SIZE.

Referenced by get_m_time().

◆ get_n_trials()

auto TuningAlgorithm::get_n_trials ( )
inlineprotected

◆ get_params()

virtual P3MParameters & TuningAlgorithm::get_params ( )
pure virtual

◆ get_time()

virtual TuningAlgorithm::Parameters TuningAlgorithm::get_time ( )
pure virtual

◆ increment_n_trials()

void TuningAlgorithm::increment_n_trials ( )
inlineprotected

Definition at line 185 of file TuningAlgorithm.hpp.

Referenced by get_mc_time().

◆ layer_correction_veto_r_cut()

virtual std::optional< std::string > TuningAlgorithm::layer_correction_veto_r_cut ( double  r_cut) const
pure virtual

Veto real-space cutoffs larger than the layer correction gap.

Implemented in CoulombTuningAlgorithm< FloatType, Architecture >, and DipolarTuningAlgorithm< FloatType, Architecture >.

Referenced by get_mc_time().

◆ on_solver_change()

virtual void TuningAlgorithm::on_solver_change ( ) const
pure virtual

Re-initialize the currently active solver.

Implemented in CoulombTuningAlgorithm< FloatType, Architecture >, and DipolarTuningAlgorithm< FloatType, Architecture >.

Referenced by get_mc_time().

◆ reset_n_trials()

void TuningAlgorithm::reset_n_trials ( )
inlineprotected

◆ setup_logger()

virtual void TuningAlgorithm::setup_logger ( bool  verbose)
pure virtual

◆ tune()

Member Data Documentation

◆ cao_best

int TuningAlgorithm::cao_best = -1
protected

◆ cao_max

int TuningAlgorithm::cao_max = -1
protected

Definition at line 75 of file TuningAlgorithm.hpp.

Referenced by determine_cao_limits(), and get_m_time().

◆ cao_min

int TuningAlgorithm::cao_min = -1
protected

Definition at line 75 of file TuningAlgorithm.hpp.

Referenced by determine_cao_limits(), and get_m_time().

◆ m_logger

◆ m_prefactor

◆ m_r_cut_iL_max

double TuningAlgorithm::m_r_cut_iL_max = -1.
protected

◆ m_r_cut_iL_min

double TuningAlgorithm::m_r_cut_iL_min = -1.
protected

Definition at line 76 of file TuningAlgorithm.hpp.

Referenced by determine_r_cut_limits(), and get_mc_time().

◆ m_system

◆ max_n_consecutive_trials

auto constexpr TuningAlgorithm::max_n_consecutive_trials = 20
staticconstexprprotected

Maximal number of consecutive trials that don't improve runtime.

Tuning halts when this threshold is reached.

Definition at line 88 of file TuningAlgorithm.hpp.

Referenced by DipolarTuningAlgorithm< FloatType, Architecture >::get_time().

◆ time_granularity

auto constexpr TuningAlgorithm::time_granularity = 2.
staticconstexprprotected

Granularity of the time measurement (milliseconds).

Tuning halts when the runtime is larger than the best time plus this value.

Definition at line 82 of file TuningAlgorithm.hpp.

Referenced by get_m_time(), and DipolarTuningAlgorithm< FloatType, Architecture >::get_time().

◆ time_sentinel

auto constexpr TuningAlgorithm::time_sentinel = std::numeric_limits<double>::max()
staticconstexprprotected

Value for invalid time measurements.

Definition at line 91 of file TuningAlgorithm.hpp.

Referenced by DipolarTuningAlgorithm< FloatType, Architecture >::get_time(), and tune().


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