1
0
mirror of https://github.com/paboyle/Grid.git synced 2025-06-17 07:17:06 +01:00

Merge branch 'feature/hadrons' into feature/qed-fvol

This commit is contained in:
James Harrison
2018-03-20 20:19:18 +00:00
44 changed files with 1695 additions and 782 deletions

View File

@ -0,0 +1,218 @@
/*************************************************************************************
Grid physics library, www.github.com/paboyle/Grid
Source file: extras/Hadrons/EigenPack.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_EigenPack_hpp_
#define Hadrons_EigenPack_hpp_
#include <Grid/Hadrons/Global.hpp>
#include <Grid/algorithms/iterative/Deflation.h>
#include <Grid/algorithms/iterative/LocalCoherenceLanczos.h>
BEGIN_HADRONS_NAMESPACE
// Lanczos type
#ifndef HADRONS_DEFAULT_LANCZOS_NBASIS
#define HADRONS_DEFAULT_LANCZOS_NBASIS 60
#endif
template <typename F>
class EigenPack
{
public:
typedef F Field;
public:
std::vector<RealD> eval;
std::vector<F> evec;
public:
EigenPack(void) = default;
virtual ~EigenPack(void) = default;
EigenPack(const size_t size, GridBase *grid)
{
resize(size, grid);
}
void resize(const size_t size, GridBase *grid)
{
eval.resize(size);
evec.resize(size, grid);
}
virtual void read(const std::string fileStem, const int traj = -1)
{
std::string evecFilename, evalFilename;
makeFilenames(evecFilename, evalFilename, fileStem, traj);
XmlReader xmlReader(evalFilename);
basicRead(evec, evecFilename, evec.size());
LOG(Message) << "Reading " << eval.size() << " eigenvalues from '"
<< evalFilename << "'" << std::endl;
Grid::read(xmlReader, "evals", eval);
}
virtual void write(const std::string fileStem, const int traj = -1)
{
std::string evecFilename, evalFilename;
makeFilenames(evecFilename, evalFilename, fileStem, traj);
XmlWriter xmlWriter(evalFilename);
basicWrite(evecFilename, evec, evec.size());
LOG(Message) << "Writing " << eval.size() << " eigenvalues to '"
<< evalFilename << "'" << std::endl;
Grid::write(xmlWriter, "evals", eval);
}
protected:
void makeFilenames(std::string &evecFilename, std::string &evalFilename,
const std::string stem, const int traj = -1)
{
std::string t = (traj < 0) ? "" : ("." + std::to_string(traj));
evecFilename = stem + "_evec" + t + ".bin";
evalFilename = stem + "_eval" + t + ".xml";
}
template <typename T>
static void basicRead(std::vector<T> &evec, const std::string filename,
const unsigned int size)
{
emptyUserRecord record;
ScidacReader binReader;
binReader.open(filename);
for(int k = 0; k < size; ++k)
{
binReader.readScidacFieldRecord(evec[k], record);
}
binReader.close();
}
template <typename T>
static void basicWrite(const std::string filename, std::vector<T> &evec,
const unsigned int size)
{
emptyUserRecord record;
ScidacWriter binWriter;
binWriter.open(filename);
for(int k = 0; k < size; ++k)
{
binWriter.writeScidacFieldRecord(evec[k], record);
}
binWriter.close();
}
};
template <typename FineF, typename CoarseF>
class CoarseEigenPack: public EigenPack<FineF>
{
public:
typedef CoarseF CoarseField;
public:
std::vector<RealD> evalCoarse;
std::vector<CoarseF> evecCoarse;
public:
CoarseEigenPack(void) = default;
virtual ~CoarseEigenPack(void) = default;
CoarseEigenPack(const size_t sizeFine, const size_t sizeCoarse,
GridBase *gridFine, GridBase *gridCoarse)
{
resize(sizeFine, sizeCoarse, gridFine, gridCoarse);
}
void resize(const size_t sizeFine, const size_t sizeCoarse,
GridBase *gridFine, GridBase *gridCoarse)
{
EigenPack<FineF>::resize(sizeFine, gridFine);
evalCoarse.resize(sizeCoarse);
evecCoarse.resize(sizeCoarse, gridCoarse);
}
virtual void read(const std::string fileStem, const int traj = -1)
{
std::string evecFineFilename, evalFineFilename;
std::string evecCoarseFilename, evalCoarseFilename;
this->makeFilenames(evecFineFilename, evalFineFilename,
fileStem + "_fine", traj);
this->makeFilenames(evecCoarseFilename, evalCoarseFilename,
fileStem + "_coarse", traj);
XmlReader xmlFineReader(evalFineFilename);
XmlReader xmlCoarseReader(evalCoarseFilename);
LOG(Message) << "Reading " << this->evec.size() << " fine eigenvectors from '"
<< evecFineFilename << "'" << std::endl;
this->basicRead(this->evec, evecFineFilename, this->evec.size());
LOG(Message) << "Reading " << evecCoarse.size() << " coarse eigenvectors from '"
<< evecCoarseFilename << "'" << std::endl;
this->basicRead(evecCoarse, evecCoarseFilename, evecCoarse.size());
LOG(Message) << "Reading " << this->eval.size() << " fine eigenvalues from '"
<< evalFineFilename << "'" << std::endl;
Grid::read(xmlFineReader, "evals", this->eval);
LOG(Message) << "Reading " << evalCoarse.size() << " coarse eigenvalues from '"
<< evalCoarseFilename << "'" << std::endl;
Grid::read(xmlCoarseReader, "evals", evalCoarse);
}
virtual void write(const std::string fileStem, const int traj = -1)
{
std::string evecFineFilename, evalFineFilename;
std::string evecCoarseFilename, evalCoarseFilename;
this->makeFilenames(evecFineFilename, evalFineFilename,
fileStem + "_fine", traj);
this->makeFilenames(evecCoarseFilename, evalCoarseFilename,
fileStem + "_coarse", traj);
XmlWriter xmlFineWriter(evalFineFilename);
XmlWriter xmlCoarseWriter(evalCoarseFilename);
LOG(Message) << "Writing " << this->evec.size() << " fine eigenvectors to '"
<< evecFineFilename << "'" << std::endl;
this->basicWrite(evecFineFilename, this->evec, this->evec.size());
LOG(Message) << "Writing " << evecCoarse.size() << " coarse eigenvectors to '"
<< evecCoarseFilename << "'" << std::endl;
this->basicWrite(evecCoarseFilename, evecCoarse, evecCoarse.size());
LOG(Message) << "Writing " << this->eval.size() << " fine eigenvalues to '"
<< evalFineFilename << "'" << std::endl;
Grid::write(xmlFineWriter, "evals", this->eval);
LOG(Message) << "Writing " << evalCoarse.size() << " coarse eigenvalues to '"
<< evalCoarseFilename << "'" << std::endl;
Grid::write(xmlCoarseWriter, "evals", evalCoarse);
}
};
template <typename FImpl>
using FermionEigenPack = EigenPack<typename FImpl::FermionField>;
template <typename FImpl, int nBasis>
using CoarseFermionEigenPack = CoarseEigenPack<
typename FImpl::FermionField,
typename LocalCoherenceLanczos<typename FImpl::SiteSpinor,
typename FImpl::SiteComplex,
nBasis>::CoarseField>;
END_HADRONS_NAMESPACE
#endif // Hadrons_EigenPack_hpp_

View File

@ -61,7 +61,7 @@ Environment::Environment(void)
// grids ///////////////////////////////////////////////////////////////////////
void Environment::createGrid(const unsigned int Ls)
{
if (grid5d_.find(Ls) == grid5d_.end())
if ((Ls > 1) and (grid5d_.find(Ls) == grid5d_.end()))
{
auto g = getGrid();
@ -70,6 +70,53 @@ void Environment::createGrid(const unsigned int Ls)
}
}
void Environment::createCoarseGrid(const std::vector<int> &blockSize,
const unsigned int Ls)
{
int nd = getNd();
std::vector<int> fineDim = getDim(), coarseDim;
unsigned int cLs;
auto key4d = blockSize, key5d = blockSize;
createGrid(Ls);
coarseDim.resize(nd);
for (int d = 0; d < coarseDim.size(); d++)
{
coarseDim[d] = fineDim[d]/blockSize[d];
if (coarseDim[d]*blockSize[d] != fineDim[d])
{
HADRON_ERROR(Size, "Fine dimension " + std::to_string(d)
+ " (" + std::to_string(fineDim[d])
+ ") not divisible by coarse dimension ("
+ std::to_string(coarseDim[d]) + ")");
}
}
if (blockSize.size() > nd)
{
cLs = Ls/blockSize[nd];
if (cLs*blockSize[nd] != Ls)
{
HADRON_ERROR(Size, "Fine Ls (" + std::to_string(Ls)
+ ") not divisible by coarse Ls ("
+ std::to_string(cLs) + ")");
}
key4d.resize(nd);
key5d.push_back(Ls);
}
gridCoarse4d_[key4d].reset(
SpaceTimeGrid::makeFourDimGrid(coarseDim,
GridDefaultSimd(nd, vComplex::Nsimd()), GridDefaultMpi()));
gridCoarseRb4d_[key4d].reset(
SpaceTimeGrid::makeFourDimRedBlackGrid(gridCoarse4d_[key4d].get()));
if (Ls > 1)
{
gridCoarse5d_[key5d].reset(
SpaceTimeGrid::makeFiveDimGrid(cLs, gridCoarse4d_[key4d].get()));
gridCoarseRb5d_[key5d].reset(
SpaceTimeGrid::makeFiveDimRedBlackGrid(cLs, gridCoarse4d_[key4d].get()));
}
}
GridCartesian * Environment::getGrid(const unsigned int Ls) const
{
try
@ -104,7 +151,55 @@ GridRedBlackCartesian * Environment::getRbGrid(const unsigned int Ls) const
}
catch(std::out_of_range &)
{
HADRON_ERROR(Definition, "no red-black 5D grid with Ls= " + std::to_string(Ls));
HADRON_ERROR(Definition, "no red-black grid with Ls= " + std::to_string(Ls));
}
}
GridCartesian * Environment::getCoarseGrid(
const std::vector<int> &blockSize, const unsigned int Ls) const
{
auto key = blockSize;
try
{
if (Ls == 1)
{
key.resize(getNd());
return gridCoarse4d_.at(key).get();
}
else
{
key.push_back(Ls);
return gridCoarse5d_.at(key).get();
}
}
catch(std::out_of_range &)
{
HADRON_ERROR(Definition, "no coarse grid with Ls= " + std::to_string(Ls));
}
}
GridRedBlackCartesian * Environment::getRbCoarseGrid(
const std::vector<int> &blockSize, const unsigned int Ls) const
{
auto key = blockSize;
try
{
if (Ls == 1)
{
key.resize(getNd());
return gridCoarseRb4d_.at(key).get();
}
else
{
key.push_back(Ls);
return gridCoarseRb5d_.at(key).get();
}
}
catch(std::out_of_range &)
{
HADRON_ERROR(Definition, "no coarse red-black grid with Ls= " + std::to_string(Ls));
}
}

View File

@ -78,7 +78,7 @@ private:
Size size{0};
Storage storage{Storage::object};
unsigned int Ls{0};
const std::type_info *type{nullptr};
const std::type_info *type{nullptr}, *derivedType{nullptr};
std::string name;
int module{-1};
std::unique_ptr<Object> data{nullptr};
@ -86,8 +86,14 @@ private:
public:
// grids
void createGrid(const unsigned int Ls);
void createCoarseGrid(const std::vector<int> &blockSize,
const unsigned int Ls = 1);
GridCartesian * getGrid(const unsigned int Ls = 1) const;
GridRedBlackCartesian * getRbGrid(const unsigned int Ls = 1) const;
GridCartesian * getCoarseGrid(const std::vector<int> &blockSize,
const unsigned int Ls = 1) const;
GridRedBlackCartesian * getRbCoarseGrid(const std::vector<int> &blockSize,
const unsigned int Ls = 1) const;
std::vector<int> getDim(void) const;
int getDim(const unsigned int mu) const;
unsigned long int getLocalVolume(void) const;
@ -110,6 +116,10 @@ public:
Ts && ... args);
void setObjectModule(const unsigned int objAddress,
const int modAddress);
template <typename B, typename T>
T * getDerivedObject(const unsigned int address) const;
template <typename B, typename T>
T * getDerivedObject(const std::string name) const;
template <typename T>
T * getObject(const unsigned int address) const;
template <typename T>
@ -155,6 +165,10 @@ private:
std::map<unsigned int, GridPt> grid5d_;
GridRbPt gridRb4d_;
std::map<unsigned int, GridRbPt> gridRb5d_;
std::map<std::vector<int>, GridPt> gridCoarse4d_;
std::map<std::vector<int>, GridRbPt> gridCoarseRb4d_;
std::map<std::vector<int>, GridPt> gridCoarse5d_;
std::map<std::vector<int>, GridRbPt> gridCoarseRb5d_;
unsigned int nd_;
// random number generator
RngPt rng4d_;
@ -176,7 +190,7 @@ Holder<T>::Holder(T *pt)
template <typename T>
T & Holder<T>::get(void) const
{
return &objPt_.get();
return *objPt_.get();
}
template <typename T>
@ -216,22 +230,24 @@ void Environment::createDerivedObject(const std::string name,
{
MemoryProfiler::stats = &memStats;
}
size_t initMem = MemoryProfiler::stats->currentlyAllocated;
object_[address].storage = storage;
object_[address].Ls = Ls;
size_t initMem = MemoryProfiler::stats->currentlyAllocated;
object_[address].storage = storage;
object_[address].Ls = Ls;
object_[address].data.reset(new Holder<B>(new T(std::forward<Ts>(args)...)));
object_[address].size = MemoryProfiler::stats->maxAllocated - initMem;
object_[address].type = &typeid(T);
object_[address].size = MemoryProfiler::stats->maxAllocated - initMem;
object_[address].type = &typeid(B);
object_[address].derivedType = &typeid(T);
if (MemoryProfiler::stats == &memStats)
{
MemoryProfiler::stats = nullptr;
}
}
// object already exists, no error if it is a cache, error otherwise
else if ((object_[address].storage != Storage::cache) or
(object_[address].storage != storage) or
(object_[address].name != name) or
(object_[address].type != &typeid(T)))
else if ((object_[address].storage != Storage::cache) or
(object_[address].storage != storage) or
(object_[address].name != name) or
(object_[address].type != &typeid(B)) or
(object_[address].derivedType != &typeid(T)))
{
HADRON_ERROR(Definition, "object '" + name + "' already allocated");
}
@ -246,21 +262,37 @@ void Environment::createObject(const std::string name,
createDerivedObject<T, T>(name, storage, Ls, std::forward<Ts>(args)...);
}
template <typename T>
T * Environment::getObject(const unsigned int address) const
template <typename B, typename T>
T * Environment::getDerivedObject(const unsigned int address) const
{
if (hasObject(address))
{
if (hasCreatedObject(address))
{
if (auto h = dynamic_cast<Holder<T> *>(object_[address].data.get()))
if (auto h = dynamic_cast<Holder<B> *>(object_[address].data.get()))
{
return h->getPt();
if (&typeid(T) == &typeid(B))
{
return dynamic_cast<T *>(h->getPt());
}
else
{
if (auto hder = dynamic_cast<T *>(h->getPt()))
{
return hder;
}
else
{
HADRON_ERROR(Definition, "object with address " + std::to_string(address) +
" cannot be casted to '" + typeName(&typeid(T)) +
"' (has type '" + typeName(&typeid(h->get())) + "')");
}
}
}
else
{
HADRON_ERROR(Definition, "object with address " + std::to_string(address) +
" does not have type '" + typeName(&typeid(T)) +
" does not have type '" + typeName(&typeid(B)) +
"' (has type '" + getObjectType(address) + "')");
}
}
@ -276,6 +308,18 @@ T * Environment::getObject(const unsigned int address) const
}
}
template <typename B, typename T>
T * Environment::getDerivedObject(const std::string name) const
{
return getDerivedObject<B, T>(getObjectAddress(name));
}
template <typename T>
T * Environment::getObject(const unsigned int address) const
{
return getDerivedObject<T, T>(address);
}
template <typename T>
T * Environment::getObject(const std::string name) const
{

View File

@ -43,12 +43,15 @@ See the full license in the file "LICENSE" in the top level distribution directo
namespace Grid {\
using namespace QCD;\
namespace Hadrons {\
using Grid::operator<<;
using Grid::operator<<;\
using Grid::operator>>;
#define END_HADRONS_NAMESPACE }}
#define BEGIN_MODULE_NAMESPACE(name)\
namespace name {\
using Grid::operator<<;
using Grid::operator<<;\
using Grid::operator>>;
#define END_MODULE_NAMESPACE }
/* the 'using Grid::operator<<;' statement prevents a very nasty compilation
@ -187,7 +190,7 @@ name + "." + std::to_string(vm().getTrajectory()) + "." + resultFileExt
// default Schur convention
#ifndef HADRONS_DEFAULT_SCHUR
#define HADRONS_DEFAULT_SCHUR DiagMooee
#define HADRONS_DEFAULT_SCHUR DiagTwo
#endif
#define _HADRONS_SCHUR_OP_(conv) Schur##conv##Operator
#define HADRONS_SCHUR_OP(conv) _HADRONS_SCHUR_OP_(conv)

View File

@ -1,115 +0,0 @@
/*************************************************************************************
Grid physics library, www.github.com/paboyle/Grid
Source file: extras/Hadrons/LanczosUtils.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_LanczosUtils_hpp_
#define Hadrons_LanczosUtils_hpp_
#include <Grid/Hadrons/Global.hpp>
#include <Grid/algorithms/iterative/LocalCoherenceLanczos.h>
BEGIN_HADRONS_NAMESPACE
// Lanczos type
#ifndef HADRONS_DEFAULT_LANCZOS_NBASIS
#define HADRONS_DEFAULT_LANCZOS_NBASIS 60
#endif
template <typename T>
struct EigenPack
{
typedef T VectorType;
std::vector<RealD> eval;
std::vector<T> evec;
EigenPack(void) = default;
EigenPack(const size_t size, GridBase *grid)
{
resize(size, grid);
}
void resize(const size_t size, GridBase *grid)
{
eval.resize(size);
evec.resize(size, grid);
}
void read(const std::string fileStem)
{
std::string evecFilename = fileStem + "_evec.bin";
std::string evalFilename = fileStem + "_eval.xml";
emptyUserRecord record;
ScidacReader binReader;
XmlReader xmlReader(evalFilename);
LOG(Message) << "Reading " << evec.size() << " eigenvectors from '"
<< evecFilename << "'" << std::endl;
binReader.open(evecFilename);
for(int k = 0; k < evec.size(); ++k)
{
binReader.readScidacFieldRecord(evec[k], record);
}
binReader.close();
LOG(Message) << "Reading " << eval.size() << " eigenvalues from '"
<< evalFilename << "'" << std::endl;
Grid::read(xmlReader, "evals", eval);
}
void write(const std::string fileStem)
{
std::string evecFilename = fileStem + "_evec.bin";
std::string evalFilename = fileStem + "_eval.xml";
emptyUserRecord record;
ScidacWriter binWriter;
XmlWriter xmlWriter(evalFilename);
LOG(Message) << "Writing " << evec.size() << " eigenvectors to '"
<< evecFilename << "'" << std::endl;
binWriter.open(fileStem + "_evec.bin");
for(int k = 0; k < evec.size(); ++k)
{
binWriter.writeScidacFieldRecord(evec[k], record);
}
binWriter.close();
LOG(Message) << "Writing " << eval.size() << " eigenvalues to '"
<< evalFilename << "'" << std::endl;
Grid::write(xmlWriter, "evals", eval);
}
};
template <typename FImpl>
using FineEigenPack = EigenPack<typename FImpl::FermionField>;
template <typename FImpl, int nBasis>
using CoarseEigenPack = EigenPack<
typename LocalCoherenceLanczos<typename FImpl::SiteSpinor,
typename FImpl::SiteComplex,
nBasis>::CoarseField>;
END_HADRONS_NAMESPACE
#endif // Hadrons_LanczosUtils_hpp_

View File

@ -21,7 +21,7 @@ nobase_libHadrons_a_HEADERS = \
GeneticScheduler.hpp \
Global.hpp \
Graph.hpp \
LanczosUtils.hpp \
EigenPack.hpp \
Module.hpp \
Modules.hpp \
ModuleFactory.hpp \

View File

@ -91,6 +91,9 @@ static ns##mod##ModuleRegistrar ns##mod##ModuleRegistrarInstance;
#define envGet(type, name)\
*env().template getObject<type>(name)
#define envGetDerived(base, type, name)\
*env().template getDerivedObject<base, type>(name)
#define envGetTmp(type, var)\
type &var = *env().template getObject<type>(getName() + "_tmp_" + #var)

View File

@ -64,6 +64,7 @@ See the full license in the file "LICENSE" in the top level distribution directo
#include <Grid/Hadrons/Modules/MAction/Wilson.hpp>
#include <Grid/Hadrons/Modules/MAction/WilsonClover.hpp>
#include <Grid/Hadrons/Modules/MAction/ZMobiusDWF.hpp>
#include <Grid/Hadrons/Modules/MScalarSUN/ShiftProbe.hpp>
#include <Grid/Hadrons/Modules/MScalarSUN/Div.hpp>
#include <Grid/Hadrons/Modules/MScalarSUN/TrMag.hpp>
#include <Grid/Hadrons/Modules/MScalarSUN/EMT.hpp>
@ -72,5 +73,7 @@ See the full license in the file "LICENSE" in the top level distribution directo
#include <Grid/Hadrons/Modules/MScalarSUN/Utils.hpp>
#include <Grid/Hadrons/Modules/MScalarSUN/TransProj.hpp>
#include <Grid/Hadrons/Modules/MScalarSUN/TrKinetic.hpp>
#include <Grid/Hadrons/Modules/MIO/LoadEigenPack.hpp>
#include <Grid/Hadrons/Modules/MIO/LoadNersc.hpp>
#include <Grid/Hadrons/Modules/MIO/LoadCoarseEigenPack.hpp>
#include <Grid/Hadrons/Modules/MIO/LoadBinary.hpp>

View File

@ -42,7 +42,8 @@ TFundtoHirep<Rep>::TFundtoHirep(const std::string name)
template <class Rep>
std::vector<std::string> TFundtoHirep<Rep>::getInput(void)
{
std::vector<std::string> in;
std::vector<std::string> in = {par().gaugeconf};
return in;
}
@ -50,6 +51,7 @@ template <class Rep>
std::vector<std::string> TFundtoHirep<Rep>::getOutput(void)
{
std::vector<std::string> out = {getName()};
return out;
}
@ -57,19 +59,19 @@ std::vector<std::string> TFundtoHirep<Rep>::getOutput(void)
template <typename Rep>
void TFundtoHirep<Rep>::setup(void)
{
envCreateLat(typename Rep::LatticeField, getName());
envCreateLat(Rep::LatticeField, getName());
}
// execution ///////////////////////////////////////////////////////////////////
template <class Rep>
void TFundtoHirep<Rep>::execute(void)
{
auto &U = *env().template getObject<LatticeGaugeField>(par().gaugeconf);
LOG(Message) << "Transforming Representation" << std::endl;
auto &U = envGet(LatticeGaugeField, par().gaugeconf);
auto &URep = envGet(Rep::LatticeField, getName());
Rep TargetRepresentation(U._grid);
TargetRepresentation.update_representation(U);
auto &URep = envGet(typename Rep::LatticeField, getName());
URep = TargetRepresentation.U;
}

View File

@ -0,0 +1,126 @@
/*************************************************************************************
Grid physics library, www.github.com/paboyle/Grid
Source file: extras/Hadrons/Modules/MIO/LoadCoarseEigenPack.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_MIO_LoadCoarseEigenPack_hpp_
#define Hadrons_MIO_LoadCoarseEigenPack_hpp_
#include <Grid/Hadrons/Global.hpp>
#include <Grid/Hadrons/Module.hpp>
#include <Grid/Hadrons/ModuleFactory.hpp>
#include <Grid/Hadrons/EigenPack.hpp>
BEGIN_HADRONS_NAMESPACE
/******************************************************************************
* Load local coherence eigen vectors/values package *
******************************************************************************/
BEGIN_MODULE_NAMESPACE(MIO)
class LoadCoarseEigenPackPar: Serializable
{
public:
GRID_SERIALIZABLE_CLASS_MEMBERS(LoadCoarseEigenPackPar,
std::string, filestem,
unsigned int, sizeFine,
unsigned int, sizeCoarse,
unsigned int, Ls,
std::vector<int>, blockSize);
};
template <typename Pack>
class TLoadCoarseEigenPack: public Module<LoadCoarseEigenPackPar>
{
public:
typedef CoarseEigenPack<typename Pack::Field, typename Pack::CoarseField> BasePack;
public:
// constructor
TLoadCoarseEigenPack(const std::string name);
// destructor
virtual ~TLoadCoarseEigenPack(void) = default;
// 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_NS(LoadCoarseFermionEigenPack,
ARG(TLoadCoarseEigenPack<CoarseFermionEigenPack<FIMPL, HADRONS_DEFAULT_LANCZOS_NBASIS>>), MIO);
/******************************************************************************
* TLoadCoarseEigenPack implementation *
******************************************************************************/
// constructor /////////////////////////////////////////////////////////////////
template <typename Pack>
TLoadCoarseEigenPack<Pack>::TLoadCoarseEigenPack(const std::string name)
: Module<LoadCoarseEigenPackPar>(name)
{}
// dependencies/products ///////////////////////////////////////////////////////
template <typename Pack>
std::vector<std::string> TLoadCoarseEigenPack<Pack>::getInput(void)
{
std::vector<std::string> in;
return in;
}
template <typename Pack>
std::vector<std::string> TLoadCoarseEigenPack<Pack>::getOutput(void)
{
std::vector<std::string> out = {getName()};
return out;
}
// setup ///////////////////////////////////////////////////////////////////////
template <typename Pack>
void TLoadCoarseEigenPack<Pack>::setup(void)
{
env().createGrid(par().Ls);
env().createCoarseGrid(par().blockSize, par().Ls);
envCreateDerived(BasePack, Pack, getName(), par().Ls, par().sizeFine,
par().sizeCoarse, env().getRbGrid(par().Ls),
env().getCoarseGrid(par().blockSize, par().Ls));
}
// execution ///////////////////////////////////////////////////////////////////
template <typename Pack>
void TLoadCoarseEigenPack<Pack>::execute(void)
{
auto &epack = envGetDerived(BasePack, Pack, getName());
epack.read(par().filestem, vm().getTrajectory());
}
END_MODULE_NAMESPACE
END_HADRONS_NAMESPACE
#endif // Hadrons_MIO_LoadCoarseEigenPack_hpp_

