1
0
mirror of https://github.com/paboyle/Grid.git synced 2024-11-10 07:55:35 +00:00

added everythong to compute sequential aslash fields

This commit is contained in:
Felix Erben 2019-03-07 17:36:53 +00:00
parent 1538bf8c34
commit dde118fed9
4 changed files with 375 additions and 0 deletions

View File

@ -0,0 +1,7 @@
#include <Hadrons/Modules/MDistil/DistilSink.hpp>
using namespace Grid;
using namespace Hadrons;
using namespace MDistil;
template class Grid::Hadrons::MDistil::TDistilSink<FIMPL>;

View File

@ -0,0 +1,183 @@
#ifndef Hadrons_MDistil_DistilSink_hpp_
#define Hadrons_MDistil_DistilSink_hpp_
#include <Hadrons/Global.hpp>
#include <Hadrons/Module.hpp>
#include <Hadrons/ModuleFactory.hpp>
#include <Hadrons/Solver.hpp>
#include <Hadrons/EigenPack.hpp>
#include <Hadrons/A2AVectors.hpp>
#include <Hadrons/DilutedNoise.hpp>
// These are members of Distillation
#include <Hadrons/Modules/MDistil/Distil.hpp>
BEGIN_HADRONS_NAMESPACE
/******************************************************************************
* DistilSink *
******************************************************************************/
BEGIN_MODULE_NAMESPACE(MDistil)
class DistilSinkPar: Serializable
{
public:
GRID_SERIALIZABLE_CLASS_MEMBERS(DistilSinkPar,
std::string, perambulator,
std::string, eigenPack,
bool, multiFile,
int, tsrc,
int, nnoise,
int, LI,
int, SI,
int, TI,
int, nvec,
int, Ns,
int, Nt,
int, Nt_inv);
};
template <typename FImpl>
class TDistilSink: public Module<DistilSinkPar>
{
public:
FERM_TYPE_ALIASES(FImpl,);
public:
// constructor
TDistilSink(const std::string name);
// destructor
virtual ~TDistilSink(void) {};
// dependency relation
virtual std::vector<std::string> getInput(void);
virtual std::vector<std::string> getOutput(void);
// setup
virtual void setup(void);
// execution
virtual void execute(void);
};
MODULE_REGISTER_TMP(DistilSink, TDistilSink<FIMPL>, MDistil);
/******************************************************************************
* TDistilSink implementation *
******************************************************************************/
// constructor /////////////////////////////////////////////////////////////////
template <typename FImpl>
TDistilSink<FImpl>::TDistilSink(const std::string name)
: Module<DistilSinkPar>(name)
{}
// dependencies/products ///////////////////////////////////////////////////////
template <typename FImpl>
std::vector<std::string> TDistilSink<FImpl>::getInput(void)
{
std::vector<std::string> in;
in.push_back(par().perambulator);
in.push_back(par().eigenPack);
return in;
}
template <typename FImpl>
std::vector<std::string> TDistilSink<FImpl>::getOutput(void)
{
std::vector<std::string> out = {getName()};
return out;
}
// setup ///////////////////////////////////////////////////////////////////////
template <typename FImpl>
void TDistilSink<FImpl>::setup(void)
{
int nnoise=par().nnoise;
int LI=par().LI;
int Ns=par().Ns;
int Nt_inv=par().Nt_inv;
envCreate(std::vector<FermionField>, getName(), 1,
nnoise*LI*Ns*Nt_inv, envGetGrid(FermionField));
GridCartesian * grid4d = env().getGrid();
std::vector<int> latt_size = GridDefaultLatt();
std::vector<int> simd_layout = GridDefaultSimd(Nd, vComplex::Nsimd());
std::vector<int> mpi_layout = GridDefaultMpi();
std::vector<int> simd_layout_3 = GridDefaultSimd(Nd-1, vComplex::Nsimd());
latt_size[Nd-1] = 1;
simd_layout_3.push_back( 1 );
mpi_layout[Nd-1] = 1;
GridCartesian * grid3d = new GridCartesian(latt_size,simd_layout_3,mpi_layout,*grid4d);
envTmp(LatticeSpinColourVector, "tmp2",1,LatticeSpinColourVector(grid4d));
envTmp(LatticeColourVector, "tmp_nospin",1,LatticeColourVector(grid4d));
envTmp(LatticeSpinColourVector, "tmp3d",1,LatticeSpinColourVector(grid3d));
envTmp(LatticeColourVector, "tmp3d_nospin",1,LatticeColourVector(grid3d));
envTmp(LatticeSpinColourVector, "sink_tslice",1,LatticeSpinColourVector(grid3d));
envTmp(LatticeColourVector, "evec3d",1,LatticeColourVector(grid3d));
}
// execution ///////////////////////////////////////////////////////////////////
template <typename FImpl>
void TDistilSink<FImpl>::execute(void)
{
auto &perambulator = envGet(Perambulator<SpinVector COMMA 6 COMMA sizeof(Real)>, par().perambulator);
auto &epack = envGet(Grid::Hadrons::EigenPack<LatticeColourVector>, par().eigenPack);
auto &phi = envGet(std::vector<FermionField>, getName());
envGetTmp(LatticeSpinColourVector, tmp2);
envGetTmp(LatticeColourVector, tmp_nospin);
envGetTmp(LatticeSpinColourVector, tmp3d);
envGetTmp(LatticeColourVector, tmp3d_nospin);
envGetTmp(LatticeSpinColourVector, sink_tslice);
envGetTmp(LatticeColourVector, evec3d);
GridCartesian * grid4d = env().getGrid();
int Ntlocal = grid4d->LocalDimensions()[3];
int Ntfirst = grid4d->LocalStarts()[3];
int tsrc=par().tsrc;
int nnoise=par().nnoise;
int LI=par().LI;
int Ns=par().Ns;
int Nt_inv=par().Nt_inv; // TODO: No input, but define through Nt, TI
int Nt=par().Nt;
int TI=par().TI;
int nvec=par().nvec;
bool full_tdil=(TI==Nt);
int vecindex;
int t_inv;
for (int inoise = 0; inoise < nnoise; inoise++) {
for (int dk = 0; dk < LI; dk++) {
for (int dt = 0; dt < Nt_inv; dt++) {
for (int ds = 0; ds < Ns; ds++) {
vecindex = inoise + nnoise * dk + nnoise * LI * ds + nnoise *LI * Ns*dt;
phi[vecindex] = zero;
for (int t = Ntfirst; t < Ntfirst + Ntlocal; t++) {
sink_tslice=zero;
for (int ivec = 0; ivec < nvec; ivec++) {
ExtractSliceLocal(evec3d,epack.evec[ivec],0,t,3);
sink_tslice += evec3d * perambulator(t, ivec, dk, inoise,dt,ds);
}
InsertSliceLocal(sink_tslice,phi[vecindex],0,t-Ntfirst,Grid::QCD::Tdir);
}
}
}
}
}
std::cout << "size phi" << phi.size() << std::endl;
}
END_MODULE_NAMESPACE
END_HADRONS_NAMESPACE
#endif // Hadrons_MDistil_DistilSink_hpp_

