mirror of
https://github.com/paboyle/Grid.git
synced 2025-04-04 19:25:56 +01:00
Hadrons: modules remember their factory registration name
This commit is contained in:
parent
013e710c7d
commit
3af663e17b
@ -51,6 +51,13 @@ Environment & ModuleBase::env(void) const
|
||||
return env_;
|
||||
}
|
||||
|
||||
// get factory registration name if available
|
||||
std::string ModuleBase::getRegisteredName(void)
|
||||
{
|
||||
HADRON_ERROR("module '" + getName() + "' has a type not registered"
|
||||
+ " in the factory");
|
||||
}
|
||||
|
||||
// execution ///////////////////////////////////////////////////////////////////
|
||||
void ModuleBase::operator()(void)
|
||||
{
|
||||
|
@ -34,7 +34,17 @@ directory.
|
||||
BEGIN_HADRONS_NAMESPACE
|
||||
|
||||
// module registration macros
|
||||
#define MODULE_REGISTER(mod)\
|
||||
#define MODULE_REGISTER(mod, base)\
|
||||
class mod: public base\
|
||||
{\
|
||||
public:\
|
||||
typedef base Base;\
|
||||
using Base::Base;\
|
||||
virtual std::string getRegisteredName(void)\
|
||||
{\
|
||||
return std::string(#mod);\
|
||||
}\
|
||||
};\
|
||||
class mod##ModuleRegistrar\
|
||||
{\
|
||||
public:\
|
||||
@ -49,7 +59,17 @@ public:\
|
||||
};\
|
||||
static mod##ModuleRegistrar mod##ModuleRegistrarInstance;
|
||||
|
||||
#define MODULE_REGISTER_NS(mod, ns)\
|
||||
#define MODULE_REGISTER_NS(mod, base, ns)\
|
||||
class mod: public base\
|
||||
{\
|
||||
public:\
|
||||
typedef base Base;\
|
||||
using Base::Base;\
|
||||
virtual std::string getRegisteredName(void)\
|
||||
{\
|
||||
return std::string(#ns "::" #mod);\
|
||||
}\
|
||||
};\
|
||||
class ns##mod##ModuleRegistrar\
|
||||
{\
|
||||
public:\
|
||||
@ -64,6 +84,8 @@ public:\
|
||||
};\
|
||||
static ns##mod##ModuleRegistrar ns##mod##ModuleRegistrarInstance;
|
||||
|
||||
#define ARG(...) __VA_ARGS__
|
||||
|
||||
/******************************************************************************
|
||||
* Module class *
|
||||
******************************************************************************/
|
||||
@ -78,6 +100,8 @@ public:
|
||||
// access
|
||||
std::string getName(void) const;
|
||||
Environment &env(void) const;
|
||||
// get factory registration name if available
|
||||
virtual std::string getRegisteredName(void);
|
||||
// dependencies/products
|
||||
virtual std::vector<std::string> getInput(void) = 0;
|
||||
virtual std::vector<std::string> getOutput(void) = 0;
|
||||
|
@ -68,6 +68,8 @@ public:
|
||||
virtual void execute(void);
|
||||
};
|
||||
|
||||
MODULE_REGISTER_NS(DWF, TDWF<FIMPL>, MAction);
|
||||
|
||||
/******************************************************************************
|
||||
* DWF template implementation *
|
||||
******************************************************************************/
|
||||
@ -109,9 +111,9 @@ template <typename FImpl>
|
||||
void TDWF<FImpl>::execute(void)
|
||||
{
|
||||
LOG(Message) << "Setting up domain wall fermion matrix with m= "
|
||||
<< par().mass << ", M5= " << par().M5 << " and Ls= "
|
||||
<< par().Ls << " using gauge field '" << par().gauge << "'"
|
||||
<< std::endl;
|
||||
<< par().mass << ", M5= " << par().M5 << " and Ls= "
|
||||
<< par().Ls << " using gauge field '" << par().gauge << "'"
|
||||
<< std::endl;
|
||||
env().createGrid(par().Ls);
|
||||
auto &U = *env().template getObject<LatticeGaugeField>(par().gauge);
|
||||
auto &g4 = *env().getGrid();
|
||||
@ -123,12 +125,8 @@ void TDWF<FImpl>::execute(void)
|
||||
env().setObject(getName(), fMatPt);
|
||||
}
|
||||
|
||||
typedef TDWF<FIMPL> DWF;
|
||||
|
||||
END_MODULE_NAMESPACE
|
||||
|
||||
MODULE_REGISTER_NS(DWF, MAction);
|
||||
|
||||
END_HADRONS_NAMESPACE
|
||||
|
||||
#endif // Hadrons_DWF_hpp_
|
||||
|
@ -66,6 +66,8 @@ public:
|
||||
virtual void execute(void);
|
||||
};
|
||||
|
||||
MODULE_REGISTER_NS(Wilson, TWilson<FIMPL>, MAction);
|
||||
|
||||
/******************************************************************************
|
||||
* TWilson template implementation *
|
||||
******************************************************************************/
|
||||
@ -98,7 +100,7 @@ void TWilson<FImpl>::setup(void)
|
||||
{
|
||||
unsigned int size;
|
||||
|
||||
size = 3*env().template lattice4dSize<typename FImpl::DoubledGaugeField>();
|
||||
size = 2*env().template lattice4dSize<typename FImpl::DoubledGaugeField>();
|
||||
env().registerObject(getName(), size);
|
||||
}
|
||||
|
||||
@ -115,12 +117,8 @@ void TWilson<FImpl>::execute()
|
||||
env().setObject(getName(), fMatPt);
|
||||
}
|
||||
|
||||
typedef TWilson<FIMPL> Wilson;
|
||||
|
||||
END_MODULE_NAMESPACE
|
||||
|
||||
MODULE_REGISTER_NS(Wilson, MAction);
|
||||
|
||||
END_HADRONS_NAMESPACE
|
||||
|
||||
#endif // Hadrons_Wilson_hpp_
|
||||
|
@ -47,7 +47,7 @@ public:
|
||||
virtual void execute(void);
|
||||
};
|
||||
|
||||
typedef TBaryon<FIMPL, FIMPL, FIMPL> Baryon;
|
||||
MODULE_REGISTER_NS(Baryon, ARG(TBaryon<FIMPL, FIMPL, FIMPL>), MContraction);
|
||||
|
||||
/******************************************************************************
|
||||
* TBaryon implementation *
|
||||
@ -97,8 +97,6 @@ void TBaryon<FImpl1, FImpl2, FImpl3>::execute(void)
|
||||
|
||||
END_MODULE_NAMESPACE
|
||||
|
||||
MODULE_REGISTER_NS(Baryon, MContraction);
|
||||
|
||||
END_HADRONS_NAMESPACE
|
||||
|
||||
#endif // Hadrons_Baryon_hpp_
|
||||
|
@ -72,6 +72,8 @@ public:
|
||||
virtual void execute(void);
|
||||
};
|
||||
|
||||
MODULE_REGISTER_NS(Meson, ARG(TMeson<FIMPL, FIMPL>), MContraction);
|
||||
|
||||
/******************************************************************************
|
||||
* TMeson implementation *
|
||||
******************************************************************************/
|
||||
@ -137,12 +139,8 @@ void TMeson<FImpl1, FImpl2>::execute(void)
|
||||
write(writer, "meson", result);
|
||||
}
|
||||
|
||||
typedef TMeson<FIMPL, FIMPL> Meson;
|
||||
|
||||
END_MODULE_NAMESPACE
|
||||
|
||||
MODULE_REGISTER_NS(Meson, MContraction);
|
||||
|
||||
END_HADRONS_NAMESPACE
|
||||
|
||||
#endif // Hadrons_Meson_hpp_
|
||||
|
@ -32,22 +32,22 @@ using namespace Hadrons;
|
||||
using namespace MGauge;
|
||||
|
||||
/******************************************************************************
|
||||
* Load implementation *
|
||||
* TLoad implementation *
|
||||
******************************************************************************/
|
||||
// constructor /////////////////////////////////////////////////////////////////
|
||||
Load::Load(const std::string name)
|
||||
TLoad::TLoad(const std::string name)
|
||||
: Module<LoadPar>(name)
|
||||
{}
|
||||
|
||||
// dependencies/products ///////////////////////////////////////////////////////
|
||||
std::vector<std::string> Load::getInput(void)
|
||||
std::vector<std::string> TLoad::getInput(void)
|
||||
{
|
||||
std::vector<std::string> in;
|
||||
|
||||
return in;
|
||||
}
|
||||
|
||||
std::vector<std::string> Load::getOutput(void)
|
||||
std::vector<std::string> TLoad::getOutput(void)
|
||||
{
|
||||
std::vector<std::string> out = {getName()};
|
||||
|
||||
@ -55,13 +55,13 @@ std::vector<std::string> Load::getOutput(void)
|
||||
}
|
||||
|
||||
// setup ///////////////////////////////////////////////////////////////////////
|
||||
void Load::setup(void)
|
||||
void TLoad::setup(void)
|
||||
{
|
||||
env().registerLattice<LatticeGaugeField>(getName());
|
||||
}
|
||||
|
||||
// execution ///////////////////////////////////////////////////////////////////
|
||||
void Load::execute(void)
|
||||
void TLoad::execute(void)
|
||||
{
|
||||
NerscField header;
|
||||
std::string fileName = par().file + "."
|
||||
|
@ -46,13 +46,13 @@ public:
|
||||
std::string, file);
|
||||
};
|
||||
|
||||
class Load: public Module<LoadPar>
|
||||
class TLoad: public Module<LoadPar>
|
||||
{
|
||||
public:
|
||||
// constructor
|
||||
Load(const std::string name);
|
||||
TLoad(const std::string name);
|
||||
// destructor
|
||||
virtual ~Load(void) = default;
|
||||
virtual ~TLoad(void) = default;
|
||||
// dependency relation
|
||||
virtual std::vector<std::string> getInput(void);
|
||||
virtual std::vector<std::string> getOutput(void);
|
||||
@ -62,9 +62,9 @@ public:
|
||||
virtual void execute(void);
|
||||
};
|
||||
|
||||
END_MODULE_NAMESPACE
|
||||
MODULE_REGISTER_NS(Load, TLoad, MGauge);
|
||||
|
||||
MODULE_REGISTER_NS(Load, MGauge);
|
||||
END_MODULE_NAMESPACE
|
||||
|
||||
END_HADRONS_NAMESPACE
|
||||
|
||||
|
@ -32,20 +32,20 @@ using namespace Hadrons;
|
||||
using namespace MGauge;
|
||||
|
||||
/******************************************************************************
|
||||
* Random implementation *
|
||||
* TRandom implementation *
|
||||
******************************************************************************/
|
||||
// constructor /////////////////////////////////////////////////////////////////
|
||||
Random::Random(const std::string name)
|
||||
TRandom::TRandom(const std::string name)
|
||||
: Module<NoPar>(name)
|
||||
{}
|
||||
|
||||
// dependencies/products ///////////////////////////////////////////////////////
|
||||
std::vector<std::string> Random::getInput(void)
|
||||
std::vector<std::string> TRandom::getInput(void)
|
||||
{
|
||||
return std::vector<std::string>();
|
||||
}
|
||||
|
||||
std::vector<std::string> Random::getOutput(void)
|
||||
std::vector<std::string> TRandom::getOutput(void)
|
||||
{
|
||||
std::vector<std::string> out = {getName()};
|
||||
|
||||
@ -53,13 +53,13 @@ std::vector<std::string> Random::getOutput(void)
|
||||
}
|
||||
|
||||
// setup ///////////////////////////////////////////////////////////////////////
|
||||
void Random::setup(void)
|
||||
void TRandom::setup(void)
|
||||
{
|
||||
env().registerLattice<LatticeGaugeField>(getName());
|
||||
}
|
||||
|
||||
// execution ///////////////////////////////////////////////////////////////////
|
||||
void Random::execute(void)
|
||||
void TRandom::execute(void)
|
||||
{
|
||||
LOG(Message) << "Generating random gauge configuration" << std::endl;
|
||||
LatticeGaugeField &U = *env().createLattice<LatticeGaugeField>(getName());
|
||||
|
@ -39,13 +39,13 @@ BEGIN_HADRONS_NAMESPACE
|
||||
******************************************************************************/
|
||||
BEGIN_MODULE_NAMESPACE(MGauge)
|
||||
|
||||
class Random: public Module<NoPar>
|
||||
class TRandom: public Module<NoPar>
|
||||
{
|
||||
public:
|
||||
// constructor
|
||||
Random(const std::string name);
|
||||
TRandom(const std::string name);
|
||||
// destructor
|
||||
virtual ~Random(void) = default;
|
||||
virtual ~TRandom(void) = default;
|
||||
// dependency relation
|
||||
virtual std::vector<std::string> getInput(void);
|
||||
virtual std::vector<std::string> getOutput(void);
|
||||
@ -55,9 +55,9 @@ public:
|
||||
virtual void execute(void);
|
||||
};
|
||||
|
||||
END_MODULE_NAMESPACE
|
||||
MODULE_REGISTER_NS(Random, TRandom, MGauge);
|
||||
|
||||
MODULE_REGISTER_NS(Random, MGauge);
|
||||
END_MODULE_NAMESPACE
|
||||
|
||||
END_HADRONS_NAMESPACE
|
||||
|
||||
|
@ -32,20 +32,20 @@ using namespace Hadrons;
|
||||
using namespace MGauge;
|
||||
|
||||
/******************************************************************************
|
||||
* Unit implementation *
|
||||
* TUnit implementation *
|
||||
******************************************************************************/
|
||||
// constructor /////////////////////////////////////////////////////////////////
|
||||
Unit::Unit(const std::string name)
|
||||
TUnit::TUnit(const std::string name)
|
||||
: Module<NoPar>(name)
|
||||
{}
|
||||
|
||||
// dependencies/products ///////////////////////////////////////////////////////
|
||||
std::vector<std::string> Unit::getInput(void)
|
||||
std::vector<std::string> TUnit::getInput(void)
|
||||
{
|
||||
return std::vector<std::string>();
|
||||
}
|
||||
|
||||
std::vector<std::string> Unit::getOutput(void)
|
||||
std::vector<std::string> TUnit::getOutput(void)
|
||||
{
|
||||
std::vector<std::string> out = {getName()};
|
||||
|
||||
@ -53,13 +53,13 @@ std::vector<std::string> Unit::getOutput(void)
|
||||
}
|
||||
|
||||
// setup ///////////////////////////////////////////////////////////////////////
|
||||
void Unit::setup(void)
|
||||
void TUnit::setup(void)
|
||||
{
|
||||
env().registerLattice<LatticeGaugeField>(getName());
|
||||
}
|
||||
|
||||
// execution ///////////////////////////////////////////////////////////////////
|
||||
void Unit::execute(void)
|
||||
void TUnit::execute(void)
|
||||
{
|
||||
LOG(Message) << "Creating unit gauge configuration" << std::endl;
|
||||
LatticeGaugeField &U = *env().createLattice<LatticeGaugeField>(getName());
|
||||
|
@ -39,13 +39,13 @@ BEGIN_HADRONS_NAMESPACE
|
||||
******************************************************************************/
|
||||
BEGIN_MODULE_NAMESPACE(MGauge)
|
||||
|
||||
class Unit: public Module<NoPar>
|
||||
class TUnit: public Module<NoPar>
|
||||
{
|
||||
public:
|
||||
// constructor
|
||||
Unit(const std::string name);
|
||||
TUnit(const std::string name);
|
||||
// destructor
|
||||
virtual ~Unit(void) = default;
|
||||
virtual ~TUnit(void) = default;
|
||||
// dependencies/products
|
||||
virtual std::vector<std::string> getInput(void);
|
||||
virtual std::vector<std::string> getOutput(void);
|
||||
@ -55,9 +55,9 @@ public:
|
||||
virtual void execute(void);
|
||||
};
|
||||
|
||||
END_MODULE_NAMESPACE
|
||||
MODULE_REGISTER_NS(Unit, TUnit, MGauge);
|
||||
|
||||
MODULE_REGISTER_NS(Unit, MGauge);
|
||||
END_MODULE_NAMESPACE
|
||||
|
||||
END_HADRONS_NAMESPACE
|
||||
|
||||
|
@ -66,6 +66,8 @@ public:
|
||||
virtual void execute(void);
|
||||
};
|
||||
|
||||
MODULE_REGISTER_NS(RBPrecCG, TRBPrecCG<FIMPL>, MSolver);
|
||||
|
||||
/******************************************************************************
|
||||
* TRBPrecCG template implementation *
|
||||
******************************************************************************/
|
||||
@ -121,12 +123,8 @@ void TRBPrecCG<FImpl>::execute(void)
|
||||
env().setObject(getName(), new SolverFn(solver));
|
||||
}
|
||||
|
||||
typedef TRBPrecCG<FIMPL> RBPrecCG;
|
||||
|
||||
END_MODULE_NAMESPACE
|
||||
|
||||
MODULE_REGISTER_NS(RBPrecCG, MSolver);
|
||||
|
||||
END_HADRONS_NAMESPACE
|
||||
|
||||
#endif // Hadrons_RBPrecCG_hpp_
|
||||
|
@ -76,6 +76,8 @@ public:
|
||||
virtual void execute(void);
|
||||
};
|
||||
|
||||
MODULE_REGISTER_NS(Point, TPoint<FIMPL>, MSource);
|
||||
|
||||
/******************************************************************************
|
||||
* TPoint template implementation *
|
||||
******************************************************************************/
|
||||
@ -124,12 +126,8 @@ void TPoint<FImpl>::execute(void)
|
||||
pokeSite(id, src, position);
|
||||
}
|
||||
|
||||
typedef TPoint<FIMPL> Point;
|
||||
|
||||
END_MODULE_NAMESPACE
|
||||
|
||||
MODULE_REGISTER_NS(Point, MSource);
|
||||
|
||||
END_HADRONS_NAMESPACE
|
||||
|
||||
#endif // Hadrons_Point_hpp_
|
||||
|
@ -57,10 +57,10 @@ public:
|
||||
virtual void execute(void);
|
||||
};
|
||||
|
||||
typedef TSeqGamma<FIMPL> SeqGamma;
|
||||
MODULE_REGISTER_NS(SeqGamma, TSeqGamma<FIMPL>, MSource);
|
||||
|
||||
/******************************************************************************
|
||||
* TSeqGamma implementation *
|
||||
* TSeqGamma implementation *
|
||||
******************************************************************************/
|
||||
// constructor /////////////////////////////////////////////////////////////////
|
||||
template <typename FImpl>
|
||||
@ -130,8 +130,6 @@ void TSeqGamma<FImpl>::execute(void)
|
||||
|
||||
END_MODULE_NAMESPACE
|
||||
|
||||
MODULE_REGISTER_NS(SeqGamma, MSource);
|
||||
|
||||
END_HADRONS_NAMESPACE
|
||||
|
||||
#endif // Hadrons_SeqGamma_hpp_
|
||||
|
@ -80,6 +80,8 @@ public:
|
||||
virtual void execute(void);
|
||||
};
|
||||
|
||||
MODULE_REGISTER_NS(Z2, TZ2<FIMPL>, MSource);
|
||||
|
||||
/******************************************************************************
|
||||
* TZ2 template implementation *
|
||||
******************************************************************************/
|
||||
@ -140,12 +142,8 @@ void TZ2<FImpl>::execute(void)
|
||||
src = src*eta;
|
||||
}
|
||||
|
||||
typedef TZ2<FIMPL> Z2;
|
||||
|
||||
END_MODULE_NAMESPACE
|
||||
|
||||
MODULE_REGISTER_NS(Z2, MSource);
|
||||
|
||||
END_HADRONS_NAMESPACE
|
||||
|
||||
#endif // Hadrons_Z2_hpp_
|
||||
|
@ -67,6 +67,8 @@ private:
|
||||
SolverFn *solver_{nullptr};
|
||||
};
|
||||
|
||||
MODULE_REGISTER(Quark, TQuark<FIMPL>);
|
||||
|
||||
/******************************************************************************
|
||||
* TQuark implementation *
|
||||
******************************************************************************/
|
||||
@ -176,10 +178,6 @@ void TQuark<FImpl>::execute(void)
|
||||
}
|
||||
}
|
||||
|
||||
typedef TQuark<FIMPL> Quark;
|
||||
|
||||
MODULE_REGISTER(Quark);
|
||||
|
||||
END_HADRONS_NAMESPACE
|
||||
|
||||
#endif // Hadrons_Quark_hpp_
|
||||
|
Loading…
x
Reference in New Issue
Block a user