View File

@ -0,0 +1,121 @@
/*************************************************************************************
Grid physics library, www.github.com/paboyle/Grid
Source file: extras/Hadrons/Modules/MIO/LoadEigenPack.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_MIO_LoadEigenPack_hpp_
#define Hadrons_MIO_LoadEigenPack_hpp_
#include <Grid/Hadrons/Global.hpp>
#include <Grid/Hadrons/Module.hpp>
#include <Grid/Hadrons/ModuleFactory.hpp>
#include <Grid/Hadrons/EigenPack.hpp>
BEGIN_HADRONS_NAMESPACE
/******************************************************************************
* Load eigen vectors/values package *
******************************************************************************/
BEGIN_MODULE_NAMESPACE(MIO)
class LoadEigenPackPar: Serializable
{
public:
GRID_SERIALIZABLE_CLASS_MEMBERS(LoadEigenPackPar,
std::string, filestem,
unsigned int, size,
unsigned int, Ls);
};
template <typename Pack>
class TLoadEigenPack: public Module<LoadEigenPackPar>
{
public:
typedef EigenPack<typename Pack::Field> BasePack;
public:
// constructor
TLoadEigenPack(const std::string name);
// destructor
virtual ~TLoadEigenPack(void) = default;
// 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_NS(LoadFermionEigenPack, TLoadEigenPack<FermionEigenPack<FIMPL>>, MIO);
/******************************************************************************
* TLoadEigenPack implementation *
******************************************************************************/
// constructor /////////////////////////////////////////////////////////////////
template <typename Pack>
TLoadEigenPack<Pack>::TLoadEigenPack(const std::string name)
: Module<LoadEigenPackPar>(name)
{}
// dependencies/products ///////////////////////////////////////////////////////
template <typename Pack>
std::vector<std::string> TLoadEigenPack<Pack>::getInput(void)
{
std::vector<std::string> in;
return in;
}
template <typename Pack>
std::vector<std::string> TLoadEigenPack<Pack>::getOutput(void)
{
std::vector<std::string> out = {getName()};
return out;
}
// setup ///////////////////////////////////////////////////////////////////////
template <typename Pack>
void TLoadEigenPack<Pack>::setup(void)
{
env().createGrid(par().Ls);
envCreateDerived(BasePack, Pack, getName(), par().Ls, par().size,
env().getRbGrid(par().Ls));
}
// execution ///////////////////////////////////////////////////////////////////
template <typename Pack>
void TLoadEigenPack<Pack>::execute(void)
{
auto &epack = envGetDerived(BasePack, Pack, getName());
epack.read(par().filestem, vm().getTrajectory());
}
END_MODULE_NAMESPACE
END_HADRONS_NAMESPACE
#endif // Hadrons_MIO_LoadEigenPack_hpp_

View File

@ -0,0 +1,169 @@
/*************************************************************************************
Grid physics library, www.github.com/paboyle/Grid
Source file: extras/Hadrons/Modules/MScalarSUN/ShiftProbe.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_MScalarSUN_ShiftProbe_hpp_
#define Hadrons_MScalarSUN_ShiftProbe_hpp_
#include <Grid/Hadrons/Global.hpp>
#include <Grid/Hadrons/Module.hpp>
#include <Grid/Hadrons/ModuleFactory.hpp>
#include <Grid/Hadrons/Modules/MScalarSUN/Utils.hpp>
BEGIN_HADRONS_NAMESPACE
/******************************************************************************
* Ward identity phi^n probe with fields at different positions *
******************************************************************************/
BEGIN_MODULE_NAMESPACE(MScalarSUN)
typedef std::pair<unsigned int, unsigned int> ShiftPair;
class ShiftProbePar: Serializable
{
public:
GRID_SERIALIZABLE_CLASS_MEMBERS(ShiftProbePar,
std::string, field,
std::string, shifts,
std::string, output);
};
template <typename SImpl>
class TShiftProbe: public Module<ShiftProbePar>
{
public:
typedef typename SImpl::Field Field;
typedef typename SImpl::ComplexField ComplexField;
class Result: Serializable
{
public:
GRID_SERIALIZABLE_CLASS_MEMBERS(Result,
std::string, op,
Complex , value);
};
public:
// constructor
TShiftProbe(const std::string name);
// destructor
virtual ~TShiftProbe(void) = default;
// 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_NS(ShiftProbeSU2, TShiftProbe<ScalarNxNAdjImplR<2>>, MScalarSUN);
MODULE_REGISTER_NS(ShiftProbeSU3, TShiftProbe<ScalarNxNAdjImplR<3>>, MScalarSUN);
MODULE_REGISTER_NS(ShiftProbeSU4, TShiftProbe<ScalarNxNAdjImplR<4>>, MScalarSUN);
MODULE_REGISTER_NS(ShiftProbeSU5, TShiftProbe<ScalarNxNAdjImplR<5>>, MScalarSUN);
MODULE_REGISTER_NS(ShiftProbeSU6, TShiftProbe<ScalarNxNAdjImplR<6>>, MScalarSUN);
/******************************************************************************
* TShiftProbe implementation *
******************************************************************************/
// constructor /////////////////////////////////////////////////////////////////
template <typename SImpl>
TShiftProbe<SImpl>::TShiftProbe(const std::string name)
: Module<ShiftProbePar>(name)
{}
// dependencies/products ///////////////////////////////////////////////////////
template <typename SImpl>
std::vector<std::string> TShiftProbe<SImpl>::getInput(void)
{
std::vector<std::string> in = {par().field};
return in;
}
template <typename SImpl>
std::vector<std::string> TShiftProbe<SImpl>::getOutput(void)
{
std::vector<std::string> out = {getName()};
return out;
}
// setup ///////////////////////////////////////////////////////////////////////
template <typename SImpl>
void TShiftProbe<SImpl>::setup(void)
{
envTmpLat(Field, "acc");
envCreateLat(ComplexField, getName());
}
// execution ///////////////////////////////////////////////////////////////////
template <typename SImpl>
void TShiftProbe<SImpl>::execute(void)
{
LOG(Message) << "Creating shift probe for shifts " << par().shifts
<< std::endl;
std::vector<ShiftPair> shift;
unsigned int sign;
auto &phi = envGet(Field, par().field);
auto &probe = envGet(ComplexField, getName());
shift = strToVec<ShiftPair>(par().shifts);
if (shift.size() % 2 != 0)
{
HADRON_ERROR(Size, "the number of shifts is odd");
}
sign = (shift.size() % 4 == 0) ? 1 : -1;
for (auto &s: shift)
{
if (s.first >= env().getNd())
{
HADRON_ERROR(Size, "dimension to large for shift <"
+ std::to_string(s.first) + " "
+ std::to_string(s.second) + ">" );
}
}
envGetTmp(Field, acc);
acc = 1.;
for (unsigned int i = 0; i < shift.size(); ++i)
{
if (shift[i].second == 0)
{
acc *= phi;
}
else
{
acc *= Cshift(phi, shift[i].first, shift[i].second);
}
}
probe = sign*trace(acc);
}
END_MODULE_NAMESPACE
END_HADRONS_NAMESPACE
#endif // Hadrons_MScalarSUN_ShiftProbe_hpp_

View File

@ -128,7 +128,7 @@ void TPoint<FImpl>::execute(void)
envGetTmp(LatticeComplex, coor);
p = strToVec<Real>(par().mom);
ph = zero;
for(unsigned int mu = 0; mu < env().getNd(); mu++)
for(unsigned int mu = 0; mu < p.size(); mu++)
{
LatticeCoordinate(coor, mu);
ph = ph + (p[mu]/env().getGrid()->_fdimensions[mu])*coor;

View File

@ -31,7 +31,7 @@ See the full license in the file "LICENSE" in the top level distribution directo
#include <Grid/Hadrons/Global.hpp>
#include <Grid/Hadrons/Module.hpp>
#include <Grid/Hadrons/ModuleFactory.hpp>
#include <Grid/Hadrons/LanczosUtils.hpp>
#include <Grid/Hadrons/EigenPack.hpp>
BEGIN_HADRONS_NAMESPACE
@ -45,8 +45,7 @@ class LocalCoherenceLanczosPar: Serializable
public:
GRID_SERIALIZABLE_CLASS_MEMBERS(LocalCoherenceLanczosPar,
std::string, action,
int, doFine,
int, doCoarse,
bool, doCoarse,
LanczosParams, fineParams,
LanczosParams, coarseParams,
ChebyParams, smoother,
@ -63,8 +62,8 @@ public:
typedef LocalCoherenceLanczos<typename FImpl::SiteSpinor,
typename FImpl::SiteComplex,
nBasis> LCL;
typedef FineEigenPack<FImpl> FinePack;
typedef CoarseEigenPack<FImpl, nBasis> CoarsePack;
typedef FermionEigenPack<FImpl> BasePack;
typedef CoarseFermionEigenPack<FImpl, nBasis> CoarsePack;
typedef HADRONS_DEFAULT_SCHUR_OP<FMat, FermionField> SchurFMat;
public:
// constructor
@ -78,16 +77,6 @@ public:
virtual void setup(void);
// execution
virtual void execute(void);
private:
void makeCoarseGrid(void);
private:
std::vector<int> coarseDim_;
int Ls_, cLs_{1};
std::unique_ptr<GridCartesian> coarseGrid4_{nullptr};
std::unique_ptr<GridCartesian> coarseGrid_{nullptr};
std::unique_ptr<GridRedBlackCartesian> coarseGrid4Rb_{nullptr};
std::unique_ptr<GridRedBlackCartesian> coarseGridRb_{nullptr};
std::string fineName_, coarseName_;
};
MODULE_REGISTER_NS(LocalCoherenceLanczos,
@ -104,10 +93,7 @@ MODULE_REGISTER_NS(ZLocalCoherenceLanczos,
template <typename FImpl, int nBasis>
TLocalCoherenceLanczos<FImpl, nBasis>::TLocalCoherenceLanczos(const std::string name)
: Module<LocalCoherenceLanczosPar>(name)
{
fineName_ = getName() + "_fine";
coarseName_ = getName() + "_coarse";
}
{}
// dependencies/products ///////////////////////////////////////////////////////
template <typename FImpl, int nBasis>
@ -121,61 +107,12 @@ std::vector<std::string> TLocalCoherenceLanczos<FImpl, nBasis>::getInput(void)
template <typename FImpl, int nBasis>
std::vector<std::string> TLocalCoherenceLanczos<FImpl, nBasis>::getOutput(void)
{
std::vector<std::string> out = {fineName_, coarseName_};
std::vector<std::string> out = {getName()};
return out;
}
// setup ///////////////////////////////////////////////////////////////////////
template <typename FImpl, int nBasis>
void TLocalCoherenceLanczos<FImpl, nBasis>::makeCoarseGrid(void)
{
int nd = env().getNd();
std::vector<int> blockSize = strToVec<int>(par().blockSize);
auto fineDim = env().getDim();
Ls_ = env().getObjectLs(par().action);
env().createGrid(Ls_);
coarseDim_.resize(nd);
for (int d = 0; d < coarseDim_.size(); d++)
{
coarseDim_[d] = fineDim[d]/blockSize[d];
if (coarseDim_[d]*blockSize[d] != fineDim[d])
{
HADRON_ERROR(Size, "Fine dimension " + std::to_string(d)
+ " (" + std::to_string(fineDim[d])
+ ") not divisible by coarse dimension ("
+ std::to_string(coarseDim_[d]) + ")");
}
}
if (blockSize.size() > nd)
{
cLs_ = Ls_/blockSize[nd];
if (cLs_*blockSize[nd] != Ls_)
{
HADRON_ERROR(Size, "Fine Ls (" + std::to_string(Ls_)
+ ") not divisible by coarse Ls ("
+ std::to_string(cLs_) + ")");
}
}
if (Ls_ > 1)
{
coarseGrid4_.reset(SpaceTimeGrid::makeFourDimGrid(
coarseDim_, GridDefaultSimd(nd, vComplex::Nsimd()),
GridDefaultMpi()));
coarseGrid4Rb_.reset(SpaceTimeGrid::makeFourDimRedBlackGrid(coarseGrid4_.get()));
coarseGrid_.reset(SpaceTimeGrid::makeFiveDimGrid(cLs_, coarseGrid4_.get()));
coarseGridRb_.reset(SpaceTimeGrid::makeFiveDimRedBlackGrid(cLs_, coarseGrid4_.get()));
}
else
{
coarseGrid_.reset(SpaceTimeGrid::makeFourDimGrid(
coarseDim_, GridDefaultSimd(nd, vComplex::Nsimd()),
GridDefaultMpi()));
coarseGridRb_.reset(SpaceTimeGrid::makeFourDimRedBlackGrid(coarseGrid_.get()));
}
}
template <typename FImpl, int nBasis>
void TLocalCoherenceLanczos<FImpl, nBasis>::setup(void)
{
@ -183,19 +120,25 @@ void TLocalCoherenceLanczos<FImpl, nBasis>::setup(void)
<< " action '" << par().action << "' (" << nBasis
<< " eigenvectors)..." << std::endl;
if (!coarseGrid_)
{
makeCoarseGrid();
}
LOG(Message) << "Coarse grid: " << coarseGrid_->GlobalDimensions() << std::endl;
envCreate(FinePack, fineName_, Ls_, par().fineParams.Nm, env().getRbGrid(Ls_));
envCreate(CoarsePack, coarseName_, Ls_, par().coarseParams.Nm, coarseGridRb_.get());
auto &fine = envGet(FinePack, fineName_);
auto &coarse = envGet(CoarsePack, coarseName_);
envTmp(SchurFMat, "mat", Ls_, envGet(FMat, par().action));
unsigned int Ls = env().getObjectLs(par().action);
auto blockSize = strToVec<int>(par().blockSize);
env().createCoarseGrid(blockSize, Ls);
auto cg = env().getCoarseGrid(blockSize, Ls);
auto cgrb = env().getRbCoarseGrid(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), cgrb);
auto &epack = envGetDerived(BasePack, CoarsePack, getName());
envTmp(SchurFMat, "mat", Ls, envGet(FMat, par().action));
envGetTmp(SchurFMat, mat);
envTmp(LCL, "solver", Ls_, env().getRbGrid(Ls_), coarseGridRb_.get(), mat,
Odd, fine.evec, coarse.evec, fine.eval, coarse.eval);
envTmp(LCL, "solver", Ls, env().getRbGrid(Ls), cgrb, mat,
Odd, epack.evec, epack.evecCoarse, epack.eval, epack.evalCoarse);
}
// execution ///////////////////////////////////////////////////////////////////
@ -204,41 +147,33 @@ void TLocalCoherenceLanczos<FImpl, nBasis>::execute(void)
{
auto &finePar = par().fineParams;
auto &coarsePar = par().coarseParams;
auto &fine = envGet(FinePack, fineName_);
auto &coarse = envGet(CoarsePack, coarseName_);
auto &epack = envGetDerived(BasePack, CoarsePack, getName());
envGetTmp(LCL, solver);
if (par().doFine)
{
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);
LOG(Message) << "Orthogonalising" << std::endl;
solver.Orthogonalise();
if (!par().output.empty())
{
fine.write(par().output + "_fine");
}
}
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().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;
<< 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.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())
{
coarse.write(par().output + "_coarse");
}
par().coarseRelaxTol);
}
if (!par().output.empty())
{
epack.write(par().output, vm().getTrajectory());
}
}

