mirror of
https://github.com/paboyle/Grid.git
synced 2025-07-27 17:57:08 +01:00
Hadrons: moving Hadrons to root directory, build system improvements
This commit is contained in:
36
Hadrons/Modules/MSolver/A2AVectors.cc
Normal file
36
Hadrons/Modules/MSolver/A2AVectors.cc
Normal file
@@ -0,0 +1,36 @@
|
||||
/*************************************************************************************
|
||||
|
||||
Grid physics library, www.github.com/paboyle/Grid
|
||||
|
||||
Source file: extras/Hadrons/Modules/MSolver/A2AVectors.cc
|
||||
|
||||
Copyright (C) 2015-2018
|
||||
|
||||
Author: Antonin Portelli <antonin.portelli@me.com>
|
||||
Author: fionnoh <fionnoh@gmail.com>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License along
|
||||
with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
|
||||
See the full license in the file "LICENSE" in the top level distribution directory
|
||||
*************************************************************************************/
|
||||
/* END LEGAL */
|
||||
#include <Hadrons/Modules/MSolver/A2AVectors.hpp>
|
||||
|
||||
using namespace Grid;
|
||||
using namespace Hadrons;
|
||||
using namespace MSolver;
|
||||
|
||||
template class Grid::Hadrons::MSolver::TA2AVectors<FIMPL, FermionEigenPack<FIMPL>>;
|
||||
template class Grid::Hadrons::MSolver::TA2AVectors<ZFIMPL, FermionEigenPack<ZFIMPL>>;
|
245
Hadrons/Modules/MSolver/A2AVectors.hpp
Normal file
245
Hadrons/Modules/MSolver/A2AVectors.hpp
Normal file
@@ -0,0 +1,245 @@
|
||||
/*************************************************************************************
|
||||
|
||||
Grid physics library, www.github.com/paboyle/Grid
|
||||
|
||||
Source file: extras/Hadrons/Modules/MSolver/A2AVectors.hpp
|
||||
|
||||
Copyright (C) 2015-2018
|
||||
|
||||
Author: Antonin Portelli <antonin.portelli@me.com>
|
||||
Author: fionnoh <fionnoh@gmail.com>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License along
|
||||
with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
|
||||
See the full license in the file "LICENSE" in the top level distribution directory
|
||||
*************************************************************************************/
|
||||
/* END LEGAL */
|
||||
#ifndef Hadrons_MSolver_A2AVectors_hpp_
|
||||
#define Hadrons_MSolver_A2AVectors_hpp_
|
||||
|
||||
#include <Hadrons/Global.hpp>
|
||||
#include <Hadrons/Module.hpp>
|
||||
#include <Hadrons/ModuleFactory.hpp>
|
||||
#include <Hadrons/Solver.hpp>
|
||||
#include <Hadrons/EigenPack.hpp>
|
||||
#include <Hadrons/A2AVectors.hpp>
|
||||
#include <Hadrons/DilutedNoise.hpp>
|
||||
|
||||
BEGIN_HADRONS_NAMESPACE
|
||||
|
||||
/******************************************************************************
|
||||
* Create all-to-all V & W vectors *
|
||||
******************************************************************************/
|
||||
BEGIN_MODULE_NAMESPACE(MSolver)
|
||||
|
||||
class A2AVectorsPar: Serializable
|
||||
{
|
||||
public:
|
||||
GRID_SERIALIZABLE_CLASS_MEMBERS(A2AVectorsPar,
|
||||
std::string, noise,
|
||||
std::string, action,
|
||||
std::string, eigenPack,
|
||||
std::string, solver);
|
||||
};
|
||||
|
||||
template <typename FImpl, typename Pack>
|
||||
class TA2AVectors : public Module<A2AVectorsPar>
|
||||
{
|
||||
public:
|
||||
FERM_TYPE_ALIASES(FImpl,);
|
||||
SOLVER_TYPE_ALIASES(FImpl,);
|
||||
typedef HADRONS_DEFAULT_SCHUR_A2A<FImpl> A2A;
|
||||
public:
|
||||
// constructor
|
||||
TA2AVectors(const std::string name);
|
||||
// destructor
|
||||
virtual ~TA2AVectors(void) {};
|
||||
// dependency relation
|
||||
virtual std::vector<std::string> getInput(void);
|
||||
virtual std::vector<std::string> getOutput(void);
|
||||
// setup
|
||||
virtual void setup(void);
|
||||
// execution
|
||||
virtual void execute(void);
|
||||
private:
|
||||
std::string solverName_;
|
||||
unsigned int Nl_{0};
|
||||
};
|
||||
|
||||
MODULE_REGISTER_TMP(A2AVectors,
|
||||
ARG(TA2AVectors<FIMPL, FermionEigenPack<FIMPL>>), MSolver);
|
||||
MODULE_REGISTER_TMP(ZA2AVectors,
|
||||
ARG(TA2AVectors<ZFIMPL, FermionEigenPack<ZFIMPL>>), MSolver);
|
||||
|
||||
/******************************************************************************
|
||||
* TA2AVectors implementation *
|
||||
******************************************************************************/
|
||||
// constructor /////////////////////////////////////////////////////////////////
|
||||
template <typename FImpl, typename Pack>
|
||||
TA2AVectors<FImpl, Pack>::TA2AVectors(const std::string name)
|
||||
: Module<A2AVectorsPar>(name)
|
||||
{}
|
||||
|
||||
// dependencies/products ///////////////////////////////////////////////////////
|
||||
template <typename FImpl, typename Pack>
|
||||
std::vector<std::string> TA2AVectors<FImpl, Pack>::getInput(void)
|
||||
{
|
||||
std::string sub_string;
|
||||
std::vector<std::string> in;
|
||||
|
||||
if (!par().eigenPack.empty())
|
||||
{
|
||||
in.push_back(par().eigenPack);
|
||||
sub_string = (!par().eigenPack.empty()) ? "_subtract" : "";
|
||||
}
|
||||
in.push_back(par().solver + sub_string);
|
||||
in.push_back(par().noise);
|
||||
|
||||
return in;
|
||||
}
|
||||
|
||||
template <typename FImpl, typename Pack>
|
||||
std::vector<std::string> TA2AVectors<FImpl, Pack>::getOutput(void)
|
||||
{
|
||||
std::vector<std::string> out = {getName() + "_v", getName() + "_w"};
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
// setup ///////////////////////////////////////////////////////////////////////
|
||||
template <typename FImpl, typename Pack>
|
||||
void TA2AVectors<FImpl, Pack>::setup(void)
|
||||
{
|
||||
bool hasLowModes = (!par().eigenPack.empty());
|
||||
std::string sub_string = (hasLowModes) ? "_subtract" : "";
|
||||
auto &noise = envGet(DilutedNoise<FImpl>, par().noise);
|
||||
auto &action = envGet(FMat, par().action);
|
||||
auto &solver = envGet(Solver, par().solver + sub_string);
|
||||
int Ls = env().getObjectLs(par().action);
|
||||
|
||||
if (hasLowModes)
|
||||
{
|
||||
auto &epack = envGet(Pack, par().eigenPack);
|
||||
Nl_ = epack.evec.size();
|
||||
}
|
||||
envCreate(std::vector<FermionField>, getName() + "_v", 1,
|
||||
Nl_ + noise.size(), FermionField(env().getGrid()));
|
||||
envCreate(std::vector<FermionField>, getName() + "_w", 1,
|
||||
Nl_ + noise.size(), FermionField(env().getGrid()));
|
||||
if (Ls > 1)
|
||||
{
|
||||
envTmpLat(FermionField, "f5", Ls);
|
||||
}
|
||||
envTmp(A2A, "a2a", 1, action, solver);
|
||||
}
|
||||
|
||||
// execution ///////////////////////////////////////////////////////////////////
|
||||
template <typename FImpl, typename Pack>
|
||||
void TA2AVectors<FImpl, Pack>::execute(void)
|
||||
{
|
||||
std::string sub_string = (Nl_ > 0) ? "_subtract" : "";
|
||||
auto &action = envGet(FMat, par().action);
|
||||
auto &solver = envGet(Solver, par().solver + sub_string);
|
||||
auto &noise = envGet(DilutedNoise<FImpl>, par().noise);
|
||||
auto &v = envGet(std::vector<FermionField>, getName() + "_v");
|
||||
auto &w = envGet(std::vector<FermionField>, getName() + "_w");
|
||||
int Ls = env().getObjectLs(par().action);
|
||||
|
||||
envGetTmp(A2A, a2a);
|
||||
|
||||
if (Nl_ > 0)
|
||||
{
|
||||
LOG(Message) << "Computing all-to-all vectors "
|
||||
<< " using eigenpack '" << par().eigenPack << "' ("
|
||||
<< Nl_ << " low modes) and noise '"
|
||||
<< par().noise << "' (" << noise.size()
|
||||
<< " noise vectors)" << std::endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
LOG(Message) << "Computing all-to-all vectors "
|
||||
<< " using noise '" << par().noise << "' (" << noise.size()
|
||||
<< " noise vectors)" << std::endl;
|
||||
}
|
||||
// Low modes
|
||||
for (unsigned int il = 0; il < Nl_; il++)
|
||||
{
|
||||
auto &epack = envGet(Pack, par().eigenPack);
|
||||
|
||||
startTimer("V low mode");
|
||||
LOG(Message) << "V vector i = " << il << " (low mode)" << std::endl;
|
||||
if (Ls == 1)
|
||||
{
|
||||
a2a.makeLowModeV(v[il], epack.evec[il], epack.eval[il]);
|
||||
}
|
||||
else
|
||||
{
|
||||
envGetTmp(FermionField, f5);
|
||||
a2a.makeLowModeV5D(v[il], f5, epack.evec[il], epack.eval[il]);
|
||||
}
|
||||
stopTimer("V low mode");
|
||||
startTimer("W low mode");
|
||||
LOG(Message) << "W vector i = " << il << " (low mode)" << std::endl;
|
||||
if (Ls == 1)
|
||||
{
|
||||
a2a.makeLowModeW(w[il], epack.evec[il], epack.eval[il]);
|
||||
}
|
||||
else
|
||||
{
|
||||
envGetTmp(FermionField, f5);
|
||||
a2a.makeLowModeW5D(w[il], f5, epack.evec[il], epack.eval[il]);
|
||||
}
|
||||
stopTimer("W low mode");
|
||||
}
|
||||
|
||||
// High modes
|
||||
for (unsigned int ih = 0; ih < noise.size(); ih++)
|
||||
{
|
||||
startTimer("V high mode");
|
||||
LOG(Message) << "V vector i = " << Nl_ + ih
|
||||
<< " (" << ((Nl_ > 0) ? "high " : "")
|
||||
<< "stochastic mode)" << std::endl;
|
||||
if (Ls == 1)
|
||||
{
|
||||
a2a.makeHighModeV(v[Nl_ + ih], noise[ih]);
|
||||
}
|
||||
else
|
||||
{
|
||||
envGetTmp(FermionField, f5);
|
||||
a2a.makeHighModeV5D(v[Nl_ + ih], f5, noise[ih]);
|
||||
}
|
||||
stopTimer("V high mode");
|
||||
startTimer("W high mode");
|
||||
LOG(Message) << "W vector i = " << Nl_ + ih
|
||||
<< " (" << ((Nl_ > 0) ? "high " : "")
|
||||
<< "stochastic mode)" << std::endl;
|
||||
if (Ls == 1)
|
||||
{
|
||||
a2a.makeHighModeW(w[Nl_ + ih], noise[ih]);
|
||||
}
|
||||
else
|
||||
{
|
||||
envGetTmp(FermionField, f5);
|
||||
a2a.makeHighModeW5D(w[Nl_ + ih], f5, noise[ih]);
|
||||
}
|
||||
stopTimer("W high mode");
|
||||
}
|
||||
}
|
||||
|
||||
END_MODULE_NAMESPACE
|
||||
|
||||
END_HADRONS_NAMESPACE
|
||||
|
||||
#endif // Hadrons_MSolver_A2AVectors_hpp_
|
36
Hadrons/Modules/MSolver/LocalCoherenceLanczos.cc
Normal file
36
Hadrons/Modules/MSolver/LocalCoherenceLanczos.cc
Normal file
@@ -0,0 +1,36 @@
|
||||
/*************************************************************************************
|
||||
|
||||
Grid physics library, www.github.com/paboyle/Grid
|
||||
|
||||
Source file: extras/Hadrons/Modules/MSolver/LocalCoherenceLanczos.cc
|
||||
|
||||
Copyright (C) 2015-2018
|
||||
|
||||
Author: Antonin Portelli <antonin.portelli@me.com>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License along
|
||||
with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
|
||||
See the full license in the file "LICENSE" in the top level distribution directory
|
||||
*************************************************************************************/
|
||||
/* END LEGAL */
|
||||
#include <Hadrons/Modules/MSolver/LocalCoherenceLanczos.hpp>
|
||||
|
||||
using namespace Grid;
|
||||
using namespace Hadrons;
|
||||
using namespace MSolver;
|
||||
|
||||
template class Grid::Hadrons::MSolver::TLocalCoherenceLanczos<FIMPL,HADRONS_DEFAULT_LANCZOS_NBASIS>;
|
||||
template class Grid::Hadrons::MSolver::TLocalCoherenceLanczos<ZFIMPL,HADRONS_DEFAULT_LANCZOS_NBASIS>;
|
||||
|
186
Hadrons/Modules/MSolver/LocalCoherenceLanczos.hpp
Normal file
186
Hadrons/Modules/MSolver/LocalCoherenceLanczos.hpp
Normal file
@@ -0,0 +1,186 @@
|
||||
/*************************************************************************************
|
||||
|
||||
Grid physics library, www.github.com/paboyle/Grid
|
||||
|
||||
Source file: extras/Hadrons/Modules/MSolver/LocalCoherenceLanczos.hpp
|
||||
|
||||
Copyright (C) 2015-2018
|
||||
|
||||
Author: Antonin Portelli <antonin.portelli@me.com>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License along
|
||||
with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
|
||||
See the full license in the file "LICENSE" in the top level distribution directory
|
||||
*************************************************************************************/
|
||||
/* END LEGAL */
|
||||
#ifndef Hadrons_MSolver_LocalCoherenceLanczos_hpp_
|
||||
#define Hadrons_MSolver_LocalCoherenceLanczos_hpp_
|
||||
|
||||
#include <Hadrons/Global.hpp>
|
||||
#include <Hadrons/Module.hpp>
|
||||
#include <Hadrons/ModuleFactory.hpp>
|
||||
#include <Hadrons/EigenPack.hpp>
|
||||
|
||||
BEGIN_HADRONS_NAMESPACE
|
||||
|
||||
/******************************************************************************
|
||||
* Local coherence Lanczos eigensolver *
|
||||
*****************************************************************************/
|
||||
BEGIN_MODULE_NAMESPACE(MSolver)
|
||||
|
||||
class LocalCoherenceLanczosPar: Serializable
|
||||
{
|
||||
public:
|
||||
GRID_SERIALIZABLE_CLASS_MEMBERS(LocalCoherenceLanczosPar,
|
||||
std::string, action,
|
||||
bool, doCoarse,
|
||||
LanczosParams, fineParams,
|
||||
LanczosParams, coarseParams,
|
||||
ChebyParams, smoother,
|
||||
RealD, coarseRelaxTol,
|
||||
std::string, blockSize,
|
||||
std::string, output,
|
||||
bool, multiFile);
|
||||
};
|
||||
|
||||
template <typename FImpl, int nBasis>
|
||||
class TLocalCoherenceLanczos: public Module<LocalCoherenceLanczosPar>
|
||||
{
|
||||
public:
|
||||
FERM_TYPE_ALIASES(FImpl,);
|
||||
typedef LocalCoherenceLanczos<typename FImpl::SiteSpinor,
|
||||
typename FImpl::SiteComplex,
|
||||
nBasis> LCL;
|
||||
typedef FermionEigenPack<FImpl> BasePack;
|
||||
typedef CoarseFermionEigenPack<FImpl, nBasis> CoarsePack;
|
||||
typedef HADRONS_DEFAULT_SCHUR_OP<FMat, FermionField> SchurFMat;
|
||||
public:
|
||||
// constructor
|
||||
TLocalCoherenceLanczos(const std::string name);
|
||||
// destructor
|
||||
virtual ~TLocalCoherenceLanczos(void) {};
|
||||
// dependency relation
|
||||
virtual std::vector<std::string> getInput(void);
|
||||
virtual std::vector<std::string> getOutput(void);
|
||||
// setup
|
||||
virtual void setup(void);
|
||||
// execution
|
||||
virtual void execute(void);
|
||||
};
|
||||
|
||||
MODULE_REGISTER_TMP(LocalCoherenceLanczos, ARG(TLocalCoherenceLanczos<FIMPL, HADRONS_DEFAULT_LANCZOS_NBASIS>), MSolver);
|
||||
MODULE_REGISTER_TMP(ZLocalCoherenceLanczos, ARG(TLocalCoherenceLanczos<ZFIMPL, HADRONS_DEFAULT_LANCZOS_NBASIS>), MSolver);
|
||||
|
||||
/******************************************************************************
|
||||
* TLocalCoherenceLanczos implementation *
|
||||
******************************************************************************/
|
||||
// constructor /////////////////////////////////////////////////////////////////
|
||||
template <typename FImpl, int nBasis>
|
||||
TLocalCoherenceLanczos<FImpl, nBasis>::TLocalCoherenceLanczos(const std::string name)
|
||||
: Module<LocalCoherenceLanczosPar>(name)
|
||||
{}
|
||||
|
||||
// dependencies/products ///////////////////////////////////////////////////////
|
||||
template <typename FImpl, int nBasis>
|
||||
std::vector<std::string> TLocalCoherenceLanczos<FImpl, nBasis>::getInput(void)
|
||||
{
|
||||
std::vector<std::string> in = {par().action};
|
||||
|
||||
return in;
|
||||
}
|
||||
|
||||
template <typename FImpl, int nBasis>
|
||||
std::vector<std::string> TLocalCoherenceLanczos<FImpl, nBasis>::getOutput(void)
|
||||
{
|
||||
std::vector<std::string> out = {getName()};
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
// setup ///////////////////////////////////////////////////////////////////////
|
||||
template <typename FImpl, int nBasis>
|
||||
void TLocalCoherenceLanczos<FImpl, nBasis>::setup(void)
|
||||
{
|
||||
LOG(Message) << "Setting up local coherence Lanczos eigensolver for"
|
||||
<< " action '" << par().action << "' (" << nBasis
|
||||
<< " eigenvectors)..." << std::endl;
|
||||
|
||||
unsigned int Ls = env().getObjectLs(par().action);
|
||||
auto blockSize = strToVec<int>(par().blockSize);
|
||||
|
||||
env().createCoarseGrid(blockSize, Ls);
|
||||
|
||||
auto cg = env().getCoarseGrid(blockSize, Ls);
|
||||
int cNm = (par().doCoarse) ? par().coarseParams.Nm : 0;
|
||||
|
||||
LOG(Message) << "Coarse grid: " << cg->GlobalDimensions() << std::endl;
|
||||
envCreateDerived(BasePack, CoarsePack, getName(), Ls,
|
||||
par().fineParams.Nm, cNm, env().getRbGrid(Ls), cg);
|
||||
|
||||
auto &epack = envGetDerived(BasePack, CoarsePack, getName());
|
||||
|
||||
envTmp(SchurFMat, "mat", Ls, envGet(FMat, par().action));
|
||||
envGetTmp(SchurFMat, mat);
|
||||
envTmp(LCL, "solver", Ls, env().getRbGrid(Ls), cg, mat,
|
||||
Odd, epack.evec, epack.evecCoarse, epack.eval, epack.evalCoarse);
|
||||
}
|
||||
|
||||
// execution ///////////////////////////////////////////////////////////////////
|
||||
template <typename FImpl, int nBasis>
|
||||
void TLocalCoherenceLanczos<FImpl, nBasis>::execute(void)
|
||||
{
|
||||
auto &finePar = par().fineParams;
|
||||
auto &coarsePar = par().coarseParams;
|
||||
auto &epack = envGetDerived(BasePack, CoarsePack, getName());
|
||||
|
||||
epack.record.operatorXml = vm().getModule(par().action)->parString();
|
||||
epack.record.solverXml = parString();
|
||||
envGetTmp(LCL, solver);
|
||||
LOG(Message) << "Performing fine grid IRL -- Nstop= "
|
||||
<< finePar.Nstop << ", Nk= " << finePar.Nk << ", Nm= "
|
||||
<< finePar.Nm << std::endl;
|
||||
solver.calcFine(finePar.Cheby, finePar.Nstop, finePar.Nk, finePar.Nm,
|
||||
finePar.resid,finePar.MaxIt, finePar.betastp,
|
||||
finePar.MinRes);
|
||||
solver.testFine(finePar.resid*100.0);
|
||||
if (!par().output.empty())
|
||||
{
|
||||
epack.writeFine(par().output, par().multiFile, vm().getTrajectory());
|
||||
}
|
||||
if (par().doCoarse)
|
||||
{
|
||||
LOG(Message) << "Orthogonalising" << std::endl;
|
||||
solver.Orthogonalise();
|
||||
LOG(Message) << "Performing coarse grid IRL -- Nstop= "
|
||||
<< coarsePar.Nstop << ", Nk= " << coarsePar.Nk << ", Nm= "
|
||||
<< coarsePar.Nm << std::endl;
|
||||
solver.calcCoarse(coarsePar.Cheby, par().smoother, par().coarseRelaxTol,
|
||||
coarsePar.Nstop, coarsePar.Nk, coarsePar.Nm,
|
||||
coarsePar.resid, coarsePar.MaxIt, coarsePar.betastp,
|
||||
coarsePar.MinRes);
|
||||
solver.testCoarse(coarsePar.resid*100.0, par().smoother,
|
||||
par().coarseRelaxTol);
|
||||
if (!par().output.empty())
|
||||
{
|
||||
epack.writeCoarse(par().output, par().multiFile, vm().getTrajectory());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
END_MODULE_NAMESPACE
|
||||
|
||||
END_HADRONS_NAMESPACE
|
||||
|
||||
#endif // Hadrons_MSolver_LocalCoherenceLanczos_hpp_
|
36
Hadrons/Modules/MSolver/RBPrecCG.cc
Normal file
36
Hadrons/Modules/MSolver/RBPrecCG.cc
Normal file
@@ -0,0 +1,36 @@
|
||||
/*************************************************************************************
|
||||
|
||||
Grid physics library, www.github.com/paboyle/Grid
|
||||
|
||||
Source file: extras/Hadrons/Modules/MSolver/RBPrecCG.cc
|
||||
|
||||
Copyright (C) 2015-2018
|
||||
|
||||
Author: Antonin Portelli <antonin.portelli@me.com>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License along
|
||||
with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
|
||||
See the full license in the file "LICENSE" in the top level distribution directory
|
||||
*************************************************************************************/
|
||||
/* END LEGAL */
|
||||
#include <Hadrons/Modules/MSolver/RBPrecCG.hpp>
|
||||
|
||||
using namespace Grid;
|
||||
using namespace Hadrons;
|
||||
using namespace MSolver;
|
||||
|
||||
template class Grid::Hadrons::MSolver::TRBPrecCG<FIMPL,HADRONS_DEFAULT_LANCZOS_NBASIS>;
|
||||
template class Grid::Hadrons::MSolver::TRBPrecCG<ZFIMPL,HADRONS_DEFAULT_LANCZOS_NBASIS>;
|
||||
|
197
Hadrons/Modules/MSolver/RBPrecCG.hpp
Normal file
197
Hadrons/Modules/MSolver/RBPrecCG.hpp
Normal file
@@ -0,0 +1,197 @@
|
||||
/*************************************************************************************
|
||||
|
||||
Grid physics library, www.github.com/paboyle/Grid
|
||||
|
||||
Source file: extras/Hadrons/Modules/MSolver/RBPrecCG.hpp
|
||||
|
||||
Copyright (C) 2015-2018
|
||||
|
||||
Author: Antonin Portelli <antonin.portelli@me.com>
|
||||
Author: fionnoh <fionnoh@gmail.com>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License along
|
||||
with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
|
||||
See the full license in the file "LICENSE" in the top level distribution directory
|
||||
*************************************************************************************/
|
||||
/* END LEGAL */
|
||||
|
||||
#ifndef Hadrons_MSolver_RBPrecCG_hpp_
|
||||
#define Hadrons_MSolver_RBPrecCG_hpp_
|
||||
|
||||
#include <Hadrons/Global.hpp>
|
||||
#include <Hadrons/Module.hpp>
|
||||
#include <Hadrons/ModuleFactory.hpp>
|
||||
#include <Hadrons/Solver.hpp>
|
||||
#include <Hadrons/EigenPack.hpp>
|
||||
|
||||
BEGIN_HADRONS_NAMESPACE
|
||||
|
||||
/******************************************************************************
|
||||
* Schur red-black preconditioned CG *
|
||||
******************************************************************************/
|
||||
BEGIN_MODULE_NAMESPACE(MSolver)
|
||||
|
||||
class RBPrecCGPar: Serializable
|
||||
{
|
||||
public:
|
||||
GRID_SERIALIZABLE_CLASS_MEMBERS(RBPrecCGPar ,
|
||||
std::string , action,
|
||||
unsigned int, maxIteration,
|
||||
double , residual,
|
||||
std::string , eigenPack);
|
||||
};
|
||||
|
||||
template <typename FImpl, int nBasis>
|
||||
class TRBPrecCG: public Module<RBPrecCGPar>
|
||||
{
|
||||
public:
|
||||
FG_TYPE_ALIASES(FImpl,);
|
||||
SOLVER_TYPE_ALIASES(FImpl,);
|
||||
typedef FermionEigenPack<FImpl> EPack;
|
||||
typedef CoarseFermionEigenPack<FImpl, nBasis> CoarseEPack;
|
||||
typedef std::shared_ptr<Guesser<FermionField>> GuesserPt;
|
||||
typedef DeflatedGuesser<typename FImpl::FermionField> FineGuesser;
|
||||
typedef LocalCoherenceDeflatedGuesser<
|
||||
typename FImpl::FermionField,
|
||||
typename CoarseEPack::CoarseField> CoarseGuesser;
|
||||
public:
|
||||
// constructor
|
||||
TRBPrecCG(const std::string name);
|
||||
// destructor
|
||||
virtual ~TRBPrecCG(void) {};
|
||||
// dependencies/products
|
||||
virtual std::vector<std::string> getInput(void);
|
||||
virtual std::vector<std::string> getReference(void);
|
||||
virtual std::vector<std::string> getOutput(void);
|
||||
protected:
|
||||
// setup
|
||||
virtual void setup(void);
|
||||
// execution
|
||||
virtual void execute(void);
|
||||
};
|
||||
|
||||
MODULE_REGISTER_TMP(RBPrecCG, ARG(TRBPrecCG<FIMPL, HADRONS_DEFAULT_LANCZOS_NBASIS>), MSolver);
|
||||
MODULE_REGISTER_TMP(ZRBPrecCG, ARG(TRBPrecCG<ZFIMPL, HADRONS_DEFAULT_LANCZOS_NBASIS>), MSolver);
|
||||
|
||||
/******************************************************************************
|
||||
* TRBPrecCG template implementation *
|
||||
******************************************************************************/
|
||||
// constructor /////////////////////////////////////////////////////////////////
|
||||
template <typename FImpl, int nBasis>
|
||||
TRBPrecCG<FImpl, nBasis>::TRBPrecCG(const std::string name)
|
||||
: Module(name)
|
||||
{}
|
||||
|
||||
// dependencies/products ///////////////////////////////////////////////////////
|
||||
template <typename FImpl, int nBasis>
|
||||
std::vector<std::string> TRBPrecCG<FImpl, nBasis>::getInput(void)
|
||||
{
|
||||
std::vector<std::string> in = {};
|
||||
|
||||
return in;
|
||||
}
|
||||
|
||||
template <typename FImpl, int nBasis>
|
||||
std::vector<std::string> TRBPrecCG<FImpl, nBasis>::getReference(void)
|
||||
{
|
||||
std::vector<std::string> ref = {par().action};
|
||||
|
||||
if (!par().eigenPack.empty())
|
||||
{
|
||||
ref.push_back(par().eigenPack);
|
||||
}
|
||||
|
||||
return ref;
|
||||
}
|
||||
|
||||
template <typename FImpl, int nBasis>
|
||||
std::vector<std::string> TRBPrecCG<FImpl, nBasis>::getOutput(void)
|
||||
{
|
||||
std::vector<std::string> out = {getName(), getName() + "_subtract"};
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
// setup ///////////////////////////////////////////////////////////////////////
|
||||
template <typename FImpl, int nBasis>
|
||||
void TRBPrecCG<FImpl, nBasis>::setup(void)
|
||||
{
|
||||
if (par().maxIteration == 0)
|
||||
{
|
||||
HADRONS_ERROR(Argument, "zero maximum iteration");
|
||||
}
|
||||
|
||||
LOG(Message) << "setting up Schur red-black preconditioned CG for"
|
||||
<< " action '" << par().action << "' with residual "
|
||||
<< par().residual << ", maximum iteration "
|
||||
<< par().maxIteration << std::endl;
|
||||
|
||||
auto Ls = env().getObjectLs(par().action);
|
||||
auto &mat = envGet(FMat, par().action);
|
||||
std::string guesserName = getName() + "_guesser";
|
||||
GuesserPt guesser{nullptr};
|
||||
|
||||
if (par().eigenPack.empty())
|
||||
{
|
||||
guesser.reset(new ZeroGuesser<FermionField>());
|
||||
}
|
||||
else
|
||||
{
|
||||
try
|
||||
{
|
||||
auto &epack = envGetDerived(EPack, CoarseEPack, par().eigenPack);
|
||||
|
||||
LOG(Message) << "using low-mode deflation with coarse eigenpack '"
|
||||
<< par().eigenPack << "' ("
|
||||
<< epack.evecCoarse.size() << " modes)" << std::endl;
|
||||
guesser.reset(new CoarseGuesser(epack.evec, epack.evecCoarse,
|
||||
epack.evalCoarse));
|
||||
}
|
||||
catch (Exceptions::ObjectType &e)
|
||||
{
|
||||
auto &epack = envGet(EPack, par().eigenPack);
|
||||
|
||||
LOG(Message) << "using low-mode deflation with eigenpack '"
|
||||
<< par().eigenPack << "' ("
|
||||
<< epack.evec.size() << " modes)" << std::endl;
|
||||
guesser.reset(new FineGuesser(epack.evec, epack.eval));
|
||||
}
|
||||
}
|
||||
auto makeSolver = [&mat, guesser, this](bool subGuess) {
|
||||
return [&mat, guesser, subGuess, this](FermionField &sol,
|
||||
const FermionField &source) {
|
||||
ConjugateGradient<FermionField> cg(par().residual,
|
||||
par().maxIteration);
|
||||
HADRONS_DEFAULT_SCHUR_SOLVE<FermionField> schurSolver(cg);
|
||||
schurSolver.subtractGuess(subGuess);
|
||||
schurSolver(mat, source, sol, *guesser);
|
||||
};
|
||||
};
|
||||
auto solver = makeSolver(false);
|
||||
envCreate(Solver, getName(), Ls, solver, mat);
|
||||
auto solver_subtract = makeSolver(true);
|
||||
envCreate(Solver, getName() + "_subtract", Ls, solver_subtract, mat);
|
||||
}
|
||||
|
||||
// execution ///////////////////////////////////////////////////////////////////
|
||||
template <typename FImpl, int nBasis>
|
||||
void TRBPrecCG<FImpl, nBasis>::execute(void)
|
||||
{}
|
||||
|
||||
END_MODULE_NAMESPACE
|
||||
|
||||
END_HADRONS_NAMESPACE
|
||||
|
||||
#endif // Hadrons_MSolver_RBPrecCG_hpp_
|
Reference in New Issue
Block a user