mirror of
https://github.com/paboyle/Grid.git
synced 2025-04-10 06:00:45 +01:00
Some fix for the GenericHMCrunner
This commit is contained in:
parent
6eb873dd96
commit
26b9740d53
@ -38,21 +38,23 @@ namespace Grid {
|
|||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
// Deterministic Reduction operations
|
// Deterministic Reduction operations
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
template<class vobj> inline RealD norm2(const Lattice<vobj> &arg){
|
template <class vobj>
|
||||||
|
inline RealD norm2(const Lattice<vobj> &arg) {
|
||||||
ComplexD nrm = innerProduct(arg, arg);
|
ComplexD nrm = innerProduct(arg, arg);
|
||||||
return std::real(nrm);
|
return std::real(nrm);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class vobj>
|
template <class vobj>
|
||||||
inline ComplexD innerProduct(const Lattice<vobj> &left,const Lattice<vobj> &right)
|
inline ComplexD innerProduct(const Lattice<vobj> &left,
|
||||||
{
|
const Lattice<vobj> &right) {
|
||||||
typedef typename vobj::scalar_type scalar_type;
|
typedef typename vobj::scalar_type scalar_type;
|
||||||
typedef typename vobj::vector_type vector_type;
|
typedef typename vobj::vector_type vector_type;
|
||||||
scalar_type nrm;
|
scalar_type nrm;
|
||||||
|
|
||||||
GridBase *grid = left._grid;
|
GridBase *grid = left._grid;
|
||||||
|
|
||||||
std::vector<vector_type,alignedAllocator<vector_type> > sumarray(grid->SumArraySize());
|
std::vector<vector_type, alignedAllocator<vector_type> > sumarray(
|
||||||
|
grid->SumArraySize());
|
||||||
for (int i = 0; i < grid->SumArraySize(); i++) {
|
for (int i = 0; i < grid->SumArraySize(); i++) {
|
||||||
sumarray[i] = zero;
|
sumarray[i] = zero;
|
||||||
}
|
}
|
||||||
@ -62,14 +64,17 @@ PARALLEL_FOR_LOOP
|
|||||||
int nwork, mywork, myoff;
|
int nwork, mywork, myoff;
|
||||||
GridThread::GetWork(left._grid->oSites(), thr, mywork, myoff);
|
GridThread::GetWork(left._grid->oSites(), thr, mywork, myoff);
|
||||||
|
|
||||||
decltype(innerProduct(left._odata[0],right._odata[0])) vnrm=zero; // private to thread; sub summation
|
decltype(innerProduct(left._odata[0], right._odata[0])) vnrm =
|
||||||
|
zero; // private to thread; sub summation
|
||||||
for (int ss = myoff; ss < mywork + myoff; ss++) {
|
for (int ss = myoff; ss < mywork + myoff; ss++) {
|
||||||
vnrm = vnrm + innerProduct(left._odata[ss], right._odata[ss]);
|
vnrm = vnrm + innerProduct(left._odata[ss], right._odata[ss]);
|
||||||
}
|
}
|
||||||
sumarray[thr] = TensorRemove(vnrm);
|
sumarray[thr] = TensorRemove(vnrm);
|
||||||
}
|
}
|
||||||
|
|
||||||
vector_type vvnrm; vvnrm=zero; // sum across threads
|
|
||||||
|
vector_type vvnrm;
|
||||||
|
vvnrm = zero; // sum across threads
|
||||||
for (int i = 0; i < grid->SumArraySize(); i++) {
|
for (int i = 0; i < grid->SumArraySize(); i++) {
|
||||||
vvnrm = vvnrm + sumarray[i];
|
vvnrm = vvnrm + sumarray[i];
|
||||||
}
|
}
|
||||||
@ -79,9 +84,9 @@ PARALLEL_FOR_LOOP
|
|||||||
}
|
}
|
||||||
|
|
||||||
template <class Op, class T1>
|
template <class Op, class T1>
|
||||||
inline auto sum(const LatticeUnaryExpression<Op,T1> & expr)
|
inline auto sum(const LatticeUnaryExpression<Op, T1> &expr) ->
|
||||||
->typename decltype(expr.first.func(eval(0,std::get<0>(expr.second))))::scalar_object
|
typename decltype(
|
||||||
{
|
expr.first.func(eval(0, std::get<0>(expr.second))))::scalar_object {
|
||||||
return sum(closure(expr));
|
return sum(closure(expr));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -47,7 +47,7 @@ class BinaryHmcRunnerTemplate {
|
|||||||
ActionSet<Field, RepresentationsPolicy> TheAction;
|
ActionSet<Field, RepresentationsPolicy> TheAction;
|
||||||
// Add here a vector of HmcObservable
|
// Add here a vector of HmcObservable
|
||||||
// that can be injected from outside
|
// that can be injected from outside
|
||||||
std::vector< HmcObservable<typename Implementation::Field> > ObservablesList;
|
std::vector< HmcObservable<typename Implementation::Field>* > ObservablesList;
|
||||||
|
|
||||||
|
|
||||||
GridCartesian *UGrid;
|
GridCartesian *UGrid;
|
||||||
@ -126,6 +126,7 @@ class BinaryHmcRunnerTemplate {
|
|||||||
std::string rng_prefix = std::string("ckpoint_rng");
|
std::string rng_prefix = std::string("ckpoint_rng");
|
||||||
IOCheckpointer Checkpoint(conf_prefix, rng_prefix, SaveInterval, format);
|
IOCheckpointer Checkpoint(conf_prefix, rng_prefix, SaveInterval, format);
|
||||||
|
|
||||||
|
|
||||||
HMCparameters HMCpar;
|
HMCparameters HMCpar;
|
||||||
HMCpar.StartTrajectory = StartTraj;
|
HMCpar.StartTrajectory = StartTraj;
|
||||||
HMCpar.Trajectories = NumTraj;
|
HMCpar.Trajectories = NumTraj;
|
||||||
@ -158,10 +159,10 @@ class BinaryHmcRunnerTemplate {
|
|||||||
SmearingPolicy.set_Field(U);
|
SmearingPolicy.set_Field(U);
|
||||||
|
|
||||||
HybridMonteCarlo<IntegratorType> HMC(HMCpar, MDynamics, sRNG, pRNG, U);
|
HybridMonteCarlo<IntegratorType> HMC(HMCpar, MDynamics, sRNG, pRNG, U);
|
||||||
//HMC.AddObservable(&Checkpoint);
|
HMC.AddObservable(&Checkpoint);
|
||||||
|
|
||||||
for (int obs = 0; obs < ObservablesList.size(); obs++)
|
for (int obs = 0; obs < ObservablesList.size(); obs++)
|
||||||
HMC.AddObservable(&ObservablesList[obs]);
|
HMC.AddObservable(ObservablesList[obs]);
|
||||||
|
|
||||||
// Run it
|
// Run it
|
||||||
HMC.evolve();
|
HMC.evolve();
|
||||||
|
@ -143,6 +143,7 @@ int main(int argc, char **argv) {
|
|||||||
|
|
||||||
random(FineRNG, Foo);
|
random(FineRNG, Foo);
|
||||||
gaussian(FineRNG, Bar);
|
gaussian(FineRNG, Bar);
|
||||||
|
|
||||||
random(FineRNG, scFoo);
|
random(FineRNG, scFoo);
|
||||||
random(FineRNG, scBar);
|
random(FineRNG, scBar);
|
||||||
|
|
||||||
@ -169,6 +170,18 @@ int main(int argc, char **argv) {
|
|||||||
abort();
|
abort();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Norm2 check
|
||||||
|
LatticeReal BarReal(&Fine);
|
||||||
|
LatticeComplex BarComplex(&Fine);
|
||||||
|
BarReal = 1.0;
|
||||||
|
BarComplex = 1.0;
|
||||||
|
|
||||||
|
|
||||||
|
std::cout << "Norm2 LatticeReal : "<< norm2(BarReal) << std::endl;
|
||||||
|
std::cout << "Norm2 LatticeComplex : "<< norm2(BarComplex) << std::endl;
|
||||||
|
|
||||||
|
exit(0);
|
||||||
|
|
||||||
TComplex tr = trace(cmat);
|
TComplex tr = trace(cmat);
|
||||||
|
|
||||||
cVec = cMat * cVec; // LatticeColourVector = LatticeColourMatrix
|
cVec = cMat * cVec; // LatticeColourVector = LatticeColourMatrix
|
||||||
|
@ -43,12 +43,13 @@ class HmcRunner : public ScalarBinaryHmcRunner {
|
|||||||
void BuildTheAction(int argc, char **argv)
|
void BuildTheAction(int argc, char **argv)
|
||||||
|
|
||||||
{
|
{
|
||||||
|
// Notice that the Grid is for reals now
|
||||||
UGrid = SpaceTimeGrid::makeFourDimGrid(
|
UGrid = SpaceTimeGrid::makeFourDimGrid(
|
||||||
GridDefaultLatt(), GridDefaultSimd(Nd, vComplex::Nsimd()),
|
GridDefaultLatt(), GridDefaultSimd(Nd, vReal::Nsimd()),
|
||||||
GridDefaultMpi());
|
GridDefaultMpi());
|
||||||
UrbGrid = SpaceTimeGrid::makeFourDimRedBlackGrid(UGrid);
|
UrbGrid = SpaceTimeGrid::makeFourDimRedBlackGrid(UGrid);
|
||||||
|
|
||||||
// Scalar action
|
// Real Scalar action
|
||||||
ScalarActionR Saction(0.11,0.);
|
ScalarActionR Saction(0.11,0.);
|
||||||
|
|
||||||
// Collect actions
|
// Collect actions
|
||||||
|
@ -82,8 +82,8 @@ class HmcRunner : public BinaryHmcRunner {
|
|||||||
TheAction.push_back(Level2);
|
TheAction.push_back(Level2);
|
||||||
|
|
||||||
// Add observables
|
// Add observables
|
||||||
//PlaquetteLogger<BinaryHmcRunner::ImplPolicy> PlaqLog(std::string("plaq"));
|
PlaquetteLogger<BinaryHmcRunner::ImplPolicy> PlaqLog(std::string("plaq"));
|
||||||
//ObservablesList.push_back(PlaqLog);
|
ObservablesList.push_back(&PlaqLog);
|
||||||
|
|
||||||
Run(argc, argv);
|
Run(argc, argv);
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user