View File

@ -0,0 +1,7 @@
#include <Hadrons/Modules/MDistil/PerambFromSolve.hpp>
using namespace Grid;
using namespace Hadrons;
using namespace MDistil;
template class Grid::Hadrons::MDistil::TPerambFromSolve<FIMPL>;

View File

@ -0,0 +1,178 @@
#ifndef Hadrons_MDistil_PerambFromSolve_hpp_
#define Hadrons_MDistil_PerambFromSolve_hpp_
#include <Hadrons/Global.hpp>
#include <Hadrons/Module.hpp>
#include <Hadrons/ModuleFactory.hpp>
#include <Hadrons/Solver.hpp>
#include <Hadrons/EigenPack.hpp>
#include <Hadrons/A2AVectors.hpp>
#include <Hadrons/DilutedNoise.hpp>
// These are members of Distillation
#include <Hadrons/Modules/MDistil/Distil.hpp>
BEGIN_HADRONS_NAMESPACE
/******************************************************************************
* PerambFromSolve *
******************************************************************************/
BEGIN_MODULE_NAMESPACE(MDistil)
/*
struct DistilParameters: Serializable {
GRID_SERIALIZABLE_CLASS_MEMBERS(DistilParameters,
int, TI,
int, LI,
int, nnoise,
int, tsrc,
int, SI,
int, Ns,
int, Nt,
int, Nt_inv)
DistilParameters() = default;
template <class ReaderClass> DistilParameters(Reader<ReaderClass>& Reader){read(Reader,"Distil",*this);}
};
*/
class PerambFromSolvePar: Serializable
{
public:
GRID_SERIALIZABLE_CLASS_MEMBERS(PerambFromSolvePar,
std::string, eigenPack,
std::string, PerambFileName,
std::string, solve,
int, nvec,
DistilParameters, Distil);
};
template <typename FImpl>
class TPerambFromSolve: public Module<PerambFromSolvePar>
{
public:
FERM_TYPE_ALIASES(FImpl,);
public:
// constructor
TPerambFromSolve(const std::string name);
// destructor
virtual ~TPerambFromSolve(void) {};
// dependency relation
virtual std::vector<std::string> getInput(void);
virtual std::vector<std::string> getOutput(void);
// setup
virtual void setup(void);
// execution
virtual void execute(void);
};
MODULE_REGISTER_TMP(PerambFromSolve, TPerambFromSolve<FIMPL>, MDistil);
/******************************************************************************
* TPerambFromSolve implementation *
******************************************************************************/
// constructor /////////////////////////////////////////////////////////////////
template <typename FImpl>
TPerambFromSolve<FImpl>::TPerambFromSolve(const std::string name)
: Module<PerambFromSolvePar>(name)
{}
// dependencies/products ///////////////////////////////////////////////////////
template <typename FImpl>
std::vector<std::string> TPerambFromSolve<FImpl>::getInput(void)
{
std::vector<std::string> in;
in.push_back(par().solve);
in.push_back(par().eigenPack);
return in;
}
template <typename FImpl>
std::vector<std::string> TPerambFromSolve<FImpl>::getOutput(void)
{
std::vector<std::string> out = {getName()};
return out;
}
// setup ///////////////////////////////////////////////////////////////////////
template <typename FImpl>
void TPerambFromSolve<FImpl>::setup(void)
{
const int nvec{par().nvec};
const DistilParameters & Distil{par().Distil};
const int LI{Distil.LI};
const int nnoise{Distil.nnoise};
const int Nt_inv{Distil.Nt_inv};
const int Ns{Distil.Ns};
std::array<std::string,6> sIndexNames{"Nt", "nvec", "LI", "nnoise", "Nt_inv", "SI"};
envCreate(Perambulator<SpinVector COMMA 6 COMMA sizeof(Real)>, getName(), 1,
sIndexNames,Distil.Nt,nvec,Distil.LI,Distil.nnoise,Distil.Nt_inv,Distil.SI);
envCreate(std::vector<Complex>, getName() + "_noise", 1,
nvec*Distil.Ns*Distil.Nt*Distil.nnoise);
}
// execution ///////////////////////////////////////////////////////////////////
template <typename FImpl>
void TPerambFromSolve<FImpl>::execute(void)
{
const int nvec{par().nvec};
const DistilParameters & Distil{par().Distil};
const int LI{Distil.LI};
const int TI{Distil.TI};
const int nnoise{Distil.nnoise};
const int Nt{Distil.Nt};
const int Nt_inv{Distil.Nt_inv};
const int tsrc{Distil.tsrc};
const int Ns{Distil.Ns};
const bool full_tdil{TI==Nt};
const bool exact_distillation{full_tdil && LI==nvec};
auto &perambulator = envGet(Perambulator<SpinVector COMMA 6 COMMA sizeof(Real)>,
getName());
auto &solve = envGet(std::vector<FermionField>, par().solve);
auto &epack = envGet(Grid::Hadrons::EigenPack<LatticeColourVector>, par().eigenPack);
envGetTmp(LatticeColourVector, result_nospin);
envGetTmp(LatticeColourVector, result_3d);
envGetTmp(LatticeColourVector, evec3d);
GridCartesian * grid4d = env().getGrid();
int Ntlocal = grid4d->LocalDimensions()[3];
int Ntfirst = grid4d->LocalStarts()[3];
const std::string &PerambFileName{par().PerambFileName};
for (int inoise = 0; inoise < nnoise; inoise++) {
for (int dk = 0; dk < LI; dk++) {
for (int dt = 0; dt < Nt_inv; dt++) {
for (int ds = 0; ds < Ns; ds++) {
for (int is = 0; is < Ns; is++) {
result_nospin = peekSpin(solve[inoise+nnoise*(dk+LI*(dt+Nt_inv*ds))],is);
for (int t = Ntfirst; t < Ntfirst + Ntlocal; t++) {
ExtractSliceLocal(result_3d,result_nospin,0,t-Ntfirst,Grid::QCD::Tdir);
for (int ivec = 0; ivec < nvec; ivec++) {
ExtractSliceLocal(evec3d,epack.evec[ivec],0,t,3);
pokeSpin(perambulator(t, ivec, dk, inoise,dt,ds),innerProduct(evec3d, result_3d),is);
std::cout << "perambulator(t, ivec, dk, inoise,dt,ds)(is) = (" << t << "," << ivec << "," << dk << "," << inoise << "," << dt << "," << ds << ")(" << is << ") = " << perambulator(t, ivec, dk, inoise,dt,ds)()(is)() << std::endl;
}
}
}
}
}
}
}
if(PerambFileName.length())
perambulator.WriteBinary(PerambFileName);
}
END_MODULE_NAMESPACE
END_HADRONS_NAMESPACE
#endif // Hadrons_MDistil_PerambFromSolve_hpp_