mirror of
https://github.com/paboyle/Grid.git
synced 2025-06-12 20:27:06 +01:00
added module to load perambulators from disk
This commit is contained in:
7
Hadrons/Modules/MIO/LoadPerambulator.cc
Normal file
7
Hadrons/Modules/MIO/LoadPerambulator.cc
Normal file
@ -0,0 +1,7 @@
|
||||
#include <Hadrons/Modules/MIO/LoadPerambulator.hpp>
|
||||
|
||||
using namespace Grid;
|
||||
using namespace Hadrons;
|
||||
using namespace MIO;
|
||||
|
||||
template class Grid::Hadrons::MIO::TLoadPerambulator<FIMPL>;
|
116
Hadrons/Modules/MIO/LoadPerambulator.hpp
Normal file
116
Hadrons/Modules/MIO/LoadPerambulator.hpp
Normal file
@ -0,0 +1,116 @@
|
||||
#ifndef Hadrons_MIO_LoadPerambulator_hpp_
|
||||
#define Hadrons_MIO_LoadPerambulator_hpp_
|
||||
|
||||
#include <Hadrons/Global.hpp>
|
||||
#include <Hadrons/Module.hpp>
|
||||
#include <Hadrons/ModuleFactory.hpp>
|
||||
#include <Hadrons/EigenPack.hpp>
|
||||
#include <Hadrons/Modules/MDistil/Distil.hpp>
|
||||
|
||||
BEGIN_HADRONS_NAMESPACE
|
||||
|
||||
/******************************************************************************
|
||||
* LoadPerambulator *
|
||||
******************************************************************************/
|
||||
BEGIN_MODULE_NAMESPACE(MIO)
|
||||
|
||||
class LoadPerambulatorPar: Serializable
|
||||
{
|
||||
public:
|
||||
GRID_SERIALIZABLE_CLASS_MEMBERS(LoadPerambulatorPar,
|
||||
std::string, PerambFileName, //stem!!!
|
||||
std::string, UniqueIdentifier,
|
||||
int, nvec,
|
||||
MDistil::DistilParameters, Distil);
|
||||
};
|
||||
|
||||
template <typename FImpl>
|
||||
class TLoadPerambulator: public Module<LoadPerambulatorPar>
|
||||
{
|
||||
public:
|
||||
// constructor
|
||||
TLoadPerambulator(const std::string name);
|
||||
// destructor
|
||||
virtual ~TLoadPerambulator(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(LoadPerambulator, TLoadPerambulator<FIMPL>, MIO);
|
||||
|
||||
/******************************************************************************
|
||||
* TLoadPerambulator implementation *
|
||||
******************************************************************************/
|
||||
// constructor /////////////////////////////////////////////////////////////////
|
||||
template <typename FImpl>
|
||||
TLoadPerambulator<FImpl>::TLoadPerambulator(const std::string name)
|
||||
: Module<LoadPerambulatorPar>(name)
|
||||
{}
|
||||
|
||||
// dependencies/products ///////////////////////////////////////////////////////
|
||||
template <typename FImpl>
|
||||
std::vector<std::string> TLoadPerambulator<FImpl>::getInput(void)
|
||||
{
|
||||
std::vector<std::string> in;
|
||||
|
||||
return in;
|
||||
}
|
||||
|
||||
template <typename FImpl>
|
||||
std::vector<std::string> TLoadPerambulator<FImpl>::getOutput(void)
|
||||
{
|
||||
std::vector<std::string> out = {getName()};
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
// setup ///////////////////////////////////////////////////////////////////////
|
||||
template <typename FImpl>
|
||||
void TLoadPerambulator<FImpl>::setup(void)
|
||||
{
|
||||
const int nvec{par().nvec};
|
||||
const MDistil::DistilParameters & Distil{par().Distil};
|
||||
const int LI{Distil.LI};
|
||||
const int nnoise{Distil.nnoise};
|
||||
const int Nt_inv{Distil.Nt_inv}; // TODO: PROBABLY BETTER: if (full_tdil) Nt_inv=1; else Nt_inv = TI;
|
||||
const int Ns{Distil.Ns};
|
||||
std::array<std::string,6> sIndexNames{"Nt", "nvec", "LI", "nnoise", "Nt_inv", "SI"};
|
||||
|
||||
envCreate(MDistil::Perambulator<SpinVector COMMA 6 COMMA sizeof(Real)>, getName() + "_perambulator_light", 1,
|
||||
sIndexNames,Distil.Nt,nvec,Distil.LI,Distil.nnoise,Distil.Nt_inv,Distil.SI);
|
||||
|
||||
}
|
||||
|
||||
// execution ///////////////////////////////////////////////////////////////////
|
||||
template <typename FImpl>
|
||||
void TLoadPerambulator<FImpl>::execute(void)
|
||||
{
|
||||
auto &perambulator = envGet(MDistil::Perambulator<SpinVector COMMA 6 COMMA sizeof(Real)>,
|
||||
getName() + "_perambulator_light");
|
||||
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
END_MODULE_NAMESPACE
|
||||
|
||||
END_HADRONS_NAMESPACE
|
||||
|
||||
#endif // Hadrons_MIO_LoadPerambulator_hpp_
|
Reference in New Issue
Block a user