View File

@ -32,6 +32,7 @@ See the full license in the file "LICENSE" in the top level distribution directo
#include <Grid/Hadrons/Global.hpp>
#include <Grid/Hadrons/Module.hpp>
#include <Grid/Hadrons/ModuleFactory.hpp>
#include <Grid/Hadrons/EigenPack.hpp>
BEGIN_HADRONS_NAMESPACE
@ -44,16 +45,24 @@ class RBPrecCGPar: Serializable
{
public:
GRID_SERIALIZABLE_CLASS_MEMBERS(RBPrecCGPar ,
std::string , action,
unsigned int , maxIteration,
double , residual);
std::string , action,
unsigned int, maxIteration,
double , residual,
std::string , eigenPack);
};
template <typename FImpl>
template <typename FImpl, int nBasis>
class TRBPrecCG: public Module<RBPrecCGPar>
{
public:
FGS_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);
@ -70,37 +79,39 @@ protected:
virtual void execute(void);
};
MODULE_REGISTER_NS(RBPrecCG, TRBPrecCG<FIMPL>, MSolver);
MODULE_REGISTER_NS(ZRBPrecCG, TRBPrecCG<ZFIMPL>, MSolver);
MODULE_REGISTER_NS(RBPrecCG,
ARG(TRBPrecCG<FIMPL, HADRONS_DEFAULT_LANCZOS_NBASIS>), MSolver);
MODULE_REGISTER_NS(ZRBPrecCG,
ARG(TRBPrecCG<ZFIMPL, HADRONS_DEFAULT_LANCZOS_NBASIS>), MSolver);
/******************************************************************************
* TRBPrecCG template implementation *
******************************************************************************/
// constructor /////////////////////////////////////////////////////////////////
template <typename FImpl>
TRBPrecCG<FImpl>::TRBPrecCG(const std::string name)
template <typename FImpl, int nBasis>
TRBPrecCG<FImpl, nBasis>::TRBPrecCG(const std::string name)
: Module(name)
{}
// dependencies/products ///////////////////////////////////////////////////////
template <typename FImpl>
std::vector<std::string> TRBPrecCG<FImpl>::getInput(void)
template <typename FImpl, int nBasis>
std::vector<std::string> TRBPrecCG<FImpl, nBasis>::getInput(void)
{
std::vector<std::string> in = {};
return in;
}
template <typename FImpl>
std::vector<std::string> TRBPrecCG<FImpl>::getReference(void)
template <typename FImpl, int nBasis>
std::vector<std::string> TRBPrecCG<FImpl, nBasis>::getReference(void)
{
std::vector<std::string> ref = {par().action};
return ref;
}
template <typename FImpl>
std::vector<std::string> TRBPrecCG<FImpl>::getOutput(void)
template <typename FImpl, int nBasis>
std::vector<std::string> TRBPrecCG<FImpl, nBasis>::getOutput(void)
{
std::vector<std::string> out = {getName()};
@ -108,30 +119,60 @@ std::vector<std::string> TRBPrecCG<FImpl>::getOutput(void)
}
// setup ///////////////////////////////////////////////////////////////////////
template <typename FImpl>
void TRBPrecCG<FImpl>::setup(void)
template <typename FImpl, int nBasis>
void TRBPrecCG<FImpl, nBasis>::setup(void)
{
if (par().maxIteration == 0)
{
HADRON_ERROR(Argument, "zero maximum iteration");
}
LOG(Message) << "setting up Schur red-black preconditioned CG for"
<< " action '" << par().action << "' with residual "
<< par().residual << std::endl;
<< par().residual << ", maximum iteration "
<< par().maxIteration << std::endl;
auto Ls = env().getObjectLs(par().action);
auto &mat = envGet(FMat, par().action);
auto solver = [&mat, this](FermionField &sol, const FermionField &source)
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);
guesser.reset(new CoarseGuesser(epack.evec, epack.evecCoarse,
epack.evalCoarse));
}
catch (Exceptions::Definition &e)
{
auto &epack = envGet(EPack, par().eigenPack);
guesser.reset(new FineGuesser(epack.evec, epack.eval));
}
}
auto solver = [&mat, guesser, this](FermionField &sol,
const FermionField &source)
{
ConjugateGradient<FermionField> cg(par().residual,
par().maxIteration);
HADRONS_DEFAULT_SCHUR_SOLVE<FermionField> schurSolver(cg);
schurSolver(mat, source, sol);
schurSolver(mat, source, sol, *guesser);
};
envCreate(SolverFn, getName(), Ls, solver);
}
// execution ///////////////////////////////////////////////////////////////////
template <typename FImpl>
void TRBPrecCG<FImpl>::execute(void)
template <typename FImpl, int nBasis>
void TRBPrecCG<FImpl, nBasis>::execute(void)
{}
END_MODULE_NAMESPACE

