1
0
mirror of https://github.com/paboyle/Grid.git synced 2025-04-09 21:50:45 +01:00

PerambLight fixes

This commit is contained in:
Michael Marshall 2019-01-31 12:24:32 +00:00
parent dae7b30b92
commit d7b9ed199d
3 changed files with 115 additions and 142 deletions

View File

@ -79,27 +79,6 @@ struct LanczosParameters: Serializable {
template <class ReaderClass> LanczosParameters(Reader<ReaderClass>& Reader){read(Reader,"Lanczos",*this);} template <class ReaderClass> LanczosParameters(Reader<ReaderClass>& Reader){read(Reader,"Lanczos",*this);}
}; };
/*struct DistilParameters: Serializable {
GRID_SERIALIZABLE_CLASS_MEMBERS(DistilParameters
,int, TI
,int, LI
,int, Nnoise
,int, tSrc
)//,int, Ls) // For makeFiveDimGrid
DistilParameters() = default;
template <class ReaderClass> DistilParameters(Reader<ReaderClass>& Reader){read(Reader,"Distil",*this);}
};
struct SolverParameters: Serializable {
GRID_SERIALIZABLE_CLASS_MEMBERS(SolverParameters,
double, CGPrecision,
int, MaxIterations,
double, mass,
double, M5)
SolverParameters() = default;
template <class ReaderClass> SolverParameters(Reader<ReaderClass>& Reader){read(Reader,"Solver",*this);}
};*/
// These are the actual parameters passed to the module during construction // These are the actual parameters passed to the module during construction
class LapEvecPar: Serializable class LapEvecPar: Serializable
@ -126,8 +105,6 @@ class TLapEvec: public Module<LapEvecPar>
{ {
public: public:
GAUGE_TYPE_ALIASES(GImpl,); GAUGE_TYPE_ALIASES(GImpl,);
public:
// constructor // constructor
TLapEvec(const std::string name); TLapEvec(const std::string name);
// destructor // destructor

View File

@ -20,36 +20,51 @@ BEGIN_HADRONS_NAMESPACE
******************************************************************************/ ******************************************************************************/
BEGIN_MODULE_NAMESPACE(MDistil) 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);}
};
struct SolverParameters: Serializable {
GRID_SERIALIZABLE_CLASS_MEMBERS(SolverParameters,
double, CGPrecision,
int, MaxIterations,
double, mass,
double, M5)
SolverParameters() = default;
template <class ReaderClass> SolverParameters(Reader<ReaderClass>& Reader){read(Reader,"Solver",*this);}
};
class PerambLightPar: Serializable class PerambLightPar: Serializable
{ {
public: public:
GRID_SERIALIZABLE_CLASS_MEMBERS(PerambLightPar, GRID_SERIALIZABLE_CLASS_MEMBERS(PerambLightPar,
std::string, eigenPack, std::string, eigenPack,
bool, multiFile, bool, multiFile,
int, tsrc, int, nvec,
int, nnoise, int, Ls, // For makeFiveDimGrid
int, LI, DistilParameters, Distil,
int, SI, SolverParameters, Solver);
int, TI,
int, nvec,
int, Ns,
int, Nt,
int, Nt_inv,
Real, mass,
Real, M5,
int, Ls,
double, CGPrecision,
int, MaxIterations);
}; };
template <typename FImpl> template <typename GImpl>
class TPerambLight: public Module<PerambLightPar> class TPerambLight: public Module<PerambLightPar>
{ {
public: public:
GAUGE_TYPE_ALIASES(GImpl,);
// constructor // constructor
TPerambLight(const std::string name); TPerambLight(const std::string name);
// destructor // destructor
virtual ~TPerambLight(void); virtual ~TPerambLight(void);
// dependency relation // dependency relation
virtual std::vector<std::string> getInput(void); virtual std::vector<std::string> getInput(void);
virtual std::vector<std::string> getOutput(void); virtual std::vector<std::string> getOutput(void);
@ -58,12 +73,12 @@ public:
// execution // execution
virtual void execute(void); virtual void execute(void);
protected: protected:
// These variables are created in setup() and freed in Cleanup() // These variables are created in setup() and freed in Cleanup()
GridCartesian * grid3d; // Owned by me, so I must delete it GridCartesian * grid3d; // Owned by me, so I must delete it
GridCartesian * grid4d; // Owned by environment (so I won't delete it) GridCartesian * grid4d; // Owned by environment (so I won't delete it)
protected: protected:
virtual void Cleanup(void); virtual void Cleanup(void);
}; };
MODULE_REGISTER_TMP(PerambLight, TPerambLight<FIMPL>, MDistil); MODULE_REGISTER_TMP(PerambLight, TPerambLight<FIMPL>, MDistil);
@ -72,21 +87,21 @@ MODULE_REGISTER_TMP(PerambLight, TPerambLight<FIMPL>, MDistil);
* TPerambLight implementation * * TPerambLight implementation *
******************************************************************************/ ******************************************************************************/
// constructor ///////////////////////////////////////////////////////////////// // constructor /////////////////////////////////////////////////////////////////
template <typename FImpl> template <typename GImpl>
TPerambLight<FImpl>::TPerambLight(const std::string name) TPerambLight<GImpl>::TPerambLight(const std::string name)
: grid3d{nullptr}, grid4d{nullptr}, Module<PerambLightPar>(name) : grid3d{nullptr}, grid4d{nullptr}, Module<PerambLightPar>(name)
{} {}
// destructor // destructor
template <typename FImpl> template <typename GImpl>
TPerambLight<FImpl>::~TPerambLight(void) TPerambLight<GImpl>::~TPerambLight(void)
{ {
Cleanup(); Cleanup();
}; };
// dependencies/products /////////////////////////////////////////////////////// // dependencies/products ///////////////////////////////////////////////////////
template <typename FImpl> template <typename GImpl>
std::vector<std::string> TPerambLight<FImpl>::getInput(void) std::vector<std::string> TPerambLight<GImpl>::getInput(void)
{ {
std::vector<std::string> in; std::vector<std::string> in;
@ -96,8 +111,8 @@ std::vector<std::string> TPerambLight<FImpl>::getInput(void)
return in; return in;
} }
template <typename FImpl> template <typename GImpl>
std::vector<std::string> TPerambLight<FImpl>::getOutput(void) std::vector<std::string> TPerambLight<GImpl>::getOutput(void)
{ {
std::vector<std::string> out = {getName() + "_perambulator_light",getName() + "_noise"}; std::vector<std::string> out = {getName() + "_perambulator_light",getName() + "_noise"};
@ -105,53 +120,40 @@ std::vector<std::string> TPerambLight<FImpl>::getOutput(void)
} }
// setup /////////////////////////////////////////////////////////////////////// // setup ///////////////////////////////////////////////////////////////////////
template <typename FImpl> template <typename GImpl>
void TPerambLight<FImpl>::setup(void) void TPerambLight<GImpl>::setup(void)
{ {
Cleanup(); Cleanup();
// auto &noise = envGet(std::vector<std::vector<std::vector<SpinVector>>>, par().noise); // auto &noise = envGet(std::vector<std::vector<std::vector<SpinVector>>>, par().noise);
const int nvec{par().nvec};
const int LI{par().LI}; const DistilParameters & Distil{par().Distil};
const int SI{par().SI};
//const int TI{par().TI};
const int nnoise{par().nnoise};
const int Nt{par().Nt};
const int Nt_inv{par().Nt_inv};
const int nvec{par().nvec};
envCreate(Perambulator<SpinVector>, getName() + "_perambulator_light", 1,
Nt,nvec,LI,nnoise,Nt_inv,SI);
envCreate(std::vector<Complex>, getName() + "_noise", 1,
nvec*Ns*Nt*nnoise);
grid4d = env().getGrid(); envCreate(Perambulator<SpinVector>, getName() + "_perambulator_light", 1,
/*std::vector<int> latt_size = GridDefaultLatt(); Distil.Nt,nvec,Distil.LI,Distil.nnoise,Distil.Nt_inv,Distil.SI);
std::vector<int> simd_layout = GridDefaultSimd(Nd, vComplex::Nsimd()); envCreate(std::vector<Complex>, getName() + "_noise", 1,
std::vector<int> mpi_layout = GridDefaultMpi(); nvec*Distil.Ns*Distil.Nt*Distil.nnoise);
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);//new GridCartesian(latt_size,simd_layout_3,mpi_layout,*grid4d);
envTmp(LatticeSpinColourVector, "dist_source",1,LatticeSpinColourVector(grid4d)); grid4d = env().getGrid();
envTmp(LatticeSpinColourVector, "tmp2",1,LatticeSpinColourVector(grid4d)); grid3d = MakeLowerDimGrid(grid4d);//new GridCartesian(latt_size,simd_layout_3,mpi_layout,*grid4d);
envTmp(LatticeSpinColourVector, "result",1,LatticeSpinColourVector(grid4d));
envTmp(LatticeSpinColourVector, "result_single_component",1,LatticeSpinColourVector(grid4d));
envTmp(LatticeColourVector, "result_nospin",1,LatticeColourVector(grid4d));
envTmp(LatticeColourVector, "tmp_nospin",1,LatticeColourVector(grid4d));
envTmp(LatticeSpinColourVector, "tmp3d",1,LatticeSpinColourVector(grid3d));
envTmp(LatticeColourVector, "tmp3d_nospin",1,LatticeColourVector(grid3d));
envTmp(LatticeColourVector, "result_3d",1,LatticeColourVector(grid3d));
envTmp(LatticeColourVector, "evec3d",1,LatticeColourVector(grid3d));
envTmp(LatticeSpinVector, "peramb_tmp",1,LatticeSpinVector(grid4d));
envTmpLat(GaugeField, "Umu");
envTmpLat(LatticeSpinColourVector, "dist_source");
envTmpLat(LatticeSpinColourVector, "tmp2");
envTmpLat(LatticeSpinColourVector, "result");
//envTmpLat(LatticeSpinColourVector, "result_single_component");
envTmpLat(LatticeColourVector, "result_nospin");
//envTmpLat(LatticeColourVector, "tmp_nospin");
//envTmpLat(LatticeSpinVector, "peramb_tmp");
envTmp(LatticeSpinColourVector, "tmp3d",1,LatticeSpinColourVector(grid3d));
envTmp(LatticeColourVector, "tmp3d_nospin",1,LatticeColourVector(grid3d));
envTmp(LatticeColourVector, "result_3d",1,LatticeColourVector(grid3d));
envTmp(LatticeColourVector, "evec3d",1,LatticeColourVector(grid3d));
} }
// clean up any temporaries created by setup (that aren't stored in the environment) // clean up any temporaries created by setup (that aren't stored in the environment)
template <typename FImpl> template <typename GImpl>
void TPerambLight<FImpl>::Cleanup(void) void TPerambLight<GImpl>::Cleanup(void)
{ {
if( grid3d != nullptr ) { if( grid3d != nullptr ) {
delete grid3d; delete grid3d;
@ -161,26 +163,30 @@ void TPerambLight<FImpl>::Cleanup(void)
} }
// execution /////////////////////////////////////////////////////////////////// // execution ///////////////////////////////////////////////////////////////////
template <typename FImpl> template <typename GImpl>
void TPerambLight<FImpl>::execute(void) void TPerambLight<GImpl>::execute(void)
{ {
const int nvec{par().nvec};
const DistilParameters & Distil{par().Distil};
const SolverParameters & Solver{par().Solver};
const int LI{Distil.LI};
//const int SI{Distil.SI};
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 &noise = envGet(std::vector<std::vector<std::vector<SpinVector>>>, par().noise); //auto &noise = envGet(std::vector<std::vector<std::vector<SpinVector>>>, par().noise);
auto &noise = envGet(std::vector<Complex>, getName() + "_noise"); auto &noise = envGet(std::vector<Complex>, getName() + "_noise");
auto &perambulator = envGet(Perambulator<SpinVector>, getName() + "_perambulator_light"); auto &perambulator = envGet(Perambulator<SpinVector>, getName() + "_perambulator_light");
auto &epack = envGet(Grid::Hadrons::EigenPack<LatticeColourVector>, par().eigenPack); auto &epack = envGet(Grid::Hadrons::EigenPack<LatticeColourVector>, par().eigenPack);
/*GridCartesian * grid4d = env().getGrid(); envGetTmp(GaugeField, Umu);
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);*/
LatticeGaugeField Umu(grid4d);
FieldMetaData header; FieldMetaData header;
if((1)){ if((1)){
const std::vector<int> seeds({1, 2, 3, 4, 5}); const std::vector<int> seeds({1, 2, 3, 4, 5});
@ -197,7 +203,7 @@ void TPerambLight<FImpl>::execute(void)
auto Usft = Umu; auto Usft = Umu;
Lattice<iScalar<vInteger> > coor(grid4d); Lattice<iScalar<vInteger> > coor(grid4d);
LatticeCoordinate(coor,Tdir); LatticeCoordinate(coor,Tdir);
for(int t=1;t<par().Nt;t++){ for(int t=1;t<Nt;t++){
// t=1 // t=1
// Umu Usft // Umu Usft
// 0,1,2,3,4,5,6,7 -> 7,0,1,2,3,4,5,6 t=1 // 0,1,2,3,4,5,6,7 -> 7,0,1,2,3,4,5,6 t=1
@ -218,30 +224,17 @@ void TPerambLight<FImpl>::execute(void)
envGetTmp(LatticeSpinColourVector, dist_source); envGetTmp(LatticeSpinColourVector, dist_source);
envGetTmp(LatticeSpinColourVector, tmp2); envGetTmp(LatticeSpinColourVector, tmp2);
envGetTmp(LatticeSpinColourVector, result); envGetTmp(LatticeSpinColourVector, result);
envGetTmp(LatticeSpinColourVector, result_single_component); //envGetTmp(LatticeSpinColourVector, result_single_component);
envGetTmp(LatticeColourVector, result_nospin); envGetTmp(LatticeColourVector, result_nospin);
envGetTmp(LatticeColourVector, tmp_nospin); //envGetTmp(LatticeColourVector, tmp_nospin);
//envGetTmp(LatticeSpinVector, peramb_tmp);
envGetTmp(LatticeSpinColourVector, tmp3d); envGetTmp(LatticeSpinColourVector, tmp3d);
envGetTmp(LatticeColourVector, tmp3d_nospin); envGetTmp(LatticeColourVector, tmp3d_nospin);
envGetTmp(LatticeColourVector, result_3d); envGetTmp(LatticeColourVector, result_3d);
envGetTmp(LatticeColourVector, evec3d); envGetTmp(LatticeColourVector, evec3d);
envGetTmp(LatticeSpinVector, peramb_tmp);
int Ntlocal = grid4d->LocalDimensions()[3]; const int Ntlocal{grid4d->LocalDimensions()[3]};
int Ntfirst = grid4d->LocalStarts()[3]; const 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;
int Nt=par().Nt;
int TI=par().TI;
int nvec=par().nvec;
bool full_tdil=(TI==Nt);
bool exact_distillation = (full_tdil && LI==nvec);
//Create Noises //Create Noises
//std::cout << pszGaugeConfigFile << std::endl; //std::cout << pszGaugeConfigFile << std::endl;
@ -266,17 +259,16 @@ void TPerambLight<FImpl>::execute(void)
} }
} }
Real mass=par().mass; // TODO Infile const Real mass{Solver.mass};
Real M5 =par().M5; // TODO Infile const Real M5 {Solver.M5};
std::cout << "init RBG " << std::endl; std::cout << "init RBG " << std::endl;
GridRedBlackCartesian RBGrid(grid4d); GridRedBlackCartesian RBGrid(grid4d);
std::cout << "init RBG done" << std::endl; std::cout << "init RBG done" << std::endl;
int Ls=par().Ls; const int Ls{par().Ls};
const double CGPrecision{Solver.CGPrecision};
double CGPrecision = par().CGPrecision; const int MaxIterations {Solver.MaxIterations};
int MaxIterations = par().MaxIterations; {
GridCartesian * FGrid = SpaceTimeGrid::makeFiveDimGrid(Ls,grid4d); GridCartesian * FGrid = SpaceTimeGrid::makeFiveDimGrid(Ls,grid4d);
GridRedBlackCartesian * FrbGrid = SpaceTimeGrid::makeFiveDimRedBlackGrid(Ls,grid4d); GridRedBlackCartesian * FrbGrid = SpaceTimeGrid::makeFiveDimRedBlackGrid(Ls,grid4d);
@ -338,6 +330,10 @@ void TPerambLight<FImpl>::execute(void)
} }
} }
} }
// Kill our 5 dimensional grid (avoid leaks). Should really declare these objects temporary
delete FrbGrid;
delete FGrid;
}
std::cout << "perambulator done" << std::endl; std::cout << "perambulator done" << std::endl;
perambulator.SliceShare( grid3d, grid4d ); perambulator.SliceShare( grid3d, grid4d );

