Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 15 additions & 4 deletions src/Control.cc
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,9 @@ void Control::print(std::ostream& os)
if (precond_type_ == 10)
{
os << " Multigrid preconditioning for wave functions:" << std::endl;
os << " # of Multigrid levels : " << mg_levels_ << std::endl;
os << " # of Multigrid levels : " << mg_levels_ << std::endl;
os << " # of pre-smoothing steps : " << mg_npresmoothing_ << std::endl;
os << " # of post-smoothing steps : " << mg_npostsmoothing_ << std::endl;
}
else
{
Expand Down Expand Up @@ -334,7 +336,7 @@ void Control::sync(void)
if (onpe0 && verbose > 0)
(*MPIdata::sout) << "Control::sync()" << std::endl;
// pack
const short size_short_buffer = 93;
const short size_short_buffer = 95;
short* short_buffer = new short[size_short_buffer];
if (mype_ == 0)
{
Expand Down Expand Up @@ -426,6 +428,8 @@ void Control::sync(void)
short_buffer[90] = (short)static_cast<int>(poisson_lap_type_);
short_buffer[91] = poisson_pc_data_;
short_buffer[92] = precond_precision_;
short_buffer[93] = mg_npresmoothing_;
short_buffer[94] = mg_npostsmoothing_;
}
else
{
Expand Down Expand Up @@ -642,6 +646,8 @@ void Control::sync(void)
poisson_lap_type_ = static_cast<PoissonFDtype>(short_buffer[90]);
poisson_pc_data_ = short_buffer[91];
precond_precision_ = short_buffer[92];
mg_npresmoothing_ = short_buffer[93];
mg_npostsmoothing_ = short_buffer[94];

numst = int_buffer[0];
nel_ = int_buffer[1];
Expand Down Expand Up @@ -1486,8 +1492,13 @@ void Control::setOptions(const boost::program_options::variables_map& vm)
std::cout << "Outer solver type: " << str << std::endl;
assert(it_algo_type_ >= 0);

mg_levels_ = vm["Quench.preconditioner_num_levels"].as<short>() - 1;
precond_precision_ = vm["Quench.preconditioner_precision"].as<short>();
// Preconditioner parameters
mg_levels_ = vm["Preconditioner.num_levels"].as<short>() - 1;
mg_npresmoothing_ = vm["Preconditioner.npresmoothing"].as<short>();
mg_npostsmoothing_ = vm["Preconditioner.npostsmoothing"].as<short>();
precond_precision_ = vm["Preconditioner.precision"].as<short>();
assert(precond_precision_==32 ||precond_precision_==64);

precond_factor = vm["Quench.step_length"].as<float>();
if (precond_factor < 0.)
{
Expand Down
9 changes: 6 additions & 3 deletions src/Control.h
Original file line number Diff line number Diff line change
Expand Up @@ -172,9 +172,6 @@ class Control
// 11=local greedy
short coloring_algo_;

// Number of MG levels for preconditioning
short mg_levels_;

// preconditioning type
// 10 = MG, block implementation
short precond_type_;
Expand Down Expand Up @@ -397,6 +394,12 @@ class Control

float betaAnderson;

// Number of MG levels for preconditioning
short mg_levels_;
short mg_npresmoothing_;
short mg_npostsmoothing_;


// dielectric model for solvation
short diel;
// Parameters for MG solver/ preconditioner for Poisson problem
Expand Down
13 changes: 9 additions & 4 deletions src/MGOrbitalsPreconditioning.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,15 @@
template <class OrbitalsType, typename PDataType>
MGOrbitalsPreconditioning<OrbitalsType, PDataType>::MGOrbitalsPreconditioning(
const short mg_levels, const short lap_type)
: mg_levels_(mg_levels), lap_type_(lap_type), is_set_(false){};
: mg_levels_(mg_levels), lap_type_(lap_type), is_set_(false)
{
Control& ct(*(Control::instance()));
Mesh* mymesh = Mesh::instance();
const pb::Grid& mygrid(mymesh->grid());

precond_ = std::make_shared<Preconditioning<PDataType>>(
lap_type_, mg_levels_, ct.mg_npresmoothing_, ct.mg_npostsmoothing_, mygrid, ct.bcWF);
}

template <class OrbitalsType, typename PDataType>
MGOrbitalsPreconditioning<OrbitalsType, PDataType>::~MGOrbitalsPreconditioning()
Expand All @@ -42,9 +50,6 @@ void MGOrbitalsPreconditioning<OrbitalsType, PDataType>::setup(
Mesh* mymesh = Mesh::instance();
const pb::Grid& mygrid(mymesh->grid());

precond_ = std::make_shared<Preconditioning<PDataType>>(
lap_type_, mg_levels_, mygrid, ct.bcWF);

if (currentMasks != nullptr)
{
// set masks in GridFuncVector class
Expand Down
33 changes: 14 additions & 19 deletions src/Preconditioning.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,19 @@
#include "Preconditioning.h"
#include "LapFactory.h"

using namespace std;

template <typename T>
Preconditioning<T>::Preconditioning(const short lap_type, const short maxlevels,
const pb::Grid& grid, const short bcWF[3])
const short npresmooth, const short npostsmooth,
const pb::Grid& grid, const short bcWF[3]):
max_levels_(maxlevels),
npresmooth_(npresmooth),
npostsmooth_(npostsmooth)
{
max_levels_ = maxlevels;
assert(npresmooth_>=0);
assert(npostsmooth_>=0);
assert(npresmooth_<100);
assert(npostsmooth_<100);

for (short i = 0; i < 3; i++)
bc_[i] = bcWF[i];

Expand All @@ -27,16 +33,6 @@ Preconditioning<T>::Preconditioning(const short lap_type, const short maxlevels,
jacobi_factor_.push_back(myoper->jacobiFactor());
}

template <typename T>
Preconditioning<T>::Preconditioning(const Preconditioning& precond)
{
max_levels_ = precond.max_levels_;
pb::Grid* mygrid = new pb::Grid(*(precond.grid_[0]));
grid_.push_back(mygrid);
for (short i = 0; i < 3; i++)
bc_[i] = precond.bc_[i];
}

template <typename T>
Preconditioning<T>::~Preconditioning()
{
Expand Down Expand Up @@ -150,8 +146,7 @@ void Preconditioning<T>::setup(
}
}

// MG V-cycle with mask corresponding to state istate
// (no mask if istate==-1)
// MG V-cycle
template <typename T>
void Preconditioning<T>::mg(pb::GridFuncVector<T, memory_space_type>& gfv_v,
const pb::GridFuncVector<T, memory_space_type>& gfv_f, const short lap_type,
Expand All @@ -164,8 +159,8 @@ void Preconditioning<T>::mg(pb::GridFuncVector<T, memory_space_type>& gfv_v,
assert(static_cast<int>(gfv_work_.size()) > level);
assert(gfv_work_[level] != nullptr);

short ncycl = 2;
if (level == max_levels_) ncycl = 4;
short ncycl = npresmooth_;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this overloading the meaning of ncycl? i.e. number of vcycle sweeps and number of smoother sweeps? Maybe we should make ncycl an interface parameter as well?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is just an intermediate variable to set the number of iterations in first (smoothing) loop. If coarsest level, will exit after that loop. Not changing behavior compared to previous version

if (level == max_levels_) ncycl = npresmooth_+npostsmooth_;

const double jacobi_factor = jacobi_factor_[level];

Expand Down Expand Up @@ -206,7 +201,7 @@ void Preconditioning<T>::mg(pb::GridFuncVector<T, memory_space_type>& gfv_v,
gfv_v -= (*gfv_work_[level]);

// post-smoothing
for (short it = 0; it < 2; it++)
for (short it = 0; it < npostsmooth_; it++)
{
gfv_v.jacobi(lap_type, gfv_f, *gfv_work_[level], jacobi_factor);
gfv_v.app_mask(level);
Expand Down
11 changes: 8 additions & 3 deletions src/Preconditioning.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,12 @@ class Preconditioning
#endif

private:
short max_levels_;
short lap_type_;

// V-cycle parameters
const short max_levels_;
const short npresmooth_;
const short npostsmooth_;

short bc_[3];

// Jacobi factor at each level
Expand All @@ -48,9 +52,10 @@ class Preconditioning

public:
Preconditioning(const short lap_type, const short maxlevels,
const short npresmooth, const short npostsmooth,
const pb::Grid& grid, const short bc[3]);

Preconditioning(const Preconditioning&);
Preconditioning(const Preconditioning&) = delete;

~Preconditioning();
void clear();
Expand Down
10 changes: 8 additions & 2 deletions src/read_config.cc
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,16 @@ int read_config(int argc, char** argv, po::variables_map& vm,
"Compute MLWF (apply rotation) in quench")(
"Quench.num_lin_iterations", po::value<short>()->default_value(0),
"Number of iterations without potential update in quench")(
"Quench.preconditioner_num_levels",
"Preconditioner.num_levels",
po::value<short>()->default_value(2),
"Number of levels for MG preconditioner")(
"Quench.preconditioner_precision",
"Preconditioner.npresmoothing",
po::value<short>()->default_value(2),
"Number of presmoothing steps i preconditioner")(
"Preconditioner.npostsmoothing",
po::value<short>()->default_value(2),
"Number of postsmoothing steps i preconditioner")(
"Preconditioner.precision",
po::value<short>()->default_value(32),
"Precision for MG preconditioner")("Quench.spread_penalty_damping",
po::value<float>()->default_value(0.),
Expand Down
3 changes: 2 additions & 1 deletion tests/LBFGS/lbfgs1.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ dt=8.
[Quench]
max_steps=50
atol=1.e-8
preconditioner_num_levels=1
[Preconditioner]
num_levels=1
[Orbitals]
initial_type=Gaussian
initial_width=2.
Expand Down
3 changes: 2 additions & 1 deletion tests/LBFGS/lbfgs2.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ dt=8.
[Quench]
max_steps=50
atol=1.e-8
preconditioner_num_levels=1
[Preconditioner]
num_levels=1
[Orbitals]
initial_type=Gaussian
initial_width=2.
Expand Down
3 changes: 2 additions & 1 deletion tests/MLWF/mlwf.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@ type=QUENCH
max_steps=300
atol=1.e-8
MLWF=true
preconditioner_num_levels=1
step_length=1.5
[Preconditioner]
num_levels=1
[Poisson]
FDtype=4th
[Orbitals]
Expand Down
3 changes: 2 additions & 1 deletion tests/SiH4/mgmol.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ type=QUENCH
max_steps=45
atol=1.e-9
num_lin_iterations=2
preconditioner_precision=64
[Preconditioner]
precision=64
[Orbitals]
initial_type=Gaussian
initial_width=2.
Expand Down