View File

@ -381,7 +381,6 @@ void VirtualMachine::makeMemoryProfile(void)
env().protectObjects(false);
GridLogMessage.Active(false);
HadronsLogMessage.Active(false);
HadronsLogError.Active(false);
for (auto it = program.rbegin(); it != program.rend(); ++it)
{
auto a = *it;
@ -397,7 +396,6 @@ void VirtualMachine::makeMemoryProfile(void)
env().protectObjects(protect);
GridLogMessage.Active(gmsg);
HadronsLogMessage.Active(hmsg);
HadronsLogError.Active(err);
LOG(Debug) << "Memory profile:" << std::endl;
LOG(Debug) << "----------------" << std::endl;
for (unsigned int a = 0; a < profile_.module.size(); ++a)
@ -632,6 +630,17 @@ void VirtualMachine::executeProgram(const Program &p) const
// build garbage collection schedule
LOG(Debug) << "Building garbage collection schedule..." << std::endl;
freeProg = makeGarbageSchedule(p);
for (unsigned int i = 0; i < freeProg.size(); ++i)
{
std::string msg = "";
for (auto &a: freeProg[i])
{
msg += env().getObjectName(a) + " ";
}
msg += "]";
LOG(Debug) << std::setw(4) << i + 1 << ": [" << msg << std::endl;
}
// program execution
LOG(Debug) << "Executing program..." << std::endl;

View File

@ -50,6 +50,7 @@ modules_hpp =\
Modules/MAction/Wilson.hpp \
Modules/MAction/WilsonClover.hpp \
Modules/MAction/ZMobiusDWF.hpp \
Modules/MScalarSUN/ShiftProbe.hpp \
Modules/MScalarSUN/Div.hpp \
Modules/MScalarSUN/TrMag.hpp \
Modules/MScalarSUN/EMT.hpp \
@ -58,6 +59,8 @@ modules_hpp =\
Modules/MScalarSUN/Utils.hpp \
Modules/MScalarSUN/TransProj.hpp \
Modules/MScalarSUN/TrKinetic.hpp \
Modules/MIO/LoadEigenPack.hpp \
Modules/MIO/LoadNersc.hpp \
Modules/MIO/LoadCoarseEigenPack.hpp \
Modules/MIO/LoadBinary.hpp