mirror of
https://github.com/paboyle/Grid.git
synced 2025-04-10 06:00:45 +01:00
added distil source module
This commit is contained in:
parent
d111c70c38
commit
2b598294c9
@ -44,6 +44,7 @@
|
||||
#include <Hadrons/Modules/MDistil/PerambFromSolve.hpp>
|
||||
#include <Hadrons/Modules/MDistil/Baryon2pt.hpp>
|
||||
#include <Hadrons/Modules/MDistil/LapEvec.hpp>
|
||||
#include <Hadrons/Modules/MDistil/DistilSource.hpp>
|
||||
#include <Hadrons/Modules/MDistil/BContraction.hpp>
|
||||
#include <Hadrons/Modules/MDistil/DistilVectors.hpp>
|
||||
#include <Hadrons/Modules/MDistil/DistilSink.hpp>
|
||||
|
7
Hadrons/Modules/MDistil/DistilSource.cc
Normal file
7
Hadrons/Modules/MDistil/DistilSource.cc
Normal file
@ -0,0 +1,7 @@
|
||||
#include <Hadrons/Modules/MDistil/DistilSource.hpp>
|
||||
|
||||
using namespace Grid;
|
||||
using namespace Hadrons;
|
||||
using namespace MDistil;
|
||||
|
||||
template class Grid::Hadrons::MDistil::TDistilSource<FIMPL>;
|
221
Hadrons/Modules/MDistil/DistilSource.hpp
Normal file
221
Hadrons/Modules/MDistil/DistilSource.hpp
Normal file
@ -0,0 +1,221 @@
|
||||
#ifndef Hadrons_MDistil_DistilSource_hpp_
|
||||
#define Hadrons_MDistil_DistilSource_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
|
||||
|
||||
|
||||
/******************************************************************************
|
||||
* DistilSource *
|
||||
******************************************************************************/
|
||||
BEGIN_MODULE_NAMESPACE(MDistil)
|
||||
|
||||
class DistilSourcePar: Serializable
|
||||
{
|
||||
public:
|
||||
GRID_SERIALIZABLE_CLASS_MEMBERS(DistilSourcePar,
|
||||
std::string, noise,
|
||||
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 TDistilSource: public Module<DistilSourcePar>
|
||||
{
|
||||
public:
|
||||
FERM_TYPE_ALIASES(FImpl,);
|
||||
public:
|
||||
// constructor
|
||||
TDistilSource(const std::string name);
|
||||
// destructor
|
||||
virtual ~TDistilSource(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);
|
||||
protected:
|
||||
// These variables are created in setup() and freed in Cleanup()
|
||||
GridCartesian * grid3d; // Owned by me, so I must delete it
|
||||
GridCartesian * grid4d; // Owned by environment (so I won't delete it)
|
||||
protected:
|
||||
virtual void Cleanup(void);
|
||||
};
|
||||
|
||||
MODULE_REGISTER_TMP(DistilSource, TDistilSource<FIMPL>, MDistil);
|
||||
|
||||
/******************************************************************************
|
||||
* TDistilSource implementation *
|
||||
******************************************************************************/
|
||||
// constructor /////////////////////////////////////////////////////////////////
|
||||
template <typename FImpl>
|
||||
TDistilSource<FImpl>::TDistilSource(const std::string name)
|
||||
: grid3d{nullptr}, grid4d{nullptr}, Module<DistilSourcePar>(name)
|
||||
{}
|
||||
// destructor
|
||||
template <typename FImpl>
|
||||
TDistilSource<FImpl>::~TDistilSource(void)
|
||||
{
|
||||
Cleanup();
|
||||
};
|
||||
|
||||
// dependencies/products ///////////////////////////////////////////////////////
|
||||
template <typename FImpl>
|
||||
std::vector<std::string> TDistilSource<FImpl>::getInput(void)
|
||||
{
|
||||
std::vector<std::string> in;
|
||||
|
||||
in.push_back(par().noise);
|
||||
in.push_back(par().eigenPack);
|
||||
|
||||
return in;
|
||||
}
|
||||
|
||||
template <typename FImpl>
|
||||
std::vector<std::string> TDistilSource<FImpl>::getOutput(void)
|
||||
{
|
||||
std::vector<std::string> out = {getName()};
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
// setup ///////////////////////////////////////////////////////////////////////
|
||||
template <typename FImpl>
|
||||
void TDistilSource<FImpl>::setup(void)
|
||||
{
|
||||
Cleanup();
|
||||
auto &noise = envGet(std::vector<Complex>, par().noise);
|
||||
|
||||
int nnoise=par().nnoise;
|
||||
int LI=par().LI;
|
||||
int Ns=par().Ns;
|
||||
int SI=par().SI;
|
||||
int Nt_inv=par().Nt_inv;
|
||||
|
||||
envCreate(std::vector<FermionField>, getName(), 1,
|
||||
nnoise*LI*SI*Nt_inv, envGetGrid(FermionField));
|
||||
|
||||
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;
|
||||
grid3d = MakeLowerDimGrid(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));
|
||||
}
|
||||
|
||||
// clean up any temporaries created by setup (that aren't stored in the environment)
|
||||
template <typename FImpl>
|
||||
void TDistilSource<FImpl>::Cleanup(void)
|
||||
{
|
||||
if( grid3d != nullptr ) {
|
||||
delete grid3d;
|
||||
grid3d = nullptr;
|
||||
}
|
||||
grid4d = nullptr;
|
||||
}
|
||||
|
||||
// execution ///////////////////////////////////////////////////////////////////
|
||||
template <typename FImpl>
|
||||
void TDistilSource<FImpl>::execute(void)
|
||||
{
|
||||
|
||||
auto &noise = envGet(std::vector<Complex>, par().noise);
|
||||
auto &epack = envGet(Grid::Hadrons::EigenPack<LatticeColourVector>, par().eigenPack);
|
||||
auto &rho = 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);
|
||||
|
||||
|
||||
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;
|
||||
int SI=par().SI;
|
||||
|
||||
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 < SI; ds++) {
|
||||
vecindex = inoise + nnoise * dk + nnoise * LI * ds + nnoise *LI * SI*dt;
|
||||
rho[vecindex] = zero;
|
||||
tmp3d_nospin = zero;
|
||||
for (int it = dt; it < Nt; it += TI){
|
||||
if (full_tdil) t_inv = tsrc; else t_inv = it;
|
||||
if( t_inv >= Ntfirst && t_inv < Ntfirst + Ntlocal ) {
|
||||
for (int ik = dk; ik < nvec; ik += LI){
|
||||
for (int is = ds; is < Ns; is += SI){
|
||||
ExtractSliceLocal(evec3d,epack.evec[ik],0,t_inv,3);
|
||||
tmp3d_nospin = evec3d * noise[inoise + nnoise*(t_inv + Nt*(ik+nvec*is))];
|
||||
tmp3d=zero;
|
||||
pokeSpin(tmp3d,tmp3d_nospin,is);
|
||||
tmp2=zero;
|
||||
InsertSliceLocal(tmp3d,tmp2,0,t_inv-Ntfirst,Grid::QCD::Tdir);
|
||||
rho[vecindex] += tmp2;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// TEST TO SEE WHETHER THIS MIGHT BE THE MEMORY LEAK
|
||||
Cleanup();
|
||||
|
||||
}
|
||||
|
||||
END_MODULE_NAMESPACE
|
||||
|
||||
END_HADRONS_NAMESPACE
|
||||
|
||||
#endif // Hadrons_MDistil_DistilSource_hpp_
|
@ -25,6 +25,7 @@ class PerambLightPar: Serializable
|
||||
public:
|
||||
GRID_SERIALIZABLE_CLASS_MEMBERS(PerambLightPar,
|
||||
std::string, eigenPack,
|
||||
std::string, noise,
|
||||
std::string, PerambFileName, //stem!!!
|
||||
std::string, UniqueIdentifier,
|
||||
bool, multiFile,
|
||||
@ -86,6 +87,7 @@ std::vector<std::string> TPerambLight<FImpl>::getInput(void)
|
||||
|
||||
in.push_back(par().eigenPack);
|
||||
in.push_back(par().solver);
|
||||
in.push_back(par().noise);
|
||||
|
||||
return in;
|
||||
}
|
||||
@ -93,7 +95,7 @@ std::vector<std::string> TPerambLight<FImpl>::getInput(void)
|
||||
template <typename FImpl>
|
||||
std::vector<std::string> TPerambLight<FImpl>::getOutput(void)
|
||||
{
|
||||
std::vector<std::string> out = {getName() + "_perambulator_light",getName() + "_noise",getName() + "_unsmeared_sink"};
|
||||
std::vector<std::string> out = {getName(),getName() + "_unsmeared_sink"};
|
||||
|
||||
return out;
|
||||
}
|
||||
@ -112,10 +114,8 @@ void TPerambLight<FImpl>::setup(void)
|
||||
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() + "_perambulator_light", 1,
|
||||
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);
|
||||
envCreate(std::vector<FermionField>, getName() + "_unsmeared_sink", 1,
|
||||
nnoise*LI*Ns*Nt_inv, envGetGrid(FermionField));
|
||||
|
||||
@ -176,50 +176,17 @@ void TPerambLight<FImpl>::execute(void)
|
||||
|
||||
const std::string &UniqueIdentifier{par().UniqueIdentifier};
|
||||
|
||||
auto &noise = envGet(std::vector<Complex>, getName() + "_noise");
|
||||
auto &noise = envGet(std::vector<Complex>, par().noise);
|
||||
auto &perambulator = envGet(Perambulator<SpinVector COMMA 6 COMMA sizeof(Real)>,
|
||||
getName() + "_perambulator_light");
|
||||
auto &epack = envGet(Grid::Hadrons::EigenPack<LatticeColourVector>, par().eigenPack);
|
||||
auto &unsmeared_sink = envGet(std::vector<FermionField>, getName() + "_unsmeared_sink");
|
||||
|
||||
//Create Noises
|
||||
GridSerialRNG sRNG;
|
||||
sRNG.SeedUniqueString(UniqueIdentifier + std::to_string(vm().getTrajectory())); //maybe add more??
|
||||
Real rn;
|
||||
|
||||
for (int inoise=0;inoise<nnoise;inoise++) {
|
||||
for (int t=0;t<Nt;t++) {
|
||||
for (int ivec=0;ivec<nvec;ivec++) {
|
||||
for (int is=0;is<Ns;is++) {
|
||||
if (exact_distillation)
|
||||
noise[inoise + nnoise*(t + Nt*(ivec+nvec*is))] = 1.;
|
||||
else{
|
||||
random(sRNG,rn);
|
||||
// We could use a greater number of complex roots of unity
|
||||
// ... but this seems to work well
|
||||
noise[inoise + nnoise*(t + Nt*(ivec+nvec*is))] = (rn > 0.5) ? -1 : 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Load perambulator if it exists on disk instead of creating it
|
||||
// Not sure this is how we want it - rather specify an input flag 'read'
|
||||
// and assert that the file is there.
|
||||
const std::string &PerambFileName{par().PerambFileName};
|
||||
/* if( PerambFileName.length() ){
|
||||
bool bExists = false;
|
||||
{
|
||||
std::ifstream f(PerambFileName, std::ios::binary);
|
||||
if( f.is_open() )
|
||||
bExists = true;
|
||||
}
|
||||
if( bExists ) {
|
||||
perambulator.ReadBinary(PerambFileName);
|
||||
return;
|
||||
}
|
||||
}*/
|
||||
|
||||
envGetTmp(LatticeSpinColourVector, dist_source);
|
||||
envGetTmp(LatticeSpinColourVector, tmp2);
|
||||
|
@ -39,6 +39,7 @@ modules_cc =\
|
||||
Modules/MDistil/g5_multiply.cc \
|
||||
Modules/MDistil/LapEvec.cc \
|
||||
Modules/MDistil/Noises.cc \
|
||||
Modules/MDistil/DistilSource.cc \
|
||||
Modules/MDistil/DistilVectors.cc \
|
||||
Modules/MDistil/BContraction.cc \
|
||||
Modules/MDistil/Baryon2pt.cc \
|
||||
@ -122,6 +123,7 @@ modules_hpp =\
|
||||
Modules/MDistil/PerambFromSolve.hpp \
|
||||
Modules/MDistil/Baryon2pt.hpp \
|
||||
Modules/MDistil/LapEvec.hpp \
|
||||
Modules/MDistil/DistilSource.hpp \
|
||||
Modules/MDistil/BContraction.hpp \
|
||||
Modules/MDistil/DistilVectors.hpp \
|
||||
Modules/MDistil/DistilSink.hpp \
|
||||
|
Loading…
x
Reference in New Issue
Block a user