mirror of
https://github.com/paboyle/Grid.git
synced 2025-06-14 13:57:07 +01:00
Merge branch 'develop' into feature/gpu-port
This commit is contained in:
35
Hadrons/Modules/MSolver/A2AAslashVectors.cc
Normal file
35
Hadrons/Modules/MSolver/A2AAslashVectors.cc
Normal file
@ -0,0 +1,35 @@
|
||||
/*************************************************************************************
|
||||
|
||||
Grid physics library, www.github.com/paboyle/Grid
|
||||
|
||||
Source file: Hadrons/Modules/MSolver/A2AAslashVectors.cc
|
||||
|
||||
Copyright (C) 2015-2018
|
||||
|
||||
Author: Vera Guelpers <Vera.Guelpers@ed.ac.uk>
|
||||
|
||||
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/A2AAslashVectors.hpp>
|
||||
|
||||
using namespace Grid;
|
||||
using namespace Hadrons;
|
||||
using namespace MSolver;
|
||||
|
||||
template class Grid::Hadrons::MSolver::TA2AAslashVectors<FIMPL>;
|
||||
template class Grid::Hadrons::MSolver::TA2AAslashVectors<ZFIMPL>;
|
194
Hadrons/Modules/MSolver/A2AAslashVectors.hpp
Normal file
194
Hadrons/Modules/MSolver/A2AAslashVectors.hpp
Normal file
@ -0,0 +1,194 @@
|
||||
/*************************************************************************************
|
||||
|
||||
Grid physics library, www.github.com/paboyle/Grid
|
||||
|
||||
Source file: Hadrons/Modules/MSolver/A2AAslashVectors.hpp
|
||||
|
||||
Copyright (C) 2015-2018
|
||||
|
||||
Author: Vera Guelpers <Vera.Guelpers@ed.ac.uk>
|
||||
|
||||
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_A2AAslashVectors_hpp_
|
||||
#define Hadrons_MSolver_A2AAslashVectors_hpp_
|
||||
|
||||
#include <Hadrons/Global.hpp>
|
||||
#include <Hadrons/Module.hpp>
|
||||
#include <Hadrons/ModuleFactory.hpp>
|
||||
#include <Hadrons/Solver.hpp>
|
||||
#include <Hadrons/A2AVectors.hpp>
|
||||
|
||||
BEGIN_HADRONS_NAMESPACE
|
||||
|
||||
/******************************************************************************
|
||||
* Create all-to-all V & W vectors *
|
||||
******************************************************************************/
|
||||
BEGIN_MODULE_NAMESPACE(MSolver)
|
||||
|
||||
/****************************************************************************
|
||||
* Calculate a sequential propagator on an insertion of i*g_mu*A_mu
|
||||
* on an A2A vector
|
||||
*
|
||||
* vv_i(y) = S(y,x) * i * g_mu*A_mu(x) * v_i(x)
|
||||
*
|
||||
* with
|
||||
*
|
||||
* - vector: A2A vector v_i(x)
|
||||
* - emField: A_mu(x): electromagnetic photon field
|
||||
* - solver: the solver for calculating the sequential propagator
|
||||
*
|
||||
*****************************************************************************/
|
||||
|
||||
class A2AAslashVectorsPar: Serializable
|
||||
{
|
||||
public:
|
||||
GRID_SERIALIZABLE_CLASS_MEMBERS(A2AAslashVectorsPar,
|
||||
std::string, vector,
|
||||
std::string, emField,
|
||||
std::string, solver,
|
||||
std::string, output,
|
||||
bool, multiFile);
|
||||
};
|
||||
|
||||
template <typename FImpl>
|
||||
class TA2AAslashVectors : public Module<A2AAslashVectorsPar>
|
||||
{
|
||||
public:
|
||||
FERM_TYPE_ALIASES(FImpl,);
|
||||
SOLVER_TYPE_ALIASES(FImpl,);
|
||||
public:
|
||||
typedef PhotonR::GaugeField EmField;
|
||||
public:
|
||||
// constructor
|
||||
TA2AAslashVectors(const std::string name);
|
||||
// destructor
|
||||
virtual ~TA2AAslashVectors(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:
|
||||
unsigned int Ls_;
|
||||
};
|
||||
|
||||
MODULE_REGISTER_TMP(A2AAslashVectors, TA2AAslashVectors<FIMPL>, MSolver);
|
||||
MODULE_REGISTER_TMP(ZA2AAslashVectors, TA2AAslashVectors<ZFIMPL>, MSolver);
|
||||
|
||||
/******************************************************************************
|
||||
* TA2AAslashVectors implementation *
|
||||
******************************************************************************/
|
||||
// constructor /////////////////////////////////////////////////////////////////
|
||||
template <typename FImpl>
|
||||
TA2AAslashVectors<FImpl>::TA2AAslashVectors(const std::string name)
|
||||
: Module<A2AAslashVectorsPar>(name)
|
||||
{}
|
||||
|
||||
// dependencies/products ///////////////////////////////////////////////////////
|
||||
template <typename FImpl>
|
||||
std::vector<std::string> TA2AAslashVectors<FImpl>::getInput(void)
|
||||
{
|
||||
std::vector<std::string> in = {par().vector, par().emField, par().solver};
|
||||
|
||||
return in;
|
||||
}
|
||||
|
||||
template <typename FImpl>
|
||||
std::vector<std::string> TA2AAslashVectors<FImpl>::getOutput(void)
|
||||
{
|
||||
std::vector<std::string> out = {getName()};
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
// setup ///////////////////////////////////////////////////////////////////////
|
||||
template <typename FImpl>
|
||||
void TA2AAslashVectors<FImpl>::setup(void)
|
||||
{
|
||||
Ls_ = env().getObjectLs(par().solver);
|
||||
auto &vvector = envGet(std::vector<FermionField>, par().vector);
|
||||
unsigned int Nmodes = vvector.size();
|
||||
envCreate(std::vector<FermionField>, getName(), 1,
|
||||
Nmodes, envGetGrid(FermionField));
|
||||
|
||||
envTmpLat(FermionField, "v4dtmp");
|
||||
envTmpLat(FermionField, "v5dtmp", Ls_);
|
||||
envTmpLat(FermionField, "v5dtmp_sol", Ls_);
|
||||
}
|
||||
|
||||
// execution ///////////////////////////////////////////////////////////////////
|
||||
template <typename FImpl>
|
||||
void TA2AAslashVectors<FImpl>::execute(void)
|
||||
{
|
||||
auto &solver = envGet(Solver, par().solver);
|
||||
auto &stoch_photon = envGet(EmField, par().emField);
|
||||
auto &vvector = envGet(std::vector<FermionField>, par().vector);
|
||||
auto &Aslashv = envGet(std::vector<FermionField>, getName());
|
||||
unsigned int Nmodes = vvector.size();
|
||||
auto &mat = solver.getFMat();
|
||||
envGetTmp(FermionField, v4dtmp);
|
||||
envGetTmp(FermionField, v5dtmp);
|
||||
envGetTmp(FermionField, v5dtmp_sol);
|
||||
|
||||
Complex ci(0.0,1.0);
|
||||
|
||||
startTimer("Seq Aslash");
|
||||
LOG(Message) << "Calculate Sequential propagator on Aslash * v with the A2A vector "
|
||||
<< par().vector << " and the photon field " << par().emField << std::endl;
|
||||
for(unsigned int i=0; i<Nmodes; i++)
|
||||
{
|
||||
v4dtmp = Zero();
|
||||
startTimer("Multiply Aslash");
|
||||
for(unsigned int mu=0;mu<=3;mu++)
|
||||
{
|
||||
Gamma gmu(Gamma::gmu[mu]);
|
||||
v4dtmp += ci * PeekIndex<LorentzIndex>(stoch_photon, mu) * (gmu * vvector[i]);
|
||||
}
|
||||
stopTimer("Multiply Aslash");
|
||||
|
||||
startTimer("Inversion");
|
||||
if (Ls_ == 1)
|
||||
{
|
||||
solver(Aslashv[i], v4dtmp);
|
||||
}
|
||||
else
|
||||
{
|
||||
mat.ImportPhysicalFermionSource(v4dtmp, v5dtmp);
|
||||
solver(v5dtmp_sol, v5dtmp);
|
||||
mat.ExportPhysicalFermionSolution(v5dtmp_sol, v4dtmp);
|
||||
Aslashv[i] = v4dtmp;
|
||||
}
|
||||
stopTimer("Inversion");
|
||||
}
|
||||
stopTimer("Seq Aslash");
|
||||
if (!par().output.empty())
|
||||
{
|
||||
startTimer("I/O");
|
||||
A2AVectorsIo::write(par().output, Aslashv, par().multiFile, vm().getTrajectory());
|
||||
stopTimer("I/O");
|
||||
}
|
||||
}
|
||||
|
||||
END_MODULE_NAMESPACE
|
||||
|
||||
END_HADRONS_NAMESPACE
|
||||
|
||||
#endif // Hadrons_MSolver_A2AAslashVectors_hpp_
|
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: 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, BaseFermionEigenPack<FIMPL>>;
|
||||
template class Grid::Hadrons::MSolver::TA2AVectors<ZFIMPL, BaseFermionEigenPack<ZFIMPL>>;
|
258
Hadrons/Modules/MSolver/A2AVectors.hpp
Normal file
258
Hadrons/Modules/MSolver/A2AVectors.hpp
Normal file
@ -0,0 +1,258 @@
|
||||
/*************************************************************************************
|
||||
|
||||
Grid physics library, www.github.com/paboyle/Grid
|
||||
|
||||
Source file: 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,
|
||||
std::string, output,
|
||||
bool, multiFile);
|
||||
};
|
||||
|
||||
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, BaseFermionEigenPack<FIMPL>>), MSolver);
|
||||
MODULE_REGISTER_TMP(ZA2AVectors,
|
||||
ARG(TA2AVectors<ZFIMPL, BaseFermionEigenPack<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(), envGetGrid(FermionField));
|
||||
envCreate(std::vector<FermionField>, getName() + "_w", 1,
|
||||
Nl_ + noise.size(), envGetGrid(FermionField));
|
||||
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");
|
||||
}
|
||||
|
||||
// I/O if necessary
|
||||
if (!par().output.empty())
|
||||
{
|
||||
startTimer("V I/O");
|
||||
A2AVectorsIo::write(par().output + "_v", v, par().multiFile, vm().getTrajectory());
|
||||
stopTimer("V I/O");
|
||||
startTimer("W I/O");
|
||||
A2AVectorsIo::write(par().output + "_w", w, par().multiFile, vm().getTrajectory());
|
||||
stopTimer("W I/O");
|
||||
}
|
||||
}
|
||||
|
||||
END_MODULE_NAMESPACE
|
||||
|
||||
END_HADRONS_NAMESPACE
|
||||
|
||||
#endif // Hadrons_MSolver_A2AVectors_hpp_
|
85
Hadrons/Modules/MSolver/Guesser.hpp
Normal file
85
Hadrons/Modules/MSolver/Guesser.hpp
Normal file
@ -0,0 +1,85 @@
|
||||
/*************************************************************************************
|
||||
|
||||
Grid physics library, www.github.com/paboyle/Grid
|
||||
|
||||
Source file: Hadrons/Modules/MSolver/Guesser.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_Guesser_hpp_
|
||||
#define Hadrons_MSolver_Guesser_hpp_
|
||||
|
||||
#include <Hadrons/Global.hpp>
|
||||
#include <Hadrons/EigenPack.hpp>
|
||||
|
||||
BEGIN_HADRONS_NAMESPACE
|
||||
BEGIN_MODULE_NAMESPACE(MSolver)
|
||||
|
||||
template <typename FImpl, int nBasis>
|
||||
std::shared_ptr<LinearFunction<typename FImpl::FermionField>>
|
||||
makeGuesser(const std::string epackName)
|
||||
{
|
||||
typedef typename FImpl::FermionField FermionField;
|
||||
typedef BaseFermionEigenPack<FImpl> EPack;
|
||||
typedef CoarseFermionEigenPack<FImpl, nBasis> CoarseEPack;
|
||||
typedef DeflatedGuesser<FermionField> FineGuesser;
|
||||
typedef LocalCoherenceDeflatedGuesser<
|
||||
FermionField, typename CoarseEPack::CoarseField> CoarseGuesser;
|
||||
|
||||
std::shared_ptr<LinearFunction<typename FImpl::FermionField>> guesserPt;
|
||||
|
||||
DEFINE_ENV_LAMBDA;
|
||||
|
||||
if (epackName.empty())
|
||||
{
|
||||
guesserPt.reset(new ZeroGuesser<FermionField>());
|
||||
}
|
||||
else
|
||||
{
|
||||
try
|
||||
{
|
||||
auto &epack = envGetDerived(EPack, CoarseEPack, epackName);
|
||||
|
||||
LOG(Message) << "using low-mode deflation with coarse eigenpack '"
|
||||
<< epackName << "' ("
|
||||
<< epack.evecCoarse.size() << " modes)" << std::endl;
|
||||
guesserPt.reset(new CoarseGuesser(epack.evec, epack.evecCoarse,
|
||||
epack.evalCoarse));
|
||||
}
|
||||
catch (Exceptions::ObjectType &e)
|
||||
{
|
||||
auto &epack = envGet(EPack, epackName);
|
||||
|
||||
LOG(Message) << "using low-mode deflation with eigenpack '"
|
||||
<< epackName << "' ("
|
||||
<< epack.evec.size() << " modes)" << std::endl;
|
||||
guesserPt.reset(new FineGuesser(epack.evec, epack.eval));
|
||||
}
|
||||
}
|
||||
|
||||
return guesserPt;
|
||||
}
|
||||
|
||||
END_MODULE_NAMESPACE
|
||||
END_HADRONS_NAMESPACE
|
||||
|
||||
#endif
|
39
Hadrons/Modules/MSolver/LocalCoherenceLanczos.cc
Normal file
39
Hadrons/Modules/MSolver/LocalCoherenceLanczos.cc
Normal file
@ -0,0 +1,39 @@
|
||||
/*************************************************************************************
|
||||
|
||||
Grid physics library, www.github.com/paboyle/Grid
|
||||
|
||||
Source file: 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>;
|
||||
#ifdef GRID_DEFAULT_PRECISION_DOUBLE
|
||||
template class Grid::Hadrons::MSolver::TLocalCoherenceLanczos<FIMPL,HADRONS_DEFAULT_LANCZOS_NBASIS, FIMPLF>;
|
||||
template class Grid::Hadrons::MSolver::TLocalCoherenceLanczos<ZFIMPL,HADRONS_DEFAULT_LANCZOS_NBASIS, ZFIMPLF>;
|
||||
#endif
|
190
Hadrons/Modules/MSolver/LocalCoherenceLanczos.hpp
Normal file
190
Hadrons/Modules/MSolver/LocalCoherenceLanczos.hpp
Normal file
@ -0,0 +1,190 @@
|
||||
/*************************************************************************************
|
||||
|
||||
Grid physics library, www.github.com/paboyle/Grid
|
||||
|
||||
Source file: 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, typename FImplIo = FImpl>
|
||||
class TLocalCoherenceLanczos: public Module<LocalCoherenceLanczosPar>
|
||||
{
|
||||
public:
|
||||
FERM_TYPE_ALIASES(FImpl,);
|
||||
typedef LocalCoherenceLanczos<typename FImpl::SiteSpinor,
|
||||
typename FImpl::SiteComplex,
|
||||
nBasis> LCL;
|
||||
typedef BaseFermionEigenPack<FImpl> BasePack;
|
||||
typedef CoarseFermionEigenPack<FImpl, nBasis, FImplIo> 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);
|
||||
#ifdef GRID_DEFAULT_PRECISION_DOUBLE
|
||||
MODULE_REGISTER_TMP(LocalCoherenceLanczosIo32, ARG(TLocalCoherenceLanczos<FIMPL, HADRONS_DEFAULT_LANCZOS_NBASIS, FIMPLF>), MSolver);
|
||||
MODULE_REGISTER_TMP(ZLocalCoherenceLanczosIo32, ARG(TLocalCoherenceLanczos<ZFIMPL, HADRONS_DEFAULT_LANCZOS_NBASIS, ZFIMPLF>), MSolver);
|
||||
#endif
|
||||
|
||||
/******************************************************************************
|
||||
* TLocalCoherenceLanczos implementation *
|
||||
******************************************************************************/
|
||||
// constructor /////////////////////////////////////////////////////////////////
|
||||
template <typename FImpl, int nBasis, typename FImplIo>
|
||||
TLocalCoherenceLanczos<FImpl, nBasis, FImplIo>::TLocalCoherenceLanczos(const std::string name)
|
||||
: Module<LocalCoherenceLanczosPar>(name)
|
||||
{}
|
||||
|
||||
// dependencies/products ///////////////////////////////////////////////////////
|
||||
template <typename FImpl, int nBasis, typename FImplIo>
|
||||
std::vector<std::string> TLocalCoherenceLanczos<FImpl, nBasis, FImplIo>::getInput(void)
|
||||
{
|
||||
std::vector<std::string> in = {par().action};
|
||||
|
||||
return in;
|
||||
}
|
||||
|
||||
template <typename FImpl, int nBasis, typename FImplIo>
|
||||
std::vector<std::string> TLocalCoherenceLanczos<FImpl, nBasis, FImplIo>::getOutput(void)
|
||||
{
|
||||
std::vector<std::string> out = {getName()};
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
// setup ///////////////////////////////////////////////////////////////////////
|
||||
template <typename FImpl, int nBasis, typename FImplIo>
|
||||
void TLocalCoherenceLanczos<FImpl, nBasis, FImplIo>::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, typename FImplIo>
|
||||
void TLocalCoherenceLanczos<FImpl, nBasis, FImplIo>::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_
|
35
Hadrons/Modules/MSolver/MixedPrecisionRBPrecCG.cc
Normal file
35
Hadrons/Modules/MSolver/MixedPrecisionRBPrecCG.cc
Normal file
@ -0,0 +1,35 @@
|
||||
/*************************************************************************************
|
||||
|
||||
Grid physics library, www.github.com/paboyle/Grid
|
||||
|
||||
Source file: Hadrons/Modules/MSolver/MixedPrecisionRBPrecCG.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/MixedPrecisionRBPrecCG.hpp>
|
||||
|
||||
using namespace Grid;
|
||||
using namespace Hadrons;
|
||||
using namespace MSolver;
|
||||
|
||||
template class Grid::Hadrons::MSolver::TMixedPrecisionRBPrecCG<FIMPLF, FIMPLD, HADRONS_DEFAULT_LANCZOS_NBASIS>;
|
||||
template class Grid::Hadrons::MSolver::TMixedPrecisionRBPrecCG<ZFIMPLF, ZFIMPLD, HADRONS_DEFAULT_LANCZOS_NBASIS>;
|
197
Hadrons/Modules/MSolver/MixedPrecisionRBPrecCG.hpp
Normal file
197
Hadrons/Modules/MSolver/MixedPrecisionRBPrecCG.hpp
Normal file
@ -0,0 +1,197 @@
|
||||
/*************************************************************************************
|
||||
|
||||
Grid physics library, www.github.com/paboyle/Grid
|
||||
|
||||
Source file: Hadrons/Modules/MSolver/MixedPrecisionRBPrecCG.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_MixedPrecisionRBPrecCG_hpp_
|
||||
#define Hadrons_MSolver_MixedPrecisionRBPrecCG_hpp_
|
||||
|
||||
#include <Hadrons/Global.hpp>
|
||||
#include <Hadrons/Module.hpp>
|
||||
#include <Hadrons/ModuleFactory.hpp>
|
||||
#include <Hadrons/Solver.hpp>
|
||||
#include <Hadrons/EigenPack.hpp>
|
||||
#include <Hadrons/Modules/MSolver/Guesser.hpp>
|
||||
|
||||
BEGIN_HADRONS_NAMESPACE
|
||||
|
||||
/******************************************************************************
|
||||
* Mixed precision schur red-black preconditioned CG *
|
||||
******************************************************************************/
|
||||
BEGIN_MODULE_NAMESPACE(MSolver)
|
||||
|
||||
class MixedPrecisionRBPrecCGPar: Serializable
|
||||
{
|
||||
public:
|
||||
GRID_SERIALIZABLE_CLASS_MEMBERS(MixedPrecisionRBPrecCGPar,
|
||||
std::string , innerAction,
|
||||
std::string , outerAction,
|
||||
unsigned int, maxInnerIteration,
|
||||
unsigned int, maxOuterIteration,
|
||||
double , residual,
|
||||
std::string , eigenPack);
|
||||
};
|
||||
|
||||
template <typename FImplInner, typename FImplOuter, int nBasis>
|
||||
class TMixedPrecisionRBPrecCG: public Module<MixedPrecisionRBPrecCGPar>
|
||||
{
|
||||
public:
|
||||
FERM_TYPE_ALIASES(FImplInner, Inner);
|
||||
FERM_TYPE_ALIASES(FImplOuter, Outer);
|
||||
SOLVER_TYPE_ALIASES(FImplOuter,);
|
||||
typedef HADRONS_DEFAULT_SCHUR_OP<FMatInner, FermionFieldInner> SchurFMatInner;
|
||||
typedef HADRONS_DEFAULT_SCHUR_OP<FMatOuter, FermionFieldOuter> SchurFMatOuter;
|
||||
private:
|
||||
template <typename Field>
|
||||
class OperatorFunctionWrapper: public OperatorFunction<Field>
|
||||
{
|
||||
public:
|
||||
OperatorFunctionWrapper(LinearFunction<Field> &fn): fn_(fn) {};
|
||||
virtual ~OperatorFunctionWrapper(void) = default;
|
||||
virtual void operator()(LinearOperatorBase<Field> &op,
|
||||
const Field &in, Field &out)
|
||||
{
|
||||
fn_(in, out);
|
||||
}
|
||||
private:
|
||||
LinearFunction<Field> &fn_;
|
||||
};
|
||||
public:
|
||||
// constructor
|
||||
TMixedPrecisionRBPrecCG(const std::string name);
|
||||
// destructor
|
||||
virtual ~TMixedPrecisionRBPrecCG(void) {};
|
||||
// dependency relation
|
||||
virtual std::vector<std::string> getInput(void);
|
||||
virtual std::vector<std::string> getReference(void);
|
||||
virtual std::vector<std::string> getOutput(void);
|
||||
// setup
|
||||
virtual void setup(void);
|
||||
// execution
|
||||
virtual void execute(void);
|
||||
};
|
||||
|
||||
MODULE_REGISTER_TMP(MixedPrecisionRBPrecCG,
|
||||
ARG(TMixedPrecisionRBPrecCG<FIMPLF, FIMPLD, HADRONS_DEFAULT_LANCZOS_NBASIS>), MSolver);
|
||||
MODULE_REGISTER_TMP(ZMixedPrecisionRBPrecCG,
|
||||
ARG(TMixedPrecisionRBPrecCG<ZFIMPLF, ZFIMPLD, HADRONS_DEFAULT_LANCZOS_NBASIS>), MSolver);
|
||||
|
||||
/******************************************************************************
|
||||
* TMixedPrecisionRBPrecCG implementation *
|
||||
******************************************************************************/
|
||||
// constructor /////////////////////////////////////////////////////////////////
|
||||
template <typename FImplInner, typename FImplOuter, int nBasis>
|
||||
TMixedPrecisionRBPrecCG<FImplInner, FImplOuter, nBasis>
|
||||
::TMixedPrecisionRBPrecCG(const std::string name)
|
||||
: Module<MixedPrecisionRBPrecCGPar>(name)
|
||||
{}
|
||||
|
||||
// dependencies/products ///////////////////////////////////////////////////////
|
||||
template <typename FImplInner, typename FImplOuter, int nBasis>
|
||||
std::vector<std::string> TMixedPrecisionRBPrecCG<FImplInner, FImplOuter, nBasis>
|
||||
::getInput(void)
|
||||
{
|
||||
std::vector<std::string> in;
|
||||
|
||||
return in;
|
||||
}
|
||||
|
||||
template <typename FImplInner, typename FImplOuter, int nBasis>
|
||||
std::vector<std::string> TMixedPrecisionRBPrecCG<FImplInner, FImplOuter, nBasis>
|
||||
::getReference(void)
|
||||
{
|
||||
std::vector<std::string> ref = {par().innerAction, par().outerAction};
|
||||
|
||||
if (!par().eigenPack.empty())
|
||||
{
|
||||
ref.push_back(par().eigenPack);
|
||||
}
|
||||
|
||||
return ref;
|
||||
}
|
||||
|
||||
template <typename FImplInner, typename FImplOuter, int nBasis>
|
||||
std::vector<std::string> TMixedPrecisionRBPrecCG<FImplInner, FImplOuter, nBasis>
|
||||
::getOutput(void)
|
||||
{
|
||||
std::vector<std::string> out = {getName(), getName() + "_subtract"};
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
// setup ///////////////////////////////////////////////////////////////////////
|
||||
template <typename FImplInner, typename FImplOuter, int nBasis>
|
||||
void TMixedPrecisionRBPrecCG<FImplInner, FImplOuter, nBasis>
|
||||
::setup(void)
|
||||
{
|
||||
LOG(Message) << "Setting up Schur red-black preconditioned mixed-precision "
|
||||
<< "CG for inner/outer action '" << par().innerAction
|
||||
<< "'/'" << par().outerAction << "', residual "
|
||||
<< par().residual << ", and maximum inner/outer iteration "
|
||||
<< par().maxInnerIteration << "/" << par().maxOuterIteration
|
||||
<< std::endl;
|
||||
|
||||
auto Ls = env().getObjectLs(par().innerAction);
|
||||
auto &imat = envGet(FMatInner, par().innerAction);
|
||||
auto &omat = envGet(FMatOuter, par().outerAction);
|
||||
auto guesserPt = makeGuesser<FImplOuter, nBasis>(par().eigenPack);
|
||||
|
||||
auto makeSolver = [&imat, &omat, guesserPt, Ls, this](bool subGuess)
|
||||
{
|
||||
return [&imat, &omat, guesserPt, subGuess, Ls, this]
|
||||
(FermionFieldOuter &sol, const FermionFieldOuter &source)
|
||||
{
|
||||
typedef typename FermionFieldInner::vector_type VTypeInner;
|
||||
|
||||
SchurFMatInner simat(imat);
|
||||
SchurFMatOuter somat(omat);
|
||||
MixedPrecisionConjugateGradient<FermionFieldOuter, FermionFieldInner>
|
||||
mpcg(par().residual, par().maxInnerIteration,
|
||||
par().maxOuterIteration,
|
||||
env().template getRbGrid<VTypeInner>(Ls),
|
||||
simat, somat);
|
||||
OperatorFunctionWrapper<FermionFieldOuter> wmpcg(mpcg);
|
||||
HADRONS_DEFAULT_SCHUR_SOLVE<FermionFieldOuter> schurSolver(wmpcg);
|
||||
schurSolver.subtractGuess(subGuess);
|
||||
schurSolver(omat, source, sol, *guesserPt);
|
||||
};
|
||||
};
|
||||
auto solver = makeSolver(false);
|
||||
envCreate(Solver, getName(), Ls, solver, omat);
|
||||
auto solver_subtract = makeSolver(true);
|
||||
envCreate(Solver, getName() + "_subtract", Ls, solver_subtract, omat);
|
||||
}
|
||||
|
||||
// execution ///////////////////////////////////////////////////////////////////
|
||||
template <typename FImplInner, typename FImplOuter, int nBasis>
|
||||
void TMixedPrecisionRBPrecCG<FImplInner, FImplOuter, nBasis>
|
||||
::execute(void)
|
||||
{}
|
||||
|
||||
END_MODULE_NAMESPACE
|
||||
|
||||
END_HADRONS_NAMESPACE
|
||||
|
||||
#endif // Hadrons_MSolver_MixedPrecisionRBPrecCG_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: 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>;
|
||||
|
164
Hadrons/Modules/MSolver/RBPrecCG.hpp
Normal file
164
Hadrons/Modules/MSolver/RBPrecCG.hpp
Normal file
@ -0,0 +1,164 @@
|
||||
/*************************************************************************************
|
||||
|
||||
Grid physics library, www.github.com/paboyle/Grid
|
||||
|
||||
Source file: 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>
|
||||
#include <Hadrons/Modules/MSolver/Guesser.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:
|
||||
FERM_TYPE_ALIASES(FImpl,);
|
||||
SOLVER_TYPE_ALIASES(FImpl,);
|
||||
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);
|
||||
auto guesserPt = makeGuesser<FImpl, nBasis>(par().eigenPack);
|
||||
|
||||
auto makeSolver = [&mat, guesserPt, this](bool subGuess) {
|
||||
return [&mat, guesserPt, 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, *guesserPt);
|
||||
};
|
||||
};
|
||||
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