2018-08-07 18:40:48 +01:00
|
|
|
/*************************************************************************************
|
|
|
|
|
|
|
|
Grid physics library, www.github.com/paboyle/Grid
|
|
|
|
|
2018-09-01 21:30:30 +01:00
|
|
|
Source file: Hadrons/Modules/MSolver/A2AVectors.hpp
|
2018-08-07 18:40:48 +01:00
|
|
|
|
|
|
|
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 */
|
2018-07-30 18:40:50 +01:00
|
|
|
#ifndef Hadrons_MSolver_A2AVectors_hpp_
|
|
|
|
#define Hadrons_MSolver_A2AVectors_hpp_
|
|
|
|
|
2018-08-28 15:00:40 +01:00
|
|
|
#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>
|
2018-07-30 18:40:50 +01:00
|
|
|
|
|
|
|
BEGIN_HADRONS_NAMESPACE
|
|
|
|
|
|
|
|
/******************************************************************************
|
2018-08-07 18:40:48 +01:00
|
|
|
* Create all-to-all V & W vectors *
|
2018-07-30 18:40:50 +01:00
|
|
|
******************************************************************************/
|
|
|
|
BEGIN_MODULE_NAMESPACE(MSolver)
|
|
|
|
|
|
|
|
class A2AVectorsPar: Serializable
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
GRID_SERIALIZABLE_CLASS_MEMBERS(A2AVectorsPar,
|
2018-08-06 12:11:52 +01:00
|
|
|
std::string, noise,
|
2018-07-30 18:40:50 +01:00
|
|
|
std::string, action,
|
|
|
|
std::string, eigenPack,
|
|
|
|
std::string, solver);
|
|
|
|
};
|
|
|
|
|
2018-08-06 12:11:52 +01:00
|
|
|
template <typename FImpl, typename Pack>
|
2018-07-30 18:40:50 +01:00
|
|
|
class TA2AVectors : public Module<A2AVectorsPar>
|
|
|
|
{
|
2018-08-06 12:11:52 +01:00
|
|
|
public:
|
2018-07-30 18:40:50 +01:00
|
|
|
FERM_TYPE_ALIASES(FImpl,);
|
|
|
|
SOLVER_TYPE_ALIASES(FImpl,);
|
2018-08-09 00:38:17 +01:00
|
|
|
typedef HADRONS_DEFAULT_SCHUR_A2A<FImpl> A2A;
|
2018-08-06 12:11:52 +01:00
|
|
|
public:
|
2018-07-30 18:40:50 +01:00
|
|
|
// 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);
|
2018-08-07 18:27:59 +01:00
|
|
|
private:
|
|
|
|
std::string solverName_;
|
|
|
|
unsigned int Nl_{0};
|
2018-07-30 18:40:50 +01:00
|
|
|
};
|
|
|
|
|
2018-08-06 12:11:52 +01:00
|
|
|
MODULE_REGISTER_TMP(A2AVectors,
|
2018-10-03 14:45:01 +01:00
|
|
|
ARG(TA2AVectors<FIMPL, BaseFermionEigenPack<FIMPL>>), MSolver);
|
2018-08-06 12:11:52 +01:00
|
|
|
MODULE_REGISTER_TMP(ZA2AVectors,
|
2018-10-03 14:45:01 +01:00
|
|
|
ARG(TA2AVectors<ZFIMPL, BaseFermionEigenPack<ZFIMPL>>), MSolver);
|
2018-07-30 18:40:50 +01:00
|
|
|
|
|
|
|
/******************************************************************************
|
2018-08-07 18:40:48 +01:00
|
|
|
* TA2AVectors implementation *
|
2018-07-30 18:40:50 +01:00
|
|
|
******************************************************************************/
|
|
|
|
// constructor /////////////////////////////////////////////////////////////////
|
2018-08-06 12:11:52 +01:00
|
|
|
template <typename FImpl, typename Pack>
|
|
|
|
TA2AVectors<FImpl, Pack>::TA2AVectors(const std::string name)
|
2018-07-30 18:40:50 +01:00
|
|
|
: Module<A2AVectorsPar>(name)
|
|
|
|
{}
|
|
|
|
|
|
|
|
// dependencies/products ///////////////////////////////////////////////////////
|
2018-08-06 12:11:52 +01:00
|
|
|
template <typename FImpl, typename Pack>
|
|
|
|
std::vector<std::string> TA2AVectors<FImpl, Pack>::getInput(void)
|
2018-07-30 18:40:50 +01:00
|
|
|
{
|
2018-08-07 18:27:59 +01:00
|
|
|
std::string sub_string;
|
|
|
|
std::vector<std::string> in;
|
2018-07-30 18:40:50 +01:00
|
|
|
|
|
|
|
if (!par().eigenPack.empty())
|
|
|
|
{
|
2018-08-07 18:27:59 +01:00
|
|
|
in.push_back(par().eigenPack);
|
|
|
|
sub_string = (!par().eigenPack.empty()) ? "_subtract" : "";
|
2018-07-30 18:40:50 +01:00
|
|
|
}
|
2018-08-07 18:27:59 +01:00
|
|
|
in.push_back(par().solver + sub_string);
|
|
|
|
in.push_back(par().noise);
|
2018-07-30 18:40:50 +01:00
|
|
|
|
2018-08-07 18:27:59 +01:00
|
|
|
return in;
|
2018-07-30 18:40:50 +01:00
|
|
|
}
|
|
|
|
|
2018-08-06 12:11:52 +01:00
|
|
|
template <typename FImpl, typename Pack>
|
|
|
|
std::vector<std::string> TA2AVectors<FImpl, Pack>::getOutput(void)
|
2018-07-30 18:40:50 +01:00
|
|
|
{
|
2018-08-07 18:27:59 +01:00
|
|
|
std::vector<std::string> out = {getName() + "_v", getName() + "_w"};
|
2018-07-30 18:40:50 +01:00
|
|
|
|
|
|
|
return out;
|
|
|
|
}
|
|
|
|
|
|
|
|
// setup ///////////////////////////////////////////////////////////////////////
|
2018-08-06 12:11:52 +01:00
|
|
|
template <typename FImpl, typename Pack>
|
|
|
|
void TA2AVectors<FImpl, Pack>::setup(void)
|
2018-07-30 18:40:50 +01:00
|
|
|
{
|
2018-08-07 18:27:59 +01:00
|
|
|
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)
|
2018-07-30 18:40:50 +01:00
|
|
|
{
|
2018-08-06 12:11:52 +01:00
|
|
|
auto &epack = envGet(Pack, par().eigenPack);
|
2018-08-07 18:27:59 +01:00
|
|
|
Nl_ = epack.evec.size();
|
2018-07-30 18:40:50 +01:00
|
|
|
}
|
2018-08-07 18:27:59 +01:00
|
|
|
envCreate(std::vector<FermionField>, getName() + "_v", 1,
|
2018-09-29 17:55:19 +01:00
|
|
|
Nl_ + noise.size(), envGetGrid(FermionField));
|
2018-08-07 18:27:59 +01:00
|
|
|
envCreate(std::vector<FermionField>, getName() + "_w", 1,
|
2018-09-29 17:55:19 +01:00
|
|
|
Nl_ + noise.size(), envGetGrid(FermionField));
|
2018-08-07 18:27:59 +01:00
|
|
|
if (Ls > 1)
|
|
|
|
{
|
|
|
|
envTmpLat(FermionField, "f5", Ls);
|
|
|
|
}
|
|
|
|
envTmp(A2A, "a2a", 1, action, solver);
|
2018-07-30 18:40:50 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// execution ///////////////////////////////////////////////////////////////////
|
2018-08-06 12:11:52 +01:00
|
|
|
template <typename FImpl, typename Pack>
|
|
|
|
void TA2AVectors<FImpl, Pack>::execute(void)
|
2018-07-30 18:40:50 +01:00
|
|
|
{
|
2018-08-07 18:27:59 +01:00
|
|
|
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);
|
2018-08-08 18:45:06 +01:00
|
|
|
|
2018-08-08 19:04:44 +01:00
|
|
|
if (Nl_ > 0)
|
2018-08-08 18:45:06 +01:00
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|
2018-08-07 18:27:59 +01:00
|
|
|
// Low modes
|
|
|
|
for (unsigned int il = 0; il < Nl_; il++)
|
|
|
|
{
|
|
|
|
auto &epack = envGet(Pack, par().eigenPack);
|
2018-07-30 18:40:50 +01:00
|
|
|
|
2018-08-14 12:15:24 +01:00
|
|
|
startTimer("V low mode");
|
2018-08-07 18:27:59 +01:00
|
|
|
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]);
|
|
|
|
}
|
2018-08-14 12:15:24 +01:00
|
|
|
stopTimer("V low mode");
|
|
|
|
startTimer("W low mode");
|
2018-08-07 18:27:59 +01:00
|
|
|
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]);
|
2018-08-14 12:15:24 +01:00
|
|
|
}
|
|
|
|
stopTimer("W low mode");
|
2018-08-07 18:27:59 +01:00
|
|
|
}
|
2018-07-30 18:40:50 +01:00
|
|
|
|
|
|
|
// High modes
|
2018-08-07 18:27:59 +01:00
|
|
|
for (unsigned int ih = 0; ih < noise.size(); ih++)
|
2018-08-06 12:11:52 +01:00
|
|
|
{
|
2018-08-14 12:15:24 +01:00
|
|
|
startTimer("V high mode");
|
2018-08-07 18:27:59 +01:00
|
|
|
LOG(Message) << "V vector i = " << Nl_ + ih
|
|
|
|
<< " (" << ((Nl_ > 0) ? "high " : "")
|
|
|
|
<< "stochastic mode)" << std::endl;
|
|
|
|
if (Ls == 1)
|
2018-07-30 18:40:50 +01:00
|
|
|
{
|
2018-08-07 18:27:59 +01:00
|
|
|
a2a.makeHighModeV(v[Nl_ + ih], noise[ih]);
|
2018-07-30 18:40:50 +01:00
|
|
|
}
|
2018-08-06 12:11:52 +01:00
|
|
|
else
|
|
|
|
{
|
2018-08-07 18:27:59 +01:00
|
|
|
envGetTmp(FermionField, f5);
|
|
|
|
a2a.makeHighModeV5D(v[Nl_ + ih], f5, noise[ih]);
|
|
|
|
}
|
2018-08-14 12:15:24 +01:00
|
|
|
stopTimer("V high mode");
|
|
|
|
startTimer("W high mode");
|
2018-08-07 18:27:59 +01:00
|
|
|
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]);
|
2018-08-06 12:11:52 +01:00
|
|
|
}
|
2018-08-14 12:15:24 +01:00
|
|
|
stopTimer("W high mode");
|
2018-08-06 12:11:52 +01:00
|
|
|
}
|
2018-07-30 18:40:50 +01:00
|
|
|
}
|
2018-08-07 18:40:48 +01:00
|
|
|
|
2018-07-30 18:40:50 +01:00
|
|
|
END_MODULE_NAMESPACE
|
|
|
|
|
|
|
|
END_HADRONS_NAMESPACE
|
|
|
|
|
|
|
|
#endif // Hadrons_MSolver_A2AVectors_hpp_
|