View File

@ -87,20 +87,20 @@ void test_Perambulators(Application &application)
// PerambLight parameters // PerambLight parameters
MDistil::PerambLight::Par PerambPar; MDistil::PerambLight::Par PerambPar;
PerambPar.eigenPack="LapEvec"; PerambPar.eigenPack="LapEvec";
PerambPar.tsrc = 0; PerambPar.Distil.tsrc = 0;
PerambPar.nnoise = 1; PerambPar.Distil.nnoise = 1;
PerambPar.LI=5; PerambPar.Distil.LI=5;
PerambPar.SI=4; PerambPar.Distil.SI=4;
PerambPar.TI=8; PerambPar.Distil.TI=8;
PerambPar.nvec=5; PerambPar.nvec=5;
PerambPar.Ns=4; PerambPar.Distil.Ns=4;
PerambPar.Nt=8; PerambPar.Distil.Nt=8;
PerambPar.Nt_inv=1; PerambPar.Distil.Nt_inv=1;
PerambPar.mass=0.005; PerambPar.Solver.mass=0.005;
PerambPar.M5=1.8; PerambPar.Solver.M5=1.8;
PerambPar.Ls=16; PerambPar.Ls=16;
PerambPar.CGPrecision=1e-8; PerambPar.Solver.CGPrecision=1e-8;
PerambPar.MaxIterations=10000; PerambPar.Solver.MaxIterations=10000;
application.createModule<MDistil::PerambLight>("Peramb",PerambPar); application.createModule<MDistil::PerambLight>("Peramb",PerambPar);
} }
///////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////