1
0
mirror of https://github.com/paboyle/Grid.git synced 2024-11-10 07:55:35 +00:00

Improving efficiency of the force term

This commit is contained in:
Guido Cossu 2017-03-15 15:16:16 +09:00
parent 831ca4e3bf
commit 38806343a8
3 changed files with 104 additions and 41 deletions

View File

@ -30,17 +30,34 @@ directory
#ifndef SCALAR_INT_ACTION_H #ifndef SCALAR_INT_ACTION_H
#define SCALAR_INT_ACTION_H #define SCALAR_INT_ACTION_H
// Note: this action can completely absorb the ScalarAction for real float fields
// use the scalarObjs to generalise the structure
namespace Grid { namespace Grid {
// FIXME drop the QCD namespace everywhere here // FIXME drop the QCD namespace everywhere here
template <class Impl> template <class Impl>
class ScalarInteractionAction : public QCD::Action<typename Impl::Field> { class ScalarInteractionAction : public QCD::Action<typename Impl::Field> {
public:
INHERIT_FIELD_TYPES(Impl);
private:
RealD mass_square; RealD mass_square;
RealD lambda; RealD lambda;
typedef typename Field::vector_object vobj;
typedef CartesianStencil<vobj,vobj> Stencil;
SimpleCompressor<vobj> compressor;
int npoint = 8;
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};
public: public:
INHERIT_FIELD_TYPES(Impl);
ScalarInteractionAction(RealD ms, RealD l) : mass_square(ms), lambda(l) {} ScalarInteractionAction(RealD ms, RealD l) : mass_square(ms), lambda(l){}
virtual std::string LogParameters() { virtual std::string LogParameters() {
std::stringstream sstream; std::stringstream sstream;
@ -51,27 +68,75 @@ class ScalarInteractionAction : public QCD::Action<typename Impl::Field> {
virtual std::string action_name() {return "ScalarAction";} virtual std::string action_name() {return "ScalarAction";}
virtual void refresh(const Field &U, virtual void refresh(const Field &U, GridParallelRNG &pRNG) {}
GridParallelRNG &pRNG) {} // noop as no pseudoferms
virtual RealD S(const Field &p) { virtual RealD S(const Field &p) {
Field action(p._grid); static Stencil phiStencil(p._grid, npoint, 0, directions, displacements);
Field pshift(p._grid); phiStencil.HaloExchange(p, compressor);
Field 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*QCD::Nd + mass_square)*phisquared + lambda*phisquared*phisquared;
for (int mu = 0; mu < QCD::Nd; mu++) { for (int mu = 0; mu < QCD::Nd; mu++) {
pshift = Cshift(p, mu, +1); // not efficient implement with stencils // pshift = Cshift(p, mu, +1); // not efficient, implement with stencils
action -= pshift*p + p*pshift; PARALLEL_FOR_LOOP
for (int i = 0; i < p._grid->oSites(); i++) {
int permute_type;
StencilEntry *SE;
vobj temp2;
vobj *temp;
vobj *t_p;
SE = phiStencil.GetEntry(permute_type, mu, i);
t_p = &p._odata[i];
if ( SE->_is_local ) {
temp = &p._odata[SE->_offset];
if ( SE->_permute ) {
permute(temp2, *temp, permute_type);
action._odata[i] -= temp2*(*t_p) + (*t_p)*temp2;
} else {
action._odata[i] -= *temp*(*t_p) + (*t_p)*(*temp);
} }
} else {
action._odata[i] -= phiStencil.CommBuf()[SE->_offset]*(*t_p) + (*t_p)*phiStencil.CommBuf()[SE->_offset];
}
}
// action -= pshift*p + p*pshift;
}
// NB the trace in the algebra is normalised to 1/2
// 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, virtual void deriv(const Field &p, Field &force) {
Field &force) {
force = (2.0*QCD::Nd + mass_square)*p + 2.0*lambda*p*p*p; force = (2.0*QCD::Nd + mass_square)*p + 2.0*lambda*p*p*p;
// following is inefficient // move this outside
for (int mu = 0; mu < QCD::Nd; mu++) force -= Cshift(p, mu, -1) + Cshift(p, mu, 1); 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++) {
PARALLEL_FOR_LOOP
for (int i = 0; i < p._grid->oSites(); i++) {
vobj *temp;
vobj temp2;
int permute_type;
StencilEntry *SE;
SE = phiStencil.GetEntry(permute_type, point, i);
if ( SE->_is_local ) {
temp = &p._odata[SE->_offset];
if ( SE->_permute ) {
permute(temp2, *temp, permute_type);
force._odata[i] -= temp2;
} else {
force._odata[i] -= *temp;
}
} else {
force._odata[i] -= phiStencil.CommBuf()[SE->_offset];
}
}
}
} }
}; };

View File

@ -33,9 +33,8 @@ using namespace std;
using namespace Grid; using namespace Grid;
using namespace Grid::QCD; using namespace Grid::QCD;
int main (int argc, char ** argv) int main(int argc, char ** argv) {
{ Grid_init(&argc, &argv);
Grid_init(&argc,&argv);
// typedef LatticeColourMatrix Field; // typedef LatticeColourMatrix Field;
typedef LatticeComplex Field; typedef LatticeComplex Field;

View File

@ -26,7 +26,7 @@ See the full license in the file "LICENSE" in the top level distribution directo
*************************************************************************************/ *************************************************************************************/
/* END LEGAL */ /* END LEGAL */
#include <Grid/Grid.h> #include <Grid/Grid.h>
namespace Grid{ namespace Grid {
class ScalarActionParameters : Serializable { class ScalarActionParameters : Serializable {
public: public:
GRID_SERIALIZABLE_CLASS_MEMBERS(ScalarActionParameters, GRID_SERIALIZABLE_CLASS_MEMBERS(ScalarActionParameters,
@ -52,7 +52,7 @@ int main(int argc, char **argv) {
// Grid from the command line // Grid from the command line
GridModule ScalarGrid; GridModule ScalarGrid;
ScalarGrid.set_full( SpaceTimeGrid::makeFourDimGrid( ScalarGrid.set_full(SpaceTimeGrid::makeFourDimGrid(
GridDefaultLatt(), GridDefaultSimd(Nd, vComplex::Nsimd()), GridDefaultLatt(), GridDefaultSimd(Nd, vComplex::Nsimd()),
GridDefaultMpi())); GridDefaultMpi()));
ScalarGrid.set_rb(SpaceTimeGrid::makeFourDimRedBlackGrid(ScalarGrid.get_full())); ScalarGrid.set_rb(SpaceTimeGrid::makeFourDimRedBlackGrid(ScalarGrid.get_full()));
@ -89,12 +89,11 @@ int main(int argc, char **argv) {
///////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////
// HMC parameters are serialisable // HMC parameters are serialisable
TheHMC.Parameters.MD.MDsteps = 10; TheHMC.Parameters.MD.MDsteps = 20;
TheHMC.Parameters.MD.trajL = 1.0; TheHMC.Parameters.MD.trajL = 1.0;
TheHMC.ReadCommandLine(argc, argv); TheHMC.ReadCommandLine(argc, argv);
TheHMC.Run(); TheHMC.Run();
Grid_finalize(); Grid_finalize();
} // main } // main