mirror of
https://github.com/paboyle/Grid.git
synced 2025-04-09 21:50:45 +01:00
Hadrons: eigen packs I/O and deflation interface
This commit is contained in:
parent
72344d1418
commit
d516938707
@ -29,6 +29,7 @@ See the full license in the file "LICENSE" in the top level distribution directo
|
|||||||
#define Hadrons_EigenPack_hpp_
|
#define Hadrons_EigenPack_hpp_
|
||||||
|
|
||||||
#include <Grid/Hadrons/Global.hpp>
|
#include <Grid/Hadrons/Global.hpp>
|
||||||
|
#include <Grid/algorithms/iterative/Deflation.h>
|
||||||
#include <Grid/algorithms/iterative/LocalCoherenceLanczos.h>
|
#include <Grid/algorithms/iterative/LocalCoherenceLanczos.h>
|
||||||
|
|
||||||
BEGIN_HADRONS_NAMESPACE
|
BEGIN_HADRONS_NAMESPACE
|
||||||
@ -38,12 +39,14 @@ BEGIN_HADRONS_NAMESPACE
|
|||||||
#define HADRONS_DEFAULT_LANCZOS_NBASIS 60
|
#define HADRONS_DEFAULT_LANCZOS_NBASIS 60
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
template <typename Field>
|
template <typename F>
|
||||||
class EigenPack
|
class EigenPack
|
||||||
{
|
{
|
||||||
|
public:
|
||||||
|
typedef F Field;
|
||||||
public:
|
public:
|
||||||
std::vector<RealD> eval;
|
std::vector<RealD> eval;
|
||||||
std::vector<Field> evec;
|
std::vector<F> evec;
|
||||||
public:
|
public:
|
||||||
EigenPack(void) = default;
|
EigenPack(void) = default;
|
||||||
virtual ~EigenPack(void) = default;
|
virtual ~EigenPack(void) = default;
|
||||||
@ -123,12 +126,14 @@ protected:
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename FineField, typename CoarseField>
|
template <typename FineF, typename CoarseF>
|
||||||
class CoarseEigenPack: public EigenPack<FineField>
|
class CoarseEigenPack: public EigenPack<FineF>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
std::vector<RealD> evalCoarse;
|
typedef CoarseF CoarseField;
|
||||||
std::vector<CoarseField> evecCoarse;
|
public:
|
||||||
|
std::vector<RealD> evalCoarse;
|
||||||
|
std::vector<CoarseF> evecCoarse;
|
||||||
public:
|
public:
|
||||||
CoarseEigenPack(void) = default;
|
CoarseEigenPack(void) = default;
|
||||||
virtual ~CoarseEigenPack(void) = default;
|
virtual ~CoarseEigenPack(void) = default;
|
||||||
@ -142,7 +147,7 @@ public:
|
|||||||
void resize(const size_t sizeFine, const size_t sizeCoarse,
|
void resize(const size_t sizeFine, const size_t sizeCoarse,
|
||||||
GridBase *gridFine, GridBase *gridCoarse)
|
GridBase *gridFine, GridBase *gridCoarse)
|
||||||
{
|
{
|
||||||
EigenPack<FineField>::resize(sizeFine, gridFine);
|
EigenPack<FineF>::resize(sizeFine, gridFine);
|
||||||
evalCoarse.resize(sizeCoarse);
|
evalCoarse.resize(sizeCoarse);
|
||||||
evecCoarse.resize(sizeCoarse, gridCoarse);
|
evecCoarse.resize(sizeCoarse, gridCoarse);
|
||||||
}
|
}
|
||||||
|
@ -78,7 +78,7 @@ private:
|
|||||||
Size size{0};
|
Size size{0};
|
||||||
Storage storage{Storage::object};
|
Storage storage{Storage::object};
|
||||||
unsigned int Ls{0};
|
unsigned int Ls{0};
|
||||||
const std::type_info *type{nullptr};
|
const std::type_info *type{nullptr}, *derivedType{nullptr};
|
||||||
std::string name;
|
std::string name;
|
||||||
int module{-1};
|
int module{-1};
|
||||||
std::unique_ptr<Object> data{nullptr};
|
std::unique_ptr<Object> data{nullptr};
|
||||||
@ -230,22 +230,24 @@ void Environment::createDerivedObject(const std::string name,
|
|||||||
{
|
{
|
||||||
MemoryProfiler::stats = &memStats;
|
MemoryProfiler::stats = &memStats;
|
||||||
}
|
}
|
||||||
size_t initMem = MemoryProfiler::stats->currentlyAllocated;
|
size_t initMem = MemoryProfiler::stats->currentlyAllocated;
|
||||||
object_[address].storage = storage;
|
object_[address].storage = storage;
|
||||||
object_[address].Ls = Ls;
|
object_[address].Ls = Ls;
|
||||||
object_[address].data.reset(new Holder<B>(new T(std::forward<Ts>(args)...)));
|
object_[address].data.reset(new Holder<B>(new T(std::forward<Ts>(args)...)));
|
||||||
object_[address].size = MemoryProfiler::stats->maxAllocated - initMem;
|
object_[address].size = MemoryProfiler::stats->maxAllocated - initMem;
|
||||||
object_[address].type = &typeid(B);
|
object_[address].type = &typeid(B);
|
||||||
|
object_[address].derivedType = &typeid(T);
|
||||||
if (MemoryProfiler::stats == &memStats)
|
if (MemoryProfiler::stats == &memStats)
|
||||||
{
|
{
|
||||||
MemoryProfiler::stats = nullptr;
|
MemoryProfiler::stats = nullptr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// object already exists, no error if it is a cache, error otherwise
|
// object already exists, no error if it is a cache, error otherwise
|
||||||
else if ((object_[address].storage != Storage::cache) or
|
else if ((object_[address].storage != Storage::cache) or
|
||||||
(object_[address].storage != storage) or
|
(object_[address].storage != storage) or
|
||||||
(object_[address].name != name) or
|
(object_[address].name != name) or
|
||||||
(object_[address].type != &typeid(B)))
|
(object_[address].type != &typeid(B)) or
|
||||||
|
(object_[address].derivedType != &typeid(T)))
|
||||||
{
|
{
|
||||||
HADRON_ERROR(Definition, "object '" + name + "' already allocated");
|
HADRON_ERROR(Definition, "object '" + name + "' already allocated");
|
||||||
}
|
}
|
||||||
|
@ -70,5 +70,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/Utils.hpp>
|
||||||
#include <Grid/Hadrons/Modules/MScalarSUN/TransProj.hpp>
|
#include <Grid/Hadrons/Modules/MScalarSUN/TransProj.hpp>
|
||||||
#include <Grid/Hadrons/Modules/MScalarSUN/TrKinetic.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/LoadNersc.hpp>
|
||||||
|
#include <Grid/Hadrons/Modules/MIO/LoadCoarseEigenPack.hpp>
|
||||||
#include <Grid/Hadrons/Modules/MIO/LoadBinary.hpp>
|
#include <Grid/Hadrons/Modules/MIO/LoadBinary.hpp>
|
||||||
|
@ -42,7 +42,8 @@ TFundtoHirep<Rep>::TFundtoHirep(const std::string name)
|
|||||||
template <class Rep>
|
template <class Rep>
|
||||||
std::vector<std::string> TFundtoHirep<Rep>::getInput(void)
|
std::vector<std::string> TFundtoHirep<Rep>::getInput(void)
|
||||||
{
|
{
|
||||||
std::vector<std::string> in;
|
std::vector<std::string> in = {par().gaugeconf};
|
||||||
|
|
||||||
return in;
|
return in;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -50,6 +51,7 @@ template <class Rep>
|
|||||||
std::vector<std::string> TFundtoHirep<Rep>::getOutput(void)
|
std::vector<std::string> TFundtoHirep<Rep>::getOutput(void)
|
||||||
{
|
{
|
||||||
std::vector<std::string> out = {getName()};
|
std::vector<std::string> out = {getName()};
|
||||||
|
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -57,19 +59,19 @@ std::vector<std::string> TFundtoHirep<Rep>::getOutput(void)
|
|||||||
template <typename Rep>
|
template <typename Rep>
|
||||||
void TFundtoHirep<Rep>::setup(void)
|
void TFundtoHirep<Rep>::setup(void)
|
||||||
{
|
{
|
||||||
envCreateLat(typename Rep::LatticeField, getName());
|
envCreateLat(Rep::LatticeField, getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
// execution ///////////////////////////////////////////////////////////////////
|
// execution ///////////////////////////////////////////////////////////////////
|
||||||
template <class Rep>
|
template <class Rep>
|
||||||
void TFundtoHirep<Rep>::execute(void)
|
void TFundtoHirep<Rep>::execute(void)
|
||||||
{
|
{
|
||||||
auto &U = *env().template getObject<LatticeGaugeField>(par().gaugeconf);
|
|
||||||
LOG(Message) << "Transforming Representation" << std::endl;
|
LOG(Message) << "Transforming Representation" << std::endl;
|
||||||
|
|
||||||
|
auto &U = envGet(LatticeGaugeField, par().gaugeconf);
|
||||||
|
auto &URep = envGet(Rep::LatticeField, getName());
|
||||||
|
|
||||||
Rep TargetRepresentation(U._grid);
|
Rep TargetRepresentation(U._grid);
|
||||||
TargetRepresentation.update_representation(U);
|
TargetRepresentation.update_representation(U);
|
||||||
|
|
||||||
auto &URep = envGet(typename Rep::LatticeField, getName());
|
|
||||||
URep = TargetRepresentation.U;
|
URep = TargetRepresentation.U;
|
||||||
}
|
}
|
||||||
|
126
extras/Hadrons/Modules/MIO/LoadCoarseEigenPack.hpp
Normal file
126
extras/Hadrons/Modules/MIO/LoadCoarseEigenPack.hpp
Normal 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_
|
121
extras/Hadrons/Modules/MIO/LoadEigenPack.hpp
Normal file
121
extras/Hadrons/Modules/MIO/LoadEigenPack.hpp
Normal 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_
|
@ -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/Global.hpp>
|
||||||
#include <Grid/Hadrons/Module.hpp>
|
#include <Grid/Hadrons/Module.hpp>
|
||||||
#include <Grid/Hadrons/ModuleFactory.hpp>
|
#include <Grid/Hadrons/ModuleFactory.hpp>
|
||||||
|
#include <Grid/Hadrons/EigenPack.hpp>
|
||||||
|
|
||||||
BEGIN_HADRONS_NAMESPACE
|
BEGIN_HADRONS_NAMESPACE
|
||||||
|
|
||||||
@ -44,15 +45,22 @@ class RBPrecCGPar: Serializable
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
GRID_SERIALIZABLE_CLASS_MEMBERS(RBPrecCGPar ,
|
GRID_SERIALIZABLE_CLASS_MEMBERS(RBPrecCGPar ,
|
||||||
std::string , action,
|
std::string , action,
|
||||||
unsigned int , maxIteration,
|
unsigned int, maxIteration,
|
||||||
double , residual);
|
double , residual,
|
||||||
|
std::string , eigenPack);
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename FImpl>
|
template <typename FImpl, int nBasis>
|
||||||
class TRBPrecCG: public Module<RBPrecCGPar>
|
class TRBPrecCG: public Module<RBPrecCGPar>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
typedef FermionEigenPack<FImpl> EPack;
|
||||||
|
typedef CoarseFermionEigenPack<FImpl, nBasis> CoarseEPack;
|
||||||
|
typedef DeflatedGuesser<typename FImpl::FermionField> FineGuesser;
|
||||||
|
typedef LocalCoherenceDeflatedGuesser<
|
||||||
|
typename FImpl::FermionField,
|
||||||
|
typename CoarseEPack::CoarseField> CoarseGuesser;
|
||||||
FGS_TYPE_ALIASES(FImpl,);
|
FGS_TYPE_ALIASES(FImpl,);
|
||||||
public:
|
public:
|
||||||
// constructor
|
// constructor
|
||||||
@ -70,37 +78,39 @@ protected:
|
|||||||
virtual void execute(void);
|
virtual void execute(void);
|
||||||
};
|
};
|
||||||
|
|
||||||
MODULE_REGISTER_NS(RBPrecCG, TRBPrecCG<FIMPL>, MSolver);
|
MODULE_REGISTER_NS(RBPrecCG,
|
||||||
MODULE_REGISTER_NS(ZRBPrecCG, TRBPrecCG<ZFIMPL>, MSolver);
|
ARG(TRBPrecCG<FIMPL, HADRONS_DEFAULT_LANCZOS_NBASIS>), MSolver);
|
||||||
|
MODULE_REGISTER_NS(ZRBPrecCG,
|
||||||
|
ARG(TRBPrecCG<ZFIMPL, HADRONS_DEFAULT_LANCZOS_NBASIS>), MSolver);
|
||||||
|
|
||||||
/******************************************************************************
|
/******************************************************************************
|
||||||
* TRBPrecCG template implementation *
|
* TRBPrecCG template implementation *
|
||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
// constructor /////////////////////////////////////////////////////////////////
|
// constructor /////////////////////////////////////////////////////////////////
|
||||||
template <typename FImpl>
|
template <typename FImpl, int nBasis>
|
||||||
TRBPrecCG<FImpl>::TRBPrecCG(const std::string name)
|
TRBPrecCG<FImpl, nBasis>::TRBPrecCG(const std::string name)
|
||||||
: Module(name)
|
: Module(name)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
// dependencies/products ///////////////////////////////////////////////////////
|
// dependencies/products ///////////////////////////////////////////////////////
|
||||||
template <typename FImpl>
|
template <typename FImpl, int nBasis>
|
||||||
std::vector<std::string> TRBPrecCG<FImpl>::getInput(void)
|
std::vector<std::string> TRBPrecCG<FImpl, nBasis>::getInput(void)
|
||||||
{
|
{
|
||||||
std::vector<std::string> in = {};
|
std::vector<std::string> in = {};
|
||||||
|
|
||||||
return in;
|
return in;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename FImpl>
|
template <typename FImpl, int nBasis>
|
||||||
std::vector<std::string> TRBPrecCG<FImpl>::getReference(void)
|
std::vector<std::string> TRBPrecCG<FImpl, nBasis>::getReference(void)
|
||||||
{
|
{
|
||||||
std::vector<std::string> ref = {par().action};
|
std::vector<std::string> ref = {par().action};
|
||||||
|
|
||||||
return ref;
|
return ref;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename FImpl>
|
template <typename FImpl, int nBasis>
|
||||||
std::vector<std::string> TRBPrecCG<FImpl>::getOutput(void)
|
std::vector<std::string> TRBPrecCG<FImpl, nBasis>::getOutput(void)
|
||||||
{
|
{
|
||||||
std::vector<std::string> out = {getName()};
|
std::vector<std::string> out = {getName()};
|
||||||
|
|
||||||
@ -108,8 +118,8 @@ std::vector<std::string> TRBPrecCG<FImpl>::getOutput(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// setup ///////////////////////////////////////////////////////////////////////
|
// setup ///////////////////////////////////////////////////////////////////////
|
||||||
template <typename FImpl>
|
template <typename FImpl, int nBasis>
|
||||||
void TRBPrecCG<FImpl>::setup(void)
|
void TRBPrecCG<FImpl, nBasis>::setup(void)
|
||||||
{
|
{
|
||||||
if (par().maxIteration == 0)
|
if (par().maxIteration == 0)
|
||||||
{
|
{
|
||||||
@ -121,23 +131,49 @@ void TRBPrecCG<FImpl>::setup(void)
|
|||||||
<< par().residual << ", maximum iteration "
|
<< par().residual << ", maximum iteration "
|
||||||
<< par().maxIteration << std::endl;
|
<< par().maxIteration << std::endl;
|
||||||
|
|
||||||
auto Ls = env().getObjectLs(par().action);
|
auto Ls = env().getObjectLs(par().action);
|
||||||
auto &mat = envGet(FMat, par().action);
|
auto &mat = envGet(FMat, par().action);
|
||||||
auto solver = [&mat, this](FermionField &sol, const FermionField &source)
|
std::string guesserName = getName() + "_guesser";
|
||||||
|
|
||||||
|
if (par().eigenPack.empty())
|
||||||
|
{
|
||||||
|
env().template createDerivedObject<Guesser<FermionField>, ZeroGuesser<FermionField>>
|
||||||
|
(guesserName, Environment::Storage::object, Ls);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
auto &epack = envGetDerived(EPack, CoarseEPack, par().eigenPack);
|
||||||
|
|
||||||
|
envCreateDerived(Guesser<FermionField>, CoarseGuesser,
|
||||||
|
guesserName, Ls, epack.evec, epack.evecCoarse,
|
||||||
|
epack.evalCoarse);
|
||||||
|
}
|
||||||
|
catch (Exceptions::Definition &e)
|
||||||
|
{
|
||||||
|
auto &epack = envGet(EPack, par().eigenPack);
|
||||||
|
|
||||||
|
envCreateDerived(Guesser<FermionField>, FineGuesser,
|
||||||
|
guesserName, Ls, epack.evec, epack.eval);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
auto &guesser = envGet(Guesser<FermionField>, guesserName);
|
||||||
|
auto solver = [&mat, &guesser, this](FermionField &sol, const FermionField &source)
|
||||||
{
|
{
|
||||||
ConjugateGradient<FermionField> cg(par().residual,
|
ConjugateGradient<FermionField> cg(par().residual,
|
||||||
par().maxIteration);
|
par().maxIteration);
|
||||||
HADRONS_DEFAULT_SCHUR_SOLVE<FermionField> schurSolver(cg);
|
HADRONS_DEFAULT_SCHUR_SOLVE<FermionField> schurSolver(cg);
|
||||||
|
|
||||||
schurSolver(mat, source, sol);
|
schurSolver(mat, source, sol, guesser);
|
||||||
};
|
};
|
||||||
envCreate(SolverFn, getName(), Ls, solver);
|
envCreate(SolverFn, getName(), Ls, solver);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// execution ///////////////////////////////////////////////////////////////////
|
// execution ///////////////////////////////////////////////////////////////////
|
||||||
template <typename FImpl>
|
template <typename FImpl, int nBasis>
|
||||||
void TRBPrecCG<FImpl>::execute(void)
|
void TRBPrecCG<FImpl, nBasis>::execute(void)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
END_MODULE_NAMESPACE
|
END_MODULE_NAMESPACE
|
||||||
|
@ -632,12 +632,14 @@ void VirtualMachine::executeProgram(const Program &p) const
|
|||||||
freeProg = makeGarbageSchedule(p);
|
freeProg = makeGarbageSchedule(p);
|
||||||
for (unsigned int i = 0; i < freeProg.size(); ++i)
|
for (unsigned int i = 0; i < freeProg.size(); ++i)
|
||||||
{
|
{
|
||||||
LOG(Debug) << std::setw(4) << i + 1 << ": [";
|
std::string msg = "";
|
||||||
|
|
||||||
for (auto &a: freeProg[i])
|
for (auto &a: freeProg[i])
|
||||||
{
|
{
|
||||||
std::cout << env().getObjectName(a) << " ";
|
msg += env().getObjectName(a) + " ";
|
||||||
}
|
}
|
||||||
std::cout << "]" << std::endl;
|
msg += "]";
|
||||||
|
LOG(Debug) << std::setw(4) << i + 1 << ": [" << msg << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
// program execution
|
// program execution
|
||||||
|
@ -53,6 +53,8 @@ modules_hpp =\
|
|||||||
Modules/MScalarSUN/Utils.hpp \
|
Modules/MScalarSUN/Utils.hpp \
|
||||||
Modules/MScalarSUN/TransProj.hpp \
|
Modules/MScalarSUN/TransProj.hpp \
|
||||||
Modules/MScalarSUN/TrKinetic.hpp \
|
Modules/MScalarSUN/TrKinetic.hpp \
|
||||||
|
Modules/MIO/LoadEigenPack.hpp \
|
||||||
Modules/MIO/LoadNersc.hpp \
|
Modules/MIO/LoadNersc.hpp \
|
||||||
|
Modules/MIO/LoadCoarseEigenPack.hpp \
|
||||||
Modules/MIO/LoadBinary.hpp
|
Modules/MIO/LoadBinary.hpp
|
||||||
|
|
||||||
|
@ -30,22 +30,31 @@ Author: Peter Boyle <paboyle@ph.ed.ac.uk>
|
|||||||
|
|
||||||
namespace Grid {
|
namespace Grid {
|
||||||
|
|
||||||
struct ZeroGuesser {
|
template<class Field>
|
||||||
|
class Guesser {
|
||||||
public:
|
public:
|
||||||
template<class Field>
|
Guesser(void) = default;
|
||||||
void operator()(const Field &src,Field &guess) { guess = Zero(); };
|
virtual ~Guesser(void) = default;
|
||||||
|
virtual void operator()(const Field &src, Field &guess) = 0;
|
||||||
};
|
};
|
||||||
struct SourceGuesser {
|
|
||||||
|
template<class Field>
|
||||||
|
class ZeroGuesser: public Guesser<Field> {
|
||||||
public:
|
public:
|
||||||
template<class Field>
|
virtual void operator()(const Field &src, Field &guess) { guess = zero; };
|
||||||
void operator()(const Field &src,Field &guess) { guess = src; };
|
};
|
||||||
|
|
||||||
|
template<class Field>
|
||||||
|
class SourceGuesser: public Guesser<Field> {
|
||||||
|
public:
|
||||||
|
virtual void operator()(const Field &src, Field &guess) { guess = src; };
|
||||||
};
|
};
|
||||||
|
|
||||||
////////////////////////////////
|
////////////////////////////////
|
||||||
// Fine grid deflation
|
// Fine grid deflation
|
||||||
////////////////////////////////
|
////////////////////////////////
|
||||||
template<class Field>
|
template<class Field>
|
||||||
struct DeflatedGuesser {
|
class DeflatedGuesser: public Guesser<Field> {
|
||||||
private:
|
private:
|
||||||
const std::vector<Field> &evec;
|
const std::vector<Field> &evec;
|
||||||
const std::vector<RealD> &eval;
|
const std::vector<RealD> &eval;
|
||||||
@ -54,7 +63,7 @@ public:
|
|||||||
|
|
||||||
DeflatedGuesser(const std::vector<Field> & _evec,const std::vector<RealD> & _eval) : evec(_evec), eval(_eval) {};
|
DeflatedGuesser(const std::vector<Field> & _evec,const std::vector<RealD> & _eval) : evec(_evec), eval(_eval) {};
|
||||||
|
|
||||||
void operator()(const Field &src,Field &guess) {
|
virtual void operator()(const Field &src,Field &guess) {
|
||||||
guess = zero;
|
guess = zero;
|
||||||
assert(evec.size()==eval.size());
|
assert(evec.size()==eval.size());
|
||||||
auto N = evec.size();
|
auto N = evec.size();
|
||||||
@ -66,7 +75,7 @@ public:
|
|||||||
};
|
};
|
||||||
|
|
||||||
template<class FineField, class CoarseField>
|
template<class FineField, class CoarseField>
|
||||||
class LocalCoherenceDeflatedGuesser {
|
class LocalCoherenceDeflatedGuesser: public Guesser<FineField> {
|
||||||
private:
|
private:
|
||||||
const std::vector<FineField> &subspace;
|
const std::vector<FineField> &subspace;
|
||||||
const std::vector<CoarseField> &evec_coarse;
|
const std::vector<CoarseField> &evec_coarse;
|
||||||
|
@ -108,7 +108,7 @@ namespace Grid {
|
|||||||
|
|
||||||
template<class Matrix>
|
template<class Matrix>
|
||||||
void operator() (Matrix & _Matrix,const Field &in, Field &out){
|
void operator() (Matrix & _Matrix,const Field &in, Field &out){
|
||||||
ZeroGuesser guess;
|
ZeroGuesser<Field> guess;
|
||||||
(*this)(_Matrix,in,out,guess);
|
(*this)(_Matrix,in,out,guess);
|
||||||
}
|
}
|
||||||
template<class Matrix, class Guesser>
|
template<class Matrix, class Guesser>
|
||||||
@ -195,7 +195,7 @@ namespace Grid {
|
|||||||
};
|
};
|
||||||
template<class Matrix>
|
template<class Matrix>
|
||||||
void operator() (Matrix & _Matrix,const Field &in, Field &out){
|
void operator() (Matrix & _Matrix,const Field &in, Field &out){
|
||||||
ZeroGuesser guess;
|
ZeroGuesser<Field> guess;
|
||||||
(*this)(_Matrix,in,out,guess);
|
(*this)(_Matrix,in,out,guess);
|
||||||
}
|
}
|
||||||
template<class Matrix, class Guesser>
|
template<class Matrix, class Guesser>
|
||||||
@ -280,7 +280,7 @@ namespace Grid {
|
|||||||
|
|
||||||
template<class Matrix>
|
template<class Matrix>
|
||||||
void operator() (Matrix & _Matrix,const Field &in, Field &out){
|
void operator() (Matrix & _Matrix,const Field &in, Field &out){
|
||||||
ZeroGuesser guess;
|
ZeroGuesser<Field> guess;
|
||||||
(*this)(_Matrix,in,out,guess);
|
(*this)(_Matrix,in,out,guess);
|
||||||
}
|
}
|
||||||
template<class Matrix,class Guesser>
|
template<class Matrix,class Guesser>
|
||||||
@ -365,7 +365,7 @@ namespace Grid {
|
|||||||
|
|
||||||
template<class Matrix>
|
template<class Matrix>
|
||||||
void operator() (Matrix & _Matrix,const Field &in, Field &out){
|
void operator() (Matrix & _Matrix,const Field &in, Field &out){
|
||||||
ZeroGuesser guess;
|
ZeroGuesser<Field> guess;
|
||||||
(*this)(_Matrix,in,out,guess);
|
(*this)(_Matrix,in,out,guess);
|
||||||
}
|
}
|
||||||
template<class Matrix, class Guesser>
|
template<class Matrix, class Guesser>
|
||||||
|
@ -232,7 +232,7 @@ namespace Grid {
|
|||||||
{
|
{
|
||||||
is >> std::boolalpha >> output;
|
is >> std::boolalpha >> output;
|
||||||
}
|
}
|
||||||
catch(std::istringstream::failure &e)
|
catch(std::ios_base::failure &e)
|
||||||
{
|
{
|
||||||
std::cerr << "numerical conversion failure on '" << s << "' ";
|
std::cerr << "numerical conversion failure on '" << s << "' ";
|
||||||
std::cerr << "(typeid: " << typeid(U).name() << ")" << std::endl;
|
std::cerr << "(typeid: " << typeid(U).name() << ")" << std::endl;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user