mirror of
https://github.com/paboyle/Grid.git
synced 2025-04-11 22:50:45 +01:00
Exposing support for Ncolours and Ndimensions and JSON input file for the ScalarAction
This commit is contained in:
parent
8546d01a4c
commit
741bc836f6
@ -40,9 +40,9 @@ namespace QCD {
|
|||||||
typedef ScalarAction<ScalarImplF> ScalarActionF;
|
typedef ScalarAction<ScalarImplF> ScalarActionF;
|
||||||
typedef ScalarAction<ScalarImplD> ScalarActionD;
|
typedef ScalarAction<ScalarImplD> ScalarActionD;
|
||||||
|
|
||||||
typedef ScalarInteractionAction<ScalarAdjImplR> ScalarAdjActionR;
|
template <int Colours, int Dimensions> using ScalarAdjActionR = ScalarInteractionAction<ScalarNxNAdjImplR<Colours>, Dimensions>;
|
||||||
typedef ScalarInteractionAction<ScalarAdjImplF> ScalarAdjActionF;
|
template <int Colours, int Dimensions> using ScalarAdjActionF = ScalarInteractionAction<ScalarNxNAdjImplF<Colours>, Dimensions>;
|
||||||
typedef ScalarInteractionAction<ScalarAdjImplD> ScalarAdjActionD;
|
template <int Colours, int Dimensions> using ScalarAdjActionD = ScalarInteractionAction<ScalarNxNAdjImplD<Colours>, Dimensions>;
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -96,7 +96,10 @@ class ScalarImplTypes {
|
|||||||
typedef ScalarAdjMatrixImplTypes<vComplexF, QCD::Nc> ScalarAdjImplF;
|
typedef ScalarAdjMatrixImplTypes<vComplexF, QCD::Nc> ScalarAdjImplF;
|
||||||
typedef ScalarAdjMatrixImplTypes<vComplexD, QCD::Nc> ScalarAdjImplD;
|
typedef ScalarAdjMatrixImplTypes<vComplexD, QCD::Nc> ScalarAdjImplD;
|
||||||
|
|
||||||
|
template <int Colours > using ScalarNxNAdjImplR = ScalarAdjMatrixImplTypes<vComplex, Colours >;
|
||||||
|
template <int Colours > using ScalarNxNAdjImplF = ScalarAdjMatrixImplTypes<vComplexF, Colours >;
|
||||||
|
template <int Colours > using ScalarNxNAdjImplD = ScalarAdjMatrixImplTypes<vComplexD, Colours >;
|
||||||
|
|
||||||
//}
|
//}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -37,11 +37,11 @@ directory
|
|||||||
namespace Grid {
|
namespace Grid {
|
||||||
// FIXME drop the QCD namespace everywhere here
|
// FIXME drop the QCD namespace everywhere here
|
||||||
|
|
||||||
template <class Impl>
|
template <class Impl, int Ndim >
|
||||||
class ScalarInteractionAction : public QCD::Action<typename Impl::Field> {
|
class ScalarInteractionAction : public QCD::Action<typename Impl::Field> {
|
||||||
public:
|
public:
|
||||||
INHERIT_FIELD_TYPES(Impl);
|
INHERIT_FIELD_TYPES(Impl);
|
||||||
private:
|
private:
|
||||||
RealD mass_square;
|
RealD mass_square;
|
||||||
RealD lambda;
|
RealD lambda;
|
||||||
|
|
||||||
@ -50,14 +50,19 @@ private:
|
|||||||
typedef CartesianStencil<vobj,vobj> Stencil;
|
typedef CartesianStencil<vobj,vobj> Stencil;
|
||||||
|
|
||||||
SimpleCompressor<vobj> compressor;
|
SimpleCompressor<vobj> compressor;
|
||||||
int npoint = 8;
|
int npoint = 2*Ndim;
|
||||||
std::vector<int> directions = {0,1,2,3,0,1,2,3}; // forcing 4 dimensions
|
std::vector<int> directions;// = {0,1,2,3,0,1,2,3}; // forcing 4 dimensions
|
||||||
std::vector<int> displacements = {1,1,1,1, -1,-1,-1,-1};
|
std::vector<int> displacements;// = {1,1,1,1, -1,-1,-1,-1};
|
||||||
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
ScalarInteractionAction(RealD ms, RealD l) : mass_square(ms), lambda(l){}
|
ScalarInteractionAction(RealD ms, RealD l) : mass_square(ms), lambda(l), displacements(2*Ndim,0), directions(2*Ndim,0){
|
||||||
|
for (int mu = 0 ; mu < Ndim; mu++){
|
||||||
|
directions[mu] = mu; directions[mu+Ndim] = mu;
|
||||||
|
displacements[mu] = 1; displacements[mu+Ndim] = -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
virtual std::string LogParameters() {
|
virtual std::string LogParameters() {
|
||||||
std::stringstream sstream;
|
std::stringstream sstream;
|
||||||
@ -71,75 +76,74 @@ private:
|
|||||||
virtual void refresh(const Field &U, GridParallelRNG &pRNG) {}
|
virtual void refresh(const Field &U, GridParallelRNG &pRNG) {}
|
||||||
|
|
||||||
virtual RealD S(const Field &p) {
|
virtual RealD S(const Field &p) {
|
||||||
static Stencil phiStencil(p._grid, npoint, 0, directions, displacements);
|
assert(p._grid->Nd() == Ndim);
|
||||||
phiStencil.HaloExchange(p, compressor);
|
static Stencil phiStencil(p._grid, npoint, 0, directions, displacements);
|
||||||
|
phiStencil.HaloExchange(p, compressor);
|
||||||
Field action(p._grid), pshift(p._grid), phisquared(p._grid);
|
Field action(p._grid), pshift(p._grid), phisquared(p._grid);
|
||||||
phisquared = p*p;
|
phisquared = p*p;
|
||||||
action = (2.0*QCD::Nd + mass_square)*phisquared + lambda*phisquared*phisquared;
|
action = (2.0*Ndim + mass_square)*phisquared + lambda*phisquared*phisquared;
|
||||||
for (int mu = 0; mu < QCD::Nd; mu++) {
|
for (int mu = 0; mu < Ndim; mu++) {
|
||||||
// pshift = Cshift(p, mu, +1); // not efficient, implement with stencils
|
// pshift = Cshift(p, mu, +1); // not efficient, implement with stencils
|
||||||
PARALLEL_FOR_LOOP
|
parallel_for (int i = 0; i < p._grid->oSites(); i++) {
|
||||||
for (int i = 0; i < p._grid->oSites(); i++) {
|
int permute_type;
|
||||||
int permute_type;
|
StencilEntry *SE;
|
||||||
StencilEntry *SE;
|
vobj temp2;
|
||||||
vobj temp2;
|
vobj *temp;
|
||||||
vobj *temp;
|
vobj *t_p;
|
||||||
vobj *t_p;
|
|
||||||
|
SE = phiStencil.GetEntry(permute_type, mu, i);
|
||||||
SE = phiStencil.GetEntry(permute_type, mu, i);
|
t_p = &p._odata[i];
|
||||||
t_p = &p._odata[i];
|
if ( SE->_is_local ) {
|
||||||
if ( SE->_is_local ) {
|
temp = &p._odata[SE->_offset];
|
||||||
temp = &p._odata[SE->_offset];
|
if ( SE->_permute ) {
|
||||||
if ( SE->_permute ) {
|
permute(temp2, *temp, permute_type);
|
||||||
permute(temp2, *temp, permute_type);
|
action._odata[i] -= temp2*(*t_p) + (*t_p)*temp2;
|
||||||
action._odata[i] -= temp2*(*t_p) + (*t_p)*temp2;
|
} else {
|
||||||
} else {
|
action._odata[i] -= *temp*(*t_p) + (*t_p)*(*temp);
|
||||||
action._odata[i] -= *temp*(*t_p) + (*t_p)*(*temp);
|
}
|
||||||
}
|
} else {
|
||||||
} else {
|
action._odata[i] -= phiStencil.CommBuf()[SE->_offset]*(*t_p) + (*t_p)*phiStencil.CommBuf()[SE->_offset];
|
||||||
action._odata[i] -= phiStencil.CommBuf()[SE->_offset]*(*t_p) + (*t_p)*phiStencil.CommBuf()[SE->_offset];
|
}
|
||||||
}
|
}
|
||||||
}
|
// action -= pshift*p + p*pshift;
|
||||||
// action -= pshift*p + p*pshift;
|
}
|
||||||
}
|
// NB the trace in the algebra is normalised to 1/2
|
||||||
// NB the trace in the algebra is normalised to 1/2
|
// minus sign coming from the antihermitian fields
|
||||||
// minus sign coming from the antihermitian fields
|
return -(TensorRemove(sum(trace(action)))).real();
|
||||||
return -(TensorRemove(sum(trace(action)))).real();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
virtual void deriv(const Field &p, Field &force) {
|
virtual void deriv(const Field &p, Field &force) {
|
||||||
force = (2.0*QCD::Nd + mass_square)*p + 2.0*lambda*p*p*p;
|
assert(p._grid->Nd() == Ndim);
|
||||||
// move this outside
|
force = (2.0*Ndim + mass_square)*p + 2.0*lambda*p*p*p;
|
||||||
static Stencil phiStencil(p._grid, npoint, 0, directions, displacements);
|
// move this outside
|
||||||
phiStencil.HaloExchange(p, compressor);
|
static Stencil phiStencil(p._grid, npoint, 0, directions, displacements);
|
||||||
|
phiStencil.HaloExchange(p, compressor);
|
||||||
//for (int mu = 0; mu < QCD::Nd; mu++) force -= Cshift(p, mu, -1) + Cshift(p, mu, 1);
|
|
||||||
for (int point = 0; point < npoint; point++) {
|
//for (int mu = 0; mu < QCD::Nd; mu++) force -= Cshift(p, mu, -1) + Cshift(p, mu, 1);
|
||||||
PARALLEL_FOR_LOOP
|
for (int point = 0; point < npoint; point++) {
|
||||||
for (int i = 0; i < p._grid->oSites(); i++) {
|
parallel_for (int i = 0; i < p._grid->oSites(); i++) {
|
||||||
vobj *temp;
|
vobj *temp;
|
||||||
vobj temp2;
|
vobj temp2;
|
||||||
int permute_type;
|
int permute_type;
|
||||||
StencilEntry *SE;
|
StencilEntry *SE;
|
||||||
SE = phiStencil.GetEntry(permute_type, point, i);
|
SE = phiStencil.GetEntry(permute_type, point, i);
|
||||||
|
|
||||||
if ( SE->_is_local ) {
|
if ( SE->_is_local ) {
|
||||||
temp = &p._odata[SE->_offset];
|
temp = &p._odata[SE->_offset];
|
||||||
if ( SE->_permute ) {
|
if ( SE->_permute ) {
|
||||||
permute(temp2, *temp, permute_type);
|
permute(temp2, *temp, permute_type);
|
||||||
force._odata[i] -= temp2;
|
force._odata[i] -= temp2;
|
||||||
} else {
|
} else {
|
||||||
force._odata[i] -= *temp;
|
force._odata[i] -= *temp;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
force._odata[i] -= phiStencil.CommBuf()[SE->_offset];
|
force._odata[i] -= phiStencil.CommBuf()[SE->_offset];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Grid
|
} // namespace Grid
|
||||||
|
|
||||||
#endif // SCALAR_INT_ACTION_H
|
#endif // SCALAR_INT_ACTION_H
|
||||||
|
@ -210,6 +210,9 @@ typedef HMCWrapperTemplate<ScalarImplR, MinimumNorm2, ScalarFields>
|
|||||||
typedef HMCWrapperTemplate<ScalarAdjImplR, MinimumNorm2, ScalarMatrixFields>
|
typedef HMCWrapperTemplate<ScalarAdjImplR, MinimumNorm2, ScalarMatrixFields>
|
||||||
ScalarAdjGenericHMCRunner;
|
ScalarAdjGenericHMCRunner;
|
||||||
|
|
||||||
|
template <int Colours>
|
||||||
|
using ScalarNxNAdjGenericHMCRunner = HMCWrapperTemplate < ScalarNxNAdjImplR<Colours>, MinimumNorm2, ScalarNxNMatrixFields<Colours> >;
|
||||||
|
|
||||||
} // namespace QCD
|
} // namespace QCD
|
||||||
} // namespace Grid
|
} // namespace Grid
|
||||||
|
|
||||||
|
@ -64,6 +64,9 @@ typedef Representations<FundamentalRepresentation> NoHirep;
|
|||||||
typedef Representations<EmptyRep<typename ScalarImplR::Field> > ScalarFields;
|
typedef Representations<EmptyRep<typename ScalarImplR::Field> > ScalarFields;
|
||||||
typedef Representations<EmptyRep<typename ScalarAdjImplR::Field> > ScalarMatrixFields;
|
typedef Representations<EmptyRep<typename ScalarAdjImplR::Field> > ScalarMatrixFields;
|
||||||
|
|
||||||
|
template < int Colours>
|
||||||
|
using ScalarNxNMatrixFields = Representations<EmptyRep<typename ScalarNxNAdjImplR<Colours>::Field> >;
|
||||||
|
|
||||||
// Helper classes to access the elements
|
// Helper classes to access the elements
|
||||||
// Strips the first N parameters from the tuple
|
// Strips the first N parameters from the tuple
|
||||||
// sequence of classes to obtain the S sequence
|
// sequence of classes to obtain the S sequence
|
||||||
|
@ -286,7 +286,7 @@ class CartesianStencil { // Stencil runs along coordinate axes only; NO diagonal
|
|||||||
{
|
{
|
||||||
int dimension = _directions[point];
|
int dimension = _directions[point];
|
||||||
int displacement = _distances[point];
|
int displacement = _distances[point];
|
||||||
|
|
||||||
int fd = _grid->_fdimensions[dimension];
|
int fd = _grid->_fdimensions[dimension];
|
||||||
int rd = _grid->_rdimensions[dimension];
|
int rd = _grid->_rdimensions[dimension];
|
||||||
|
|
||||||
|
@ -32,68 +32,116 @@ class ScalarActionParameters : Serializable {
|
|||||||
GRID_SERIALIZABLE_CLASS_MEMBERS(ScalarActionParameters,
|
GRID_SERIALIZABLE_CLASS_MEMBERS(ScalarActionParameters,
|
||||||
double, mass_squared,
|
double, mass_squared,
|
||||||
double, lambda);
|
double, lambda);
|
||||||
|
|
||||||
|
template <class ReaderClass >
|
||||||
|
ScalarActionParameters(Reader<ReaderClass>& Reader){
|
||||||
|
read(Reader, "ScalarAction", *this);
|
||||||
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
int main(int argc, char **argv) {
|
int main(int argc, char **argv) {
|
||||||
using namespace Grid;
|
using namespace Grid;
|
||||||
using namespace Grid::QCD;
|
using namespace Grid::QCD;
|
||||||
|
typedef Grid::JSONReader Serialiser;
|
||||||
|
|
||||||
Grid_init(&argc, &argv);
|
Grid_init(&argc, &argv);
|
||||||
int threads = GridThread::GetThreads();
|
int threads = GridThread::GetThreads();
|
||||||
// here make a routine to print all the relevant information on the run
|
// here make a routine to print all the relevant information on the run
|
||||||
std::cout << GridLogMessage << "Grid is setup to use " << threads << " threads" << std::endl;
|
std::cout << GridLogMessage << "Grid is setup to use " << threads << " threads" << std::endl;
|
||||||
|
|
||||||
// Typedefs to simplify notation
|
// Typedefs to simplify notation
|
||||||
typedef ScalarAdjGenericHMCRunner HMCWrapper; // Uses the default minimum norm, real scalar fields
|
constexpr int Ncolours = 4;
|
||||||
|
constexpr int Ndimensions = 3;
|
||||||
|
typedef ScalarNxNAdjGenericHMCRunner<Ncolours> HMCWrapper; // Uses the default minimum norm, real scalar fields
|
||||||
|
typedef ScalarAdjActionR<Ncolours, Ndimensions> ScalarAction;
|
||||||
//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
|
//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
|
||||||
HMCWrapper TheHMC;
|
HMCWrapper TheHMC;
|
||||||
|
TheHMC.ReadCommandLine(argc, argv);
|
||||||
|
|
||||||
|
if (TheHMC.ParameterFile.empty()){
|
||||||
|
std::cout << "Input file not specified."
|
||||||
|
<< "Use --ParameterFile option in the command line.\nAborting"
|
||||||
|
<< std::endl;
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
Serialiser Reader(TheHMC.ParameterFile);
|
||||||
|
|
||||||
// Grid from the command line
|
// Grid from the command line
|
||||||
GridModule ScalarGrid;
|
GridModule ScalarGrid;
|
||||||
ScalarGrid.set_full(SpaceTimeGrid::makeFourDimGrid(
|
if (GridDefaultLatt().size() != Ndimensions){
|
||||||
GridDefaultLatt(), GridDefaultSimd(Nd, vComplex::Nsimd()),
|
std::cout << "Incorrect dimension of the grid\n. Expected dim="<< Ndimensions << std::endl;
|
||||||
GridDefaultMpi()));
|
exit(1);
|
||||||
ScalarGrid.set_rb(SpaceTimeGrid::makeFourDimRedBlackGrid(ScalarGrid.get_full()));
|
}
|
||||||
|
if (GridDefaultMpi().size() != Ndimensions){
|
||||||
|
std::cout << "Incorrect dimension of the mpi grid\n. Expected dim="<< Ndimensions << std::endl;
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
ScalarGrid.set_full(new GridCartesian(GridDefaultLatt(),GridDefaultSimd(Ndimensions, vComplex::Nsimd()),GridDefaultMpi()));
|
||||||
|
ScalarGrid.set_rb(new GridRedBlackCartesian(ScalarGrid.get_full()));
|
||||||
TheHMC.Resources.AddGrid("scalar", ScalarGrid);
|
TheHMC.Resources.AddGrid("scalar", ScalarGrid);
|
||||||
// Possibile to create the module by hand
|
std::cout << "Lattice size : " << GridDefaultLatt() << std::endl;
|
||||||
// hardcoding parameters or using a Reader
|
|
||||||
|
|
||||||
// Checkpointer definition
|
// Checkpointer definition
|
||||||
CheckpointerParameters CPparams;
|
CheckpointerParameters CPparams(Reader);
|
||||||
CPparams.config_prefix = "ckpoint_scalar_lat";
|
|
||||||
CPparams.rng_prefix = "ckpoint_scalar_rng";
|
|
||||||
CPparams.saveInterval = 50;
|
|
||||||
CPparams.format = "IEEE64BIG";
|
|
||||||
|
|
||||||
TheHMC.Resources.LoadBinaryCheckpointer(CPparams);
|
TheHMC.Resources.LoadBinaryCheckpointer(CPparams);
|
||||||
|
|
||||||
RNGModuleParameters RNGpar;
|
RNGModuleParameters RNGpar(Reader);
|
||||||
RNGpar.serial_seeds = "1 2 3 4 5";
|
|
||||||
RNGpar.parallel_seeds = "6 7 8 9 10";
|
|
||||||
TheHMC.Resources.SetRNGSeeds(RNGpar);
|
TheHMC.Resources.SetRNGSeeds(RNGpar);
|
||||||
/////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////
|
||||||
// Collect actions, here use more encapsulation
|
// Collect actions, here use more encapsulation
|
||||||
|
|
||||||
// Scalar action in adjoint representation
|
// Scalar action in adjoint representation
|
||||||
ScalarActionParameters SPar;
|
ScalarActionParameters SPar(Reader);
|
||||||
SPar.mass_squared = 0.5;
|
ScalarAction Saction(SPar.mass_squared, SPar.lambda);
|
||||||
SPar.lambda = 0.1;
|
|
||||||
ScalarAdjActionR Saction(SPar.mass_squared, SPar.lambda);
|
|
||||||
|
|
||||||
// Collect actions
|
// Collect actions
|
||||||
ActionLevel<ScalarAdjActionR::Field, ScalarMatrixFields> Level1(1);
|
ActionLevel<ScalarAction::Field, ScalarNxNMatrixFields<Ncolours>> Level1(1);
|
||||||
Level1.push_back(&Saction);
|
Level1.push_back(&Saction);
|
||||||
TheHMC.TheAction.push_back(Level1);
|
TheHMC.TheAction.push_back(Level1);
|
||||||
/////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////
|
||||||
|
TheHMC.Parameters.initialize(Reader);
|
||||||
|
|
||||||
// HMC parameters are serialisable
|
|
||||||
TheHMC.Parameters.MD.MDsteps = 20;
|
|
||||||
TheHMC.Parameters.MD.trajL = 1.0;
|
|
||||||
|
|
||||||
TheHMC.ReadCommandLine(argc, argv);
|
|
||||||
TheHMC.Run();
|
TheHMC.Run();
|
||||||
|
|
||||||
Grid_finalize();
|
Grid_finalize();
|
||||||
} // main
|
} // main
|
||||||
|
|
||||||
|
/* Examples for input files
|
||||||
|
|
||||||
|
JSON
|
||||||
|
|
||||||
|
{
|
||||||
|
"Checkpointer": {
|
||||||
|
"config_prefix": "ckpoint_scalar_lat",
|
||||||
|
"rng_prefix": "ckpoint_scalar_rng",
|
||||||
|
"saveInterval": 1,
|
||||||
|
"format": "IEEE64BIG"
|
||||||
|
},
|
||||||
|
"RandomNumberGenerator": {
|
||||||
|
"serial_seeds": "1 2 3 4 6",
|
||||||
|
"parallel_seeds": "6 7 8 9 11"
|
||||||
|
},
|
||||||
|
"ScalarAction":{
|
||||||
|
"mass_squared": 0.5,
|
||||||
|
"lambda": 0.1
|
||||||
|
},
|
||||||
|
"HMC":{
|
||||||
|
"StartTrajectory": 0,
|
||||||
|
"Trajectories": 100,
|
||||||
|
"MetropolisTest": true,
|
||||||
|
"NoMetropolisUntil": 10,
|
||||||
|
"StartingType": "HotStart",
|
||||||
|
"MD":{
|
||||||
|
"name": "MinimumNorm2",
|
||||||
|
"MDsteps": 15,
|
||||||
|
"trajL": 2.0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
XML example not provided yet
|
||||||
|
|
||||||
|
*/
|
Loading…
x
Reference in New Issue
Block a user