ESPResSo
Extensible Simulation Package for Research on Soft Matter Systems
|
Tuning algorithm for P3M. More...
#include <TuningAlgorithm.hpp>
Classes | |
struct | Parameters |
Public Member Functions | |
TuningAlgorithm (System::System &system, double prefactor, int timings) | |
virtual | ~TuningAlgorithm ()=default |
virtual P3MParameters & | get_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::System & | m_system |
double | m_prefactor |
std::unique_ptr< TuningLogger > | m_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. | |
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.
|
inline |
Definition at line 94 of file TuningAlgorithm.hpp.
|
virtualdefault |
|
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.
[in] | mesh | number of mesh points per coordinate direction (>0), in real space. |
[in] | cao | charge assignment order ([0,7]). |
[in] | r_cut_iL | cutoff radius for real space electrostatics (>0), rescaled to r_cut_iL = r_cut * box_l_i . |
Ewald splitting parameter (0.
Implemented in CoulombTuningAlgorithm< FloatType, Architecture >, and DipolarTuningAlgorithm< FloatType, Architecture >.
Referenced by get_mc_time().
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().
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().
|
pure virtual |
Determine a sensible range for the mesh.
Implemented in CoulombTuningAlgorithm< FloatType, Architecture >, and DipolarTuningAlgorithm< FloatType, Architecture >.
void TuningAlgorithm::determine_r_cut_limits | ( | ) |
Determine a sensible range for the real-space cutoff.
Definition at line 59 of file TuningAlgorithm.cpp.
References System::System::box_geo, System::System::cell_structure, get_params(), System::System::local_geo, m_logger, m_r_cut_iL_max, m_r_cut_iL_min, m_system, and P3MParameters::r_cut_iL.
Referenced by CoulombP3MImpl< FloatType, Architecture >::tune(), and DipolarP3MImpl< FloatType, Architecture >::tune().
|
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().
|
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.
[in] | mesh | number of mesh points per coordinate direction (>0), in real space. |
[in,out] | tuned_cao | initial guess for the |
charge assignment order ([0,7]).
[out] | tuned_r_cut_iL | cutoff radius for real space electrostatics (>0), rescaled to r_cut_iL = r_cut * box_l_i . |
[out] | tuned_alpha_L | Ewald splitting parameter (0. |
[out] | tuned_accuracy | accuracy of the actual parameter set. |
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().
|
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.
[in] | mesh | number of mesh points per coordinate direction (>0), in real space. |
[in] | cao | charge assignment order ([0,7]). |
[in,out] | tuned_r_cut_iL | cutoff radius for real space electrostatics (>0), rescaled to r_cut_iL = r_cut * box_l_i . |
[in,out] | tuned_alpha_L | Ewald splitting parameter (0. |
[in,out] | tuned_accuracy | accuracy of the actual parameter set. |
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().
|
inlineprotected |
Definition at line 184 of file TuningAlgorithm.hpp.
Referenced by DipolarTuningAlgorithm< FloatType, Architecture >::get_time().
|
pure virtual |
Get the P3M parameters.
Implemented in CoulombTuningAlgorithm< FloatType, Architecture >, and DipolarTuningAlgorithm< FloatType, Architecture >.
Referenced by commit(), determine_cao_limits(), determine_r_cut_limits(), get_mc_time(), and tune().
|
pure virtual |
Tuning loop entry point.
Implemented in CoulombTuningAlgorithm< FloatType, Architecture >, and DipolarTuningAlgorithm< FloatType, Architecture >.
Referenced by tune().
|
inlineprotected |
Definition at line 185 of file TuningAlgorithm.hpp.
Referenced by get_mc_time().
|
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().
|
pure virtual |
Re-initialize the currently active solver.
Implemented in CoulombTuningAlgorithm< FloatType, Architecture >, and DipolarTuningAlgorithm< FloatType, Architecture >.
Referenced by get_mc_time().
|
inlineprotected |
Definition at line 186 of file TuningAlgorithm.hpp.
Referenced by DipolarTuningAlgorithm< FloatType, Architecture >::get_time().
|
pure virtual |
Configure the logger.
Implemented in CoulombTuningAlgorithm< FloatType, Architecture >, and DipolarTuningAlgorithm< FloatType, Architecture >.
|
inline |
Definition at line 160 of file TuningAlgorithm.hpp.
References P3MParameters::accuracy, commit(), get_params(), get_time(), m_logger, time_sentinel, and P3MParameters::tuning.
Referenced by CoulombP3MImpl< FloatType, Architecture >::tune(), and DipolarP3MImpl< FloatType, Architecture >::tune().
|
protected |
Definition at line 75 of file TuningAlgorithm.hpp.
Referenced by determine_cao_limits(), and DipolarTuningAlgorithm< FloatType, Architecture >::get_time().
|
protected |
Definition at line 75 of file TuningAlgorithm.hpp.
Referenced by determine_cao_limits(), and get_m_time().
|
protected |
Definition at line 75 of file TuningAlgorithm.hpp.
Referenced by determine_cao_limits(), and get_m_time().
|
protected |
Definition at line 74 of file TuningAlgorithm.hpp.
Referenced by determine_cao_limits(), DipolarTuningAlgorithm< FloatType, Architecture >::determine_mesh_limits(), determine_r_cut_limits(), get_mc_time(), CoulombTuningAlgorithm< FloatType, Architecture >::setup_logger(), DipolarTuningAlgorithm< FloatType, Architecture >::setup_logger(), and tune().
|
protected |
Definition at line 73 of file TuningAlgorithm.hpp.
Referenced by CoulombTuningAlgorithm< FloatType, Architecture >::setup_logger(), and DipolarTuningAlgorithm< FloatType, Architecture >::setup_logger().
|
protected |
Definition at line 76 of file TuningAlgorithm.hpp.
Referenced by determine_r_cut_limits(), get_mc_time(), and DipolarTuningAlgorithm< FloatType, Architecture >::get_time().
|
protected |
Definition at line 76 of file TuningAlgorithm.hpp.
Referenced by determine_r_cut_limits(), and get_mc_time().
|
protected |
Definition at line 66 of file TuningAlgorithm.hpp.
Referenced by DipolarTuningAlgorithm< FloatType, Architecture >::calculate_accuracy(), commit(), determine_r_cut_limits(), get_mc_time(), CoulombTuningAlgorithm< FloatType, Architecture >::layer_correction_veto_r_cut(), CoulombTuningAlgorithm< FloatType, Architecture >::on_solver_change(), DipolarTuningAlgorithm< FloatType, Architecture >::on_solver_change(), CoulombTuningAlgorithm< FloatType, Architecture >::setup_logger(), and DipolarTuningAlgorithm< FloatType, Architecture >::setup_logger().
|
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().
|
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().
|
staticconstexprprotected |
Value for invalid time measurements.
Definition at line 91 of file TuningAlgorithm.hpp.
Referenced by DipolarTuningAlgorithm< FloatType, Architecture >::get_time(), and tune().