diff --git a/.gitignore b/.gitignore index 45a3ea53..5338acb9 100644 --- a/.gitignore +++ b/.gitignore @@ -114,3 +114,4 @@ gh-pages/ ##################### Grid/qcd/spin/gamma-gen/*.h Grid/qcd/spin/gamma-gen/*.cc +Grid/util/Version.h diff --git a/ChangeLog b/ChangeLog index e69de29b..a0211af1 100644 --- a/ChangeLog +++ b/ChangeLog @@ -0,0 +1,5 @@ +Version : 0.8.0 + +- Clang 3.5 and above, ICPC v16 and above, GCC 6.3 and above recommended +- MPI and MPI3 comms optimisations for KNL and OPA finished +- Half precision comms diff --git a/Grid/Grid.h b/Grid/Grid.h index 0fdd5268..70859c81 100644 --- a/Grid/Grid.h +++ b/Grid/Grid.h @@ -1,4 +1,4 @@ -/************************************************************************************* + /************************************************************************************* Grid physics library, www.github.com/paboyle/Grid @@ -25,8 +25,8 @@ Author: paboyle 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. See the full license in the file "LICENSE" in the top level distribution directory -*************************************************************************************/ -/* END LEGAL */ + *************************************************************************************/ + /* END LEGAL */ // // Grid.h // simd @@ -42,9 +42,8 @@ Author: paboyle #include #include #include -NAMESPACE_CHECK(GaugeFix); +#include #include -NAMESPACE_CHECK(Smearing); #include #include diff --git a/Grid/algorithms/Algorithms.h b/Grid/algorithms/Algorithms.h index b716c48f..f1ac1c81 100644 --- a/Grid/algorithms/Algorithms.h +++ b/Grid/algorithms/Algorithms.h @@ -55,13 +55,9 @@ Author: Peter Boyle #include #include #include +#include + #include #include -// EigCg -// Pcg -// Hdcg -// GCR -// etc.. - #endif diff --git a/Grid/algorithms/LinearOperator.h b/Grid/algorithms/LinearOperator.h index a5b88d34..c309ad41 100644 --- a/Grid/algorithms/LinearOperator.h +++ b/Grid/algorithms/LinearOperator.h @@ -171,144 +171,142 @@ public: } }; -////////////////////////////////////////////////////////// -// Even Odd Schur decomp operators; there are several -// ways to introduce the even odd checkerboarding -////////////////////////////////////////////////////////// + ////////////////////////////////////////////////////////// + // Even Odd Schur decomp operators; there are several + // ways to introduce the even odd checkerboarding + ////////////////////////////////////////////////////////// -template -class SchurOperatorBase : public LinearOperatorBase { -public: - virtual RealD Mpc (const Field &in, Field &out) =0; - virtual RealD MpcDag (const Field &in, Field &out) =0; - virtual void MpcDagMpc(const Field &in, Field &out,RealD &ni,RealD &no) - { - Field tmp(in.Grid()); - tmp.Checkerboard() = in.Checkerboard(); - ni=Mpc(in,tmp); - no=MpcDag(tmp,out); - } - virtual void HermOpAndNorm(const Field &in, Field &out,RealD &n1,RealD &n2){ - out.Checkerboard() = in.Checkerboard(); - MpcDagMpc(in,out,n1,n2); - } - virtual void HermOp(const Field &in, Field &out){ - RealD n1,n2; - HermOpAndNorm(in,out,n1,n2); - } - void Op (const Field &in, Field &out){ - Mpc(in,out); - } - void AdjOp (const Field &in, Field &out){ - MpcDag(in,out); - } - // Support for coarsening to a multigrid - void OpDiag (const Field &in, Field &out) { - assert(0); // must coarsen the unpreconditioned system - } - void OpDir (const Field &in, Field &out,int dir,int disp) { - assert(0); - } -}; -template -class SchurDiagMooeeOperator : public SchurOperatorBase { -protected: - Matrix &_Mat; -public: - SchurDiagMooeeOperator (Matrix &Mat): _Mat(Mat){}; - virtual RealD Mpc (const Field &in, Field &out) { - Field tmp(in.Grid()); - // std::cout <<"grid pointers: in.Grid()="<< in.Grid() << " out.Grid()=" << out.Grid() << " _Mat.Grid=" << _Mat.Grid() << " _Mat.RedBlackGrid=" << _Mat.RedBlackGrid() << std::endl; - tmp.Checkerboard() = !in.Checkerboard(); + template + class SchurOperatorBase : public LinearOperatorBase { + public: + virtual RealD Mpc (const Field &in, Field &out) =0; + virtual RealD MpcDag (const Field &in, Field &out) =0; + virtual void MpcDagMpc(const Field &in, Field &out,RealD &ni,RealD &no) { + Field tmp(in.Grid()); + tmp.Checkerboard() = in.Checkerboard(); + ni=Mpc(in,tmp); + no=MpcDag(tmp,out); + } + virtual void HermOpAndNorm(const Field &in, Field &out,RealD &n1,RealD &n2){ + out.Checkerboard() = in.Checkerboard(); + MpcDagMpc(in,out,n1,n2); + } + virtual void HermOp(const Field &in, Field &out){ + RealD n1,n2; + HermOpAndNorm(in,out,n1,n2); + } + void Op (const Field &in, Field &out){ + Mpc(in,out); + } + void AdjOp (const Field &in, Field &out){ + MpcDag(in,out); + } + // Support for coarsening to a multigrid + void OpDiag (const Field &in, Field &out) { + assert(0); // must coarsen the unpreconditioned system + } + void OpDir (const Field &in, Field &out,int dir,int disp) { + assert(0); + } + }; + template + class SchurDiagMooeeOperator : public SchurOperatorBase { + public: + Matrix &_Mat; + SchurDiagMooeeOperator (Matrix &Mat): _Mat(Mat){}; + virtual RealD Mpc (const Field &in, Field &out) { + Field tmp(in.Grid()); + tmp.Checkerboard() = !in.Checkerboard(); + //std::cout <<"grid pointers: in._grid="<< in._grid << " out._grid=" << out._grid << " _Mat.Grid=" << _Mat.Grid() << " _Mat.RedBlackGrid=" << _Mat.RedBlackGrid() << std::endl; - _Mat.Meooe(in,tmp); - _Mat.MooeeInv(tmp,out); - _Mat.Meooe(out,tmp); + _Mat.Meooe(in,tmp); + _Mat.MooeeInv(tmp,out); + _Mat.Meooe(out,tmp); //std::cout << "cb in " << in.Checkerboard() << " cb out " << out.Checkerboard() << std::endl; - _Mat.Mooee(in,out); - return axpy_norm(out,-1.0,tmp,out); - } - virtual RealD MpcDag (const Field &in, Field &out){ - Field tmp(in.Grid()); + _Mat.Mooee(in,out); + return axpy_norm(out,-1.0,tmp,out); + } + virtual RealD MpcDag (const Field &in, Field &out){ + Field tmp(in.Grid()); - _Mat.MeooeDag(in,tmp); - _Mat.MooeeInvDag(tmp,out); - _Mat.MeooeDag(out,tmp); + _Mat.MeooeDag(in,tmp); + _Mat.MooeeInvDag(tmp,out); + _Mat.MeooeDag(out,tmp); - _Mat.MooeeDag(in,out); - return axpy_norm(out,-1.0,tmp,out); - } -}; -template -class SchurDiagOneOperator : public SchurOperatorBase { -protected: - Matrix &_Mat; -public: - SchurDiagOneOperator (Matrix &Mat): _Mat(Mat){}; + _Mat.MooeeDag(in,out); + return axpy_norm(out,-1.0,tmp,out); + } + }; + template + class SchurDiagOneOperator : public SchurOperatorBase { + protected: + Matrix &_Mat; + public: + SchurDiagOneOperator (Matrix &Mat): _Mat(Mat){}; - virtual RealD Mpc (const Field &in, Field &out) { - Field tmp(in.Grid()); + virtual RealD Mpc (const Field &in, Field &out) { + Field tmp(in.Grid()); - _Mat.Meooe(in,out); - _Mat.MooeeInv(out,tmp); - _Mat.Meooe(tmp,out); - _Mat.MooeeInv(out,tmp); + _Mat.Meooe(in,out); + _Mat.MooeeInv(out,tmp); + _Mat.Meooe(tmp,out); + _Mat.MooeeInv(out,tmp); - return axpy_norm(out,-1.0,tmp,in); - } - virtual RealD MpcDag (const Field &in, Field &out){ - Field tmp(in.Grid()); + return axpy_norm(out,-1.0,tmp,in); + } + virtual RealD MpcDag (const Field &in, Field &out){ + Field tmp(in.Grid()); - _Mat.MooeeInvDag(in,out); - _Mat.MeooeDag(out,tmp); - _Mat.MooeeInvDag(tmp,out); - _Mat.MeooeDag(out,tmp); + _Mat.MooeeInvDag(in,out); + _Mat.MeooeDag(out,tmp); + _Mat.MooeeInvDag(tmp,out); + _Mat.MeooeDag(out,tmp); - return axpy_norm(out,-1.0,tmp,in); - } -}; -template -class SchurDiagTwoOperator : public SchurOperatorBase { -protected: - Matrix &_Mat; -public: - SchurDiagTwoOperator (Matrix &Mat): _Mat(Mat){}; + return axpy_norm(out,-1.0,tmp,in); + } + }; + template + class SchurDiagTwoOperator : public SchurOperatorBase { + protected: + Matrix &_Mat; + public: + SchurDiagTwoOperator (Matrix &Mat): _Mat(Mat){}; - virtual RealD Mpc (const Field &in, Field &out) { - Field tmp(in.Grid()); + virtual RealD Mpc (const Field &in, Field &out) { + Field tmp(in.Grid()); - _Mat.MooeeInv(in,out); - _Mat.Meooe(out,tmp); - _Mat.MooeeInv(tmp,out); - _Mat.Meooe(out,tmp); + _Mat.MooeeInv(in,out); + _Mat.Meooe(out,tmp); + _Mat.MooeeInv(tmp,out); + _Mat.Meooe(out,tmp); - return axpy_norm(out,-1.0,tmp,in); - } - virtual RealD MpcDag (const Field &in, Field &out){ - Field tmp(in.Grid()); + return axpy_norm(out,-1.0,tmp,in); + } + virtual RealD MpcDag (const Field &in, Field &out){ + Field tmp(in.Grid()); - _Mat.MeooeDag(in,out); - _Mat.MooeeInvDag(out,tmp); - _Mat.MeooeDag(tmp,out); - _Mat.MooeeInvDag(out,tmp); + _Mat.MeooeDag(in,out); + _Mat.MooeeInvDag(out,tmp); + _Mat.MeooeDag(tmp,out); + _Mat.MooeeInvDag(out,tmp); - return axpy_norm(out,-1.0,tmp,in); - } -}; -/////////////////////////////////////////////////////////////////////////////////////////////////// -// Left handed Moo^-1 ; (Moo - Moe Mee^-1 Meo) psi = eta --> ( 1 - Moo^-1 Moe Mee^-1 Meo ) psi = Moo^-1 eta -// Right handed Moo^-1 ; (Moo - Moe Mee^-1 Meo) Moo^-1 Moo psi = eta --> ( 1 - Moe Mee^-1 Meo ) Moo^-1 phi=eta ; psi = Moo^-1 phi -/////////////////////////////////////////////////////////////////////////////////////////////////// -template using SchurDiagOneRH = SchurDiagTwoOperator ; -template using SchurDiagOneLH = SchurDiagOneOperator ; -/////////////////////////////////////////////////////////////////////////////////////////////////// -// Staggered use -/////////////////////////////////////////////////////////////////////////////////////////////////// -template -class SchurStaggeredOperator : public SchurOperatorBase { -protected: - Matrix &_Mat; + return axpy_norm(out,-1.0,tmp,in); + } + }; + /////////////////////////////////////////////////////////////////////////////////////////////////// + // Left handed Moo^-1 ; (Moo - Moe Mee^-1 Meo) psi = eta --> ( 1 - Moo^-1 Moe Mee^-1 Meo ) psi = Moo^-1 eta + // Right handed Moo^-1 ; (Moo - Moe Mee^-1 Meo) Moo^-1 Moo psi = eta --> ( 1 - Moe Mee^-1 Meo ) Moo^-1 phi=eta ; psi = Moo^-1 phi + /////////////////////////////////////////////////////////////////////////////////////////////////// + template using SchurDiagOneRH = SchurDiagTwoOperator ; + template using SchurDiagOneLH = SchurDiagOneOperator ; + /////////////////////////////////////////////////////////////////////////////////////////////////// + // Staggered use + /////////////////////////////////////////////////////////////////////////////////////////////////// + template + class SchurStaggeredOperator : public SchurOperatorBase { + protected: + Matrix &_Mat; Field tmp; RealD mass; double tMpc; diff --git a/Grid/algorithms/SparseMatrix.h b/Grid/algorithms/SparseMatrix.h index c1473e56..ffed7527 100644 --- a/Grid/algorithms/SparseMatrix.h +++ b/Grid/algorithms/SparseMatrix.h @@ -60,7 +60,7 @@ public: // Query the even even properties to make algorithmic decisions ////////////////////////////////////////////////////////////////////// virtual RealD Mass(void) { return 0.0; }; - virtual int ConstEE(void) { return 0; }; // Disable assumptions unless overridden + virtual int ConstEE(void) { return 1; }; // Disable assumptions unless overridden virtual int isTrivialEE(void) { return 0; }; // by a derived class that knows better // half checkerboard operaions diff --git a/Grid/algorithms/iterative/ConjugateGradient.h b/Grid/algorithms/iterative/ConjugateGradient.h index a67c8981..398f578f 100644 --- a/Grid/algorithms/iterative/ConjugateGradient.h +++ b/Grid/algorithms/iterative/ConjugateGradient.h @@ -93,6 +93,8 @@ public: // Check if guess is really REALLY good :) if (cp <= rsq) { + std::cout << GridLogMessage << "ConjugateGradient guess is converged already " << std::endl; + IterationsToComplete = 0; return; } @@ -108,7 +110,7 @@ public: SolverTimer.Start(); int k; - for (k = 1; k <= MaxIterations*1000; k++) { + for (k = 1; k <= MaxIterations; k++) { c = cp; MatrixTimer.Start(); @@ -172,8 +174,7 @@ public: return; } } - std::cout << GridLogMessage << "ConjugateGradient did NOT converge" - << std::endl; + std::cout << GridLogMessage << "ConjugateGradient did NOT converge "< NAMESPACE_BEGIN(Grid); -//Mixed precision restarted defect correction CG -template::value == 2, int>::type = 0, - typename std::enable_if< getPrecision::value == 1, int>::type = 0> -class MixedPrecisionConjugateGradient : public LinearFunction { -public: - RealD Tolerance; - RealD InnerTolerance; //Initial tolerance for inner CG. Defaults to Tolerance but can be changed - Integer MaxInnerIterations; - Integer MaxOuterIterations; - GridBase* SinglePrecGrid; //Grid for single-precision fields - RealD OuterLoopNormMult; //Stop the outer loop and move to a final double prec solve when the residual is OuterLoopNormMult * Tolerance - LinearOperatorBase &Linop_f; - LinearOperatorBase &Linop_d; + //Mixed precision restarted defect correction CG + template::value == 2, int>::type = 0, + typename std::enable_if< getPrecision::value == 1, int>::type = 0> + class MixedPrecisionConjugateGradient : public LinearFunction { + public: + RealD Tolerance; + RealD InnerTolerance; //Initial tolerance for inner CG. Defaults to Tolerance but can be changed + Integer MaxInnerIterations; + Integer MaxOuterIterations; + GridBase* SinglePrecGrid; //Grid for single-precision fields + RealD OuterLoopNormMult; //Stop the outer loop and move to a final double prec solve when the residual is OuterLoopNormMult * Tolerance + LinearOperatorBase &Linop_f; + LinearOperatorBase &Linop_d; - Integer TotalInnerIterations; //Number of inner CG iterations - Integer TotalOuterIterations; //Number of restarts - Integer TotalFinalStepIterations; //Number of CG iterations in final patch-up step + Integer TotalInnerIterations; //Number of inner CG iterations + Integer TotalOuterIterations; //Number of restarts + Integer TotalFinalStepIterations; //Number of CG iterations in final patch-up step - //Option to speed up *inner single precision* solves using a LinearFunction that produces a guess - LinearFunction *guesser; + //Option to speed up *inner single precision* solves using a LinearFunction that produces a guess + LinearFunction *guesser; - MixedPrecisionConjugateGradient(RealD tol, Integer maxinnerit, Integer maxouterit, GridBase* _sp_grid, LinearOperatorBase &_Linop_f, LinearOperatorBase &_Linop_d) : - Linop_f(_Linop_f), Linop_d(_Linop_d), - Tolerance(tol), InnerTolerance(tol), MaxInnerIterations(maxinnerit), MaxOuterIterations(maxouterit), SinglePrecGrid(_sp_grid), - OuterLoopNormMult(100.), guesser(NULL){ }; + MixedPrecisionConjugateGradient(RealD tol, + Integer maxinnerit, + Integer maxouterit, + GridBase* _sp_grid, + LinearOperatorBase &_Linop_f, + LinearOperatorBase &_Linop_d) : + Linop_f(_Linop_f), Linop_d(_Linop_d), + Tolerance(tol), InnerTolerance(tol), MaxInnerIterations(maxinnerit), MaxOuterIterations(maxouterit), SinglePrecGrid(_sp_grid), + OuterLoopNormMult(100.), guesser(NULL){ }; - void useGuesser(LinearFunction &g){ - guesser = &g; - } + void useGuesser(LinearFunction &g){ + guesser = &g; + } void operator() (const FieldD &src_d_in, FieldD &sol_d){ TotalInnerIterations = 0; diff --git a/Grid/algorithms/iterative/Deflation.h b/Grid/algorithms/iterative/Deflation.h index 509970c7..626b60e3 100644 --- a/Grid/algorithms/iterative/Deflation.h +++ b/Grid/algorithms/iterative/Deflation.h @@ -35,7 +35,11 @@ class ZeroGuesser: public LinearFunction { public: virtual void operator()(const Field &src, Field &guess) { guess = Zero(); }; }; - +template +class DoNothingGuesser: public LinearFunction { +public: + virtual void operator()(const Field &src, Field &guess) { }; +}; template class SourceGuesser: public LinearFunction { public: diff --git a/Grid/algorithms/iterative/PowerMethod.h b/Grid/algorithms/iterative/PowerMethod.h new file mode 100644 index 00000000..e85f258c --- /dev/null +++ b/Grid/algorithms/iterative/PowerMethod.h @@ -0,0 +1,45 @@ +#pragma once +namespace Grid { +template class PowerMethod +{ + public: + + template static RealD normalise(T& v) + { + RealD nn = norm2(v); + nn = sqrt(nn); + v = v * (1.0/nn); + return nn; + } + + RealD operator()(LinearOperatorBase &HermOp, const Field &src) + { + GridBase *grid = src._grid; + + // quickly get an idea of the largest eigenvalue to more properly normalize the residuum + RealD evalMaxApprox = 0.0; + auto src_n = src; + auto tmp = src; + const int _MAX_ITER_EST_ = 50; + + for (int i=0;i<_MAX_ITER_EST_;i++) { + + normalise(src_n); + HermOp.HermOp(src_n,tmp); + RealD vnum = real(innerProduct(src_n,tmp)); // HermOp. + RealD vden = norm2(src_n); + RealD na = vnum/vden; + + if ( (fabs(evalMaxApprox/na - 1.0) < 0.01) || (i==_MAX_ITER_EST_-1) ) { + evalMaxApprox = na; + return evalMaxApprox; + } + evalMaxApprox = na; + std::cout << GridLogMessage << " Approximation of largest eigenvalue: " << evalMaxApprox << std::endl; + src_n = tmp; + } + assert(0); + return 0; + } +}; +} diff --git a/Grid/algorithms/iterative/SchurRedBlack.h b/Grid/algorithms/iterative/SchurRedBlack.h index 4b9a2ed8..dd8a14b6 100644 --- a/Grid/algorithms/iterative/SchurRedBlack.h +++ b/Grid/algorithms/iterative/SchurRedBlack.h @@ -99,10 +99,13 @@ namespace Grid { OperatorFunction & _HermitianRBSolver; int CBfactorise; bool subGuess; + bool useSolnAsInitGuess; // if true user-supplied solution vector is used as initial guess for solver public: - SchurRedBlackBase(OperatorFunction &HermitianRBSolver, const bool initSubGuess = false) : - _HermitianRBSolver(HermitianRBSolver) + SchurRedBlackBase(OperatorFunction &HermitianRBSolver, const bool initSubGuess = false, + const bool _solnAsInitGuess = false) : + _HermitianRBSolver(HermitianRBSolver), + useSolnAsInitGuess(_solnAsInitGuess) { CBfactorise = 0; subtractGuess(initSubGuess); @@ -156,7 +159,11 @@ namespace Grid { if ( subGuess ) guess_save.resize(nblock,grid); for(int b=0;b Matrix; - SchurRedBlackStaggeredSolve(OperatorFunction &HermitianRBSolver, const bool initSubGuess = false) - : SchurRedBlackBase (HermitianRBSolver,initSubGuess) + SchurRedBlackStaggeredSolve(OperatorFunction &HermitianRBSolver, const bool initSubGuess = false, + const bool _solnAsInitGuess = false) + : SchurRedBlackBase (HermitianRBSolver,initSubGuess,_solnAsInitGuess) { } @@ -333,8 +344,9 @@ namespace Grid { public: typedef CheckerBoardedSparseMatrixBase Matrix; - SchurRedBlackDiagMooeeSolve(OperatorFunction &HermitianRBSolver, const bool initSubGuess = false) - : SchurRedBlackBase (HermitianRBSolver,initSubGuess) {}; + SchurRedBlackDiagMooeeSolve(OperatorFunction &HermitianRBSolver, const bool initSubGuess = false, + const bool _solnAsInitGuess = false) + : SchurRedBlackBase (HermitianRBSolver,initSubGuess,_solnAsInitGuess) {}; ////////////////////////////////////////////////////// @@ -405,8 +417,9 @@ namespace Grid { ///////////////////////////////////////////////////// // Wrap the usual normal equations Schur trick ///////////////////////////////////////////////////// - SchurRedBlackDiagTwoSolve(OperatorFunction &HermitianRBSolver, const bool initSubGuess = false) - : SchurRedBlackBase(HermitianRBSolver,initSubGuess) {}; + SchurRedBlackDiagTwoSolve(OperatorFunction &HermitianRBSolver, const bool initSubGuess = false, + const bool _solnAsInitGuess = false) + : SchurRedBlackBase(HermitianRBSolver,initSubGuess,_solnAsInitGuess) {}; virtual void RedBlackSource(Matrix & _Matrix,const Field &src, Field &src_e,Field &src_o) { diff --git a/Grid/communicator/Communicator_mpi3.cc b/Grid/communicator/Communicator_mpi3.cc index 4d02c7b9..2576b1fa 100644 --- a/Grid/communicator/Communicator_mpi3.cc +++ b/Grid/communicator/Communicator_mpi3.cc @@ -44,10 +44,13 @@ void CartesianCommunicator::Init(int *argc, char ***argv) MPI_Initialized(&flag); // needed to coexist with other libs apparently if ( !flag ) { MPI_Init_thread(argc,argv,MPI_THREAD_MULTIPLE,&provided); - // assert (provided == MPI_THREAD_MULTIPLE); + //If only 1 comms thread we require any threading mode other than SINGLE, but for multiple comms threads we need MULTIPLE - if( (nCommThreads == 1 && provided == MPI_THREAD_SINGLE) || - (nCommThreads > 1 && provided != MPI_THREAD_MULTIPLE) ) { + if( (nCommThreads == 1) && (provided == MPI_THREAD_SINGLE) ) { + assert(0); + } + + if( (nCommThreads > 1) && (provided != MPI_THREAD_MULTIPLE) ) { assert(0); } } @@ -55,9 +58,12 @@ void CartesianCommunicator::Init(int *argc, char ***argv) // Never clean up as done once. MPI_Comm_dup (MPI_COMM_WORLD,&communicator_world); + Grid_quiesce_nodes(); GlobalSharedMemory::Init(communicator_world); - GlobalSharedMemory::SharedMemoryAllocate(GlobalSharedMemory::MAX_MPI_SHM_BYTES, - GlobalSharedMemory::Hugepages); + GlobalSharedMemory::SharedMemoryAllocate( + GlobalSharedMemory::MAX_MPI_SHM_BYTES, + GlobalSharedMemory::Hugepages); + Grid_unquiesce_nodes(); } /////////////////////////////////////////////////////////////////////////// @@ -106,8 +112,7 @@ CartesianCommunicator::CartesianCommunicator(const Coordinate &processors) ////////////////////////////////// CartesianCommunicator::CartesianCommunicator(const Coordinate &processors,const CartesianCommunicator &parent,int &srank) { - _ndimension = processors.size(); - + _ndimension = processors.size(); assert(_ndimension>=1); int parent_ndimension = parent._ndimension; assert(_ndimension >= parent._ndimension); Coordinate parent_processor_coor(_ndimension,0); Coordinate parent_processors (_ndimension,1); diff --git a/Grid/communicator/Communicator_none.cc b/Grid/communicator/Communicator_none.cc index d9c4e558..b8a15a0e 100644 --- a/Grid/communicator/Communicator_none.cc +++ b/Grid/communicator/Communicator_none.cc @@ -52,7 +52,7 @@ CartesianCommunicator::CartesianCommunicator(const Coordinate &processors,const CartesianCommunicator::CartesianCommunicator(const Coordinate &processors) { _processors = processors; - _ndimension = processors.size(); + _ndimension = processors.size(); assert(_ndimension>=1); _processor_coor.resize(_ndimension); // Require 1^N processor grid for fake diff --git a/Grid/communicator/SharedMemory.h b/Grid/communicator/SharedMemory.h index fc9366b2..439d0ae2 100644 --- a/Grid/communicator/SharedMemory.h +++ b/Grid/communicator/SharedMemory.h @@ -90,7 +90,9 @@ public: // Create an optimal reordered communicator that makes MPI_Cart_create get it right ////////////////////////////////////////////////////////////////////////////////////// static void Init(Grid_MPI_Comm comm); // Typically MPI_COMM_WORLD - static void OptimalCommunicator(const Coordinate &processors,Grid_MPI_Comm & optimal_comm); // Turns MPI_COMM_WORLD into right layout for Cartesian + static void OptimalCommunicator (const Coordinate &processors,Grid_MPI_Comm & optimal_comm); // Turns MPI_COMM_WORLD into right layout for Cartesian + static void OptimalCommunicatorHypercube (const Coordinate &processors,Grid_MPI_Comm & optimal_comm); // Turns MPI_COMM_WORLD into right layout for Cartesian + static void OptimalCommunicatorSharedMemory(const Coordinate &processors,Grid_MPI_Comm & optimal_comm); // Turns MPI_COMM_WORLD into right layout for Cartesian /////////////////////////////////////////////////// // Provide shared memory facilities off comm world /////////////////////////////////////////////////// diff --git a/Grid/communicator/SharedMemoryMPI.cc b/Grid/communicator/SharedMemoryMPI.cc index 4ba9449a..926c7c94 100644 --- a/Grid/communicator/SharedMemoryMPI.cc +++ b/Grid/communicator/SharedMemoryMPI.cc @@ -141,8 +141,22 @@ int Log2Size(int TwoToPower,int MAXLOG2) } void GlobalSharedMemory::OptimalCommunicator(const Coordinate &processors,Grid_MPI_Comm & optimal_comm) { -#ifdef HYPERCUBE -#warning "HPE 8600 Hypercube optimisations enabled" + ////////////////////////////////////////////////////////////////////////////// + // Look and see if it looks like an HPE 8600 based on hostname conventions + ////////////////////////////////////////////////////////////////////////////// + const int namelen = _POSIX_HOST_NAME_MAX; + char name[namelen]; + int R; + int I; + int N; + gethostname(name,namelen); + int nscan = sscanf(name,"r%di%dn%d",&R,&I,&N) ; + + if(nscan==3) OptimalCommunicatorHypercube(processors,optimal_comm); + else OptimalCommunicatorSharedMemory(processors,optimal_comm); +} +void GlobalSharedMemory::OptimalCommunicatorHypercube(const Coordinate &processors,Grid_MPI_Comm & optimal_comm) +{ //////////////////////////////////////////////////////////////// // Assert power of two shm_size. //////////////////////////////////////////////////////////////// @@ -208,7 +222,8 @@ void GlobalSharedMemory::OptimalCommunicator(const Coordinate &processors,Grid_M //////////////////////////////////////////////////////////////// int ndimension = processors.size(); std::vector processor_coor(ndimension); - std::vector WorldDims = processors; std::vector ShmDims (ndimension,1); std::vector NodeDims (ndimension); + std::vector WorldDims = processors.toVector(); + std::vector ShmDims (ndimension,1); std::vector NodeDims (ndimension); std::vector ShmCoor (ndimension); std::vector NodeCoor (ndimension); std::vector WorldCoor(ndimension); std::vector HyperCoor(ndimension); int dim = 0; @@ -263,7 +278,9 @@ void GlobalSharedMemory::OptimalCommunicator(const Coordinate &processors,Grid_M ///////////////////////////////////////////////////////////////// int ierr= MPI_Comm_split(WorldComm,0,rank,&optimal_comm); assert(ierr==0); -#else +} +void GlobalSharedMemory::OptimalCommunicatorSharedMemory(const Coordinate &processors,Grid_MPI_Comm & optimal_comm) +{ //////////////////////////////////////////////////////////////// // Assert power of two shm_size. //////////////////////////////////////////////////////////////// @@ -316,7 +333,6 @@ void GlobalSharedMemory::OptimalCommunicator(const Coordinate &processors,Grid_M ///////////////////////////////////////////////////////////////// int ierr= MPI_Comm_split(WorldComm,0,rank,&optimal_comm); assert(ierr==0); -#endif } //////////////////////////////////////////////////////////////////////////////////////////// // SHMGET @@ -347,7 +363,7 @@ void GlobalSharedMemory::SharedMemoryAllocate(uint64_t bytes, int flags) int errsv = errno; printf("Errno %d\n",errsv); printf("key %d\n",key); - printf("size %lld\n",size); + printf("size %ld\n",size); printf("flags %d\n",flags); perror("shmget"); exit(1); diff --git a/Grid/log/Log.cc b/Grid/log/Log.cc index cbeb8b78..9302b4cc 100644 --- a/Grid/log/Log.cc +++ b/Grid/log/Log.cc @@ -77,19 +77,18 @@ void GridLogConfigure(std::vector &logstreams) { GridLogIterative.Active(0); GridLogDebug.Active(0); GridLogPerformance.Active(0); - GridLogIntegrator.Active(0); + GridLogIntegrator.Active(1); GridLogColours.Active(0); for (int i = 0; i < logstreams.size(); i++) { - if (logstreams[i] == std::string("Error")) GridLogError.Active(1); - if (logstreams[i] == std::string("Warning")) GridLogWarning.Active(1); - if (logstreams[i] == std::string("NoMessage")) GridLogMessage.Active(0); - if (logstreams[i] == std::string("Iterative")) GridLogIterative.Active(1); - if (logstreams[i] == std::string("Debug")) GridLogDebug.Active(1); - if (logstreams[i] == std::string("Performance")) - GridLogPerformance.Active(1); - if (logstreams[i] == std::string("Integrator")) GridLogIntegrator.Active(1); - if (logstreams[i] == std::string("Colours")) GridLogColours.Active(1); + if (logstreams[i] == std::string("Error")) GridLogError.Active(1); + if (logstreams[i] == std::string("Warning")) GridLogWarning.Active(1); + if (logstreams[i] == std::string("NoMessage")) GridLogMessage.Active(0); + if (logstreams[i] == std::string("Iterative")) GridLogIterative.Active(1); + if (logstreams[i] == std::string("Debug")) GridLogDebug.Active(1); + if (logstreams[i] == std::string("Performance")) GridLogPerformance.Active(1); + if (logstreams[i] == std::string("Integrator")) GridLogIntegrator.Active(1); + if (logstreams[i] == std::string("Colours")) GridLogColours.Active(1); } } diff --git a/Grid/parallelIO/BinaryIO.h b/Grid/parallelIO/BinaryIO.h index 3a75cbfe..f90c34a9 100644 --- a/Grid/parallelIO/BinaryIO.h +++ b/Grid/parallelIO/BinaryIO.h @@ -204,10 +204,10 @@ class BinaryIO { static inline void le32toh_v(void *file_object,uint64_t bytes) { uint32_t *fp = (uint32_t *)file_object; - uint32_t f; uint64_t count = bytes/sizeof(uint32_t); thread_for(i,count,{ + uint32_t f; f = fp[i]; // got network order and the network to host f = ((f&0xFF)<<24) | ((f&0xFF00)<<8) | ((f&0xFF0000)>>8) | ((f&0xFF000000UL)>>24) ; @@ -229,10 +229,9 @@ class BinaryIO { static inline void le64toh_v(void *file_object,uint64_t bytes) { uint64_t *fp = (uint64_t *)file_object; - uint64_t f,g; - uint64_t count = bytes/sizeof(uint64_t); thread_for( i, count, { + uint64_t f,g; f = fp[i]; // got network order and the network to host g = ((f&0xFF)<<24) | ((f&0xFF00)<<8) | ((f&0xFF0000)>>8) | ((f&0xFF000000UL)>>24) ; @@ -343,7 +342,8 @@ class BinaryIO { int ieee32 = (format == std::string("IEEE32")); int ieee64big = (format == std::string("IEEE64BIG")); int ieee64 = (format == std::string("IEEE64")); - + assert(ieee64||ieee32|ieee64big||ieee32big); + assert((ieee64+ieee32+ieee64big+ieee32big)==1); ////////////////////////////////////////////////////////////////////////////// // Do the I/O ////////////////////////////////////////////////////////////////////////////// @@ -613,6 +613,7 @@ class BinaryIO { { std::cout << GridLogMessage << "writeLatticeObject: read test checksum failure, re-writing (" << attemptsLeft << " attempt(s) remaining)" << std::endl; offset = offsetCopy; + thread_for(x,lsites, { munge(scalardata[x],iodata[x]); }); } else { diff --git a/Grid/parallelIO/IldgIO.h b/Grid/parallelIO/IldgIO.h index e1503ea1..b564371b 100644 --- a/Grid/parallelIO/IldgIO.h +++ b/Grid/parallelIO/IldgIO.h @@ -44,6 +44,12 @@ extern "C" { NAMESPACE_BEGIN(Grid); +#define GRID_FIELD_NORM "FieldNormMetaData" +#define GRID_FIELD_NORM_CALC(FieldNormMetaData_, n2ck) \ +0.5*fabs(FieldNormMetaData_.norm2 - n2ck)/(FieldNormMetaData_.norm2 + n2ck) +#define GRID_FIELD_NORM_CHECK(FieldNormMetaData_, n2ck) \ +assert(GRID_FIELD_NORM_CALC(FieldNormMetaData_, n2ck) < 1.0e-5); + ///////////////////////////////// // Encode word types as strings ///////////////////////////////// @@ -203,6 +209,7 @@ class GridLimeReader : public BinaryIO { { typedef typename vobj::scalar_object sobj; scidacChecksum scidacChecksum_; + FieldNormMetaData FieldNormMetaData_; uint32_t nersc_csum,scidac_csuma,scidac_csumb; std::string format = getFormatString(); @@ -231,21 +238,52 @@ class GridLimeReader : public BinaryIO { // std::cout << " ReadLatticeObject from offset "< munge; BinaryIO::readLatticeObject< vobj, sobj >(field, filename, munge, offset, format,nersc_csum,scidac_csuma,scidac_csumb); - std::cout << GridLogMessage << "SciDAC checksum A " << std::hex << scidac_csuma << std::dec << std::endl; - std::cout << GridLogMessage << "SciDAC checksum B " << std::hex << scidac_csumb << std::dec << std::endl; + std::cout << GridLogMessage << "SciDAC checksum A " << std::hex << scidac_csuma << std::dec << std::endl; + std::cout << GridLogMessage << "SciDAC checksum B " << std::hex << scidac_csumb << std::dec << std::endl; ///////////////////////////////////////////// // Insist checksum is next record ///////////////////////////////////////////// - readLimeObject(scidacChecksum_,std::string("scidacChecksum"),std::string(SCIDAC_CHECKSUM)); - + readScidacChecksum(scidacChecksum_,FieldNormMetaData_); ///////////////////////////////////////////// // Verify checksums ///////////////////////////////////////////// + if(FieldNormMetaData_.norm2 != 0.0){ + RealD n2ck = norm2(field); + std::cout << GridLogMessage << "Field norm: metadata= " << FieldNormMetaData_.norm2 + << " / field= " << n2ck << " / rdiff= " << GRID_FIELD_NORM_CALC(FieldNormMetaData_,n2ck) << std::endl; + GRID_FIELD_NORM_CHECK(FieldNormMetaData_,n2ck); + } assert(scidacChecksumVerify(scidacChecksum_,scidac_csuma,scidac_csumb)==1); + + // find out if next field is a GridFieldNorm return; } } } + void readScidacChecksum(scidacChecksum &scidacChecksum_, + FieldNormMetaData &FieldNormMetaData_) + { + FieldNormMetaData_.norm2 =0.0; + std::string scidac_str(SCIDAC_CHECKSUM); + std::string field_norm_str(GRID_FIELD_NORM); + while ( limeReaderNextRecord(LimeR) == LIME_SUCCESS ) { + uint64_t nbytes = limeReaderBytes(LimeR);//size of this record (configuration) + std::vector xmlc(nbytes+1,'\0'); + limeReaderReadData((void *)&xmlc[0], &nbytes, LimeR); + std::string xmlstring = std::string(&xmlc[0]); + XmlReader RD(xmlstring, true, ""); + if ( !strncmp(limeReaderType(LimeR), field_norm_str.c_str(),strlen(field_norm_str.c_str()) ) ) { + // std::cout << "FieldNormMetaData "<IsBoss() ); + FieldNormMetaData FNMD; FNMD.norm2 = norm2(field); + //////////////////////////////////////////// // Create record header //////////////////////////////////////////// @@ -446,6 +486,7 @@ class GridLimeWriter : public BinaryIO checksum.suma= streama.str(); checksum.sumb= streamb.str(); if ( boss_node ) { + writeLimeObject(0,0,FNMD,std::string(GRID_FIELD_NORM),std::string(GRID_FIELD_NORM)); writeLimeObject(0,1,checksum,std::string("scidacChecksum"),std::string(SCIDAC_CHECKSUM)); } } @@ -623,6 +664,12 @@ class IldgWriter : public ScidacWriter { assert(header.nd==4); assert(header.nd==header.dimension.size()); + ////////////////////////////////////////////////////////////////////////////// + // Field norm tests + ////////////////////////////////////////////////////////////////////////////// + FieldNormMetaData FieldNormMetaData_; + FieldNormMetaData_.norm2 = norm2(Umu); + ////////////////////////////////////////////////////////////////////////////// // Fill the USQCD info field ////////////////////////////////////////////////////////////////////////////// @@ -631,11 +678,12 @@ class IldgWriter : public ScidacWriter { info.plaq = header.plaquette; info.linktr = header.link_trace; - std::cout << GridLogMessage << " Writing config; IldgIO "< munge; @@ -845,6 +900,13 @@ class IldgReader : public GridLimeReader { //////////////////////////////////////////////////////////// // Really really want to mandate a scidac checksum //////////////////////////////////////////////////////////// + if ( found_FieldNormMetaData ) { + RealD nn = norm2(Umu); + GRID_FIELD_NORM_CHECK(FieldNormMetaData_,nn); + std::cout << GridLogMessage<<"FieldNormMetaData matches " << std::endl; + } else { + std::cout << GridLogWarning<<"FieldNormMetaData not found. " << std::endl; + } if ( found_scidacChecksum ) { FieldMetaData_.scidac_checksuma = stoull(scidacChecksum_.suma,0,16); FieldMetaData_.scidac_checksumb = stoull(scidacChecksum_.sumb,0,16); diff --git a/Grid/parallelIO/MetaData.h b/Grid/parallelIO/MetaData.h index 88a600e5..2e211838 100644 --- a/Grid/parallelIO/MetaData.h +++ b/Grid/parallelIO/MetaData.h @@ -52,35 +52,40 @@ template static std::string getFormatString (void) format = std::string("IEEE64BIG"); } return format; -} -//////////////////////////////////////////////////////////////////////////////// -// header specification/interpretation -//////////////////////////////////////////////////////////////////////////////// -class FieldMetaData : Serializable { -public: +}; - GRID_SERIALIZABLE_CLASS_MEMBERS(FieldMetaData, - int, nd, - std::vector, dimension, - std::vector, boundary, - int, data_start, - std::string, hdr_version, - std::string, storage_format, - double, link_trace, - double, plaquette, - uint32_t, checksum, - uint32_t, scidac_checksuma, - uint32_t, scidac_checksumb, - unsigned int, sequence_number, - std::string, data_type, - std::string, ensemble_id, - std::string, ensemble_label, - std::string, ildg_lfn, - std::string, creator, - std::string, creator_hardware, - std::string, creation_date, - std::string, archive_date, - std::string, floating_point); + //////////////////////////////////////////////////////////////////////////////// + // header specification/interpretation + //////////////////////////////////////////////////////////////////////////////// + class FieldNormMetaData : Serializable { + public: + GRID_SERIALIZABLE_CLASS_MEMBERS(FieldNormMetaData, double, norm2); + }; + class FieldMetaData : Serializable { + public: + + GRID_SERIALIZABLE_CLASS_MEMBERS(FieldMetaData, + int, nd, + std::vector, dimension, + std::vector, boundary, + int, data_start, + std::string, hdr_version, + std::string, storage_format, + double, link_trace, + double, plaquette, + uint32_t, checksum, + uint32_t, scidac_checksuma, + uint32_t, scidac_checksumb, + unsigned int, sequence_number, + std::string, data_type, + std::string, ensemble_id, + std::string, ensemble_label, + std::string, ildg_lfn, + std::string, creator, + std::string, creator_hardware, + std::string, creation_date, + std::string, archive_date, + std::string, floating_point); // WARNING: non-initialised values might lead to twisted parallel IO // issues, std::string are fine because they initliase to size 0 // as per C++ standard. @@ -89,7 +94,7 @@ public: link_trace(0.), plaquette(0.), checksum(0), scidac_checksuma(0), scidac_checksumb(0), sequence_number(0) {} -}; + }; // PB disable using namespace - this is a header and forces namesapce visibility for all // including files diff --git a/Grid/qcd/action/ActionParams.h b/Grid/qcd/action/ActionParams.h index 1c34ce86..0e6a11c6 100644 --- a/Grid/qcd/action/ActionParams.h +++ b/Grid/qcd/action/ActionParams.h @@ -57,14 +57,15 @@ struct StaggeredImplParams { StaggeredImplParams() {}; }; -struct OneFlavourRationalParams : Serializable { - GRID_SERIALIZABLE_CLASS_MEMBERS(OneFlavourRationalParams, - RealD, lo, - RealD, hi, - int, MaxIter, - RealD, tolerance, - int, degree, - int, precision); + struct OneFlavourRationalParams : Serializable { + GRID_SERIALIZABLE_CLASS_MEMBERS(OneFlavourRationalParams, + RealD, lo, + RealD, hi, + int, MaxIter, + RealD, tolerance, + int, degree, + int, precision, + int, BoundsCheckFreq); // MaxIter and tolerance, vectors?? @@ -74,15 +75,17 @@ struct OneFlavourRationalParams : Serializable { int _maxit = 1000, RealD tol = 1.0e-8, int _degree = 10, - int _precision = 64) - : lo(_lo), - hi(_hi), - MaxIter(_maxit), - tolerance(tol), - degree(_degree), - precision(_precision){}; -}; - + int _precision = 64, + int _BoundsCheckFreq=20) + : lo(_lo), + hi(_hi), + MaxIter(_maxit), + tolerance(tol), + degree(_degree), + precision(_precision), + BoundsCheckFreq(_BoundsCheckFreq){}; + }; + NAMESPACE_END(Grid); #endif diff --git a/Grid/qcd/action/fermion/DomainWallFermion.h b/Grid/qcd/action/fermion/DomainWallFermion.h index c8b3755a..e32e5917 100644 --- a/Grid/qcd/action/fermion/DomainWallFermion.h +++ b/Grid/qcd/action/fermion/DomainWallFermion.h @@ -41,7 +41,7 @@ public: INHERIT_IMPL_TYPES(Impl); public: - void FreePropagator(const FermionField &in,FermionField &out,RealD mass, std::vector twist, bool fiveD) { + void FreePropagator(const FermionField &in,FermionField &out,RealD mass,std::vector boundary, std::vector twist, bool fiveD) { FermionField in_k(in.Grid()); FermionField prop_k(in.Grid()); @@ -54,15 +54,19 @@ public: typedef typename Simd::scalar_type Scalar; Scalar ci(0.0,1.0); assert(twist.size() == Nd);//check that twist is Nd + assert(boundary.size() == Nd);//check that boundary conditions is Nd int shift = 0; if(fiveD) shift = 1; for(unsigned int nu = 0; nu < Nd; nu++) { // Shift coordinate lattice index by 1 to account for 5th dimension. LatticeCoordinate(coor, nu + shift); - ph = ph + twist[nu]*coor*((1./(in.Grid()->FullDimensions()[nu+shift]))); + double boundary_phase = ::acos(real(boundary[nu])); + ph = ph + boundary_phase*coor*((1./(in.Grid()->_fdimensions[nu+shift]))); + //momenta for propagator shifted by twist+boundary + twist[nu] = twist[nu] + boundary_phase/((2.0*M_PI)); } - in_buf = exp(Scalar(2.0*M_PI)*ci*ph*(-1.0))*in; + in_buf = exp(ci*ph*(-1.0))*in; if(fiveD){//FFT only on temporal and spatial dimensions std::vector mask(Nd+1,1); mask[0] = 0; @@ -75,26 +79,29 @@ public: this->MomentumSpacePropagatorHt(prop_k,in_k,mass,twist); theFFT.FFT_all_dim(out,prop_k,FFT::backward); } - //phase for boundary condition out = out * exp(Scalar(2.0*M_PI)*ci*ph); }; - virtual void FreePropagator(const FermionField &in,FermionField &out,RealD mass,std::vector twist) { + virtual void FreePropagator(const FermionField &in,FermionField &out,RealD mass,std::vector boundary,std::vector twist) { bool fiveD = true; //5d propagator by default - FreePropagator(in,out,mass,twist,fiveD); + FreePropagator(in,out,mass,boundary,twist,fiveD); }; virtual void FreePropagator(const FermionField &in,FermionField &out,RealD mass, bool fiveD) { std::vector twist(Nd,0.0); //default: periodic boundarys in all directions - FreePropagator(in,out,mass,twist,fiveD); + std::vector boundary; + for(int i=0;i twist(Nd,0.0); //default: periodic boundarys in all directions - FreePropagator(in,out,mass,twist,fiveD); - }; + std::vector twist(Nd,0.0); //default: twist angle 0 + std::vector boundary; + for(int i=0;i twist) { assert(0);}; - virtual void FreePropagator(const FermionField &in,FermionField &out,RealD mass,std::vector twist) + virtual void FreePropagator(const FermionField &in,FermionField &out,RealD mass,std::vector boundary,std::vector twist) { FFT theFFT((GridCartesian *) in.Grid()); @@ -106,27 +106,35 @@ public: ComplexField coor(in.Grid()); ComplexField ph(in.Grid()); ph = Zero(); FermionField in_buf(in.Grid()); in_buf = Zero(); + Scalar ci(0.0,1.0); assert(twist.size() == Nd);//check that twist is Nd + assert(boundary.size() == Nd);//check that boundary conditions is Nd for(unsigned int nu = 0; nu < Nd; nu++) { LatticeCoordinate(coor, nu); - ph = ph + twist[nu]*coor*((1./(in.Grid()->_fdimensions[nu]))); + double boundary_phase = ::acos(real(boundary[nu])); + ph = ph + boundary_phase*coor*((1./(in.Grid()->_fdimensions[nu]))); + //momenta for propagator shifted by twist+boundary + twist[nu] = twist[nu] + boundary_phase/((2.0*M_PI)); } - in_buf = (exp(Scalar(2.0*M_PI)*ci*ph*(-1.0)))*in; + in_buf = exp(ci*ph*(-1.0))*in; theFFT.FFT_all_dim(in_k,in_buf,FFT::forward); this->MomentumSpacePropagator(prop_k,in_k,mass,twist); - theFFT.FFT_all_dim(out,prop_k,FFT::backward); + theFFT.FFT_all_dim(out,prop_k,FFT::backward); //phase for boundary condition out = out * exp(Scalar(2.0*M_PI)*ci*ph); }; + virtual void FreePropagator(const FermionField &in,FermionField &out,RealD mass) { - std::vector twist(Nd,0.0); //default: periodic boundarys in all directions - FreePropagator(in,out,mass,twist); - }; + std::vector boundary; + for(int i=0;i twist(Nd,0.0); //default: periodic boundarys in all directions + FreePropagator(in,out,mass,boundary,twist); + }; /////////////////////////////////////////////// // Updates gauge field during HMC @@ -146,8 +154,14 @@ public: Current curr_type, unsigned int mu, unsigned int tmin, - unsigned int tmax, - ComplexField &lattice_cmplx)=0; + unsigned int tmax, + ComplexField &lattice_cmplx)=0; + + // Only reimplemented in Wilson5D + // Default to just a zero correlation function + virtual void ContractJ5q(FermionField &q_in ,ComplexField &J5q) { J5q=Zero(); }; + virtual void ContractJ5q(PropagatorField &q_in,ComplexField &J5q) { J5q=Zero(); }; + /////////////////////////////////////////////// // Physical field import/export /////////////////////////////////////////////// diff --git a/Grid/qcd/action/fermion/WilsonCloverFermion.h b/Grid/qcd/action/fermion/WilsonCloverFermion.h index 87bfab88..3847b0d9 100644 --- a/Grid/qcd/action/fermion/WilsonCloverFermion.h +++ b/Grid/qcd/action/fermion/WilsonCloverFermion.h @@ -63,6 +63,7 @@ public: public: typedef WilsonFermion WilsonBase; + virtual int ConstEE(void) { return 0; }; virtual void Instantiatable(void){}; // Constructors WilsonCloverFermion(GaugeField &_Umu, GridCartesian &Fgrid, diff --git a/Grid/qcd/action/fermion/WilsonFermion5D.h b/Grid/qcd/action/fermion/WilsonFermion5D.h index 37c79094..8f1073db 100644 --- a/Grid/qcd/action/fermion/WilsonFermion5D.h +++ b/Grid/qcd/action/fermion/WilsonFermion5D.h @@ -229,6 +229,10 @@ public: unsigned int tmin, unsigned int tmax, ComplexField &lattice_cmplx); + + void ContractJ5q(PropagatorField &q_in,ComplexField &J5q); + void ContractJ5q(FermionField &q_in,ComplexField &J5q); + }; NAMESPACE_END(Grid); diff --git a/Grid/qcd/action/fermion/implementation/WilsonFermion5DImplementation.h b/Grid/qcd/action/fermion/implementation/WilsonFermion5DImplementation.h index 61aaec83..3dd68532 100644 --- a/Grid/qcd/action/fermion/implementation/WilsonFermion5DImplementation.h +++ b/Grid/qcd/action/fermion/implementation/WilsonFermion5DImplementation.h @@ -898,6 +898,79 @@ void WilsonFermion5D::MomentumSpacePropagatorHw(FermionField &out,const Fe merge(qSiteRev, qSiteVec); \ } +// psi = chiralProjectPlus(Result_s[Ls/2-1]); +// psi+= chiralProjectMinus(Result_s[Ls/2]); +// PJ5q+=localInnerProduct(psi,psi); + +template +Lattice spProj5p(const Lattice & in) +{ + GridBase *grid=in.Grid(); + Gamma G5(Gamma::Algebra::Gamma5); + Lattice ret(grid); + auto ret_v = ret.View(); + auto in_v = in.View(); + thread_for(ss,grid->oSites(),{ + ret_v[ss] = in_v[ss] + G5*in_v[ss]; + }); + return ret; +} +template +Lattice spProj5m(const Lattice & in) +{ + Gamma G5(Gamma::Algebra::Gamma5); + GridBase *grid=in.Grid(); + Lattice ret(grid); + auto ret_v = ret.View(); + auto in_v = in.View(); + thread_for(ss,grid->oSites(),{ + ret_v[ss] = in_v[ss] - G5*in_v[ss]; + }); + return ret; +} + +template +void WilsonFermion5D::ContractJ5q(FermionField &q_in,ComplexField &J5q) +{ + conformable(GaugeGrid(), J5q.Grid()); + conformable(q_in.Grid(), FermionGrid()); + + // 4d field + int Ls = this->Ls; + FermionField psi(GaugeGrid()); + FermionField p_plus (GaugeGrid()); + FermionField p_minus(GaugeGrid()); + FermionField p(GaugeGrid()); + + ExtractSlice(p_plus , q_in, Ls/2 , 0); + ExtractSlice(p_minus, q_in, Ls/2-1 , 0); + p_plus = spProj5p(p_plus ); + p_minus= spProj5m(p_minus); + p=p_plus+p_minus; + J5q = localInnerProduct(p,p); +} + +template +void WilsonFermion5D::ContractJ5q(PropagatorField &q_in,ComplexField &J5q) +{ + conformable(GaugeGrid(), J5q.Grid()); + conformable(q_in.Grid(), FermionGrid()); + + // 4d field + int Ls = this->Ls; + PropagatorField psi(GaugeGrid()); + PropagatorField p_plus (GaugeGrid()); + PropagatorField p_minus(GaugeGrid()); + PropagatorField p(GaugeGrid()); + + ExtractSlice(p_plus , q_in, Ls/2 , 0); + ExtractSlice(p_minus, q_in, Ls/2-1 , 0); + p_plus = spProj5p(p_plus ); + p_minus= spProj5m(p_minus); + p=p_plus+p_minus; + J5q = localInnerProduct(p,p); +} + template void WilsonFermion5D::ContractConservedCurrent(PropagatorField &q_in_1, PropagatorField &q_in_2, @@ -908,6 +981,7 @@ void WilsonFermion5D::ContractConservedCurrent(PropagatorField &q_in_1, conformable(q_in_1.Grid(), FermionGrid()); conformable(q_in_1.Grid(), q_in_2.Grid()); conformable(_FourDimGrid, q_out.Grid()); + PropagatorField tmp1(FermionGrid()), tmp2(FermionGrid()); unsigned int LLs = q_in_1.Grid()->_rdimensions[0]; q_out = Zero(); @@ -960,7 +1034,6 @@ void WilsonFermion5D::ContractConservedCurrent(PropagatorField &q_in_1, } - template void WilsonFermion5D::SeqConservedCurrent(PropagatorField &q_in, PropagatorField &q_out, diff --git a/Grid/qcd/action/gauge/GaugeImplTypes.h b/Grid/qcd/action/gauge/GaugeImplTypes.h index dca0c34f..b9a5296d 100644 --- a/Grid/qcd/action/gauge/GaugeImplTypes.h +++ b/Grid/qcd/action/gauge/GaugeImplTypes.h @@ -29,14 +29,24 @@ directory #ifndef GRID_GAUGE_IMPL_TYPES_H #define GRID_GAUGE_IMPL_TYPES_H + NAMESPACE_BEGIN(Grid); +#define CPS_MD_TIME + +#ifdef CPS_MD_TIME +#define HMC_MOMENTUM_DENOMINATOR (2.0) +#else +#define HMC_MOMENTUM_DENOMINATOR (1.0) +#endif + //////////////////////////////////////////////////////////////////////// // Implementation dependent gauge types //////////////////////////////////////////////////////////////////////// #define INHERIT_GIMPL_TYPES(GImpl) \ typedef typename GImpl::Simd Simd; \ + typedef typename GImpl::Scalar Scalar; \ typedef typename GImpl::LinkField GaugeLinkField; \ typedef typename GImpl::Field GaugeField; \ typedef typename GImpl::ComplexField ComplexField;\ @@ -54,7 +64,8 @@ NAMESPACE_BEGIN(Grid); template class GaugeImplTypes { public: typedef S Simd; - + typedef typename Simd::scalar_type scalar_type; + typedef scalar_type Scalar; template using iImplScalar = iScalar > >; template using iImplGaugeLink = iScalar > >; template using iImplGaugeField = iVector >, Nd>; @@ -85,12 +96,10 @@ public: /////////////////////////////////////////////////////////// // Move these to another class // HMC auxiliary functions - static inline void generate_momenta(Field &P, GridParallelRNG &pRNG) { - // specific for SU gauge fields - LinkField Pmu(P.Grid()); - Pmu = Zero(); - // + static inline void generate_momenta(Field &P, GridParallelRNG &pRNG) + { // Zbigniew Srocinsky thesis: + // // P(p) = N \Prod_{x\mu}e^-{1/2 Tr (p^2_mux)} // // p_x,mu = c_x,mu,a T_a @@ -101,26 +110,16 @@ public: // // = N \Prod_{x,\mu,a} e^-{1/2 (c_xmua/sqrt{2})^2 } // - // Expect cx' = cxmua/sqrt(2) to be a unit variance gaussian. // - // Expect cxmua_new variance sqrt(2). - // Was variance cxmua_old variance 1 - // - // tau_old * Pold = 1 = tau_old/sqrt(2) * [Pold * sqrt(2)] - // = tau_new * Pnew + // Expect cxmua variance sqrt(2). // - // Hence tau_new = tau_cps = tau_guido/sqrt(2). + // Must scale the momentum by sqrt(2) to invoke CPS and UKQCD conventions // - // - // Must scale the momentum by sqrt(2) up to invoke CPS and UKQCD conventions - // - // - // Hence expect cxmua = cx'*sqrt(2). - // - // Seek the scale parameter to be + LinkField Pmu(P.Grid()); + Pmu = Zero(); for (int mu = 0; mu < Nd; mu++) { SU::GaussianFundamentalLieAlgebraMatrix(pRNG, Pmu); - RealD scale = ::sqrt(2) ; + RealD scale = ::sqrt(HMC_MOMENTUM_DENOMINATOR) ; Pmu = Pmu*scale; PokeIndex(P, Pmu, mu); } diff --git a/Grid/qcd/action/gauge/Photon.h b/Grid/qcd/action/gauge/Photon.h index f9f07a83..465aa8bd 100644 --- a/Grid/qcd/action/gauge/Photon.h +++ b/Grid/qcd/action/gauge/Photon.h @@ -36,6 +36,7 @@ NAMESPACE_BEGIN(Grid); { public: typedef S Simd; + typedef typename Simd::scalar_type Scalar; template using iImplGaugeLink = iScalar>>; diff --git a/Grid/qcd/action/gauge/PlaqPlusRectangleAction.h b/Grid/qcd/action/gauge/PlaqPlusRectangleAction.h index f9ef0e87..639aca19 100644 --- a/Grid/qcd/action/gauge/PlaqPlusRectangleAction.h +++ b/Grid/qcd/action/gauge/PlaqPlusRectangleAction.h @@ -74,7 +74,7 @@ public: virtual void deriv(const GaugeField &Umu,GaugeField & dSdU) { //extend Ta to include Lorentz indexes RealD factor_p = c_plaq/RealD(Nc)*0.5; - RealD factor_r = c_rect/RealD(Nc)*0.5; + RealD factor_r = c_rect/RealD(Nc)*0.5; GridBase *grid = Umu.Grid(); diff --git a/Grid/qcd/action/pseudofermion/Bounds.h b/Grid/qcd/action/pseudofermion/Bounds.h new file mode 100644 index 00000000..081ebba2 --- /dev/null +++ b/Grid/qcd/action/pseudofermion/Bounds.h @@ -0,0 +1,53 @@ +#pragma once + +namespace Grid{ + namespace QCD{ + + template + void HighBoundCheck(LinearOperatorBase &HermOp, + Field &Phi, + RealD hi) + { + // Eigenvalue bound check at high end + PowerMethod power_method; + auto lambda_max = power_method(HermOp,Phi); + std::cout << GridLogMessage << "Pseudofermion action lamda_max "< void InverseSqrtBoundsCheck(int MaxIter,double tol, + LinearOperatorBase &HermOp, + Field &GaussNoise, + MultiShiftFunction &PowerNegHalf) + { + GridBase *FermionGrid = GaussNoise._grid; + + Field X(FermionGrid); + Field Y(FermionGrid); + Field Z(FermionGrid); + + X=GaussNoise; + RealD Nx = norm2(X); + + ConjugateGradientMultiShift msCG(MaxIter,PowerNegHalf); + msCG(HermOp,X,Y); + msCG(HermOp,Y,Z); + + RealD Nz = norm2(Z); + + HermOp.HermOp(Z,Y); + RealD Ny = norm2(Y); + + X=X-Y; + RealD Nd = norm2(X); + std::cout << "************************* "< -class ExactOneFlavourRatioPseudoFermionAction : public Action -{ -public: - INHERIT_IMPL_TYPES(Impl); - typedef OneFlavourRationalParams Params; - Params param; - MultiShiftFunction PowerNegHalf; - -private: - bool use_heatbath_forecasting; - AbstractEOFAFermion& Lop; // the basic LH operator - AbstractEOFAFermion& Rop; // the basic RH operator - SchurRedBlackDiagMooeeSolve Solver; - FermionField Phi; // the pseudofermion field for this trajectory - -public: - ExactOneFlavourRatioPseudoFermionAction(AbstractEOFAFermion& _Lop, AbstractEOFAFermion& _Rop, - OperatorFunction& S, Params& p, bool use_fc=false) : Lop(_Lop), Rop(_Rop), Solver(S), - Phi(_Lop.FermionGrid()), param(p), use_heatbath_forecasting(use_fc) + template + class ExactOneFlavourRatioPseudoFermionAction : public Action { - AlgRemez remez(param.lo, param.hi, param.precision); + public: + INHERIT_IMPL_TYPES(Impl); + typedef OneFlavourRationalParams Params; + Params param; + MultiShiftFunction PowerNegHalf; - // MdagM^(+- 1/2) - std::cout << GridLogMessage << "Generating degree " << param.degree << " for x^(-1/2)" << std::endl; - remez.generateApprox(param.degree, 1, 2); - PowerNegHalf.Init(remez, param.tolerance, true); - }; + private: + bool use_heatbath_forecasting; + AbstractEOFAFermion& Lop; // the basic LH operator + AbstractEOFAFermion& Rop; // the basic RH operator + SchurRedBlackDiagMooeeSolve SolverHB; + SchurRedBlackDiagMooeeSolve SolverL; + SchurRedBlackDiagMooeeSolve SolverR; + SchurRedBlackDiagMooeeSolve DerivativeSolverL; + SchurRedBlackDiagMooeeSolve DerivativeSolverR; + FermionField Phi; // the pseudofermion field for this trajectory - virtual std::string action_name() { return "ExactOneFlavourRatioPseudoFermionAction"; } + public: + ExactOneFlavourRatioPseudoFermionAction(AbstractEOFAFermion& _Lop, + AbstractEOFAFermion& _Rop, + OperatorFunction& HeatbathCG, + OperatorFunction& ActionCGL, OperatorFunction& ActionCGR, + OperatorFunction& DerivCGL , OperatorFunction& DerivCGR, + Params& p, + bool use_fc=false) : + Lop(_Lop), + Rop(_Rop), + SolverHB(HeatbathCG,false,true), + SolverL(ActionCGL, false, true), SolverR(ActionCGR, false, true), + DerivativeSolverL(DerivCGL, false, true), DerivativeSolverR(DerivCGR, false, true), + Phi(_Lop.FermionGrid()), + param(p), + use_heatbath_forecasting(use_fc) + { + AlgRemez remez(param.lo, param.hi, param.precision); - virtual std::string LogParameters() { - std::stringstream sstream; - sstream << GridLogMessage << "[" << action_name() << "] Low :" << param.lo << std::endl; - sstream << GridLogMessage << "[" << action_name() << "] High :" << param.hi << std::endl; - sstream << GridLogMessage << "[" << action_name() << "] Max iterations :" << param.MaxIter << std::endl; - sstream << GridLogMessage << "[" << action_name() << "] Tolerance :" << param.tolerance << std::endl; - sstream << GridLogMessage << "[" << action_name() << "] Degree :" << param.degree << std::endl; - sstream << GridLogMessage << "[" << action_name() << "] Precision :" << param.precision << std::endl; - return sstream.str(); - } + // MdagM^(+- 1/2) + std::cout << GridLogMessage << "Generating degree " << param.degree << " for x^(-1/2)" << std::endl; + remez.generateApprox(param.degree, 1, 2); + PowerNegHalf.Init(remez, param.tolerance, true); + }; - // Spin projection - void spProj(const FermionField& in, FermionField& out, int sign, int Ls) - { - if(sign == 1){ for(int s=0; s tmp(2, Lop.FermionGrid()); - - // Use chronological inverter to forecast solutions across poles - std::vector prev_solns; - if(use_heatbath_forecasting){ prev_solns.reserve(param.degree); } - ChronoForecast, FermionField> Forecast; - - // Seed with Gaussian noise vector (var = 0.5) - RealD scale = std::sqrt(0.5); - gaussian(pRNG,eta); - eta = eta * scale; - printf("Heatbath source vector: <\\eta|\\eta> = %1.15e\n", norm2(eta)); - - // \Phi = ( \alpha_{0} + \sum_{k=1}^{N_{p}} \alpha_{l} * \gamma_{l} ) * \eta - RealD N(PowerNegHalf.norm); - for(int k=0; k tmp(2, Lop.FermionGrid()); + + // Use chronological inverter to forecast solutions across poles + std::vector prev_solns; + if(use_heatbath_forecasting){ prev_solns.reserve(param.degree); } + ChronoForecast, FermionField> Forecast; + + // Seed with Gaussian noise vector (var = 0.5) + RealD scale = std::sqrt(0.5); + gaussian(pRNG,eta); + eta = eta * scale; + + // \Phi = ( \alpha_{0} + \sum_{k=1}^{N_{p}} \alpha_{l} * \gamma_{l} ) * \eta + RealD N(PowerNegHalf.norm); + for(int k=0; k tmp(2, Lop.FermionGrid()); + mPhi = phi; + + // LH term: S = S - k <\Phi| P_{-} \Omega_{-}^{\dagger} H(mf)^{-1} \Omega_{-} P_{-} |\Phi> + spProj(Phi, spProj_Phi, -1, Lop.Ls); + Lop.Omega(spProj_Phi, tmp[0], -1, 0); + G5R5(tmp[1], tmp[0]); + tmp[0] = zero; + SolverL(Lop, tmp[1], tmp[0]); + Lop.Dtilde(tmp[0], tmp[1]); // We actually solved Cayley preconditioned system: transform back + Lop.Omega(tmp[1], tmp[0], -1, 1); + mPhi = mPhi - Lop.k * innerProduct(spProj_Phi, tmp[0]).real(); + + // RH term: S = S + k <\Phi| P_{+} \Omega_{+}^{\dagger} ( H(mb) + // - \Delta_{+}(mf,mb) P_{+} )^{-1} \Omega_{-} P_{-} |\Phi> + spProj(Phi, spProj_Phi, 1, Rop.Ls); + Rop.Omega(spProj_Phi, tmp[0], 1, 0); + G5R5(tmp[1], tmp[0]); + tmp[0] = zero; + SolverR(Rop, tmp[1], tmp[0]); + Rop.Dtilde(tmp[0], tmp[1]); + Rop.Omega(tmp[1], tmp[0], 1, 1); + action += Rop.k * innerProduct(spProj_Phi, tmp[0]).real(); +#endif + } + + // EOFA action: see Eqn. (10) of arXiv:1706.05843 + virtual RealD S(const GaugeField& U) + { + Lop.ImportGauge(U); + Rop.ImportGauge(U); + + FermionField spProj_Phi(Lop.FermionGrid()); + std::vector tmp(2, Lop.FermionGrid()); + + // S = <\Phi|\Phi> + RealD action(norm2(Phi)); + + // LH term: S = S - k <\Phi| P_{-} \Omega_{-}^{\dagger} H(mf)^{-1} \Omega_{-} P_{-} |\Phi> + spProj(Phi, spProj_Phi, -1, Lop.Ls); + Lop.Omega(spProj_Phi, tmp[0], -1, 0); + G5R5(tmp[1], tmp[0]); + tmp[0] = zero; + SolverL(Lop, tmp[1], tmp[0]); + Lop.Dtilde(tmp[0], tmp[1]); // We actually solved Cayley preconditioned system: transform back + Lop.Omega(tmp[1], tmp[0], -1, 1); + action -= Lop.k * innerProduct(spProj_Phi, tmp[0]).real(); + + // RH term: S = S + k <\Phi| P_{+} \Omega_{+}^{\dagger} ( H(mb) + // - \Delta_{+}(mf,mb) P_{+} )^{-1} \Omega_{-} P_{-} |\Phi> + spProj(Phi, spProj_Phi, 1, Rop.Ls); + Rop.Omega(spProj_Phi, tmp[0], 1, 0); + G5R5(tmp[1], tmp[0]); + tmp[0] = zero; + SolverR(Rop, tmp[1], tmp[0]); + Rop.Dtilde(tmp[0], tmp[1]); + Rop.Omega(tmp[1], tmp[0], 1, 1); + action += Rop.k * innerProduct(spProj_Phi, tmp[0]).real(); + + return action; + }; + + // EOFA pseudofermion force: see Eqns. (34)-(36) of arXiv:1706.05843 + virtual void deriv(const GaugeField& U, GaugeField& dSdU) + { + Lop.ImportGauge(U); + Rop.ImportGauge(U); + + FermionField spProj_Phi (Lop.FermionGrid()); + FermionField Omega_spProj_Phi(Lop.FermionGrid()); + FermionField CG_src (Lop.FermionGrid()); + FermionField Chi (Lop.FermionGrid()); + FermionField g5_R5_Chi (Lop.FermionGrid()); + + GaugeField force(Lop.GaugeGrid()); + + ///////////////////////////////////////////// + // PAB: + // Optional single precision derivative ? + ///////////////////////////////////////////// + + // LH: dSdU = k \chi_{L}^{\dagger} \gamma_{5} R_{5} ( \partial_{x,\mu} D_{w} ) \chi_{L} + // \chi_{L} = H(mf)^{-1} \Omega_{-} P_{-} \Phi + spProj(Phi, spProj_Phi, -1, Lop.Ls); + Lop.Omega(spProj_Phi, Omega_spProj_Phi, -1, 0); + G5R5(CG_src, Omega_spProj_Phi); + spProj_Phi = zero; + DerivativeSolverL(Lop, CG_src, spProj_Phi); + Lop.Dtilde(spProj_Phi, Chi); + G5R5(g5_R5_Chi, Chi); + Lop.MDeriv(force, g5_R5_Chi, Chi, DaggerNo); + dSdU = -Lop.k * force; + + // RH: dSdU = dSdU - k \chi_{R}^{\dagger} \gamma_{5} R_{5} ( \partial_{x,\mu} D_{w} ) \chi_{} + // \chi_{R} = ( H(mb) - \Delta_{+}(mf,mb) P_{+} )^{-1} \Omega_{+} P_{+} \Phi + spProj(Phi, spProj_Phi, 1, Rop.Ls); + Rop.Omega(spProj_Phi, Omega_spProj_Phi, 1, 0); + G5R5(CG_src, Omega_spProj_Phi); + spProj_Phi = zero; + DerivativeSolverR(Rop, CG_src, spProj_Phi); + Rop.Dtilde(spProj_Phi, Chi); + G5R5(g5_R5_Chi, Chi); + Lop.MDeriv(force, g5_R5_Chi, Chi, DaggerNo); + dSdU = dSdU + Rop.k * force; + }; }; - - // EOFA action: see Eqn. (10) of arXiv:1706.05843 - virtual RealD S(const GaugeField& U) - { - Lop.ImportGauge(U); - Rop.ImportGauge(U); - - FermionField spProj_Phi(Lop.FermionGrid()); - std::vector tmp(2, Lop.FermionGrid()); - - // S = <\Phi|\Phi> - RealD action(norm2(Phi)); - - // LH term: S = S - k <\Phi| P_{-} \Omega_{-}^{\dagger} H(mf)^{-1} \Omega_{-} P_{-} |\Phi> - spProj(Phi, spProj_Phi, -1, Lop.Ls); - Lop.Omega(spProj_Phi, tmp[0], -1, 0); - G5R5(tmp[1], tmp[0]); - tmp[0] = Zero(); - Solver(Lop, tmp[1], tmp[0]); - Lop.Dtilde(tmp[0], tmp[1]); // We actually solved Cayley preconditioned system: transform back - Lop.Omega(tmp[1], tmp[0], -1, 1); - action -= Lop.k * innerProduct(spProj_Phi, tmp[0]).real(); - - // RH term: S = S + k <\Phi| P_{+} \Omega_{+}^{\dagger} ( H(mb) - // - \Delta_{+}(mf,mb) P_{+} )^{-1} \Omega_{-} P_{-} |\Phi> - spProj(Phi, spProj_Phi, 1, Rop.Ls); - Rop.Omega(spProj_Phi, tmp[0], 1, 0); - G5R5(tmp[1], tmp[0]); - tmp[0] = Zero(); - Solver(Rop, tmp[1], tmp[0]); - Rop.Dtilde(tmp[0], tmp[1]); - Rop.Omega(tmp[1], tmp[0], 1, 1); - action += Rop.k * innerProduct(spProj_Phi, tmp[0]).real(); - - return action; - }; - - // EOFA pseudofermion force: see Eqns. (34)-(36) of arXiv:1706.05843 - virtual void deriv(const GaugeField& U, GaugeField& dSdU) - { - Lop.ImportGauge(U); - Rop.ImportGauge(U); - - FermionField spProj_Phi (Lop.FermionGrid()); - FermionField Omega_spProj_Phi(Lop.FermionGrid()); - FermionField CG_src (Lop.FermionGrid()); - FermionField Chi (Lop.FermionGrid()); - FermionField g5_R5_Chi (Lop.FermionGrid()); - - GaugeField force(Lop.GaugeGrid()); - - // LH: dSdU = k \chi_{L}^{\dagger} \gamma_{5} R_{5} ( \partial_{x,\mu} D_{w} ) \chi_{L} - // \chi_{L} = H(mf)^{-1} \Omega_{-} P_{-} \Phi - spProj(Phi, spProj_Phi, -1, Lop.Ls); - Lop.Omega(spProj_Phi, Omega_spProj_Phi, -1, 0); - G5R5(CG_src, Omega_spProj_Phi); - spProj_Phi = Zero(); - Solver(Lop, CG_src, spProj_Phi); - Lop.Dtilde(spProj_Phi, Chi); - G5R5(g5_R5_Chi, Chi); - Lop.MDeriv(force, g5_R5_Chi, Chi, DaggerNo); - dSdU = Lop.k * force; - - // RH: dSdU = dSdU - k \chi_{R}^{\dagger} \gamma_{5} R_{5} ( \partial_{x,\mu} D_{w} ) \chi_{} - // \chi_{R} = ( H(mb) - \Delta_{+}(mf,mb) P_{+} )^{-1} \Omega_{+} P_{+} \Phi - spProj(Phi, spProj_Phi, 1, Rop.Ls); - Rop.Omega(spProj_Phi, Omega_spProj_Phi, 1, 0); - G5R5(CG_src, Omega_spProj_Phi); - spProj_Phi = Zero(); - Solver(Rop, CG_src, spProj_Phi); - Rop.Dtilde(spProj_Phi, Chi); - G5R5(g5_R5_Chi, Chi); - Lop.MDeriv(force, g5_R5_Chi, Chi, DaggerNo); - dSdU = dSdU - Rop.k * force; - }; -}; - -NAMESPACE_END(Grid); +}} #endif diff --git a/Grid/qcd/action/pseudofermion/OneFlavourEvenOddRational.h b/Grid/qcd/action/pseudofermion/OneFlavourEvenOddRational.h index e78ac2cb..56dff94d 100644 --- a/Grid/qcd/action/pseudofermion/OneFlavourEvenOddRational.h +++ b/Grid/qcd/action/pseudofermion/OneFlavourEvenOddRational.h @@ -156,6 +156,13 @@ public: msCG(Mpc, PhiOdd, Y); + if ( (rand()%param.BoundsCheckFreq)==0 ) { + FermionField gauss(FermOp.FermionRedBlackGrid()); + gauss = PhiOdd; + HighBoundCheck(Mpc,gauss,param.hi); + InverseSqrtBoundsCheck(param.MaxIter,param.tolerance*100,Mpc,gauss,PowerNegHalf); + } + RealD action = norm2(Y); std::cout << GridLogMessage << "Pseudofermion action FIXME -- is -1/4 " "solve or -1/2 solve faster??? " diff --git a/Grid/qcd/action/pseudofermion/OneFlavourEvenOddRationalRatio.h b/Grid/qcd/action/pseudofermion/OneFlavourEvenOddRationalRatio.h index a00665bc..84fe4de0 100644 --- a/Grid/qcd/action/pseudofermion/OneFlavourEvenOddRationalRatio.h +++ b/Grid/qcd/action/pseudofermion/OneFlavourEvenOddRationalRatio.h @@ -1,4 +1,4 @@ -/************************************************************************************* + /************************************************************************************* Grid physics library, www.github.com/paboyle/Grid @@ -23,257 +23,267 @@ Author: Peter Boyle 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. See the full license in the file "LICENSE" in the top level distribution directory -*************************************************************************************/ -/* END LEGAL */ + *************************************************************************************/ + /* END LEGAL */ #ifndef QCD_PSEUDOFERMION_ONE_FLAVOUR_EVEN_ODD_RATIONAL_RATIO_H #define QCD_PSEUDOFERMION_ONE_FLAVOUR_EVEN_ODD_RATIONAL_RATIO_H -NAMESPACE_BEGIN(Grid); - -/////////////////////////////////////// -// One flavour rational -/////////////////////////////////////// +namespace Grid{ + namespace QCD{ -// S_f = chi^dag* P(V^dag*V)/Q(V^dag*V)* N(M^dag*M)/D(M^dag*M)* P(V^dag*V)/Q(V^dag*V)* chi -// -// Here P/Q \sim R_{1/4} ~ (V^dagV)^{1/4} -// Here N/D \sim R_{-1/2} ~ (M^dagM)^{-1/2} - -template -class OneFlavourEvenOddRatioRationalPseudoFermionAction : public Action { -public: - - INHERIT_IMPL_TYPES(Impl); - - typedef OneFlavourRationalParams Params; - Params param; - - MultiShiftFunction PowerHalf ; - MultiShiftFunction PowerNegHalf; - MultiShiftFunction PowerQuarter; - MultiShiftFunction PowerNegQuarter; - -private: - - FermionOperator & NumOp;// the basic operator - FermionOperator & DenOp;// the basic operator - FermionField PhiEven; // the pseudo fermion field for this trajectory - FermionField PhiOdd; // the pseudo fermion field for this trajectory - -public: - - OneFlavourEvenOddRatioRationalPseudoFermionAction(FermionOperator &_NumOp, - FermionOperator &_DenOp, - Params & p - ) : - NumOp(_NumOp), - DenOp(_DenOp), - PhiOdd (_NumOp.FermionRedBlackGrid()), - PhiEven(_NumOp.FermionRedBlackGrid()), - param(p) - { - AlgRemez remez(param.lo,param.hi,param.precision); - - // MdagM^(+- 1/2) - std::cout< sig^2 = 0.5. - // - // So eta should be of width sig = 1/sqrt(2). + // Here P/Q \sim R_{1/4} ~ (V^dagV)^{1/4} + // Here N/D \sim R_{-1/2} ~ (M^dagM)^{-1/2} + + template + class OneFlavourEvenOddRatioRationalPseudoFermionAction : public Action { + public: - RealD scale = std::sqrt(0.5); + INHERIT_IMPL_TYPES(Impl); - FermionField eta(NumOp.FermionGrid()); - FermionField etaOdd (NumOp.FermionRedBlackGrid()); - FermionField etaEven(NumOp.FermionRedBlackGrid()); - FermionField tmp(NumOp.FermionRedBlackGrid()); + typedef OneFlavourRationalParams Params; + Params param; - gaussian(pRNG,eta); eta=eta*scale; + MultiShiftFunction PowerHalf ; + MultiShiftFunction PowerNegHalf; + MultiShiftFunction PowerQuarter; + MultiShiftFunction PowerNegQuarter; - pickCheckerboard(Even,etaEven,eta); - pickCheckerboard(Odd,etaOdd,eta); + private: + + FermionOperator & NumOp;// the basic operator + FermionOperator & DenOp;// the basic operator + FermionField PhiEven; // the pseudo fermion field for this trajectory + FermionField PhiOdd; // the pseudo fermion field for this trajectory - NumOp.ImportGauge(U); - DenOp.ImportGauge(U); + public: + + OneFlavourEvenOddRatioRationalPseudoFermionAction(FermionOperator &_NumOp, + FermionOperator &_DenOp, + Params & p + ) : + NumOp(_NumOp), + DenOp(_DenOp), + PhiOdd (_NumOp.FermionRedBlackGrid()), + PhiEven(_NumOp.FermionRedBlackGrid()), + param(p) + { + AlgRemez remez(param.lo,param.hi,param.precision); + + // MdagM^(+- 1/2) + std::cout< sig^2 = 0.5. + // + // So eta should be of width sig = 1/sqrt(2). + + RealD scale = std::sqrt(0.5); + + FermionField eta(NumOp.FermionGrid()); + FermionField etaOdd (NumOp.FermionRedBlackGrid()); + FermionField etaEven(NumOp.FermionRedBlackGrid()); + FermionField tmp(NumOp.FermionRedBlackGrid()); + + gaussian(pRNG,eta); eta=eta*scale; + + pickCheckerboard(Even,etaEven,eta); + pickCheckerboard(Odd,etaOdd,eta); + + NumOp.ImportGauge(U); + DenOp.ImportGauge(U); - // MdagM^1/4 eta - SchurDifferentiableOperator MdagM(DenOp); - ConjugateGradientMultiShift msCG_M(param.MaxIter,PowerQuarter); - msCG_M(MdagM,etaOdd,tmp); + // MdagM^1/4 eta + SchurDifferentiableOperator MdagM(DenOp); + ConjugateGradientMultiShift msCG_M(param.MaxIter,PowerQuarter); + msCG_M(MdagM,etaOdd,tmp); - // VdagV^-1/4 MdagM^1/4 eta - SchurDifferentiableOperator VdagV(NumOp); - ConjugateGradientMultiShift msCG_V(param.MaxIter,PowerNegQuarter); - msCG_V(VdagV,tmp,PhiOdd); + // VdagV^-1/4 MdagM^1/4 eta + SchurDifferentiableOperator VdagV(NumOp); + ConjugateGradientMultiShift msCG_V(param.MaxIter,PowerNegQuarter); + msCG_V(VdagV,tmp,PhiOdd); - assert(NumOp.ConstEE() == 1); - assert(DenOp.ConstEE() == 1); - PhiEven = Zero(); + assert(NumOp.ConstEE() == 1); + assert(DenOp.ConstEE() == 1); + PhiEven = zero; - }; + }; - ////////////////////////////////////////////////////// - // S_f = chi^dag* P(V^dag*V)/Q(V^dag*V)* N(M^dag*M)/D(M^dag*M)* P(V^dag*V)/Q(V^dag*V)* chi - ////////////////////////////////////////////////////// - virtual RealD S(const GaugeField &U) { + ////////////////////////////////////////////////////// + // S_f = chi^dag* P(V^dag*V)/Q(V^dag*V)* N(M^dag*M)/D(M^dag*M)* P(V^dag*V)/Q(V^dag*V)* chi + ////////////////////////////////////////////////////// + virtual RealD S(const GaugeField &U) { - NumOp.ImportGauge(U); - DenOp.ImportGauge(U); + NumOp.ImportGauge(U); + DenOp.ImportGauge(U); - FermionField X(NumOp.FermionRedBlackGrid()); - FermionField Y(NumOp.FermionRedBlackGrid()); + FermionField X(NumOp.FermionRedBlackGrid()); + FermionField Y(NumOp.FermionRedBlackGrid()); - // VdagV^1/4 Phi - SchurDifferentiableOperator VdagV(NumOp); - ConjugateGradientMultiShift msCG_V(param.MaxIter,PowerQuarter); - msCG_V(VdagV,PhiOdd,X); + // VdagV^1/4 Phi + SchurDifferentiableOperator VdagV(NumOp); + ConjugateGradientMultiShift msCG_V(param.MaxIter,PowerQuarter); + msCG_V(VdagV,PhiOdd,X); - // MdagM^-1/4 VdagV^1/4 Phi - SchurDifferentiableOperator MdagM(DenOp); - ConjugateGradientMultiShift msCG_M(param.MaxIter,PowerNegQuarter); - msCG_M(MdagM,X,Y); + // MdagM^-1/4 VdagV^1/4 Phi + SchurDifferentiableOperator MdagM(DenOp); + ConjugateGradientMultiShift msCG_M(param.MaxIter,PowerNegQuarter); + msCG_M(MdagM,X,Y); - // Phidag VdagV^1/4 MdagM^-1/4 MdagM^-1/4 VdagV^1/4 Phi - RealD action = norm2(Y); + // Randomly apply rational bounds checks. + if ( (rand()%param.BoundsCheckFreq)==0 ) { + FermionField gauss(NumOp.FermionRedBlackGrid()); + gauss = PhiOdd; + HighBoundCheck(MdagM,gauss,param.hi); + InverseSqrtBoundsCheck(param.MaxIter,param.tolerance*100,MdagM,gauss,PowerNegHalf); + } - return action; - }; + // Phidag VdagV^1/4 MdagM^-1/4 MdagM^-1/4 VdagV^1/4 Phi + RealD action = norm2(Y); - // S_f = chi^dag* P(V^dag*V)/Q(V^dag*V)* N(M^dag*M)/D(M^dag*M)* P(V^dag*V)/Q(V^dag*V)* chi - // - // Here, M is some 5D operator and V is the Pauli-Villars field - // N and D makeup the rat. poly of the M term and P and & makeup the rat.poly of the denom term - // - // Need - // dS_f/dU = chi^dag d[P/Q] N/D P/Q chi - // + chi^dag P/Q d[N/D] P/Q chi - // + chi^dag P/Q N/D d[P/Q] chi - // - // P/Q is expressed as partial fraction expansion: - // - // a0 + \sum_k ak/(V^dagV + bk) - // - // d[P/Q] is then - // - // \sum_k -ak [V^dagV+bk]^{-1} [ dV^dag V + V^dag dV ] [V^dag V + bk]^{-1} - // - // and similar for N/D. - // - // Need - // MpvPhi_k = [Vdag V + bk]^{-1} chi - // MpvPhi = {a0 + \sum_k ak [Vdag V + bk]^{-1} }chi - // - // MfMpvPhi_k = [MdagM+bk]^{-1} MpvPhi - // MfMpvPhi = {a0 + \sum_k ak [Mdag M + bk]^{-1} } MpvPhi - // - // MpvMfMpvPhi_k = [Vdag V + bk]^{-1} MfMpvchi - // + return action; + }; - virtual void deriv(const GaugeField &U,GaugeField & dSdU) { + // S_f = chi^dag* P(V^dag*V)/Q(V^dag*V)* N(M^dag*M)/D(M^dag*M)* P(V^dag*V)/Q(V^dag*V)* chi + // + // Here, M is some 5D operator and V is the Pauli-Villars field + // N and D makeup the rat. poly of the M term and P and & makeup the rat.poly of the denom term + // + // Need + // dS_f/dU = chi^dag d[P/Q] N/D P/Q chi + // + chi^dag P/Q d[N/D] P/Q chi + // + chi^dag P/Q N/D d[P/Q] chi + // + // P/Q is expressed as partial fraction expansion: + // + // a0 + \sum_k ak/(V^dagV + bk) + // + // d[P/Q] is then + // + // \sum_k -ak [V^dagV+bk]^{-1} [ dV^dag V + V^dag dV ] [V^dag V + bk]^{-1} + // + // and similar for N/D. + // + // Need + // MpvPhi_k = [Vdag V + bk]^{-1} chi + // MpvPhi = {a0 + \sum_k ak [Vdag V + bk]^{-1} }chi + // + // MfMpvPhi_k = [MdagM+bk]^{-1} MpvPhi + // MfMpvPhi = {a0 + \sum_k ak [Mdag M + bk]^{-1} } MpvPhi + // + // MpvMfMpvPhi_k = [Vdag V + bk]^{-1} MfMpvchi + // - const int n_f = PowerNegHalf.poles.size(); - const int n_pv = PowerQuarter.poles.size(); + virtual void deriv(const GaugeField &U,GaugeField & dSdU) { - std::vector MpvPhi_k (n_pv,NumOp.FermionRedBlackGrid()); - std::vector MpvMfMpvPhi_k(n_pv,NumOp.FermionRedBlackGrid()); - std::vector MfMpvPhi_k (n_f ,NumOp.FermionRedBlackGrid()); + const int n_f = PowerNegHalf.poles.size(); + const int n_pv = PowerQuarter.poles.size(); - FermionField MpvPhi(NumOp.FermionRedBlackGrid()); - FermionField MfMpvPhi(NumOp.FermionRedBlackGrid()); - FermionField MpvMfMpvPhi(NumOp.FermionRedBlackGrid()); - FermionField Y(NumOp.FermionRedBlackGrid()); + std::vector MpvPhi_k (n_pv,NumOp.FermionRedBlackGrid()); + std::vector MpvMfMpvPhi_k(n_pv,NumOp.FermionRedBlackGrid()); + std::vector MfMpvPhi_k (n_f ,NumOp.FermionRedBlackGrid()); - GaugeField tmp(NumOp.GaugeGrid()); + FermionField MpvPhi(NumOp.FermionRedBlackGrid()); + FermionField MfMpvPhi(NumOp.FermionRedBlackGrid()); + FermionField MpvMfMpvPhi(NumOp.FermionRedBlackGrid()); + FermionField Y(NumOp.FermionRedBlackGrid()); - NumOp.ImportGauge(U); - DenOp.ImportGauge(U); + GaugeField tmp(NumOp.GaugeGrid()); - SchurDifferentiableOperator VdagV(NumOp); - SchurDifferentiableOperator MdagM(DenOp); + NumOp.ImportGauge(U); + DenOp.ImportGauge(U); - ConjugateGradientMultiShift msCG_V(param.MaxIter,PowerQuarter); - ConjugateGradientMultiShift msCG_M(param.MaxIter,PowerNegHalf); + SchurDifferentiableOperator VdagV(NumOp); + SchurDifferentiableOperator MdagM(DenOp); - msCG_V(VdagV,PhiOdd,MpvPhi_k,MpvPhi); - msCG_M(MdagM,MpvPhi,MfMpvPhi_k,MfMpvPhi); - msCG_V(VdagV,MfMpvPhi,MpvMfMpvPhi_k,MpvMfMpvPhi); + ConjugateGradientMultiShift msCG_V(param.MaxIter,PowerQuarter); + ConjugateGradientMultiShift msCG_M(param.MaxIter,PowerNegHalf); - RealD ak; + msCG_V(VdagV,PhiOdd,MpvPhi_k,MpvPhi); + msCG_M(MdagM,MpvPhi,MfMpvPhi_k,MfMpvPhi); + msCG_V(VdagV,MfMpvPhi,MpvMfMpvPhi_k,MpvMfMpvPhi); - dSdU = Zero(); + RealD ak; - // With these building blocks - // - // dS/dU = - // \sum_k -ak MfMpvPhi_k^dag [ dM^dag M + M^dag dM ] MfMpvPhi_k (1) - // + \sum_k -ak MpvMfMpvPhi_k^\dag [ dV^dag V + V^dag dV ] MpvPhi_k (2) - // -ak MpvPhi_k^dag [ dV^dag V + V^dag dV ] MpvMfMpvPhi_k (3) + dSdU = zero; - //(1) - for(int k=0;k 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. See the full license in the file "LICENSE" in the top level distribution directory -*************************************************************************************/ -/* END LEGAL */ + *************************************************************************************/ + /* END LEGAL */ #ifndef QCD_PSEUDOFERMION_ONE_FLAVOUR_RATIONAL_H #define QCD_PSEUDOFERMION_ONE_FLAVOUR_RATIONAL_H -NAMESPACE_BEGIN(Grid); +namespace Grid{ + namespace QCD{ -/////////////////////////////////////// -// One flavour rational -/////////////////////////////////////// + /////////////////////////////////////// + // One flavour rational + /////////////////////////////////////// -// S_f = chi^dag * N(M^dag*M)/D(M^dag*M) * chi -// -// Here, M is some operator -// N and D makeup the rat. poly -// + // S_f = chi^dag * N(M^dag*M)/D(M^dag*M) * chi + // + // Here, M is some operator + // N and D makeup the rat. poly + // -template -class OneFlavourRationalPseudoFermionAction : public Action { -public: - INHERIT_IMPL_TYPES(Impl); + template + class OneFlavourRationalPseudoFermionAction : public Action { + public: + INHERIT_IMPL_TYPES(Impl); - typedef OneFlavourRationalParams Params; - Params param; + typedef OneFlavourRationalParams Params; + Params param; - MultiShiftFunction PowerHalf ; - MultiShiftFunction PowerNegHalf; - MultiShiftFunction PowerQuarter; - MultiShiftFunction PowerNegQuarter; + MultiShiftFunction PowerHalf ; + MultiShiftFunction PowerNegHalf; + MultiShiftFunction PowerQuarter; + MultiShiftFunction PowerNegQuarter; -private: + private: - FermionOperator & FermOp;// the basic operator + FermionOperator & FermOp;// the basic operator - // NOT using "Nroots"; IroIro is -- perhaps later, but this wasn't good for us historically - // and hasenbusch works better + // NOT using "Nroots"; IroIro is -- perhaps later, but this wasn't good for us historically + // and hasenbusch works better - FermionField Phi; // the pseudo fermion field for this trajectory + FermionField Phi; // the pseudo fermion field for this trajectory -public: + public: - OneFlavourRationalPseudoFermionAction(FermionOperator &Op, - Params & p - ) : FermOp(Op), Phi(Op.FermionGrid()), param(p) - { - AlgRemez remez(param.lo,param.hi,param.precision); + OneFlavourRationalPseudoFermionAction(FermionOperator &Op, + Params & p + ) : FermOp(Op), Phi(Op.FermionGrid()), param(p) + { + AlgRemez remez(param.lo,param.hi,param.precision); - // MdagM^(+- 1/2) - std::cout< sig^2 = 0.5. - // - // So eta should be of width sig = 1/sqrt(2). + // P(phi) = e^{- phi^dag (MdagM)^-1/2 phi} + // = e^{- phi^dag (MdagM)^-1/4 (MdagM)^-1/4 phi} + // Phi = Mdag^{1/4} eta + // P(eta) = e^{- eta^dag eta} + // + // e^{x^2/2 sig^2} => sig^2 = 0.5. + // + // So eta should be of width sig = 1/sqrt(2). - RealD scale = std::sqrt(0.5); + RealD scale = std::sqrt(0.5); - FermionField eta(FermOp.FermionGrid()); + FermionField eta(FermOp.FermionGrid()); - gaussian(pRNG,eta); + gaussian(pRNG,eta); - FermOp.ImportGauge(U); + FermOp.ImportGauge(U); - // mutishift CG - MdagMLinearOperator ,FermionField> MdagMOp(FermOp); - ConjugateGradientMultiShift msCG(param.MaxIter,PowerQuarter); - msCG(MdagMOp,eta,Phi); + // mutishift CG + MdagMLinearOperator ,FermionField> MdagMOp(FermOp); + ConjugateGradientMultiShift msCG(param.MaxIter,PowerQuarter); + msCG(MdagMOp,eta,Phi); - Phi=Phi*scale; + Phi=Phi*scale; - }; + }; - ////////////////////////////////////////////////////// - // S = phi^dag (Mdag M)^-1/2 phi - ////////////////////////////////////////////////////// - virtual RealD S(const GaugeField &U) { + ////////////////////////////////////////////////////// + // S = phi^dag (Mdag M)^-1/2 phi + ////////////////////////////////////////////////////// + virtual RealD S(const GaugeField &U) { - FermOp.ImportGauge(U); + FermOp.ImportGauge(U); - FermionField Y(FermOp.FermionGrid()); + FermionField Y(FermOp.FermionGrid()); - MdagMLinearOperator ,FermionField> MdagMOp(FermOp); + MdagMLinearOperator ,FermionField> MdagMOp(FermOp); - ConjugateGradientMultiShift msCG(param.MaxIter,PowerNegQuarter); + ConjugateGradientMultiShift msCG(param.MaxIter,PowerNegQuarter); - msCG(MdagMOp,Phi,Y); + msCG(MdagMOp,Phi,Y); - RealD action = norm2(Y); - std::cout << GridLogMessage << "Pseudofermion action FIXME -- is -1/4 solve or -1/2 solve faster??? "< MPhi_k (Npole,FermOp.FermionGrid()); + ////////////////////////////////////////////////////// + // Need + // dS_f/dU = chi^dag d[N/D] chi + // + // N/D is expressed as partial fraction expansion: + // + // a0 + \sum_k ak/(M^dagM + bk) + // + // d[N/D] is then + // + // \sum_k -ak [M^dagM+bk]^{-1} [ dM^dag M + M^dag dM ] [M^dag M + bk]^{-1} + // + // Need + // Mf Phi_k = [MdagM+bk]^{-1} Phi + // Mf Phi = \sum_k ak [MdagM+bk]^{-1} Phi + // + // With these building blocks + // + // dS/dU = \sum_k -ak Mf Phi_k^dag [ dM^dag M + M^dag dM ] Mf Phi_k + // S = innerprodReal(Phi,Mf Phi); + ////////////////////////////////////////////////////// + virtual void deriv(const GaugeField &U,GaugeField & dSdU) { - FermionField X(FermOp.FermionGrid()); - FermionField Y(FermOp.FermionGrid()); + const int Npole = PowerNegHalf.poles.size(); - GaugeField tmp(FermOp.GaugeGrid()); + std::vector MPhi_k (Npole,FermOp.FermionGrid()); - FermOp.ImportGauge(U); + FermionField X(FermOp.FermionGrid()); + FermionField Y(FermOp.FermionGrid()); - MdagMLinearOperator ,FermionField> MdagMOp(FermOp); + GaugeField tmp(FermOp.GaugeGrid()); - ConjugateGradientMultiShift msCG(param.MaxIter,PowerNegHalf); + FermOp.ImportGauge(U); - msCG(MdagMOp,Phi,MPhi_k); + MdagMLinearOperator ,FermionField> MdagMOp(FermOp); - dSdU = Zero(); - for(int k=0;k msCG(param.MaxIter,PowerNegHalf); - RealD ak = PowerNegHalf.residues[k]; + msCG(MdagMOp,Phi,MPhi_k); - X = MPhi_k[k]; + dSdU = zero; + for(int k=0;k 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. See the full license in the file "LICENSE" in the top level distribution directory -*************************************************************************************/ -/* END LEGAL */ + *************************************************************************************/ + /* END LEGAL */ #ifndef QCD_PSEUDOFERMION_ONE_FLAVOUR_RATIONAL_RATIO_H #define QCD_PSEUDOFERMION_ONE_FLAVOUR_RATIONAL_RATIO_H -NAMESPACE_BEGIN(Grid); - -/////////////////////////////////////// -// One flavour rational -/////////////////////////////////////// +namespace Grid{ + namespace QCD{ -// S_f = chi^dag* P(V^dag*V)/Q(V^dag*V)* N(M^dag*M)/D(M^dag*M)* P(V^dag*V)/Q(V^dag*V)* chi -// -// Here P/Q \sim R_{1/4} ~ (V^dagV)^{1/4} -// Here N/D \sim R_{-1/2} ~ (M^dagM)^{-1/2} - -template -class OneFlavourRatioRationalPseudoFermionAction : public Action { -public: - - INHERIT_IMPL_TYPES(Impl); - - typedef OneFlavourRationalParams Params; - Params param; - - MultiShiftFunction PowerHalf ; - MultiShiftFunction PowerNegHalf; - MultiShiftFunction PowerQuarter; - MultiShiftFunction PowerNegQuarter; - -private: - - FermionOperator & NumOp;// the basic operator - FermionOperator & DenOp;// the basic operator - FermionField Phi; // the pseudo fermion field for this trajectory - -public: - - OneFlavourRatioRationalPseudoFermionAction(FermionOperator &_NumOp, - FermionOperator &_DenOp, - Params & p - ) : NumOp(_NumOp), DenOp(_DenOp), Phi(_NumOp.FermionGrid()), param(p) - { - AlgRemez remez(param.lo,param.hi,param.precision); - - // MdagM^(+- 1/2) - std::cout< sig^2 = 0.5. - // - // So eta should be of width sig = 1/sqrt(2). + // Here P/Q \sim R_{1/4} ~ (V^dagV)^{1/4} + // Here N/D \sim R_{-1/2} ~ (M^dagM)^{-1/2} + + template + class OneFlavourRatioRationalPseudoFermionAction : public Action { + public: - RealD scale = std::sqrt(0.5); + INHERIT_IMPL_TYPES(Impl); - FermionField tmp(NumOp.FermionGrid()); - FermionField eta(NumOp.FermionGrid()); + typedef OneFlavourRationalParams Params; + Params param; - gaussian(pRNG,eta); + MultiShiftFunction PowerHalf ; + MultiShiftFunction PowerNegHalf; + MultiShiftFunction PowerQuarter; + MultiShiftFunction PowerNegQuarter; - NumOp.ImportGauge(U); - DenOp.ImportGauge(U); + private: + + FermionOperator & NumOp;// the basic operator + FermionOperator & DenOp;// the basic operator + FermionField Phi; // the pseudo fermion field for this trajectory - // MdagM^1/4 eta - MdagMLinearOperator ,FermionField> MdagM(DenOp); - ConjugateGradientMultiShift msCG_M(param.MaxIter,PowerQuarter); - msCG_M(MdagM,eta,tmp); + public: - // VdagV^-1/4 MdagM^1/4 eta - MdagMLinearOperator ,FermionField> VdagV(NumOp); - ConjugateGradientMultiShift msCG_V(param.MaxIter,PowerNegQuarter); - msCG_V(VdagV,tmp,Phi); + OneFlavourRatioRationalPseudoFermionAction(FermionOperator &_NumOp, + FermionOperator &_DenOp, + Params & p + ) : NumOp(_NumOp), DenOp(_DenOp), Phi(_NumOp.FermionGrid()), param(p) + { + AlgRemez remez(param.lo,param.hi,param.precision); - Phi=Phi*scale; + // MdagM^(+- 1/2) + std::cout< sig^2 = 0.5. + // + // So eta should be of width sig = 1/sqrt(2). + + RealD scale = std::sqrt(0.5); + + FermionField tmp(NumOp.FermionGrid()); + FermionField eta(NumOp.FermionGrid()); + + gaussian(pRNG,eta); + + NumOp.ImportGauge(U); + DenOp.ImportGauge(U); + + // MdagM^1/4 eta + MdagMLinearOperator ,FermionField> MdagM(DenOp); + ConjugateGradientMultiShift msCG_M(param.MaxIter,PowerQuarter); + msCG_M(MdagM,eta,tmp); + + // VdagV^-1/4 MdagM^1/4 eta + MdagMLinearOperator ,FermionField> VdagV(NumOp); + ConjugateGradientMultiShift msCG_V(param.MaxIter,PowerNegQuarter); + msCG_V(VdagV,tmp,Phi); + + Phi=Phi*scale; - }; + }; - ////////////////////////////////////////////////////// - // S_f = chi^dag* P(V^dag*V)/Q(V^dag*V)* N(M^dag*M)/D(M^dag*M)* P(V^dag*V)/Q(V^dag*V)* chi - ////////////////////////////////////////////////////// - virtual RealD S(const GaugeField &U) { + ////////////////////////////////////////////////////// + // S_f = chi^dag* P(V^dag*V)/Q(V^dag*V)* N(M^dag*M)/D(M^dag*M)* P(V^dag*V)/Q(V^dag*V)* chi + ////////////////////////////////////////////////////// + virtual RealD S(const GaugeField &U) { - NumOp.ImportGauge(U); - DenOp.ImportGauge(U); + NumOp.ImportGauge(U); + DenOp.ImportGauge(U); - FermionField X(NumOp.FermionGrid()); - FermionField Y(NumOp.FermionGrid()); + FermionField X(NumOp.FermionGrid()); + FermionField Y(NumOp.FermionGrid()); - // VdagV^1/4 Phi - MdagMLinearOperator ,FermionField> VdagV(NumOp); - ConjugateGradientMultiShift msCG_V(param.MaxIter,PowerQuarter); - msCG_V(VdagV,Phi,X); + // VdagV^1/4 Phi + MdagMLinearOperator ,FermionField> VdagV(NumOp); + ConjugateGradientMultiShift msCG_V(param.MaxIter,PowerQuarter); + msCG_V(VdagV,Phi,X); - // MdagM^-1/4 VdagV^1/4 Phi - MdagMLinearOperator ,FermionField> MdagM(DenOp); - ConjugateGradientMultiShift msCG_M(param.MaxIter,PowerNegQuarter); - msCG_M(MdagM,X,Y); + // MdagM^-1/4 VdagV^1/4 Phi + MdagMLinearOperator ,FermionField> MdagM(DenOp); + ConjugateGradientMultiShift msCG_M(param.MaxIter,PowerNegQuarter); + msCG_M(MdagM,X,Y); - // Phidag VdagV^1/4 MdagM^-1/4 MdagM^-1/4 VdagV^1/4 Phi - RealD action = norm2(Y); + // Randomly apply rational bounds checks. + if ( (rand()%param.BoundsCheckFreq)==0 ) { + FermionField gauss(NumOp.FermionGrid()); + gauss = Phi; + HighBoundCheck(MdagM,gauss,param.hi); + InverseSqrtBoundsCheck(param.MaxIter,param.tolerance*100,MdagM,gauss,PowerNegHalf); + } - return action; - }; + // Phidag VdagV^1/4 MdagM^-1/4 MdagM^-1/4 VdagV^1/4 Phi + RealD action = norm2(Y); - // S_f = chi^dag* P(V^dag*V)/Q(V^dag*V)* N(M^dag*M)/D(M^dag*M)* P(V^dag*V)/Q(V^dag*V)* chi - // - // Here, M is some 5D operator and V is the Pauli-Villars field - // N and D makeup the rat. poly of the M term and P and & makeup the rat.poly of the denom term - // - // Need - // dS_f/dU = chi^dag d[P/Q] N/D P/Q chi - // + chi^dag P/Q d[N/D] P/Q chi - // + chi^dag P/Q N/D d[P/Q] chi - // - // P/Q is expressed as partial fraction expansion: - // - // a0 + \sum_k ak/(V^dagV + bk) - // - // d[P/Q] is then - // - // \sum_k -ak [V^dagV+bk]^{-1} [ dV^dag V + V^dag dV ] [V^dag V + bk]^{-1} - // - // and similar for N/D. - // - // Need - // MpvPhi_k = [Vdag V + bk]^{-1} chi - // MpvPhi = {a0 + \sum_k ak [Vdag V + bk]^{-1} }chi - // - // MfMpvPhi_k = [MdagM+bk]^{-1} MpvPhi - // MfMpvPhi = {a0 + \sum_k ak [Mdag M + bk]^{-1} } MpvPhi - // - // MpvMfMpvPhi_k = [Vdag V + bk]^{-1} MfMpvchi - // + return action; + }; - virtual void deriv(const GaugeField &U,GaugeField & dSdU) { + // S_f = chi^dag* P(V^dag*V)/Q(V^dag*V)* N(M^dag*M)/D(M^dag*M)* P(V^dag*V)/Q(V^dag*V)* chi + // + // Here, M is some 5D operator and V is the Pauli-Villars field + // N and D makeup the rat. poly of the M term and P and & makeup the rat.poly of the denom term + // + // Need + // dS_f/dU = chi^dag d[P/Q] N/D P/Q chi + // + chi^dag P/Q d[N/D] P/Q chi + // + chi^dag P/Q N/D d[P/Q] chi + // + // P/Q is expressed as partial fraction expansion: + // + // a0 + \sum_k ak/(V^dagV + bk) + // + // d[P/Q] is then + // + // \sum_k -ak [V^dagV+bk]^{-1} [ dV^dag V + V^dag dV ] [V^dag V + bk]^{-1} + // + // and similar for N/D. + // + // Need + // MpvPhi_k = [Vdag V + bk]^{-1} chi + // MpvPhi = {a0 + \sum_k ak [Vdag V + bk]^{-1} }chi + // + // MfMpvPhi_k = [MdagM+bk]^{-1} MpvPhi + // MfMpvPhi = {a0 + \sum_k ak [Mdag M + bk]^{-1} } MpvPhi + // + // MpvMfMpvPhi_k = [Vdag V + bk]^{-1} MfMpvchi + // - const int n_f = PowerNegHalf.poles.size(); - const int n_pv = PowerQuarter.poles.size(); + virtual void deriv(const GaugeField &U,GaugeField & dSdU) { - std::vector MpvPhi_k (n_pv,NumOp.FermionGrid()); - std::vector MpvMfMpvPhi_k(n_pv,NumOp.FermionGrid()); - std::vector MfMpvPhi_k (n_f,NumOp.FermionGrid()); + const int n_f = PowerNegHalf.poles.size(); + const int n_pv = PowerQuarter.poles.size(); - FermionField MpvPhi(NumOp.FermionGrid()); - FermionField MfMpvPhi(NumOp.FermionGrid()); - FermionField MpvMfMpvPhi(NumOp.FermionGrid()); - FermionField Y(NumOp.FermionGrid()); + std::vector MpvPhi_k (n_pv,NumOp.FermionGrid()); + std::vector MpvMfMpvPhi_k(n_pv,NumOp.FermionGrid()); + std::vector MfMpvPhi_k (n_f,NumOp.FermionGrid()); - GaugeField tmp(NumOp.GaugeGrid()); + FermionField MpvPhi(NumOp.FermionGrid()); + FermionField MfMpvPhi(NumOp.FermionGrid()); + FermionField MpvMfMpvPhi(NumOp.FermionGrid()); + FermionField Y(NumOp.FermionGrid()); - NumOp.ImportGauge(U); - DenOp.ImportGauge(U); + GaugeField tmp(NumOp.GaugeGrid()); - MdagMLinearOperator ,FermionField> MdagM(DenOp); - MdagMLinearOperator ,FermionField> VdagV(NumOp); + NumOp.ImportGauge(U); + DenOp.ImportGauge(U); - ConjugateGradientMultiShift msCG_V(param.MaxIter,PowerQuarter); - ConjugateGradientMultiShift msCG_M(param.MaxIter,PowerNegHalf); + MdagMLinearOperator ,FermionField> MdagM(DenOp); + MdagMLinearOperator ,FermionField> VdagV(NumOp); - msCG_V(VdagV,Phi,MpvPhi_k,MpvPhi); - msCG_M(MdagM,MpvPhi,MfMpvPhi_k,MfMpvPhi); - msCG_V(VdagV,MfMpvPhi,MpvMfMpvPhi_k,MpvMfMpvPhi); + ConjugateGradientMultiShift msCG_V(param.MaxIter,PowerQuarter); + ConjugateGradientMultiShift msCG_M(param.MaxIter,PowerNegHalf); - RealD ak; + msCG_V(VdagV,Phi,MpvPhi_k,MpvPhi); + msCG_M(MdagM,MpvPhi,MfMpvPhi_k,MfMpvPhi); + msCG_V(VdagV,MfMpvPhi,MpvMfMpvPhi_k,MpvMfMpvPhi); - dSdU = Zero(); + RealD ak; - // With these building blocks - // - // dS/dU = - // \sum_k -ak MfMpvPhi_k^dag [ dM^dag M + M^dag dM ] MfMpvPhi_k (1) - // + \sum_k -ak MpvMfMpvPhi_k^\dag [ dV^dag V + V^dag dV ] MpvPhi_k (2) - // -ak MpvPhi_k^dag [ dV^dag V + V^dag dV ] MpvMfMpvPhi_k (3) + dSdU = zero; - //(1) - for(int k=0;k + #include #include #include diff --git a/Grid/qcd/action/pseudofermion/TwoFlavour.h b/Grid/qcd/action/pseudofermion/TwoFlavour.h index 15c86ac8..f905a675 100644 --- a/Grid/qcd/action/pseudofermion/TwoFlavour.h +++ b/Grid/qcd/action/pseudofermion/TwoFlavour.h @@ -84,21 +84,20 @@ public: // and must multiply by 0.707.... // // Chroma has this scale factor: two_flavor_monomial_w.h + // CPS uses this factor // IroIro: does not use this scale. It is absorbed by a change of vars // in the Phi integral, and thus is only an irrelevant prefactor for // the partition function. // - RealD scale = std::sqrt(0.5); + const RealD scale = std::sqrt(0.5); FermionField eta(FermOp.FermionGrid()); - gaussian(pRNG, eta); + gaussian(pRNG, eta); eta = scale *eta; FermOp.ImportGauge(U); FermOp.Mdag(eta, Phi); - - Phi = Phi * scale; }; ////////////////////////////////////////////////////// diff --git a/Grid/qcd/action/pseudofermion/TwoFlavourEvenOddRatio.h b/Grid/qcd/action/pseudofermion/TwoFlavourEvenOddRatio.h index 61a38448..e9a8853a 100644 --- a/Grid/qcd/action/pseudofermion/TwoFlavourEvenOddRatio.h +++ b/Grid/qcd/action/pseudofermion/TwoFlavourEvenOddRatio.h @@ -1,4 +1,4 @@ -/************************************************************************************* + /************************************************************************************* Grid physics library, www.github.com/paboyle/Grid @@ -24,186 +24,194 @@ Author: paboyle 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. See the full license in the file "LICENSE" in the top level distribution directory -*************************************************************************************/ -/* END LEGAL */ + *************************************************************************************/ + /* END LEGAL */ #ifndef QCD_PSEUDOFERMION_TWO_FLAVOUR_EVEN_ODD_RATIO_H #define QCD_PSEUDOFERMION_TWO_FLAVOUR_EVEN_ODD_RATIO_H -NAMESPACE_BEGIN(Grid); +namespace Grid{ + namespace QCD{ -/////////////////////////////////////// -// Two flavour ratio -/////////////////////////////////////// -template -class TwoFlavourEvenOddRatioPseudoFermionAction : public Action { -public: - INHERIT_IMPL_TYPES(Impl); + /////////////////////////////////////// + // Two flavour ratio + /////////////////////////////////////// + template + class TwoFlavourEvenOddRatioPseudoFermionAction : public Action { + public: + INHERIT_IMPL_TYPES(Impl); -private: - FermionOperator & NumOp;// the basic operator - FermionOperator & DenOp;// the basic operator + private: + FermionOperator & NumOp;// the basic operator + FermionOperator & DenOp;// the basic operator - OperatorFunction &DerivativeSolver; - OperatorFunction &ActionSolver; + OperatorFunction &DerivativeSolver; + OperatorFunction &ActionSolver; + OperatorFunction &HeatbathSolver; - FermionField PhiOdd; // the pseudo fermion field for this trajectory - FermionField PhiEven; // the pseudo fermion field for this trajectory + FermionField PhiOdd; // the pseudo fermion field for this trajectory + FermionField PhiEven; // the pseudo fermion field for this trajectory -public: - TwoFlavourEvenOddRatioPseudoFermionAction(FermionOperator &_NumOp, - FermionOperator &_DenOp, - OperatorFunction & DS, - OperatorFunction & AS) : - NumOp(_NumOp), - DenOp(_DenOp), - DerivativeSolver(DS), - ActionSolver(AS), - PhiEven(_NumOp.FermionRedBlackGrid()), - PhiOdd(_NumOp.FermionRedBlackGrid()) - { - conformable(_NumOp.FermionGrid(), _DenOp.FermionGrid()); - conformable(_NumOp.FermionRedBlackGrid(), _DenOp.FermionRedBlackGrid()); - conformable(_NumOp.GaugeGrid(), _DenOp.GaugeGrid()); - conformable(_NumOp.GaugeRedBlackGrid(), _DenOp.GaugeRedBlackGrid()); - }; + public: + TwoFlavourEvenOddRatioPseudoFermionAction(FermionOperator &_NumOp, + FermionOperator &_DenOp, + OperatorFunction & DS, + OperatorFunction & AS ) : + TwoFlavourEvenOddRatioPseudoFermionAction(_NumOp,_DenOp, DS,AS,AS) {}; - virtual std::string action_name(){return "TwoFlavourEvenOddRatioPseudoFermionAction";} + TwoFlavourEvenOddRatioPseudoFermionAction(FermionOperator &_NumOp, + FermionOperator &_DenOp, + OperatorFunction & DS, + OperatorFunction & AS, OperatorFunction & HS) : + NumOp(_NumOp), + DenOp(_DenOp), + DerivativeSolver(DS), + ActionSolver(AS), + HeatbathSolver(HS), + PhiEven(_NumOp.FermionRedBlackGrid()), + PhiOdd(_NumOp.FermionRedBlackGrid()) + { + conformable(_NumOp.FermionGrid(), _DenOp.FermionGrid()); + conformable(_NumOp.FermionRedBlackGrid(), _DenOp.FermionRedBlackGrid()); + conformable(_NumOp.GaugeGrid(), _DenOp.GaugeGrid()); + conformable(_NumOp.GaugeRedBlackGrid(), _DenOp.GaugeRedBlackGrid()); + }; - virtual std::string LogParameters(){ - std::stringstream sstream; - sstream << GridLogMessage << "["< sig^2 = 0.5. - // - RealD scale = std::sqrt(0.5); + // P(phi) = e^{- phi^dag Vpc (MpcdagMpc)^-1 Vpcdag phi} + // + // NumOp == V + // DenOp == M + // + // Take phi_o = Vpcdag^{-1} Mpcdag eta_o ; eta_o = Mpcdag^{-1} Vpcdag Phi + // + // P(eta_o) = e^{- eta_o^dag eta_o} + // + // e^{x^2/2 sig^2} => sig^2 = 0.5. + // + RealD scale = std::sqrt(0.5); - FermionField eta (NumOp.FermionGrid()); - FermionField etaOdd (NumOp.FermionRedBlackGrid()); - FermionField etaEven(NumOp.FermionRedBlackGrid()); - FermionField tmp (NumOp.FermionRedBlackGrid()); + FermionField eta (NumOp.FermionGrid()); + FermionField etaOdd (NumOp.FermionRedBlackGrid()); + FermionField etaEven(NumOp.FermionRedBlackGrid()); + FermionField tmp (NumOp.FermionRedBlackGrid()); - gaussian(pRNG,eta); + gaussian(pRNG,eta); - pickCheckerboard(Even,etaEven,eta); - pickCheckerboard(Odd,etaOdd,eta); + pickCheckerboard(Even,etaEven,eta); + pickCheckerboard(Odd,etaOdd,eta); - NumOp.ImportGauge(U); - DenOp.ImportGauge(U); + NumOp.ImportGauge(U); + DenOp.ImportGauge(U); - SchurDifferentiableOperator Mpc(DenOp); - SchurDifferentiableOperator Vpc(NumOp); + SchurDifferentiableOperator Mpc(DenOp); + SchurDifferentiableOperator Vpc(NumOp); - // Odd det factors - Mpc.MpcDag(etaOdd,PhiOdd); - tmp=Zero(); - ActionSolver(Vpc,PhiOdd,tmp); - Vpc.Mpc(tmp,PhiOdd); + // Odd det factors + Mpc.MpcDag(etaOdd,PhiOdd); + tmp=zero; + HeatbathSolver(Vpc,PhiOdd,tmp); + Vpc.Mpc(tmp,PhiOdd); - // Even det factors - DenOp.MooeeDag(etaEven,tmp); - NumOp.MooeeInvDag(tmp,PhiEven); + // Even det factors + DenOp.MooeeDag(etaEven,tmp); + NumOp.MooeeInvDag(tmp,PhiEven); - PhiOdd =PhiOdd*scale; - PhiEven=PhiEven*scale; + PhiOdd =PhiOdd*scale; + PhiEven=PhiEven*scale; - }; + }; - ////////////////////////////////////////////////////// - // S = phi^dag V (Mdag M)^-1 Vdag phi - ////////////////////////////////////////////////////// - virtual RealD S(const GaugeField &U) { + ////////////////////////////////////////////////////// + // S = phi^dag V (Mdag M)^-1 Vdag phi + ////////////////////////////////////////////////////// + virtual RealD S(const GaugeField &U) { - NumOp.ImportGauge(U); - DenOp.ImportGauge(U); + NumOp.ImportGauge(U); + DenOp.ImportGauge(U); - SchurDifferentiableOperator Mpc(DenOp); - SchurDifferentiableOperator Vpc(NumOp); + SchurDifferentiableOperator Mpc(DenOp); + SchurDifferentiableOperator Vpc(NumOp); - FermionField X(NumOp.FermionRedBlackGrid()); - FermionField Y(NumOp.FermionRedBlackGrid()); + FermionField X(NumOp.FermionRedBlackGrid()); + FermionField Y(NumOp.FermionRedBlackGrid()); - Vpc.MpcDag(PhiOdd,Y); // Y= Vdag phi - X=Zero(); - ActionSolver(Mpc,Y,X); // X= (MdagM)^-1 Vdag phi - //Mpc.Mpc(X,Y); // Y= Mdag^-1 Vdag phi - // Multiply by Ydag - RealD action = real(innerProduct(Y,X)); + Vpc.MpcDag(PhiOdd,Y); // Y= Vdag phi + X=zero; + ActionSolver(Mpc,Y,X); // X= (MdagM)^-1 Vdag phi + //Mpc.Mpc(X,Y); // Y= Mdag^-1 Vdag phi + // Multiply by Ydag + RealD action = real(innerProduct(Y,X)); - //RealD action = norm2(Y); + //RealD action = norm2(Y); - // The EE factorised block; normally can replace with Zero() if det is constant (gauge field indept) - // Only really clover term that creates this. Leave the EE portion as a future to do to make most - // rapid progresss on DWF for now. - // - NumOp.MooeeDag(PhiEven,X); - DenOp.MooeeInvDag(X,Y); - action = action + norm2(Y); + // The EE factorised block; normally can replace with zero if det is constant (gauge field indept) + // Only really clover term that creates this. Leave the EE portion as a future to do to make most + // rapid progresss on DWF for now. + // + NumOp.MooeeDag(PhiEven,X); + DenOp.MooeeInvDag(X,Y); + action = action + norm2(Y); - return action; - }; + return action; + }; - ////////////////////////////////////////////////////// - // dS/du = phi^dag dV (Mdag M)^-1 V^dag phi - // - phi^dag V (Mdag M)^-1 [ Mdag dM + dMdag M ] (Mdag M)^-1 V^dag phi - // + phi^dag V (Mdag M)^-1 dV^dag phi - ////////////////////////////////////////////////////// - virtual void deriv(const GaugeField &U,GaugeField & dSdU) { + ////////////////////////////////////////////////////// + // dS/du = phi^dag dV (Mdag M)^-1 V^dag phi + // - phi^dag V (Mdag M)^-1 [ Mdag dM + dMdag M ] (Mdag M)^-1 V^dag phi + // + phi^dag V (Mdag M)^-1 dV^dag phi + ////////////////////////////////////////////////////// + virtual void deriv(const GaugeField &U,GaugeField & dSdU) { - NumOp.ImportGauge(U); - DenOp.ImportGauge(U); + NumOp.ImportGauge(U); + DenOp.ImportGauge(U); - SchurDifferentiableOperator Mpc(DenOp); - SchurDifferentiableOperator Vpc(NumOp); + SchurDifferentiableOperator Mpc(DenOp); + SchurDifferentiableOperator Vpc(NumOp); - FermionField X(NumOp.FermionRedBlackGrid()); - FermionField Y(NumOp.FermionRedBlackGrid()); + FermionField X(NumOp.FermionRedBlackGrid()); + FermionField Y(NumOp.FermionRedBlackGrid()); - // This assignment is necessary to be compliant with the HMC grids - GaugeField force(dSdU.Grid()); + // This assignment is necessary to be compliant with the HMC grids + GaugeField force(dSdU._grid); - //Y=Vdag phi - //X = (Mdag M)^-1 V^dag phi - //Y = (Mdag)^-1 V^dag phi - Vpc.MpcDag(PhiOdd,Y); // Y= Vdag phi - X=Zero(); - DerivativeSolver(Mpc,Y,X); // X= (MdagM)^-1 Vdag phi - Mpc.Mpc(X,Y); // Y= Mdag^-1 Vdag phi + //Y=Vdag phi + //X = (Mdag M)^-1 V^dag phi + //Y = (Mdag)^-1 V^dag phi + Vpc.MpcDag(PhiOdd,Y); // Y= Vdag phi + X=zero; + DerivativeSolver(Mpc,Y,X); // X= (MdagM)^-1 Vdag phi + Mpc.Mpc(X,Y); // Y= Mdag^-1 Vdag phi - // phi^dag V (Mdag M)^-1 dV^dag phi - Vpc.MpcDagDeriv(force , X, PhiOdd ); dSdU = force; + // phi^dag V (Mdag M)^-1 dV^dag phi + Vpc.MpcDagDeriv(force , X, PhiOdd ); dSdU = force; - // phi^dag dV (Mdag M)^-1 V^dag phi - Vpc.MpcDeriv(force , PhiOdd, X ); dSdU = dSdU+force; + // phi^dag dV (Mdag M)^-1 V^dag phi + Vpc.MpcDeriv(force , PhiOdd, X ); dSdU = dSdU+force; - // - phi^dag V (Mdag M)^-1 Mdag dM (Mdag M)^-1 V^dag phi - // - phi^dag V (Mdag M)^-1 dMdag M (Mdag M)^-1 V^dag phi - Mpc.MpcDeriv(force,Y,X); dSdU = dSdU-force; - Mpc.MpcDagDeriv(force,X,Y); dSdU = dSdU-force; + // - phi^dag V (Mdag M)^-1 Mdag dM (Mdag M)^-1 V^dag phi + // - phi^dag V (Mdag M)^-1 dMdag M (Mdag M)^-1 V^dag phi + Mpc.MpcDeriv(force,Y,X); dSdU = dSdU-force; + Mpc.MpcDagDeriv(force,X,Y); dSdU = dSdU-force; - // FIXME No force contribution from EvenEven assumed here - // Needs a fix for clover. - assert(NumOp.ConstEE() == 1); - assert(DenOp.ConstEE() == 1); + // FIXME No force contribution from EvenEven assumed here + // Needs a fix for clover. + assert(NumOp.ConstEE() == 1); + assert(DenOp.ConstEE() == 1); - dSdU = -dSdU; + dSdU = -dSdU; - }; -}; - -NAMESPACE_END(Grid); - + }; + }; + } +} #endif diff --git a/Grid/qcd/hmc/integrators/Integrator.h b/Grid/qcd/hmc/integrators/Integrator.h index b795d75a..91af7372 100644 --- a/Grid/qcd/hmc/integrators/Integrator.h +++ b/Grid/qcd/hmc/integrators/Integrator.h @@ -41,19 +41,16 @@ public: GRID_SERIALIZABLE_CLASS_MEMBERS(IntegratorParameters, std::string, name, // name of the integrator unsigned int, MDsteps, // number of outer steps - RealD, trajL, // trajectory length - ) + RealD, trajL) // trajectory length IntegratorParameters(int MDsteps_ = 10, RealD trajL_ = 1.0) : MDsteps(MDsteps_), - trajL(trajL_){ - // empty body constructor - }; - + trajL(trajL_) {}; template ::value, int >::type = 0 > - IntegratorParameters(ReaderClass & Reader){ - std::cout << "Reading integrator\n"; + IntegratorParameters(ReaderClass & Reader) + { + std::cout << GridLogMessage << "Reading integrator\n"; read(Reader, "Integrator", *this); } @@ -83,17 +80,18 @@ protected: const ActionSet as; - void update_P(Field& U, int level, double ep) { + void update_P(Field& U, int level, double ep) + { t_P[level] += ep; update_P(P, U, level, ep); - std::cout << GridLogIntegrator << "[" << level << "] P " - << " dt " << ep << " : t_P " << t_P[level] << std::endl; + std::cout << GridLogIntegrator << "[" << level << "] P " << " dt " << ep << " : t_P " << t_P[level] << std::endl; } // to be used by the actionlevel class to iterate // over the representations - struct _updateP { + struct _updateP + { template void operator()(std::vector*> repr_set, Repr& Rep, GF& Mom, GF& U, double ep) { @@ -104,7 +102,7 @@ protected: GF force = Rep.RtoFundamentalProject(forceR); // Ta for the fundamental rep Real force_abs = std::sqrt(norm2(force)/(U.Grid()->gSites())); std::cout << GridLogIntegrator << "Hirep Force average: " << force_abs << std::endl; - Mom -= force * ep ; + Mom -= force * ep* HMC_MOMENTUM_DENOMINATOR;; } } } update_P_hireps{}; @@ -128,18 +126,19 @@ protected: double end_force = usecond(); Real force_abs = std::sqrt(norm2(force)/U.Grid()->gSites()); std::cout << GridLogIntegrator << "["<is_smeared); + Field& Us = Smearer.get_U(as[level].actions.at(actionID)->is_smeared); as[level].actions.at(actionID)->refresh(Us, pRNG); } @@ -251,13 +255,11 @@ public: // over the representations struct _S { template - void operator()(std::vector*> repr_set, Repr& Rep, - int level, RealD& H) { + void operator()(std::vector*> repr_set, Repr& Rep, int level, RealD& H) { for (int a = 0; a < repr_set.size(); ++a) { RealD Hterm = repr_set.at(a)->S(Rep.U); - std::cout << GridLogMessage << "S Level " << level << " term " << a - << " H Hirep = " << Hterm << std::endl; + std::cout << GridLogMessage << "S Level " << level << " term " << a << " H Hirep = " << Hterm << std::endl; H += Hterm; } @@ -265,22 +267,24 @@ public: } S_hireps{}; // Calculate action - RealD S(Field& U) { // here also U not used + RealD S(Field& U) + { // here also U not used + + std::cout << GridLogIntegrator << "Integrator action\n"; + + RealD H = - FieldImplementation::FieldSquareNorm(P)/HMC_MOMENTUM_DENOMINATOR; // - trace (P*P)/denom - RealD H = - FieldImplementation::FieldSquareNorm(P); // - trace (P*P) RealD Hterm; - std::cout << GridLogMessage << "Momentum action H_p = " << H << "\n"; // Actions for (int level = 0; level < as.size(); ++level) { for (int actionID = 0; actionID < as[level].actions.size(); ++actionID) { // get gauge field from the SmearingPolicy and // based on the boolean is_smeared in actionID - Field& Us = - Smearer.get_U(as[level].actions.at(actionID)->is_smeared); + Field& Us = Smearer.get_U(as[level].actions.at(actionID)->is_smeared); + std::cout << GridLogMessage << "S [" << level << "][" << actionID << "] action eval " << std::endl; Hterm = as[level].actions.at(actionID)->S(Us); - std::cout << GridLogMessage << "S Level " << level << " term " - << actionID << " H = " << Hterm << std::endl; + std::cout << GridLogMessage << "S [" << level << "][" << actionID << "] H = " << Hterm << std::endl; H += Hterm; } as[level].apply(S_hireps, Representations, level, H); @@ -289,7 +293,8 @@ public: return H; } - void integrate(Field& U) { + void integrate(Field& U) + { // reset the clocks t_U = 0; for (int level = 0; level < as.size(); ++level) { @@ -305,8 +310,7 @@ public: // Check the clocks all match on all levels for (int level = 0; level < as.size(); ++level) { assert(fabs(t_U - t_P[level]) < 1.0e-6); // must be the same - std::cout << GridLogIntegrator << " times[" << level - << "]= " << t_P[level] << " " << t_U << std::endl; + std::cout << GridLogIntegrator << " times[" << level << "]= " << t_P[level] << " " << t_U << std::endl; } // and that we indeed got to the end of the trajectory diff --git a/Grid/qcd/hmc/integrators/Integrator_algorithm.h b/Grid/qcd/hmc/integrators/Integrator_algorithm.h index 86df988f..b05c4ea8 100644 --- a/Grid/qcd/hmc/integrators/Integrator_algorithm.h +++ b/Grid/qcd/hmc/integrators/Integrator_algorithm.h @@ -26,15 +26,15 @@ with this program; if not, write to the Free Software Foundation, Inc., See the full license in the file "LICENSE" in the top level distribution directory *************************************************************************************/ - /* END LEGAL */ - //-------------------------------------------------------------------- +/* END LEGAL */ +//-------------------------------------------------------------------- - /*! @file Integrator_algorithm.h - * @brief Declaration of classes for the Molecular Dynamics algorithms - * - */ - //-------------------------------------------------------------------- +/*! @file Integrator_algorithm.h + * @brief Declaration of classes for the Molecular Dynamics algorithms + * + */ +//-------------------------------------------------------------------- #ifndef INTEGRATOR_ALG_INCLUDED #define INTEGRATOR_ALG_INCLUDED @@ -92,22 +92,17 @@ NAMESPACE_BEGIN(Grid); * P 1/2 P 1/2 */ -template > -class LeapFrog : public Integrator { +template > +class LeapFrog : public Integrator +{ public: - typedef LeapFrog - Algorithm; + typedef LeapFrog Algorithm; INHERIT_FIELD_TYPES(FieldImplementation); std::string integrator_name(){return "LeapFrog";} - LeapFrog(GridBase* grid, IntegratorParameters Par, - ActionSet& Aset, SmearingPolicy& Sm) - : Integrator( - grid, Par, Aset, Sm){}; + LeapFrog(GridBase* grid, IntegratorParameters Par, ActionSet& Aset, SmearingPolicy& Sm) + : Integrator(grid, Par, Aset, Sm){}; void step(Field& U, int level, int _first, int _last) { int fl = this->as.size() - 1; @@ -140,21 +135,17 @@ public: } }; -template > -class MinimumNorm2 : public Integrator { +template > +class MinimumNorm2 : public Integrator +{ private: const RealD lambda = 0.1931833275037836; public: INHERIT_FIELD_TYPES(FieldImplementation); - MinimumNorm2(GridBase* grid, IntegratorParameters Par, - ActionSet& Aset, SmearingPolicy& Sm) - : Integrator( - grid, Par, Aset, Sm){}; + MinimumNorm2(GridBase* grid, IntegratorParameters Par, ActionSet& Aset, SmearingPolicy& Sm) + : Integrator(grid, Par, Aset, Sm){}; std::string integrator_name(){return "MininumNorm2";} @@ -201,14 +192,11 @@ public: } }; -template > -class ForceGradient : public Integrator { +template > +class ForceGradient : public Integrator +{ private: const RealD lambda = 1.0 / 6.0; - ; const RealD chi = 1.0 / 72.0; const RealD xi = 0.0; const RealD theta = 0.0; @@ -230,8 +218,7 @@ public: Field Pfg(U.Grid()); Ufg = U; Pfg = Zero(); - std::cout << GridLogIntegrator << "FG update " << fg_dt << " " << ep - << std::endl; + std::cout << GridLogIntegrator << "FG update " << fg_dt << " " << ep << std::endl; // prepare_fg; no prediction/result cache for now // could relax CG stopping conditions for the // derivatives in the small step since the force gets multiplied by @@ -270,8 +257,7 @@ public: this->step(U, level + 1, first_step, 0); } - this->FG_update_P(U, level, 2 * Chi / ((1.0 - 2.0 * lambda) * eps), - (1.0 - 2.0 * lambda) * eps); + this->FG_update_P(U, level, 2 * Chi / ((1.0 - 2.0 * lambda) * eps), (1.0 - 2.0 * lambda) * eps); if (level == fl) { // lowest level this->update_U(U, 0.5 * eps); diff --git a/Grid/qcd/spin/Gamma.cc b/Grid/qcd/spin/Gamma.cc index 1056f330..de56d713 100644 --- a/Grid/qcd/spin/Gamma.cc +++ b/Grid/qcd/spin/Gamma.cc @@ -10,6 +10,24 @@ const std::array Gamma::gmu = {{ Gamma(Gamma::Algebra::GammaZ), Gamma(Gamma::Algebra::GammaT)}}; +const std::array Gamma::gall = {{ + Gamma(Gamma::Algebra::Identity), + Gamma(Gamma::Algebra::Gamma5), + Gamma(Gamma::Algebra::GammaX), + Gamma(Gamma::Algebra::GammaY), + Gamma(Gamma::Algebra::GammaZ), + Gamma(Gamma::Algebra::GammaT), + Gamma(Gamma::Algebra::GammaXGamma5), + Gamma(Gamma::Algebra::GammaYGamma5), + Gamma(Gamma::Algebra::GammaZGamma5), + Gamma(Gamma::Algebra::GammaTGamma5), + Gamma(Gamma::Algebra::SigmaXT), + Gamma(Gamma::Algebra::SigmaXY), + Gamma(Gamma::Algebra::SigmaXZ), + Gamma(Gamma::Algebra::SigmaYT), + Gamma(Gamma::Algebra::SigmaYZ), + Gamma(Gamma::Algebra::SigmaZT)}}; + const std::array Gamma::name = {{ "-Gamma5 ", "Gamma5 ", diff --git a/Grid/qcd/spin/Gamma.h b/Grid/qcd/spin/Gamma.h index 4d2bc5a9..e9778ffc 100644 --- a/Grid/qcd/spin/Gamma.h +++ b/Grid/qcd/spin/Gamma.h @@ -47,6 +47,7 @@ class Gamma { static const std::array, nGamma> mul; static const std::array adj; static const std::array gmu; + static const std::array gall; Algebra g; public: accelerator Gamma(Algebra initg): g(initg) {} diff --git a/Grid/qcd/spin/gamma-gen/gamma-gen.nb b/Grid/qcd/spin/gamma-gen/gamma-gen.nb index 4167b6e2..dc8a242e 100644 --- a/Grid/qcd/spin/gamma-gen/gamma-gen.nb +++ b/Grid/qcd/spin/gamma-gen/gamma-gen.nb @@ -10,10 +10,10 @@ NotebookFileLineBreakTest NotebookFileLineBreakTest NotebookDataPosition[ 158, 7] -NotebookDataLength[ 75090, 1956] -NotebookOptionsPosition[ 69536, 1867] -NotebookOutlinePosition[ 69898, 1883] -CellTagsIndexPosition[ 69855, 1880] +NotebookDataLength[ 67118, 1714] +NotebookOptionsPosition[ 63485, 1652] +NotebookOutlinePosition[ 63842, 1668] +CellTagsIndexPosition[ 63799, 1665] WindowFrame->Normal*) (* Beginning of Notebook Content *) @@ -76,234 +76,6 @@ Cell[BoxData["\<\"/Users/antonin/Development/Grid/lib/qcd/spin/gamma-gen\"\>"]\ Cell[CellGroupData[{ -Cell[BoxData[ - RowBox[{"FactorInteger", "[", "3152", "]"}]], "Input", - CellChangeTimes->{{3.7432347536316767`*^9, 3.7432347764739027`*^9}, { - 3.743234833567358*^9, - 3.743234862146022*^9}},ExpressionUUID->"d1a0fd03-85e1-43af-ba80-\ -3ca4235675d8"], - -Cell[BoxData[ - RowBox[{"{", - RowBox[{ - RowBox[{"{", - RowBox[{"2", ",", "4"}], "}"}], ",", - RowBox[{"{", - RowBox[{"197", ",", "1"}], "}"}]}], "}"}]], "Output", - CellChangeTimes->{{3.743234836792224*^9, - 3.743234862493619*^9}},ExpressionUUID->"16d3f953-4b24-4ed2-ae62-\ -306dcab66ca7"] -}, Open ]], - -Cell[CellGroupData[{ - -Cell[BoxData[ - RowBox[{"sol", "=", - RowBox[{"Solve", "[", - RowBox[{ - RowBox[{ - RowBox[{ - SuperscriptBox["x", "2"], "+", - SuperscriptBox["y", "2"], "+", - SuperscriptBox["z", "2"]}], "\[Equal]", "2"}], ",", - RowBox[{"{", - RowBox[{"x", ",", "y", ",", "z"}], "}"}], ",", "Integers"}], - "]"}]}]], "Input", - CellChangeTimes->{{3.743235304127721*^9, - 3.7432353087929983`*^9}},ExpressionUUID->"f0fa2a5c-3d81-4d75-a447-\ -50c7ca3459ff"], - -Cell[BoxData[ - RowBox[{"{", - RowBox[{ - RowBox[{"{", - RowBox[{ - RowBox[{"x", "\[Rule]", - RowBox[{"-", "1"}]}], ",", - RowBox[{"y", "\[Rule]", - RowBox[{"-", "1"}]}], ",", - RowBox[{"z", "\[Rule]", "0"}]}], "}"}], ",", - RowBox[{"{", - RowBox[{ - RowBox[{"x", "\[Rule]", - RowBox[{"-", "1"}]}], ",", - RowBox[{"y", "\[Rule]", "0"}], ",", - RowBox[{"z", "\[Rule]", - RowBox[{"-", "1"}]}]}], "}"}], ",", - RowBox[{"{", - RowBox[{ - RowBox[{"x", "\[Rule]", - RowBox[{"-", "1"}]}], ",", - RowBox[{"y", "\[Rule]", "0"}], ",", - RowBox[{"z", "\[Rule]", "1"}]}], "}"}], ",", - RowBox[{"{", - RowBox[{ - RowBox[{"x", "\[Rule]", - RowBox[{"-", "1"}]}], ",", - RowBox[{"y", "\[Rule]", "1"}], ",", - RowBox[{"z", "\[Rule]", "0"}]}], "}"}], ",", - RowBox[{"{", - RowBox[{ - RowBox[{"x", "\[Rule]", "0"}], ",", - RowBox[{"y", "\[Rule]", - RowBox[{"-", "1"}]}], ",", - RowBox[{"z", "\[Rule]", - RowBox[{"-", "1"}]}]}], "}"}], ",", - RowBox[{"{", - RowBox[{ - RowBox[{"x", "\[Rule]", "0"}], ",", - RowBox[{"y", "\[Rule]", - RowBox[{"-", "1"}]}], ",", - RowBox[{"z", "\[Rule]", "1"}]}], "}"}], ",", - RowBox[{"{", - RowBox[{ - RowBox[{"x", "\[Rule]", "0"}], ",", - RowBox[{"y", "\[Rule]", "1"}], ",", - RowBox[{"z", "\[Rule]", - RowBox[{"-", "1"}]}]}], "}"}], ",", - RowBox[{"{", - RowBox[{ - RowBox[{"x", "\[Rule]", "0"}], ",", - RowBox[{"y", "\[Rule]", "1"}], ",", - RowBox[{"z", "\[Rule]", "1"}]}], "}"}], ",", - RowBox[{"{", - RowBox[{ - RowBox[{"x", "\[Rule]", "1"}], ",", - RowBox[{"y", "\[Rule]", - RowBox[{"-", "1"}]}], ",", - RowBox[{"z", "\[Rule]", "0"}]}], "}"}], ",", - RowBox[{"{", - RowBox[{ - RowBox[{"x", "\[Rule]", "1"}], ",", - RowBox[{"y", "\[Rule]", "0"}], ",", - RowBox[{"z", "\[Rule]", - RowBox[{"-", "1"}]}]}], "}"}], ",", - RowBox[{"{", - RowBox[{ - RowBox[{"x", "\[Rule]", "1"}], ",", - RowBox[{"y", "\[Rule]", "0"}], ",", - RowBox[{"z", "\[Rule]", "1"}]}], "}"}], ",", - RowBox[{"{", - RowBox[{ - RowBox[{"x", "\[Rule]", "1"}], ",", - RowBox[{"y", "\[Rule]", "1"}], ",", - RowBox[{"z", "\[Rule]", "0"}]}], "}"}]}], "}"}]], "Output", - CellChangeTimes->{{3.743235305220907*^9, - 3.743235309139554*^9}},ExpressionUUID->"d9825c95-24bb-442a-8734-\ -4c0f47e99dfc"] -}, Open ]], - -Cell[BoxData[ - RowBox[{ - RowBox[{"xmlElem", "[", "x_", "]"}], ":=", - RowBox[{"Print", "[", - RowBox[{"\"\<\>\"", "<>", - RowBox[{"ToString", "[", - RowBox[{"x", "[", - RowBox[{"[", "1", "]"}], "]"}], "]"}], "<>", "\"\< \>\"", "<>", - RowBox[{"ToString", "[", - RowBox[{"x", "[", - RowBox[{"[", "2", "]"}], "]"}], "]"}], "<>", "\"\< \>\"", "<>", - RowBox[{"ToString", "[", - RowBox[{"x", "[", - RowBox[{"[", "3", "]"}], "]"}], "]"}], "<>", "\"\<\>\""}], - "]"}]}]], "Input", - CellChangeTimes->{{3.74323534002862*^9, 3.743235351000985*^9}, { - 3.743235403233039*^9, 3.743235413488028*^9}, {3.743235473169856*^9, - 3.7432354747126904`*^9}},ExpressionUUID->"aea76313-c89e-45e8-b429-\ -3f454091666d"], - -Cell[CellGroupData[{ - -Cell[BoxData[ - RowBox[{ - RowBox[{ - RowBox[{"xmlElem", "[", - RowBox[{ - RowBox[{"{", - RowBox[{"x", ",", "y", ",", "z"}], "}"}], "/.", "#"}], "]"}], "&"}], "/@", - "sol"}]], "Input", - CellChangeTimes->{{3.743235415820318*^9, - 3.743235467025091*^9}},ExpressionUUID->"07da3998-8eab-40ba-8c0b-\ -ac6b130cb4fb"], - -Cell[CellGroupData[{ - -Cell[BoxData["\<\"-1 -1 0\"\>"], "Print", - CellChangeTimes->{ - 3.743235476581676*^9},ExpressionUUID->"c577ba06-b67a-405a-9ff5-\ -2bf7dc898d03"], - -Cell[BoxData["\<\"-1 0 -1\"\>"], "Print", - CellChangeTimes->{ - 3.743235476588011*^9},ExpressionUUID->"d041aa36-0cea-457c-9d4b-\ -1fe9be66e2ab"], - -Cell[BoxData["\<\"-1 0 1\"\>"], "Print", - CellChangeTimes->{ - 3.743235476596887*^9},ExpressionUUID->"bf141b55-86b2-4430-a994-\ -5c03d5a19441"], - -Cell[BoxData["\<\"-1 1 0\"\>"], "Print", - CellChangeTimes->{ - 3.743235476605785*^9},ExpressionUUID->"4968a660-4ecf-4b66-9071-\ -8bd798c18d21"], - -Cell[BoxData["\<\"0 -1 -1\"\>"], "Print", - CellChangeTimes->{ - 3.743235476613523*^9},ExpressionUUID->"4e22d943-2680-416b-a1d7-\ -a16ca20b781f"], - -Cell[BoxData["\<\"0 -1 1\"\>"], "Print", - CellChangeTimes->{ - 3.7432354766218576`*^9},ExpressionUUID->"6dd38385-08b3-4dd9-932f-\ -98a00c6db1b2"], - -Cell[BoxData["\<\"0 1 -1\"\>"], "Print", - CellChangeTimes->{ - 3.743235476629427*^9},ExpressionUUID->"ef3baad3-91d1-4735-9a22-\ -53495a624c15"], - -Cell[BoxData["\<\"0 1 1\"\>"], "Print", - CellChangeTimes->{ - 3.743235476638257*^9},ExpressionUUID->"413fbb68-5017-4272-a62a-\ -fa234e6daaea"], - -Cell[BoxData["\<\"1 -1 0\"\>"], "Print", - CellChangeTimes->{ - 3.743235476646203*^9},ExpressionUUID->"3a832a60-ae00-414b-a9ac-\ -f5e86e67e917"], - -Cell[BoxData["\<\"1 0 -1\"\>"], "Print", - CellChangeTimes->{ - 3.743235476653907*^9},ExpressionUUID->"bfc79ef6-f6c7-4f1e-88e8-\ -005ac314be9c"], - -Cell[BoxData["\<\"1 0 1\"\>"], "Print", - CellChangeTimes->{ - 3.743235476662575*^9},ExpressionUUID->"0f892891-f885-489c-9925-\ -ddef4d698410"], - -Cell[BoxData["\<\"1 1 0\"\>"], "Print", - CellChangeTimes->{ - 3.7432354766702337`*^9},ExpressionUUID->"2906f190-e673-4f33-9c34-\ -e8e56efe7a27"] -}, Open ]], - -Cell[BoxData[ - RowBox[{"{", - RowBox[{ - "Null", ",", "Null", ",", "Null", ",", "Null", ",", "Null", ",", "Null", - ",", "Null", ",", "Null", ",", "Null", ",", "Null", ",", "Null", ",", - "Null"}], "}"}]], "Output", - CellChangeTimes->{ - 3.7432354246225967`*^9, {3.7432354674878073`*^9, - 3.743235476678007*^9}},ExpressionUUID->"500ca3c1-88d8-46e5-a1a1-\ -86a7878e5638"] -}, Open ]], - -Cell[CellGroupData[{ - Cell["Clifford algebra generation", "Section", CellChangeTimes->{{3.6942089434583883`*^9, 3.694208978559093*^9}},ExpressionUUID->"a5b064b3-3011-4922-8559-\ @@ -1048,9 +820,10 @@ generated by the Mathematica notebook gamma-gen/gamma-gen.nb\n\n#include \ "\"\< static const std::array \ name;\n static const std::array, nGamma> mul;\n\ static const std::array adj;\n \ -static const std::array gmu;\n \ -Algebra g;\n public:\n \ - Gamma(Algebra initg): g(initg) {} \n};\n\n\>\""}]}], ";", +static const std::array gmu;\n static \ +const std::array gall;\n Algebra \ + g;\n public:\n \ +Gamma(Algebra initg): g(initg) {} \n};\n\n\>\""}]}], ";", "\[IndentingNewLine]", RowBox[{"out", " ", "=", RowBox[{"out", "<>", "funcCode"}]}], ";", "\[IndentingNewLine]", @@ -1076,7 +849,8 @@ Algebra g;\n public:\n \ 3.694963343265525*^9}, {3.694964367519239*^9, 3.69496439461199*^9}, { 3.694964462130747*^9, 3.6949644669959793`*^9}, 3.694964509762739*^9, { 3.694964705045744*^9, 3.694964723148797*^9}, {3.694964992988984*^9, - 3.6949649968504257`*^9}},ExpressionUUID->"c7103bd6-b539-4495-b98c-\ + 3.6949649968504257`*^9}, {3.758291687176977*^9, + 3.758291694181189*^9}},ExpressionUUID->"c7103bd6-b539-4495-b98c-\ d4d12ac6cad8"], Cell["Gamma enum generation:", "Text", @@ -1745,8 +1519,17 @@ namespace QCD {\>\""}]}], ";", "\[IndentingNewLine]", "\"\<\n\nconst std::array Gamma::gmu = {{\n \ Gamma(Gamma::Algebra::GammaX),\n Gamma(Gamma::Algebra::GammaY),\n \ Gamma(Gamma::Algebra::GammaZ),\n Gamma(Gamma::Algebra::GammaT)}};\n\nconst \ -std::array Gamma::name = {{\n\>\""}]}], ";", - "\[IndentingNewLine]", +std::array Gamma::gall = {{\n \ +Gamma(Gamma::Algebra::Identity),\n Gamma(Gamma::Algebra::Gamma5),\n \ +Gamma(Gamma::Algebra::GammaX),\n Gamma(Gamma::Algebra::GammaY),\n \ +Gamma(Gamma::Algebra::GammaZ),\n Gamma(Gamma::Algebra::GammaT),\n \ +Gamma(Gamma::Algebra::GammaXGamma5),\n Gamma(Gamma::Algebra::GammaYGamma5),\n\ + Gamma(Gamma::Algebra::GammaZGamma5),\n \ +Gamma(Gamma::Algebra::GammaTGamma5),\n Gamma(Gamma::Algebra::SigmaXT), \ +\n Gamma(Gamma::Algebra::SigmaXY), \n Gamma(Gamma::Algebra::SigmaXZ), \ + \n Gamma(Gamma::Algebra::SigmaYT),\n Gamma(Gamma::Algebra::SigmaYZ),\n \ +Gamma(Gamma::Algebra::SigmaZT)}};\n\nconst std::array Gamma::name = {{\n\>\""}]}], ";", "\[IndentingNewLine]", RowBox[{"Do", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"out", " ", "=", " ", @@ -1847,7 +1630,9 @@ Gamma::nGamma> Gamma::mul = {{\\n\>\""}]}], ";", "\[IndentingNewLine]", 3.694963031525289*^9}, {3.694963065828494*^9, 3.694963098327538*^9}, { 3.6949632020836153`*^9, 3.6949632715940027`*^9}, {3.694963440035037*^9, 3.6949634418966017`*^9}, {3.6949651447067547`*^9, 3.694965161228381*^9}, { - 3.694967957845581*^9, 3.694967958364184*^9}}], + 3.694967957845581*^9, 3.694967958364184*^9}, {3.758291673792514*^9, + 3.758291676983432*^9}},ExpressionUUID->"b1b309f8-a3a7-4081-a781-\ +c3845e3cd372"], Cell[BoxData[ RowBox[{ @@ -1867,8 +1652,8 @@ Cell[BoxData[""], "Input", }, WindowSize->{1246, 1005}, WindowMargins->{{282, Automatic}, {Automatic, 14}}, -FrontEndVersion->"11.2 for Mac OS X x86 (32-bit, 64-bit Kernel) (September \ -10, 2017)", +FrontEndVersion->"11.3 for Mac OS X x86 (32-bit, 64-bit Kernel) (March 5, \ +2018)", StyleDefinitions->"Default.nb" ] (* End of Notebook Content *) @@ -1888,75 +1673,48 @@ Cell[1948, 43, 570, 11, 73, "Input",ExpressionUUID->"5c937a3e-adfd-4d7e-8fde-afb Cell[2521, 56, 1172, 17, 34, "Output",ExpressionUUID->"72817ba6-2f6a-4a4d-8212-6f0970f49e7c"] }, Open ]], Cell[CellGroupData[{ -Cell[3730, 78, 248, 5, 30, "Input",ExpressionUUID->"d1a0fd03-85e1-43af-ba80-3ca4235675d8"], -Cell[3981, 85, 299, 9, 34, "Output",ExpressionUUID->"16d3f953-4b24-4ed2-ae62-306dcab66ca7"] +Cell[3730, 78, 174, 3, 67, "Section",ExpressionUUID->"a5b064b3-3011-4922-8559-ead857cad102"], +Cell[3907, 83, 535, 16, 52, "Input",ExpressionUUID->"aa28f02b-31e1-4df2-9b5d-482177464b59"], +Cell[4445, 101, 250, 4, 35, "Text",ExpressionUUID->"c8896b88-f1db-4ce4-b7a6-0c9838bdb8f1"], +Cell[4698, 107, 5511, 169, 425, "Input",ExpressionUUID->"52a96ff6-047e-4043-86d0-e303866e5f8e"], +Cell[CellGroupData[{ +Cell[10234, 280, 2183, 58, 135, "Input",ExpressionUUID->"8b0f4955-2c3f-418c-9226-9be8f87621e8"], +Cell[12420, 340, 1027, 27, 56, "Output",ExpressionUUID->"edd0619f-6f12-4070-a1d2-6b547877fadc"] }, Open ]], Cell[CellGroupData[{ -Cell[4317, 99, 469, 14, 33, "Input",ExpressionUUID->"f0fa2a5c-3d81-4d75-a447-50c7ca3459ff"], -Cell[4789, 115, 2423, 77, 56, "Output",ExpressionUUID->"d9825c95-24bb-442a-8734-4c0f47e99dfc"] +Cell[13484, 372, 1543, 46, 114, "Input",ExpressionUUID->"fb45123c-c610-4075-99b0-7cd71c728ae7"], +Cell[15030, 420, 1311, 32, 87, "Output",ExpressionUUID->"2ae14565-b412-4dc0-9dce-bd6c1ba5ef27"] }, Open ]], -Cell[7227, 195, 751, 18, 30, "Input",ExpressionUUID->"aea76313-c89e-45e8-b429-3f454091666d"], +Cell[16356, 455, 179, 3, 35, "Text",ExpressionUUID->"af247231-a58d-417b-987a-26908dafffdb"], +Cell[16538, 460, 2175, 65, 94, "Input",ExpressionUUID->"7c44cadd-e488-4f51-87d8-c64eef11f40c"], +Cell[18716, 527, 193, 3, 35, "Text",ExpressionUUID->"856f1746-1107-4509-a5ce-ac9c7f56cdb1"], Cell[CellGroupData[{ -Cell[8003, 217, 323, 10, 30, "Input",ExpressionUUID->"07da3998-8eab-40ba-8c0b-ac6b130cb4fb"], -Cell[CellGroupData[{ -Cell[8351, 231, 156, 3, 24, "Print",ExpressionUUID->"c577ba06-b67a-405a-9ff5-2bf7dc898d03"], -Cell[8510, 236, 156, 3, 24, "Print",ExpressionUUID->"d041aa36-0cea-457c-9d4b-1fe9be66e2ab"], -Cell[8669, 241, 155, 3, 24, "Print",ExpressionUUID->"bf141b55-86b2-4430-a994-5c03d5a19441"], -Cell[8827, 246, 155, 3, 24, "Print",ExpressionUUID->"4968a660-4ecf-4b66-9071-8bd798c18d21"], -Cell[8985, 251, 156, 3, 24, "Print",ExpressionUUID->"4e22d943-2680-416b-a1d7-a16ca20b781f"], -Cell[9144, 256, 157, 3, 24, "Print",ExpressionUUID->"6dd38385-08b3-4dd9-932f-98a00c6db1b2"], -Cell[9304, 261, 155, 3, 24, "Print",ExpressionUUID->"ef3baad3-91d1-4735-9a22-53495a624c15"], -Cell[9462, 266, 154, 3, 24, "Print",ExpressionUUID->"413fbb68-5017-4272-a62a-fa234e6daaea"], -Cell[9619, 271, 155, 3, 24, "Print",ExpressionUUID->"3a832a60-ae00-414b-a9ac-f5e86e67e917"], -Cell[9777, 276, 155, 3, 24, "Print",ExpressionUUID->"bfc79ef6-f6c7-4f1e-88e8-005ac314be9c"], -Cell[9935, 281, 154, 3, 24, "Print",ExpressionUUID->"0f892891-f885-489c-9925-ddef4d698410"], -Cell[10092, 286, 156, 3, 24, "Print",ExpressionUUID->"2906f190-e673-4f33-9c34-e8e56efe7a27"] -}, Open ]], -Cell[10263, 292, 376, 9, 34, "Output",ExpressionUUID->"500ca3c1-88d8-46e5-a1a1-86a7878e5638"] +Cell[18934, 534, 536, 16, 30, "Input",ExpressionUUID->"8674484a-8543-434f-b177-3b27f9353212"], +Cell[19473, 552, 1705, 35, 87, "Output",ExpressionUUID->"c3b3f84d-91f6-41af-af6b-a394ca020511"] }, Open ]], +Cell[21193, 590, 170, 3, 35, "Text",ExpressionUUID->"518a3040-54b1-4d43-8947-5c7d12efa94d"], Cell[CellGroupData[{ -Cell[10676, 306, 174, 3, 67, "Section",ExpressionUUID->"a5b064b3-3011-4922-8559-ead857cad102"], -Cell[10853, 311, 535, 16, 52, "Input",ExpressionUUID->"aa28f02b-31e1-4df2-9b5d-482177464b59"], -Cell[11391, 329, 250, 4, 35, "Text",ExpressionUUID->"c8896b88-f1db-4ce4-b7a6-0c9838bdb8f1"], -Cell[11644, 335, 5511, 169, 425, "Input",ExpressionUUID->"52a96ff6-047e-4043-86d0-e303866e5f8e"], -Cell[CellGroupData[{ -Cell[17180, 508, 2183, 58, 135, "Input",ExpressionUUID->"8b0f4955-2c3f-418c-9226-9be8f87621e8"], -Cell[19366, 568, 1027, 27, 67, "Output",ExpressionUUID->"edd0619f-6f12-4070-a1d2-6b547877fadc"] -}, Open ]], -Cell[CellGroupData[{ -Cell[20430, 600, 1543, 46, 114, "Input",ExpressionUUID->"fb45123c-c610-4075-99b0-7cd71c728ae7"], -Cell[21976, 648, 1311, 32, 98, "Output",ExpressionUUID->"2ae14565-b412-4dc0-9dce-bd6c1ba5ef27"] -}, Open ]], -Cell[23302, 683, 179, 3, 35, "Text",ExpressionUUID->"af247231-a58d-417b-987a-26908dafffdb"], -Cell[23484, 688, 2175, 65, 94, "Input",ExpressionUUID->"7c44cadd-e488-4f51-87d8-c64eef11f40c"], -Cell[25662, 755, 193, 3, 35, "Text",ExpressionUUID->"856f1746-1107-4509-a5ce-ac9c7f56cdb1"], -Cell[CellGroupData[{ -Cell[25880, 762, 536, 16, 30, "Input",ExpressionUUID->"8674484a-8543-434f-b177-3b27f9353212"], -Cell[26419, 780, 1705, 35, 87, "Output",ExpressionUUID->"c3b3f84d-91f6-41af-af6b-a394ca020511"] -}, Open ]], -Cell[28139, 818, 170, 3, 35, "Text",ExpressionUUID->"518a3040-54b1-4d43-8947-5c7d12efa94d"], -Cell[CellGroupData[{ -Cell[28334, 825, 536, 14, 30, "Input",ExpressionUUID->"61a2e974-2b39-4a07-8043-2dfd39a70569"], -Cell[28873, 841, 6754, 167, 303, "Output",ExpressionUUID->"73480ac0-3043-4077-80cc-b952a94c822a"] +Cell[21388, 597, 536, 14, 30, "Input",ExpressionUUID->"61a2e974-2b39-4a07-8043-2dfd39a70569"], +Cell[21927, 613, 6754, 167, 303, "Output",ExpressionUUID->"73480ac0-3043-4077-80cc-b952a94c822a"] }, Open ]] }, Open ]], Cell[CellGroupData[{ -Cell[35676, 1014, 226, 4, 67, "Section",ExpressionUUID->"4e833cd6-9f0e-4aa3-a873-3d579e874720"], -Cell[35905, 1020, 188, 4, 44, "Text",ExpressionUUID->"6d27fc04-3a60-4e03-8df7-3dd3aeee35b4"], -Cell[36096, 1026, 2980, 53, 703, "Input",ExpressionUUID->"c7103bd6-b539-4495-b98c-d4d12ac6cad8"], -Cell[39079, 1081, 221, 4, 44, "Text",ExpressionUUID->"0625593d-290f-4a39-9d80-8e2c6fdbc94e"], -Cell[39303, 1087, 4936, 150, 682, "Input",ExpressionUUID->"1ad4904c-352f-4b1d-a7c7-91e1b0549409"], -Cell[44242, 1239, 2645, 56, 199, "Input",ExpressionUUID->"0221674f-9b63-4662-91bc-ccc8c6ae9589"], -Cell[46890, 1297, 209, 4, 44, "Text",ExpressionUUID->"d2d2257a-487b-416f-bc40-abd4482225f7"], -Cell[47102, 1303, 15306, 397, 2131, "Input",ExpressionUUID->"daea68a9-c9e8-46ab-9bc8-5186e2cf477c"], -Cell[62411, 1702, 137, 2, 44, "Text",ExpressionUUID->"76ba9d5a-7ee3-4888-be7e-6377003275e8"], -Cell[62551, 1706, 521, 12, 30, "Input",ExpressionUUID->"4ec61f4c-3fd3-49ea-b5ef-6f7f04a16b34"] +Cell[28730, 786, 226, 4, 67, "Section",ExpressionUUID->"4e833cd6-9f0e-4aa3-a873-3d579e874720"], +Cell[28959, 792, 188, 4, 44, "Text",ExpressionUUID->"6d27fc04-3a60-4e03-8df7-3dd3aeee35b4"], +Cell[29150, 798, 3104, 55, 724, "Input",ExpressionUUID->"c7103bd6-b539-4495-b98c-d4d12ac6cad8"], +Cell[32257, 855, 221, 4, 44, "Text",ExpressionUUID->"0625593d-290f-4a39-9d80-8e2c6fdbc94e"], +Cell[32481, 861, 4936, 150, 682, "Input",ExpressionUUID->"1ad4904c-352f-4b1d-a7c7-91e1b0549409"], +Cell[37420, 1013, 2645, 56, 199, "Input",ExpressionUUID->"0221674f-9b63-4662-91bc-ccc8c6ae9589"], +Cell[40068, 1071, 209, 4, 44, "Text",ExpressionUUID->"d2d2257a-487b-416f-bc40-abd4482225f7"], +Cell[40280, 1077, 15306, 397, 2131, "Input",ExpressionUUID->"daea68a9-c9e8-46ab-9bc8-5186e2cf477c"], +Cell[55589, 1476, 137, 2, 44, "Text",ExpressionUUID->"76ba9d5a-7ee3-4888-be7e-6377003275e8"], +Cell[55729, 1480, 521, 12, 30, "Input",ExpressionUUID->"4ec61f4c-3fd3-49ea-b5ef-6f7f04a16b34"] }, Open ]], Cell[CellGroupData[{ -Cell[63109, 1723, 167, 2, 67, "Section",ExpressionUUID->"a4458b3a-09b5-4e36-a1fc-781d6702b2dc"], -Cell[63279, 1727, 5693, 122, 829, "Input",ExpressionUUID->"b1b309f8-a3a7-4081-a781-c3845e3cd372"], -Cell[68975, 1851, 448, 10, 30, "Input",ExpressionUUID->"cba42949-b0f2-42ce-aebd-ffadfd83ef88"], -Cell[69426, 1863, 94, 1, 30, "Input",ExpressionUUID->"6175b72c-af9f-43c2-b4ca-bd84c48a456d"] +Cell[56287, 1497, 167, 2, 67, "Section",ExpressionUUID->"a4458b3a-09b5-4e36-a1fc-781d6702b2dc"], +Cell[56457, 1501, 6464, 133, 1207, "Input",ExpressionUUID->"b1b309f8-a3a7-4081-a781-c3845e3cd372"], +Cell[62924, 1636, 448, 10, 30, "Input",ExpressionUUID->"cba42949-b0f2-42ce-aebd-ffadfd83ef88"], +Cell[63375, 1648, 94, 1, 30, "Input",ExpressionUUID->"6175b72c-af9f-43c2-b4ca-bd84c48a456d"] }, Open ]] } ] diff --git a/Grid/qcd/utils/A2Autils.h b/Grid/qcd/utils/A2Autils.h index c4f106f2..b0972bb9 100644 --- a/Grid/qcd/utils/A2Autils.h +++ b/Grid/qcd/utils/A2Autils.h @@ -995,21 +995,20 @@ void A2Autils::ContractWWVV(std::vector &WWVV, auto vs_v = vs[s].View(); auto tmp1 = vs_v[ss]; vobj tmp2 = Zero(); - + vobj tmp3 = Zero(); for(int d=d_o;d class CovariantSmearing : public Gimpl +{ +public: + INHERIT_GIMPL_TYPES(Gimpl); + + typedef typename Gimpl::GaugeLinkField GaugeMat; + typedef typename Gimpl::GaugeField GaugeLorentz; + + template + static void GaussianSmear(const std::vector& U, + T& chi, + const Real& width, int Iterations, int orthog) + { + GridBase *grid = chi._grid; + T psi(grid); + + //////////////////////////////////////////////////////////////////////////////////// + // Follow Chroma conventions for width to keep compatibility with previous data + // Free field iterates + // chi = (1 - w^2/4N p^2)^N chi + // + // ~ (e^(-w^2/4N p^2)^N chi + // ~ (e^(-w^2/4 p^2) chi + // ~ (e^(-w'^2/2 p^2) chi [ w' = w/sqrt(2) ] + // + // Which in coordinate space is proportional to + // + // e^(-x^2/w^2) = e^(-x^2/2w'^2) + // + // The 4 is a bit unconventional from Gaussian width perspective, but... it's Chroma convention. + // 2nd derivative approx d^2/dx^2 = x+mu + x-mu - 2x + // + // d^2/dx^2 = - p^2 + // + // chi = ( 1 + w^2/4N d^2/dx^2 )^N chi + // + //////////////////////////////////////////////////////////////////////////////////// + Real coeff = (width*width) / Real(4*Iterations); + + int dims = Nd; + if( orthog < Nd ) dims=Nd-1; + + for(int n = 0; n < Iterations; ++n) { + psi = (-2.0*dims)*chi; + for(int mu=0;mu NAMESPACE_BEGIN(Grid); + template class FourierAcceleratedGaugeFixer : public Gimpl { public: @@ -45,30 +46,57 @@ public: A[mu] = Ta(U[mu]) * cmi; } } - static void DmuAmu(const std::vector &A,GaugeMat &dmuAmu) { + static void DmuAmu(const std::vector &A,GaugeMat &dmuAmu,int orthog) { dmuAmu=Zero(); for(int mu=0;mu::avgPlaquette(Umu); Real org_link_trace=WilsonLoops::linkTrace(Umu); Real old_trace = org_link_trace; Real trG; + + xform=1.0; std::vector U(Nd,grid); GaugeMat dmuAmu(grid); - for(int i=0;i(Umu,mu); - if ( Fourier==false ) { - trG = SteepestDescentStep(U,alpha,dmuAmu); + { + Real plaq =WilsonLoops::avgPlaquette(Umu); + Real link_trace=WilsonLoops::linkTrace(Umu); + if( (orthog>=0) && (orthog(Umu,U[mu],mu); // Monitor progress and convergence test // infrequently to minimise cost overhead @@ -84,7 +112,6 @@ public: Real Phi = 1.0 - old_trace / link_trace ; Real Omega= 1.0 - trG; - std::cout << GridLogMessage << " Iteration "< &U,Real & alpha, GaugeMat & dmuAmu) { + static Real SteepestDescentStep(std::vector &U,GaugeMat &xform,Real & alpha, GaugeMat & dmuAmu,int orthog) { GridBase *grid = U[0].Grid(); std::vector A(Nd,grid); GaugeMat g(grid); GaugeLinkToLieAlgebraField(U,A); - ExpiAlphaDmuAmu(A,g,alpha,dmuAmu); + ExpiAlphaDmuAmu(A,g,alpha,dmuAmu,orthog); Real vol = grid->gSites(); Real trG = TensorRemove(sum(trace(g))).real()/vol/Nc; + xform = g*xform ; SU::GaugeTransform(U,g); return trG; } - static Real FourierAccelSteepestDescentStep(std::vector &U,Real & alpha, GaugeMat & dmuAmu) { + static Real FourierAccelSteepestDescentStep(std::vector &U,GaugeMat &xform,Real & alpha, GaugeMat & dmuAmu,int orthog) { GridBase *grid = U[0].Grid(); @@ -133,38 +161,41 @@ public: GaugeLinkToLieAlgebraField(U,A); - DmuAmu(A,dmuAmu); + DmuAmu(A,dmuAmu,orthog); - theFFT.FFT_all_dim(dmuAmu_p,dmuAmu,FFT::forward); + std::vector mask(Nd,1); + for(int mu=0;muGlobalDimensions(); Coordinate coor(grid->_ndimension,0); for(int mu=0;mu=0) && (orthogGlobalDimensions()[orthog];t++){ + coor[orthog]=t; + pokeSite(TComplex(16.0),Fp,coor); + } + } + dmuAmu_p = dmuAmu_p * Fp; - theFFT.FFT_all_dim(dmuAmu,dmuAmu_p,FFT::backward); + theFFT.FFT_dim_mask(dmuAmu,dmuAmu_p,mask,FFT::backward); GaugeMat ciadmam(grid); Complex cialpha(0.0,-alpha); @@ -173,16 +204,17 @@ public: Real trG = TensorRemove(sum(trace(g))).real()/vol/Nc; + xform = g*xform ; SU::GaugeTransform(U,g); return trG; } - static void ExpiAlphaDmuAmu(const std::vector &A,GaugeMat &g,Real & alpha, GaugeMat &dmuAmu) { + static void ExpiAlphaDmuAmu(const std::vector &A,GaugeMat &g,Real & alpha, GaugeMat &dmuAmu,int orthog) { GridBase *grid = g.Grid(); Complex cialpha(0.0,-alpha); GaugeMat ciadmam(grid); - DmuAmu(A,dmuAmu); + DmuAmu(A,dmuAmu,orthog); ciadmam = dmuAmu*cialpha; SU::taExp(ciadmam,g); } diff --git a/Grid/qcd/utils/SUn.h b/Grid/qcd/utils/SUn.h index 5db095ea..7ad80d00 100644 --- a/Grid/qcd/utils/SUn.h +++ b/Grid/qcd/utils/SUn.h @@ -678,9 +678,18 @@ public: out += la; } } - /* - add GaugeTrans - */ +/* + * Fundamental rep gauge xform + */ + template + static void GaugeTransformFundamental( Fundamental &ferm, GaugeMat &g){ + GridBase *grid = ferm._grid; + conformable(grid,g._grid); + ferm = g*ferm; + } +/* + * Adjoint rep gauge xform + */ template static void GaugeTransform( GaugeField &Umu, GaugeMat &g){ diff --git a/Grid/serialisation/BaseIO.h b/Grid/serialisation/BaseIO.h index dd15e7da..e9d5bedf 100644 --- a/Grid/serialisation/BaseIO.h +++ b/Grid/serialisation/BaseIO.h @@ -33,12 +33,76 @@ Author: Guido Cossu #include #include #include +#include namespace Grid { + namespace EigenIO { + // EigenIO works for scalars that are not just Grid supported scalars + template struct is_complex : public std::false_type {}; + // Support all complex types (not just Grid complex types) - even if the definitions overlap (!) + template struct is_complex< T , typename + std::enable_if< ::Grid::is_complex< T >::value>::type> : public std::true_type {}; + template struct is_complex, typename + std::enable_if>::value>::type> : public std::true_type {}; + + // Helpers to support I/O for Eigen tensors of arithmetic scalars, complex types, or Grid tensors + template struct is_scalar : public std::false_type {}; + template struct is_scalar::value || is_complex::value>::type> : public std::true_type {}; + + // Is this an Eigen tensor + template struct is_tensor : std::integral_constant, T>::value> {}; + + // Is this an Eigen tensor of a supported scalar + template struct is_tensor_of_scalar : public std::false_type {}; + template struct is_tensor_of_scalar::value && is_scalar::value>::type> : public std::true_type {}; + + // Is this an Eigen tensor of a supported container + template struct is_tensor_of_container : public std::false_type {}; + template struct is_tensor_of_container::value && isGridTensor::value>::type> : public std::true_type {}; + + // These traits describe the scalars inside Eigen tensors + // I wish I could define these in reference to the scalar type (so there would be fewer traits defined) + // but I'm unable to find a syntax to make this work + template struct Traits {}; + // Traits are the default for scalars, or come from GridTypeMapper for GridTensors + template struct Traits::value>::type> + : public GridTypeMapper_Base { + using scalar_type = typename T::Scalar; // ultimate base scalar + static constexpr bool is_complex = ::Grid::EigenIO::is_complex::value; + }; + // Traits are the default for scalars, or come from GridTypeMapper for GridTensors + template struct Traits::value>::type> { + using BaseTraits = GridTypeMapper; + using scalar_type = typename BaseTraits::scalar_type; // ultimate base scalar + static constexpr bool is_complex = ::Grid::EigenIO::is_complex::value; + static constexpr int TensorLevel = BaseTraits::TensorLevel; + static constexpr int Rank = BaseTraits::Rank; + static constexpr std::size_t count = BaseTraits::count; + static constexpr int Dimension(int dim) { return BaseTraits::Dimension(dim); } + }; + + // Is this a fixed-size Eigen tensor + template struct is_tensor_fixed : public std::false_type {}; + template + struct is_tensor_fixed> + : public std::true_type {}; + template class MapPointer_> + struct is_tensor_fixed, MapOptions_, MapPointer_>> + : public std::true_type {}; + + // Is this a variable-size Eigen tensor + template struct is_tensor_variable : public std::false_type {}; + template struct is_tensor_variable::value + && !is_tensor_fixed::value>::type> : public std::true_type {}; + } + // Abstract writer/reader classes //////////////////////////////////////////// // static polymorphism implemented using CRTP idiom class Serializable; - + // Static abstract writer template class Writer @@ -49,10 +113,10 @@ namespace Grid { void push(const std::string &s); void pop(void); template - typename std::enable_if::value, void>::type + typename std::enable_if::value>::type write(const std::string& s, const U &output); template - typename std::enable_if::value, void>::type + typename std::enable_if::value && !EigenIO::is_tensor::value>::type write(const std::string& s, const U &output); template void write(const std::string &s, const iScalar &output); @@ -60,6 +124,42 @@ namespace Grid { void write(const std::string &s, const iVector &output); template void write(const std::string &s, const iMatrix &output); + template + typename std::enable_if::value>::type + write(const std::string &s, const ETensor &output); + + // Helper functions for Scalar vs Container specialisations + template + inline typename std::enable_if::value, + const typename ETensor::Scalar *>::type + getFirstScalar(const ETensor &output) + { + return output.data(); + } + + template + inline typename std::enable_if::value, + const typename EigenIO::Traits::scalar_type *>::type + getFirstScalar(const ETensor &output) + { + return output.data()->begin(); + } + + template + inline typename std::enable_if::value, void>::type + copyScalars(S * &pCopy, const S &Source) + { + * pCopy ++ = Source; + } + + template + inline typename std::enable_if::value, void>::type + copyScalars(typename GridTypeMapper::scalar_type * &pCopy, const S &Source) + { + for( const typename GridTypeMapper::scalar_type &item : Source ) + * pCopy ++ = item; + } + void scientificFormat(const bool set); bool isScientific(void); void setPrecision(const unsigned int prec); @@ -83,7 +183,8 @@ namespace Grid { typename std::enable_if::value, void>::type read(const std::string& s, U &output); template - typename std::enable_if::value, void>::type + typename std::enable_if::value + && !EigenIO::is_tensor::value, void>::type read(const std::string& s, U &output); template void read(const std::string &s, iScalar &output); @@ -91,6 +192,32 @@ namespace Grid { void read(const std::string &s, iVector &output); template void read(const std::string &s, iMatrix &output); + template + typename std::enable_if::value, void>::type + read(const std::string &s, ETensor &output); + template + typename std::enable_if::value, void>::type + Reshape(ETensor &t, const std::array &dims ); + template + typename std::enable_if::value, void>::type + Reshape(ETensor &t, const std::array &dims ); + + // Helper functions for Scalar vs Container specialisations + template + inline typename std::enable_if::value, void>::type + copyScalars(S &Dest, const S * &pSource) + { + Dest = * pSource ++; + } + + template + inline typename std::enable_if::value, void>::type + copyScalars(S &Dest, const typename GridTypeMapper::scalar_type * &pSource) + { + for( typename GridTypeMapper::scalar_type &item : Dest ) + item = * pSource ++; + } + protected: template void fromString(U &output, const std::string &s); @@ -135,12 +262,14 @@ namespace Grid { template template - typename std::enable_if::value, void>::type + typename std::enable_if::value + && !EigenIO::is_tensor::value, void>::type Writer::write(const std::string &s, const U &output) { upcast->writeDefault(s, output); } + template template void Writer::write(const std::string &s, const iScalar &output) @@ -161,6 +290,57 @@ namespace Grid { { upcast->writeDefault(s, tensorToVec(output)); } + + // Eigen::Tensors of Grid tensors (iScalar, iVector, iMatrix) + template + template + typename std::enable_if::value, void>::type + Writer::write(const std::string &s, const ETensor &output) + { + using Index = typename ETensor::Index; + using Container = typename ETensor::Scalar; // NB: could be same as scalar + using Traits = EigenIO::Traits; + using Scalar = typename Traits::scalar_type; // type of the underlying scalar + constexpr unsigned int TensorRank{ETensor::NumIndices}; + constexpr unsigned int ContainerRank{Traits::Rank}; // Only non-zero for containers + constexpr unsigned int TotalRank{TensorRank + ContainerRank}; + const Index NumElements{output.size()}; + assert( NumElements > 0 ); + + // Get the dimensionality of the tensor + std::vector TotalDims(TotalRank); + for(auto i = 0; i < TensorRank; i++ ) { + auto dim = output.dimension(i); + TotalDims[i] = static_cast(dim); + assert( TotalDims[i] == dim ); // check we didn't lose anything in the conversion + } + for(auto i = 0; i < ContainerRank; i++ ) + TotalDims[TensorRank + i] = Traits::Dimension(i); + + // If the Tensor isn't in Row-Major order, then we'll need to copy it's data + const bool CopyData{NumElements > 1 && ETensor::Layout != Eigen::StorageOptions::RowMajor}; + const Scalar * pWriteBuffer; + std::vector CopyBuffer; + const Index TotalNumElements = NumElements * Traits::count; + if( !CopyData ) { + pWriteBuffer = getFirstScalar( output ); + } else { + // Regardless of the Eigen::Tensor storage order, the copy will be Row Major + CopyBuffer.resize( TotalNumElements ); + Scalar * pCopy = &CopyBuffer[0]; + pWriteBuffer = pCopy; + std::array MyIndex; + for( auto &idx : MyIndex ) idx = 0; + for( auto n = 0; n < NumElements; n++ ) { + const Container & c = output( MyIndex ); + copyScalars( pCopy, c ); + // Now increment the index + for( int i = output.NumDimensions - 1; i >= 0 && ++MyIndex[i] == output.dimension(i); i-- ) + MyIndex[i] = 0; + } + } + upcast->template writeMultiDim(s, TotalDims, pWriteBuffer, TotalNumElements); + } template void Writer::scientificFormat(const bool set) @@ -215,7 +395,8 @@ namespace Grid { template template - typename std::enable_if::value, void>::type + typename std::enable_if::value + && !EigenIO::is_tensor::value, void>::type Reader::read(const std::string &s, U &output) { upcast->readDefault(s, output); @@ -251,6 +432,79 @@ namespace Grid { vecToTensor(output, v); } + template + template + typename std::enable_if::value, void>::type + Reader::read(const std::string &s, ETensor &output) + { + using Index = typename ETensor::Index; + using Container = typename ETensor::Scalar; // NB: could be same as scalar + using Traits = EigenIO::Traits; + using Scalar = typename Traits::scalar_type; // type of the underlying scalar + constexpr unsigned int TensorRank{ETensor::NumIndices}; + constexpr unsigned int ContainerRank{Traits::Rank}; // Only non-zero for containers + constexpr unsigned int TotalRank{TensorRank + ContainerRank}; + using ETDims = std::array; // Dimensions of the tensor + + // read the (flat) data and dimensionality + std::vector dimData; + std::vector buf; + upcast->readMultiDim( s, buf, dimData ); + assert(dimData.size() == TotalRank && "EigenIO: Tensor rank mismatch" ); + // Make sure that the number of elements read matches dimensions read + std::size_t NumContainers = 1; + for( auto i = 0 ; i < TensorRank ; i++ ) + NumContainers *= dimData[i]; + // If our scalar object is a Container, make sure it's dimensions match what we read back + std::size_t ElementsPerContainer = 1; + for( auto i = 0 ; i < ContainerRank ; i++ ) { + assert( dimData[TensorRank+i] == Traits::Dimension(i) && "Tensor Container dimensions don't match data" ); + ElementsPerContainer *= dimData[TensorRank+i]; + } + assert( NumContainers * ElementsPerContainer == buf.size() && "EigenIO: Number of elements != product of dimensions" ); + // Now see whether the tensor is the right shape, or can be made to be + const auto & dims = output.dimensions(); + bool bShapeOK = (output.data() != nullptr); + for( auto i = 0; bShapeOK && i < TensorRank ; i++ ) + if( dims[i] != dimData[i] ) + bShapeOK = false; + // Make the tensor the same size as the data read + ETDims MyIndex; + if( !bShapeOK ) { + for( auto i = 0 ; i < TensorRank ; i++ ) + MyIndex[i] = dimData[i]; + Reshape(output, MyIndex); + } + // Copy the data into the tensor + for( auto &d : MyIndex ) d = 0; + const Scalar * pSource = &buf[0]; + for( std::size_t n = 0 ; n < NumContainers ; n++ ) { + Container & c = output( MyIndex ); + copyScalars( c, pSource ); + // Now increment the index + for( int i = TensorRank - 1; i != -1 && ++MyIndex[i] == dims[i]; i-- ) + MyIndex[i] = 0; + } + assert( pSource == &buf[NumContainers * ElementsPerContainer] ); + } + + template + template + typename std::enable_if::value, void>::type + Reader::Reshape(ETensor &t, const std::array &dims ) + { + assert( 0 && "EigenIO: Fixed tensor dimensions can't be changed" ); + } + + template + template + typename std::enable_if::value, void>::type + Reader::Reshape(ETensor &t, const std::array &dims ) + { + //t.reshape( dims ); + t.resize( dims ); + } + template template void Reader::fromString(U &output, const std::string &s) @@ -289,8 +543,70 @@ namespace Grid { { return os; } + + template + static inline typename std::enable_if::value || !EigenIO::is_tensor::value, bool>::type + CompareMember(const T1 &lhs, const T2 &rhs) { + return lhs == rhs; + } + + template + static inline typename std::enable_if::value && EigenIO::is_tensor::value, bool>::type + CompareMember(const T1 &lhs, const T2 &rhs) { + // First check whether dimensions match (Eigen tensor library will assert if they don't match) + bool bReturnValue = (T1::NumIndices == T2::NumIndices); + for( auto i = 0 ; bReturnValue && i < T1::NumIndices ; i++ ) + bReturnValue = ( lhs.dimension(i) == rhs.dimension(i) ); + if( bReturnValue ) { + Eigen::Tensor bResult = (lhs == rhs).all(); + bReturnValue = bResult(0); + } + return bReturnValue; + } + + template + static inline typename std::enable_if::value, bool>::type + CompareMember(const std::vector &lhs, const std::vector &rhs) { + const auto NumElements = lhs.size(); + bool bResult = ( NumElements == rhs.size() ); + for( auto i = 0 ; i < NumElements && bResult ; i++ ) + bResult = CompareMember(lhs[i], rhs[i]); + return bResult; + } + + template + static inline typename std::enable_if::value, void>::type + WriteMember(std::ostream &os, const T &object) { + os << object; + } + + template + static inline typename std::enable_if::value, void>::type + WriteMember(std::ostream &os, const T &object) { + using Index = typename T::Index; + const Index NumElements{object.size()}; + assert( NumElements > 0 ); + Index count = 1; + os << "T<"; + for( int i = 0; i < T::NumIndices; i++ ) { + Index dim = object.dimension(i); + count *= dim; + if( i ) + os << ","; + os << dim; + } + assert( count == NumElements && "Number of elements doesn't match tensor dimensions" ); + os << ">{"; + const typename T::Scalar * p = object.data(); + for( Index i = 0; i < count; i++ ) { + if( i ) + os << ","; + os << *p++; + } + os << "}"; + } }; - + // Generic writer interface ////////////////////////////////////////////////// template inline void push(Writer &w, const std::string &s) { diff --git a/Grid/serialisation/BinaryIO.h b/Grid/serialisation/BinaryIO.h index 2c3ac98f..bf011454 100644 --- a/Grid/serialisation/BinaryIO.h +++ b/Grid/serialisation/BinaryIO.h @@ -1,4 +1,4 @@ -/************************************************************************************* + /************************************************************************************* Grid physics library, www.github.com/paboyle/Grid @@ -24,8 +24,8 @@ Author: Peter Boyle 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. See the full license in the file "LICENSE" in the top level distribution directory -*************************************************************************************/ -/* END LEGAL */ + *************************************************************************************/ + /* END LEGAL */ #ifndef GRID_SERIALISATION_BINARY_READER_H #define GRID_SERIALISATION_BINARY_READER_H @@ -37,83 +37,132 @@ Author: Peter Boyle #include #include -NAMESPACE_BEGIN(Grid); +namespace Grid { -class BinaryWriter: public Writer -{ -public: - BinaryWriter(const std::string &fileName); - virtual ~BinaryWriter(void) = default; - void push(const std::string &s) {}; - void pop(void) {}; + class BinaryWriter: public Writer + { + public: + BinaryWriter(const std::string &fileName); + virtual ~BinaryWriter(void) = default; + void push(const std::string &s) {}; + void pop(void) {}; + template + void writeDefault(const std::string &s, const U &x); + template + void writeDefault(const std::string &s, const std::vector &x); + void writeDefault(const std::string &s, const char *x); + template + void writeMultiDim(const std::string &s, const std::vector & Dimensions, const U * pDataRowMajor, size_t NumElements); + private: + std::ofstream file_; + }; + + class BinaryReader: public Reader + { + public: + BinaryReader(const std::string &fileName); + virtual ~BinaryReader(void) = default; + bool push(const std::string &s) {return true;} + void pop(void) {}; + template + void readDefault(const std::string &s, U &output); + template + void readDefault(const std::string &s, std::vector &output); + template + void readMultiDim(const std::string &s, std::vector &buf, std::vector &dim); + private: + std::ifstream file_; + }; + + // Writer template implementation //////////////////////////////////////////// template - void writeDefault(const std::string &s, const U &x); + void BinaryWriter::writeDefault(const std::string &s, const U &x) + { + file_.write((char *)&x, sizeof(U)); + } + + template <> + void BinaryWriter::writeDefault(const std::string &s, const std::string &x); + template - void writeDefault(const std::string &s, const std::vector &x); - void writeDefault(const std::string &s, const char *x); -private: - std::ofstream file_; -}; - -class BinaryReader: public Reader -{ -public: - BinaryReader(const std::string &fileName); - virtual ~BinaryReader(void) = default; - bool push(const std::string &s) {return true;} - void pop(void) {}; - template - void readDefault(const std::string &s, U &output); - template - void readDefault(const std::string &s, std::vector &output); -private: - std::ifstream file_; -}; - -// Writer template implementation //////////////////////////////////////////// -template -void BinaryWriter::writeDefault(const std::string &s, const U &x) -{ - file_.write((char *)&x, sizeof(U)); -} - -template <> -void BinaryWriter::writeDefault(const std::string &s, const std::string &x); - -template -void BinaryWriter::writeDefault(const std::string &s, const std::vector &x) -{ - uint64_t sz = x.size(); + void BinaryWriter::writeDefault(const std::string &s, const std::vector &x) + { + uint64_t sz = x.size(); - write("", sz); - for (uint64_t i = 0; i < sz; ++i) + write("", sz); + for (uint64_t i = 0; i < sz; ++i) { write("", x[i]); } -} + } -// Reader template implementation //////////////////////////////////////////// -template <> void BinaryReader::readDefault(const std::string &s, std::string &output); + template + void BinaryWriter::writeMultiDim(const std::string &s, const std::vector & Dimensions, const U * pDataRowMajor, size_t NumElements) + { + uint64_t rank = static_cast( Dimensions.size() ); + uint64_t tmp = 1; + for( auto i = 0 ; i < rank ; i++ ) + tmp *= Dimensions[i]; + assert( tmp == NumElements && "Dimensions don't match size of data being written" ); + // Total number of elements + write("", tmp); + // Number of dimensions + write("", rank); + // Followed by each dimension + for( auto i = 0 ; i < rank ; i++ ) { + tmp = Dimensions[i]; + write("", tmp); + } + for( auto i = 0; i < NumElements; ++i) + write("", pDataRowMajor[i]); + } + + // Reader template implementation //////////////////////////////////////////// + template + void BinaryReader::readDefault(const std::string &s, U &output) + { + file_.read((char *)&output, sizeof(U)); + } -template -void BinaryReader::readDefault(const std::string &s, U &output) -{ - file_.read((char *)&output, sizeof(U)); -} + template <> + void BinaryReader::readDefault(const std::string &s, std::string &output); -template -void BinaryReader::readDefault(const std::string &s, std::vector &output) -{ - uint64_t sz; + template + void BinaryReader::readDefault(const std::string &s, std::vector &output) + { + uint64_t sz; - read("", sz); - output.resize(sz); - for (uint64_t i = 0; i < sz; ++i) + read("", sz); + output.resize(sz); + for (uint64_t i = 0; i < sz; ++i) { read("", output[i]); } + } + + template + void BinaryReader::readMultiDim(const std::string &s, std::vector &buf, std::vector &dim) + { + // Number of elements + uint64_t NumElements; + read("", NumElements); + // Number of dimensions + uint64_t rank; + read("", rank); + // Followed by each dimension + uint64_t count = 1; + dim.resize(rank); + uint64_t tmp; + for( auto i = 0 ; i < rank ; i++ ) { + read("", tmp); + dim[i] = tmp; + count *= tmp; + } + assert( count == NumElements && "Dimensions don't match size of data being read" ); + buf.resize(count); + for( auto i = 0; i < count; ++i) + read("", buf[i]); + } } -NAMESPACE_END(Grid); - #endif diff --git a/Grid/serialisation/Hdf5IO.h b/Grid/serialisation/Hdf5IO.h index 59804240..19537599 100644 --- a/Grid/serialisation/Hdf5IO.h +++ b/Grid/serialisation/Hdf5IO.h @@ -3,6 +3,7 @@ #include #include +#include #include #include #include @@ -38,6 +39,8 @@ namespace Grid template typename std::enable_if>::is_number, void>::type writeDefault(const std::string &s, const std::vector &x); + template + void writeMultiDim(const std::string &s, const std::vector & Dimensions, const U * pDataRowMajor, size_t NumElements); H5NS::Group & getGroup(void); private: template @@ -48,7 +51,7 @@ namespace Grid std::vector path_; H5NS::H5File file_; H5NS::Group group_; - unsigned int dataSetThres_{HDF5_DEF_DATASET_THRES}; + const unsigned int dataSetThres_{HDF5_DEF_DATASET_THRES}; }; class Hdf5Reader: public Reader @@ -66,6 +69,8 @@ namespace Grid template typename std::enable_if>::is_number, void>::type readDefault(const std::string &s, std::vector &x); + template + void readMultiDim(const std::string &s, std::vector &buf, std::vector &dim); H5NS::Group & getGroup(void); private: template @@ -101,6 +106,75 @@ namespace Grid template <> void Hdf5Writer::writeDefault(const std::string &s, const std::string &x); + template + void Hdf5Writer::writeMultiDim(const std::string &s, const std::vector & Dimensions, const U * pDataRowMajor, size_t NumElements) + { + // Hdf5 needs the dimensions as hsize_t + const int rank = static_cast(Dimensions.size()); + std::vector dim(rank); + for(int i = 0; i < rank; i++) + dim[i] = Dimensions[i]; + // write the entire dataset to file + H5NS::DataSpace dataSpace(rank, dim.data()); + + if (NumElements > dataSetThres_) + { + // Make sure 1) each dimension; and 2) chunk size is < 4GB + const hsize_t MaxElements = ( sizeof( U ) == 1 ) ? 0xffffffff : 0x100000000 / sizeof( U ); + hsize_t ElementsPerChunk = 1; + bool bTooBig = false; + for( int i = rank - 1 ; i != -1 ; i-- ) { + auto &d = dim[i]; + if( bTooBig ) + d = 1; // Chunk size is already as big as can be - remaining dimensions = 1 + else { + // If individual dimension too big, reduce by prime factors if possible + while( d > MaxElements && ( d & 1 ) == 0 ) + d >>= 1; + const char ErrorMsg[] = " dimension > 4GB and not divisible by 2^n. " + "Hdf5IO chunk size will be inefficient. NB Serialisation is not intended for large datasets - please consider alternatives."; + if( d > MaxElements ) { + std::cout << GridLogWarning << "Individual" << ErrorMsg << std::endl; + hsize_t quotient = d / MaxElements; + if( d % MaxElements ) + quotient++; + d /= quotient; + } + // Now make sure overall size is not too big + hsize_t OverflowCheck = ElementsPerChunk; + ElementsPerChunk *= d; + assert( OverflowCheck == ElementsPerChunk / d && "Product of dimensions overflowed hsize_t" ); + // If product of dimensions too big, reduce by prime factors + while( ElementsPerChunk > MaxElements && ( ElementsPerChunk & 1 ) == 0 ) { + bTooBig = true; + d >>= 1; + ElementsPerChunk >>= 1; + } + if( ElementsPerChunk > MaxElements ) { + std::cout << GridLogWarning << "Product of" << ErrorMsg << std::endl; + hsize_t quotient = ElementsPerChunk / MaxElements; + if( ElementsPerChunk % MaxElements ) + quotient++; + d /= quotient; + ElementsPerChunk /= quotient; + } + } + } + H5NS::DataSet dataSet; + H5NS::DSetCreatPropList plist; + plist.setChunk(rank, dim.data()); + plist.setFletcher32(); + dataSet = group_.createDataSet(s, Hdf5Type::type(), dataSpace, plist); + dataSet.write(pDataRowMajor, Hdf5Type::type()); + } + else + { + H5NS::Attribute attribute; + attribute = group_.createAttribute(s, Hdf5Type::type(), dataSpace); + attribute.write(Hdf5Type::type(), pDataRowMajor); + } + } + template typename std::enable_if>::is_number, void>::type Hdf5Writer::writeDefault(const std::string &s, const std::vector &x) @@ -110,34 +184,11 @@ namespace Grid // flatten the vector and getting dimensions Flatten> flat(x); - std::vector dim; + std::vector dim; const auto &flatx = flat.getFlatVector(); - for (auto &d: flat.getDim()) - { dim.push_back(d); - } - - // write to file - H5NS::DataSpace dataSpace(dim.size(), dim.data()); - - if (flatx.size() > dataSetThres_) - { - H5NS::DataSet dataSet; - H5NS::DSetCreatPropList plist; - - plist.setChunk(dim.size(), dim.data()); - plist.setFletcher32(); - dataSet = group_.createDataSet(s, Hdf5Type::type(), dataSpace, plist); - dataSet.write(flatx.data(), Hdf5Type::type()); - } - else - { - H5NS::Attribute attribute; - - attribute = group_.createAttribute(s, Hdf5Type::type(), dataSpace); - attribute.write(Hdf5Type::type(), flatx.data()); - } + writeMultiDim(s, dim, &flatx[0], flatx.size()); } template @@ -173,10 +224,9 @@ namespace Grid template <> void Hdf5Reader::readDefault(const std::string &s, std::string &x); - + template - typename std::enable_if>::is_number, void>::type - Hdf5Reader::readDefault(const std::string &s, std::vector &x) + void Hdf5Reader::readMultiDim(const std::string &s, std::vector &buf, std::vector &dim) { // alias to element type typedef typename element>::type Element; @@ -184,7 +234,6 @@ namespace Grid // read the dimensions H5NS::DataSpace dataSpace; std::vector hdim; - std::vector dim; hsize_t size = 1; if (group_.attrExists(s)) @@ -204,8 +253,8 @@ namespace Grid } // read the flat vector - std::vector buf(size); - + buf.resize(size); + if (size > dataSetThres_) { H5NS::DataSet dataSet; @@ -220,7 +269,19 @@ namespace Grid attribute = group_.openAttribute(s); attribute.read(Hdf5Type::type(), buf.data()); } - + } + + template + typename std::enable_if>::is_number, void>::type + Hdf5Reader::readDefault(const std::string &s, std::vector &x) + { + // alias to element type + typedef typename element>::type Element; + + std::vector dim; + std::vector buf; + readMultiDim( s, buf, dim ); + // reconstruct the multidimensional vector Reconstruct> r(buf, dim); diff --git a/Grid/serialisation/MacroMagic.h b/Grid/serialisation/MacroMagic.h index 9139fd98..7866327e 100644 --- a/Grid/serialisation/MacroMagic.h +++ b/Grid/serialisation/MacroMagic.h @@ -107,9 +107,10 @@ THE SOFTWARE. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// #define GRID_MACRO_MEMBER(A,B) A B; -#define GRID_MACRO_COMP_MEMBER(A,B) result = (result and (lhs. B == rhs. B)); -#define GRID_MACRO_OS_WRITE_MEMBER(A,B) os<< #A <<" " #B << " = " << obj. B << " ; " < void writeDefault(const std::string &s, const std::vector &x); + template + void writeMultiDim(const std::string &s, const std::vector & Dimensions, const U * pDataRowMajor, size_t NumElements); private: void indent(void); private: @@ -69,6 +71,8 @@ namespace Grid void readDefault(const std::string &s, U &output); template void readDefault(const std::string &s, std::vector &output); + template + void readMultiDim(const std::string &s, std::vector &buf, std::vector &dim); private: void checkIndent(void); private: @@ -95,7 +99,18 @@ namespace Grid write(s, x[i]); } } - + + template + void TextWriter::writeMultiDim(const std::string &s, const std::vector & Dimensions, const U * pDataRowMajor, size_t NumElements) + { + uint64_t Rank = Dimensions.size(); + write(s, Rank); + for( uint64_t d : Dimensions ) + write(s, d); + while( NumElements-- ) + write(s, *pDataRowMajor++); + } + // Reader template implementation //////////////////////////////////////////// template <> void TextReader::readDefault(const std::string &s, std::string &output); @@ -122,7 +137,22 @@ namespace Grid } } - + template + void TextReader::readMultiDim(const std::string &s, std::vector &buf, std::vector &dim) + { + const char sz[] = ""; + uint64_t Rank; + read(sz, Rank); + dim.resize( Rank ); + size_t NumElements = 1; + for( auto &d : dim ) { + read(sz, d); + NumElements *= d; + } + buf.resize( NumElements ); + for( auto &x : buf ) + read(s, x); + } } diff --git a/Grid/serialisation/VectorUtils.h b/Grid/serialisation/VectorUtils.h index b6b95c10..a5a73992 100644 --- a/Grid/serialisation/VectorUtils.h +++ b/Grid/serialisation/VectorUtils.h @@ -1,3 +1,32 @@ +/************************************************************************************* + + Grid physics library, www.github.com/paboyle/Grid + + Source file: ./Grid/serialisation/VectorUtils.h + + Copyright (C) 2015 + + Author: Antonin Portelli + Author: Peter Boyle + Author: paboyle + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + + See the full license in the file "LICENSE" in the top level distribution directory + *************************************************************************************/ +/* END LEGAL */ #ifndef GRID_SERIALISATION_VECTORUTILS_H #define GRID_SERIALISATION_VECTORUTILS_H @@ -53,6 +82,17 @@ namespace Grid { return os; } + // std::vector> nested to specified Rank ////////////////////////////////// + template + struct NestedStdVector { + typedef typename std::vector::type> type; + }; + + template + struct NestedStdVector { + typedef T type; + }; + // Grid scalar tensors to nested std::vectors ////////////////////////////////// template struct TensorToVec @@ -436,4 +476,4 @@ std::string vecToStr(const std::vector &v) return sstr.str(); } -#endif \ No newline at end of file +#endif diff --git a/Grid/serialisation/XmlIO.h b/Grid/serialisation/XmlIO.h index d8636faf..cb9a49e7 100644 --- a/Grid/serialisation/XmlIO.h +++ b/Grid/serialisation/XmlIO.h @@ -57,6 +57,8 @@ namespace Grid void writeDefault(const std::string &s, const U &x); template void writeDefault(const std::string &s, const std::vector &x); + template + void writeMultiDim(const std::string &s, const std::vector & Dimensions, const U * pDataRowMajor, size_t NumElements); std::string docString(void); std::string string(void); private: @@ -78,6 +80,8 @@ namespace Grid template void readDefault(const std::string &s, U &output); template void readDefault(const std::string &s, std::vector &output); + template + void readMultiDim(const std::string &s, std::vector &buf, std::vector &dim); void readCurrentSubtree(std::string &s); private: @@ -122,13 +126,45 @@ namespace Grid void XmlWriter::writeDefault(const std::string &s, const std::vector &x) { push(s); - for (auto &x_i: x) + for( auto &u : x ) { - write("elem", x_i); + write("elem", u); } pop(); } - + + template + void XmlWriter::writeMultiDim(const std::string &s, const std::vector & Dimensions, const U * pDataRowMajor, size_t NumElements) + { + push(s); + size_t count = 1; + const int Rank = static_cast( Dimensions.size() ); + write("rank", Rank ); + std::vector MyIndex( Rank ); + for( auto d : Dimensions ) { + write("dim", d); + count *= d; + } + assert( count == NumElements && "XmlIO : element count doesn't match dimensions" ); + static const char sName[] = "tensor"; + for( int i = 0 ; i < Rank ; i++ ) { + MyIndex[i] = 0; + push(sName); + } + while (NumElements--) { + write("elem", *pDataRowMajor++); + int i; + for( i = Rank - 1 ; i != -1 && ++MyIndex[i] == Dimensions[i] ; i-- ) + MyIndex[i] = 0; + int Rollover = Rank - 1 - i; + for( i = 0 ; i < Rollover ; i++ ) + pop(); + for( i = 0 ; NumElements && i < Rollover ; i++ ) + push(sName); + } + pop(); + } + // Reader template implementation //////////////////////////////////////////// template <> void XmlReader::readDefault(const std::string &s, std::string &output); template @@ -143,25 +179,66 @@ namespace Grid template void XmlReader::readDefault(const std::string &s, std::vector &output) { - std::string buf; - unsigned int i = 0; - if (!push(s)) { std::cout << GridLogWarning << "XML: cannot open node '" << s << "'"; std::cout << std::endl; - - return; + } else { + for(unsigned int i = 0; node_.child("elem"); ) + { + output.resize(i + 1); + read("elem", output[i++]); + node_.child("elem").set_name("elem-done"); + } + pop(); + } + } + + template + void XmlReader::readMultiDim(const std::string &s, std::vector &buf, std::vector &dim) + { + if (!push(s)) + { + std::cout << GridLogWarning << "XML: cannot open node '" << s << "'"; + std::cout << std::endl; + } else { + static const char sName[] = "tensor"; + static const char sNameDone[] = "tensor-done"; + int Rank; + read("rank", Rank); + dim.resize( Rank ); + size_t NumElements = 1; + for( auto &d : dim ) + { + read("dim", d); + node_.child("dim").set_name("dim-done"); + NumElements *= d; + } + buf.resize( NumElements ); + std::vector MyIndex( Rank ); + for( int i = 0 ; i < Rank ; i++ ) { + MyIndex[i] = 0; + push(sName); + } + + for( auto &x : buf ) + { + NumElements--; + read("elem", x); + node_.child("elem").set_name("elem-done"); + int i; + for( i = Rank - 1 ; i != -1 && ++MyIndex[i] == dim[i] ; i-- ) + MyIndex[i] = 0; + int Rollover = Rank - 1 - i; + for( i = 0 ; i < Rollover ; i++ ) { + node_.set_name(sNameDone); + pop(); + } + for( i = 0 ; NumElements && i < Rollover ; i++ ) + push(sName); + } + pop(); } - while (node_.child("elem")) - { - output.resize(i + 1); - read("elem", output[i]); - node_.child("elem").set_name("elem-done"); - i++; - } - pop(); } - } #endif diff --git a/Grid/simd/Grid_gpu.h b/Grid/simd/Grid_gpu.h deleted file mode 100644 index 6dc5123a..00000000 --- a/Grid/simd/Grid_gpu.h +++ /dev/null @@ -1,652 +0,0 @@ - /************************************************************************************* - - Grid physics library, www.github.com/paboyle/Grid - - Source file: ./lib/simd/Grid_gpu.h - - Copyright (C) 2018 - -Author: Peter Boyle - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - - See the full license in the file "LICENSE" in the top level distribution directory - *************************************************************************************/ - /* END LEGAL */ -//---------------------------------------------------------------------- -/*! @file Grid_gpu.h - @brief Optimization libraries for GPU - Use float4, double2 -*/ -//---------------------------------------------------------------------- - -#include - -namespace Grid { - - // re im, re, im, re, im etc.. -struct half8 { - half ax, ay, az, aw, bx, by, bz, bw; -}; -accelerator_inline float half2float(half h) -{ - float f; -#ifdef __CUDA_ARCH__ - f = __half2float(h); -#else - //f = __half2float(h); - __half_raw hr(h); - Grid_half hh; - hh.x = hr.x; - f= sfw_half_to_float(hh); -#endif - return f; -} -accelerator_inline half float2half(float f) -{ - half h; -#ifdef __CUDA_ARCH__ - h = __float2half(f); -#else - Grid_half hh = sfw_float_to_half(f); - __half_raw hr; - hr.x = hh.x; - h = __half(hr); -#endif - return h; -} - -namespace Optimization { - - inline accelerator float4 operator*(float4 a,float4 b) {return make_float4(a.x*b.x,a.y*b.y,a.z*b.z,a.w*b.w);} - inline accelerator float4 operator+(float4 a,float4 b) {return make_float4(a.x+b.x,a.y+b.y,a.z+b.z,a.w+b.w);} - inline accelerator float4 operator-(float4 a,float4 b) {return make_float4(a.x-b.x,a.y-b.y,a.z-b.z,a.w-b.w);} - inline accelerator float4 operator/(float4 a,float4 b) {return make_float4(a.x/b.x,a.y/b.y,a.z/b.z,a.w/b.w);} - - inline accelerator double2 operator*(double2 a,double2 b) {return make_double2(a.x*b.x,a.y*b.y);} - inline accelerator double2 operator+(double2 a,double2 b) {return make_double2(a.x+b.x,a.y+b.y);} - inline accelerator double2 operator-(double2 a,double2 b) {return make_double2(a.x-b.x,a.y-b.y);} - inline accelerator double2 operator/(double2 a,double2 b) {return make_double2(a.x/b.x,a.y/b.y);} - - inline accelerator int4 operator*(int4 a,int4 b) {return make_int4(a.x*b.x,a.y*b.y,a.z*b.z,a.w*b.w);} - inline accelerator int4 operator+(int4 a,int4 b) {return make_int4(a.x+b.x,a.y+b.y,a.z+b.z,a.w+b.w);} - inline accelerator int4 operator-(int4 a,int4 b) {return make_int4(a.x-b.x,a.y-b.y,a.z-b.z,a.w-b.w);} - inline accelerator int4 operator/(int4 a,int4 b) {return make_int4(a.x/b.x,a.y/b.y,a.z/b.z,a.w/b.w);} - - struct Vsplat{ - //Complex float - accelerator_inline float4 operator()(float a, float b){ - float4 ret; - ret.x=ret.z=a; - ret.y=ret.w=b; - return ret; - } - // Real float - accelerator_inline float4 operator()(float a){ - float4 ret; - ret.x=ret.y=ret.z=ret.w = a; - return ret; - } - //Complex double - accelerator_inline double2 operator()(double a, double b){ - double2 ret; - ret.x=a; - ret.y=b; - return ret; - } - //Real double - accelerator_inline double2 operator()(double a){ - double2 ret; - ret.x = ret.y = a; - return ret; - } - //Integer - accelerator_inline int4 operator()(Integer a){ - int4 ret; - ret.x=ret.y=ret.z=ret.w=a; - return ret; - } - }; - - struct Vstore{ - //Float - accelerator_inline void operator()(float4 a, float* F){ - float4 *F4 = (float4 *)F; - *F4 = a; - } - //Double - accelerator_inline void operator()(double2 a, double* D){ - double2 *D2 = (double2 *)D; - *D2 = a; - } - //Integer - accelerator_inline void operator()(int4 a, Integer* I){ - int4 *I4 = (int4 *)I; - *I4 = a; - } - - }; - - struct Vstream{ - //Float - accelerator_inline void operator()(float * a, float4 b){ - float4 * a4 = (float4 *)a; - *a4 = b; - } - //Double - accelerator_inline void operator()(double * a, double2 b){ - double2 * a2 = (double2 *)a; - *a2 = b; - } - - }; - - struct Vset{ - // Complex float - accelerator_inline float4 operator()(Grid::ComplexF *a){ - float4 ret; - ret.x = a[0].real(); - ret.y = a[0].imag(); - ret.z = a[1].real(); - ret.w = a[1].imag(); - return ret; - } - // Complex double - accelerator_inline double2 operator()(Grid::ComplexD *a){ - double2 ret; - ret.x = a[0].real(); - ret.y = a[0].imag(); - return ret; - } - // Real float - accelerator_inline float4 operator()(float *a){ - float4 ret; - ret.x = a[0]; - ret.y = a[1]; - ret.z = a[2]; - ret.w = a[3]; - return ret; - } - // Real double - accelerator_inline double2 operator()(double *a){ - double2 ret; - ret.x = a[0]; - ret.y = a[1]; - return ret; - } - // Integer - accelerator_inline int4 operator()(Integer *a){ - int4 ret; - ret.x = a[0]; - ret.y = a[1]; - ret.z = a[2]; - ret.w = a[3]; - return ret; - } - - }; - - template - struct Reduce{ - //Need templated class to overload output type - //General form must generate error if compiled - accelerator_inline Out_type operator()(In_type in){ - printf("Error, using wrong Reduce function\n"); - exit(1); - return 0; - } - }; - - ///////////////////////////////////////////////////// - // Arithmetic operations - ///////////////////////////////////////////////////// - struct Sum{ - //Complex/Real float - accelerator_inline float4 operator()(float4 a, float4 b){ - return a+b; - } - //Complex/Real double - accelerator_inline double2 operator()(double2 a, double2 b){ - return a+b; - } - //Integer - accelerator_inline int4 operator()(int4 a,int4 b){ - return a+b; - } - }; - - struct Sub{ - //Complex/Real float - accelerator_inline float4 operator()(float4 a, float4 b){ - return a-b; - } - //Complex/Real double - accelerator_inline double2 operator()(double2 a, double2 b){ - return a-b; - } - //Integer - accelerator_inline int4 operator()(int4 a, int4 b){ - return a-b; - } - }; - - struct MultRealPart{ - accelerator_inline float4 operator()(float4 a, float4 b){ - float4 ymm0; - ymm0.x = a.x; - ymm0.y = a.x; - ymm0.z = a.z; - ymm0.w = a.z; - return ymm0*b; - // ymm0 = _mm_shuffle_ps(a,a,_MM_SELECT_FOUR_FOUR(2,2,0,0)); // ymm0 <- ar ar, - // return _mm_mul_ps(ymm0,b); // ymm0 <- ar bi, ar br - } - accelerator_inline double2 operator()(double2 a, double2 b){ - double2 ymm0; - ymm0.x = a.x; - ymm0.y = a.x; - return ymm0*b; - // ymm0 = _mm_shuffle_pd(a,a,0x0); // ymm0 <- ar ar, ar,ar b'00,00 - // return _mm_mul_pd(ymm0,b); // ymm0 <- ar bi, ar br - } - }; - struct MaddRealPart{ - accelerator_inline float4 operator()(float4 a, float4 b, float4 c){ - float4 ymm0; // = _mm_shuffle_ps(a,a,_MM_SELECT_FOUR_FOUR(2,2,0,0)); // ymm0 <- ar ar, - ymm0.x = a.x; - ymm0.y = a.x; - ymm0.z = a.z; - ymm0.w = a.z; - return c+ymm0*b; - } - accelerator_inline double2 operator()(double2 a, double2 b, double2 c){ - // ymm0 = _mm_shuffle_pd( a, a, 0x0 ); - double2 ymm0; - ymm0.x = a.x; - ymm0.y = a.x; - return c+ymm0*b; - } - }; - - struct MultComplex{ - // Complex float - accelerator_inline float4 operator()(float4 a, float4 b){ - float4 ymm0; - ymm0.x = a.x*b.x - a.y*b.y ; // rr - ii - ymm0.y = a.x*b.y + a.y*b.x ; // ir + ri - ymm0.z = a.z*b.z - a.w*b.w ; // rr - ii - ymm0.w = a.w*b.z + a.z*b.w ; // ir + ri - return ymm0; - } - // Complex double - accelerator_inline double2 operator()(double2 a, double2 b){ - double2 ymm0; - ymm0.x = a.x*b.x - a.y*b.y ; // rr - ii - ymm0.y = a.x*b.y + a.y*b.x ; // ir + ri - return ymm0; - } - }; - - struct Mult{ - - accelerator_inline void mac(float4 &a, float4 b, float4 c){ - a= a+b*c; - } - - accelerator_inline void mac(double2 &a, double2 b, double2 c){ - a= a+b*c; - } - - // Real float - accelerator_inline float4 operator()(float4 a, float4 b){ - return a*b; - } - // Real double - accelerator_inline double2 operator()(double2 a, double2 b){ - return a*b; - } - // Integer - accelerator_inline int4 operator()(int4 a, int4 b){ - return a*b; - } - }; - - struct Div{ - // Real float - accelerator_inline float4 operator()(float4 a, float4 b){ - return a/b; - } - // Real double - accelerator_inline double2 operator()(double2 a, double2 b){ - return a/b; - } - }; - - - struct Conj{ - // Complex single - accelerator_inline float4 operator()(float4 in){ - float4 ret; - ret.x = in.x; - ret.y = - in.y; - ret.z = in.z; - ret.w = - in.w; - return ret; - } - // Complex double - accelerator_inline double2 operator()(double2 in){ - double2 ret; - ret.x = in.x; - ret.y = - in.y; - return ret; - } - // do not define for integer input - }; - - struct TimesMinusI{ - //Complex single - accelerator_inline float4 operator()(float4 in, float4 ret){ - float4 tmp; - tmp.x = in.y; - tmp.y = - in.x; - tmp.z = in.w; - tmp.w = - in.z; - return tmp; - } - //Complex double - accelerator_inline double2 operator()(double2 in, double2 ret){ - double2 tmp; - tmp.x = in.y; - tmp.y = - in.x; - return tmp; - } - }; - - struct TimesI{ - //Complex single - accelerator_inline float4 operator()(float4 in, float4 ret){ - float4 tmp; - tmp.x = - in.y; - tmp.y = in.x; - tmp.z = - in.w; - tmp.w = in.z; - return tmp; - } - //Complex double - accelerator_inline double2 operator()(double2 in, double2 ret){ - double2 tmp ; - tmp.x = - in.y; - tmp.y = in.x; - return tmp; - } - }; - - struct Permute{ - - static accelerator_inline float4 Permute0(float4 in){ - float4 tmp; - tmp.x = in.z; - tmp.y = in.w; - tmp.z = in.x; - tmp.w = in.y; - return tmp; - }; - static accelerator_inline float4 Permute1(float4 in){ - float4 tmp; - tmp.x = in.y; - tmp.y = in.x; - tmp.z = in.w; - tmp.w = in.z; - return tmp; - }; - static accelerator_inline float4 Permute2(float4 in){ - return in; - }; - static accelerator_inline float4 Permute3(float4 in){ - return in; - }; - - static accelerator_inline double2 Permute0(double2 in){ //AB -> BA - double2 tmp; - tmp.x = in.y; - tmp.y = in.x; - return tmp; - }; - static accelerator_inline double2 Permute1(double2 in){ - return in; - }; - static accelerator_inline double2 Permute2(double2 in){ - return in; - }; - static accelerator_inline double2 Permute3(double2 in){ - return in; - }; - }; - - struct PrecisionChange { - static accelerator_inline half8 StoH (float4 a,float4 b) { - half8 h; - h.ax = float2half(a.x); - h.ay = float2half(a.y); - h.az = float2half(a.z); - h.aw = float2half(a.w); - h.bx = float2half(b.x); - h.by = float2half(b.y); - h.bz = float2half(b.z); - h.bw = float2half(b.w); - return h; - } - static accelerator_inline void HtoS (half8 h,float4 &sa,float4 &sb) { - sa.x = half2float(h.ax); - sa.y = half2float(h.ay); - sa.z = half2float(h.az); - sa.w = half2float(h.aw); - sb.x = half2float(h.bx); - sb.y = half2float(h.by); - sb.z = half2float(h.bz); - sb.w = half2float(h.bw); - } - static accelerator_inline float4 DtoS (double2 a,double2 b) { - float4 s; - s.x = a.x; - s.y = a.y; - s.z = b.x; - s.w = b.y; - return s; - } - static accelerator_inline void StoD (float4 s,double2 &a,double2 &b) { - a.x = s.x; - a.y = s.y; - b.x = s.z; - b.y = s.w; - } - static accelerator_inline half8 DtoH (double2 a,double2 b,double2 c,double2 d) { - float4 sa,sb; - sa = DtoS(a,b); - sb = DtoS(c,d); - return StoH(sa,sb); - } - static accelerator_inline void HtoD (half8 h,double2 &a,double2 &b,double2 &c,double2 &d) { - float4 sa,sb; - HtoS(h,sa,sb); - StoD(sa,a,b); - StoD(sb,c,d); - } - }; - - struct Exchange{ - // 3210 ordering - - static accelerator_inline void Exchange0(float4 &out1,float4 &out2,float4 in1,float4 in2){ - out1.x = in1.x; - out1.y = in1.y; - out1.z = in2.x; - out1.w = in2.y; - - out2.x = in1.z; - out2.y = in1.w; - out2.z = in2.z; - out2.w = in2.w; - - // out1= _mm_shuffle_ps(in1,in2,_MM_SELECT_FOUR_FOUR(1,0,1,0)); - // out2= _mm_shuffle_ps(in1,in2,_MM_SELECT_FOUR_FOUR(3,2,3,2)); - return; - }; - - static accelerator_inline void Exchange1(float4 &out1,float4 &out2,float4 in1,float4 in2){ - - out1.x = in1.x; - out1.y = in2.x; - out1.z = in1.z; - out1.w = in2.z; - - out2.x = in1.y; - out2.y = in2.y; - out2.z = in1.w; - out2.w = in2.w; - - // out1= _mm_shuffle_ps(in1,in2,_MM_SELECT_FOUR_FOUR(2,0,2,0)); /*ACEG*/ - // out2= _mm_shuffle_ps(in1,in2,_MM_SELECT_FOUR_FOUR(3,1,3,1)); /*BDFH*/ - // out1= _mm_shuffle_ps(out1,out1,_MM_SELECT_FOUR_FOUR(3,1,2,0)); /*AECG*/ - // out2= _mm_shuffle_ps(out2,out2,_MM_SELECT_FOUR_FOUR(3,1,2,0)); /*AECG*/ - }; - static accelerator_inline void Exchange2(float4 &out1,float4 &out2,float4 in1,float4 in2){ - assert(0); - return; - }; - static accelerator_inline void Exchange3(float4 &out1,float4 &out2,float4 in1,float4 in2){ - assert(0); - return; - }; - - static accelerator_inline void Exchange0(double2 &out1,double2 &out2,double2 in1,double2 in2){ - out1.x = in1.x; - out1.y = in2.x; - out2.x = in1.y; - out2.y = in2.y; - // out1= _mm_shuffle_pd(in1,in2,0x0); - // out2= _mm_shuffle_pd(in1,in2,0x3); - }; - static accelerator_inline void Exchange1(double2 &out1,double2 &out2,double2 in1,double2 in2){ - assert(0); - return; - }; - static accelerator_inline void Exchange2(double2 &out1,double2 &out2,double2 in1,double2 in2){ - assert(0); - return; - }; - static accelerator_inline void Exchange3(double2 &out1,double2 &out2,double2 in1,double2 in2){ - assert(0); - return; - }; - }; - - struct Rotate{ - - static accelerator_inline float4 rotate(float4 in,int n){ - float4 ret; - switch(n){ - case 0: ret = in ; break; - case 1: ret.x = in.y; ret.y = in.z ; ret.z = in.w ; ret.w = in.x; break; - case 2: ret.x = in.z; ret.y = in.w ; ret.z = in.x ; ret.w = in.y; break; - case 3: ret.x = in.w; ret.y = in.x ; ret.z = in.y ; ret.w = in.z; break; - default: break; - } - return ret; - } - static accelerator_inline double2 rotate(double2 in,int n){ - double2 ret; - switch(n){ - case 0: ret = in; break; - case 1: ret.x = in.y; ret.y = in.x ; break; - default: break; - } - return ret; - } - - template static accelerator_inline float4 tRotate(float4 in){ - return rotate(in,n); - }; - template static accelerator_inline double2 tRotate(double2 in){ - return rotate(in,n); - }; - - }; - ////////////////////////////////////////////// - // Some Template specialization - - //Complex float Reduce - template<> - accelerator_inline Grid::ComplexF Reduce::operator()(float4 in){ - Grid::ComplexF ret(in.x+in.z,in.y+in.w); - return ret; - } - //Real float Reduce - template<> - accelerator_inline Grid::RealF Reduce::operator()(float4 in){ - return in.x+in.y+in.z+in.w; - } - - //Complex double Reduce - template<> - accelerator_inline Grid::ComplexD Reduce::operator()(double2 in){ - return Grid::ComplexD(in.x,in.y); - } - - //Real double Reduce - template<> - accelerator_inline Grid::RealD Reduce::operator()(double2 in){ - return in.x+in.y; - } - - //Integer Reduce - template<> - accelerator_inline Integer Reduce::operator()(int4 in){ - return in.x+in.y+in.z+in.w; - } -} - -////////////////////////////////////////////////////////////////////////////////////// -// Here assign types -////////////////////////////////////////////////////////////////////////////////////// - typedef half8 SIMD_Htype; // Single precision type - typedef float4 SIMD_Ftype; // Single precision type - typedef double2 SIMD_Dtype; // Double precision type - typedef int4 SIMD_Itype; // Integer type - - // prefetch utilities - accelerator_inline void v_prefetch0(int size, const char *ptr){}; - accelerator_inline void prefetch_HINT_T0(const char *ptr){}; - - // Function name aliases - typedef Optimization::Vsplat VsplatSIMD; - typedef Optimization::Vstore VstoreSIMD; - typedef Optimization::Vset VsetSIMD; - typedef Optimization::Vstream VstreamSIMD; - template using ReduceSIMD = Optimization::Reduce; - - // Arithmetic operations - typedef Optimization::Sum SumSIMD; - typedef Optimization::Sub SubSIMD; - typedef Optimization::Div DivSIMD; - typedef Optimization::Mult MultSIMD; - typedef Optimization::MultComplex MultComplexSIMD; - typedef Optimization::MultRealPart MultRealPartSIMD; - typedef Optimization::MaddRealPart MaddRealPartSIMD; - typedef Optimization::Conj ConjSIMD; - typedef Optimization::TimesMinusI TimesMinusISIMD; - typedef Optimization::TimesI TimesISIMD; - -} diff --git a/Grid/simd/Grid_vector_types.h b/Grid/simd/Grid_vector_types.h index 760981ff..4d506261 100644 --- a/Grid/simd/Grid_vector_types.h +++ b/Grid/simd/Grid_vector_types.h @@ -11,6 +11,7 @@ Author: Guido Cossu Author: Peter Boyle Author: neo Author: paboyle +Author: Michael Marshall This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -109,9 +110,6 @@ accelerator_inline Grid_half sfw_float_to_half(float ff) { #ifdef GPU_VEC #include "Grid_gpu_vec.h" #endif -#ifdef GPU -#include "Grid_gpu.h" -#endif #ifdef GEN #include "Grid_generic.h" #endif @@ -162,17 +160,25 @@ template using NotEnableIf = Invoke struct is_complex : public std::false_type {}; -template <> struct is_complex > : public std::true_type {}; -template <> struct is_complex > : public std::true_type {}; +template <> struct is_complex : public std::true_type {}; +template <> struct is_complex : public std::true_type {}; -template using IfReal = Invoke::value, int> >; +template struct is_real : public std::false_type {}; +template struct is_real::value, + void>::type> : public std::true_type {}; + +template struct is_integer : public std::false_type {}; +template struct is_integer::value, + void>::type> : public std::true_type {}; + +template using IfReal = Invoke::value, int> >; template using IfComplex = Invoke::value, int> >; -template using IfInteger = Invoke::value, int> >; +template using IfInteger = Invoke::value, int> >; template using IfSame = Invoke::value, int> >; -template using IfNotReal = Invoke::value, int> >; +template using IfNotReal = Invoke::value, int> >; template using IfNotComplex = Invoke::value, int> >; -template using IfNotInteger = Invoke::value, int> >; +template using IfNotInteger = Invoke::value, int> >; template using IfNotSame = Invoke::value, int> >; //////////////////////////////////////////////////////// @@ -957,8 +963,10 @@ template struct is_simd : public std::false_type {}; template <> struct is_simd : public std::true_type {}; template <> struct is_simd : public std::true_type {}; +template <> struct is_simd : public std::true_type {}; template <> struct is_simd : public std::true_type {}; template <> struct is_simd : public std::true_type {}; +template <> struct is_simd : public std::true_type {}; template <> struct is_simd : public std::true_type {}; template using IfSimd = Invoke::value, int> >; diff --git a/Grid/tensors/Tensor_class.h b/Grid/tensors/Tensor_class.h index 84df7d4f..cdcd18e8 100644 --- a/Grid/tensors/Tensor_class.h +++ b/Grid/tensors/Tensor_class.h @@ -5,6 +5,7 @@ Copyright (C) 2015 Author: Azusa Yamaguchi Author: Peter Boyle +Author: Michael Marshall This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -21,8 +22,7 @@ See the full license in the file "LICENSE" in the top level distribution directory *************************************************************************************/ /* END LEGAL */ -#ifndef GRID_MATH_TENSORS_H -#define GRID_MATH_TENSORS_H +#pragma once NAMESPACE_BEGIN(Grid); @@ -42,27 +42,26 @@ NAMESPACE_BEGIN(Grid); // class GridTensorBase {}; +// Too late to remove these traits from Grid Tensors, so inherit from GridTypeMapper +#define GridVector_CopyTraits \ + using element = vtype; \ + using scalar_type = typename Traits::scalar_type; \ + using vector_type = typename Traits::vector_type; \ + using vector_typeD = typename Traits::vector_typeD; \ + using tensor_reduced = typename Traits::tensor_reduced; \ + using scalar_object = typename Traits::scalar_object; \ + using Complexified = typename Traits::Complexified; \ + using Realified = typename Traits::Realified; \ + using DoublePrecision = typename Traits::DoublePrecision; \ + static constexpr int TensorLevel = Traits::TensorLevel + template class iScalar { public: vtype _internal; - typedef vtype element; - typedef typename GridTypeMapper::scalar_type scalar_type; - typedef typename GridTypeMapper::vector_type vector_type; - typedef typename GridTypeMapper::vector_typeD vector_typeD; - typedef typename GridTypeMapper::tensor_reduced tensor_reduced_v; - typedef typename GridTypeMapper::scalar_object recurse_scalar_object; - typedef iScalar tensor_reduced; - typedef iScalar scalar_object; - // substitutes a real or complex version with same tensor structure - typedef iScalar::Complexified> Complexified; - typedef iScalar::Realified> Realified; - - // get double precision version - typedef iScalar::DoublePrecision> DoublePrecision; - - enum { TensorLevel = GridTypeMapper::TensorLevel + 1 }; + using Traits = GridTypeMapper >; + GridVector_CopyTraits; static accelerator_inline constexpr int Nsimd(void) { return sizeof(vector_type)/sizeof(scalar_type); } @@ -160,6 +159,10 @@ public: stream << "S {" << o._internal << "}"; return stream; }; + strong_inline const scalar_type * begin() const { return reinterpret_cast(&_internal); } + strong_inline scalar_type * begin() { return reinterpret_cast< scalar_type *>(&_internal); } + strong_inline const scalar_type * end() const { return begin() + Traits::count; } + strong_inline scalar_type * end() { return begin() + Traits::count; } }; /////////////////////////////////////////////////////////// @@ -180,35 +183,22 @@ template class iVector { public: vtype _internal[N]; + + using Traits = GridTypeMapper >; - typedef vtype element; - typedef typename GridTypeMapper::scalar_type scalar_type; - typedef typename GridTypeMapper::vector_type vector_type; - typedef typename GridTypeMapper::vector_typeD vector_typeD; - typedef typename GridTypeMapper::tensor_reduced tensor_reduced_v; - typedef typename GridTypeMapper::scalar_object recurse_scalar_object; - typedef iScalar tensor_reduced; - typedef iVector scalar_object; - - // substitutes a real or complex version with same tensor structure - typedef iVector::Complexified, N> Complexified; - typedef iVector::Realified, N> Realified; - - // get double precision version - typedef iVector::DoublePrecision, N> DoublePrecision; + GridVector_CopyTraits; static accelerator_inline constexpr int Nsimd(void) { return sizeof(vector_type)/sizeof(scalar_type); } - + template ::value, T>::type * = nullptr> - accelerator_inline auto operator=(T arg) -> iVector { + strong_inline auto operator=(T arg) -> iVector { zeroit(*this); for (int i = 0; i < N; i++) _internal[i] = arg; return *this; } - enum { TensorLevel = GridTypeMapper::TensorLevel + 1 }; - accelerator_inline iVector(const Zero &z) { zeroit(*this); }; accelerator iVector() = default; + accelerator_inline iVector(const Zero &z) { zeroit(*this); }; accelerator_inline iVector &operator=(const Zero &hero) { zeroit(*this); @@ -281,6 +271,15 @@ public: stream << "}"; return stream; }; + // strong_inline vtype && operator ()(int i) { + // return _internal[i]; + // } + + strong_inline const scalar_type * begin() const { return reinterpret_cast(_internal); } + strong_inline scalar_type * begin() { return reinterpret_cast< scalar_type *>(_internal); } + strong_inline const scalar_type * end() const { return begin() + Traits::count; } + strong_inline scalar_type * end() { return begin() + Traits::count; } + }; template @@ -288,25 +287,9 @@ class iMatrix { public: vtype _internal[N][N]; - typedef vtype element; - typedef typename GridTypeMapper::scalar_type scalar_type; - typedef typename GridTypeMapper::vector_type vector_type; - typedef typename GridTypeMapper::vector_typeD vector_typeD; - typedef typename GridTypeMapper::tensor_reduced tensor_reduced_v; - typedef typename GridTypeMapper::scalar_object recurse_scalar_object; + using Traits = GridTypeMapper >; - // substitutes a real or complex version with same tensor structure - typedef iMatrix::Complexified, N> Complexified; - typedef iMatrix::Realified, N> Realified; - - // get double precision version - typedef iMatrix::DoublePrecision, N> DoublePrecision; - - // Tensor removal - typedef iScalar tensor_reduced; - typedef iMatrix scalar_object; - - enum { TensorLevel = GridTypeMapper::TensorLevel + 1 }; + GridVector_CopyTraits; static accelerator_inline constexpr int Nsimd(void) { return sizeof(vector_type)/sizeof(scalar_type); } @@ -428,6 +411,14 @@ public: return stream; }; + // strong_inline vtype && operator ()(int i,int j) { + // return _internal[i][j]; + // } + + strong_inline const scalar_type * begin() const { return reinterpret_cast(_internal[0]); } + strong_inline scalar_type * begin() { return reinterpret_cast< scalar_type *>(_internal[0]); } + strong_inline const scalar_type * end() const { return begin() + Traits::count; } + strong_inline scalar_type * end() { return begin() + Traits::count; } }; template accelerator_inline @@ -451,4 +442,3 @@ void vprefetch(const iMatrix &vv) { NAMESPACE_END(Grid); -#endif diff --git a/Grid/tensors/Tensor_traits.h b/Grid/tensors/Tensor_traits.h index 12021cf9..45a1d807 100644 --- a/Grid/tensors/Tensor_traits.h +++ b/Grid/tensors/Tensor_traits.h @@ -1,10 +1,11 @@ -/************************************************************************************* + /************************************************************************************* Grid physics library, www.github.com/paboyle/Grid Source file: ./lib/tensors/Tensor_traits.h Copyright (C) 2015 Author: Azusa Yamaguchi Author: Peter Boyle Author: Christopher Kelly +Author: Michael Marshall This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or @@ -17,14 +18,25 @@ Author: Christopher Kelly with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. See the full license in the file "LICENSE" in the top level distribution directory -*************************************************************************************/ -/* END LEGAL */ + *************************************************************************************/ + /* END LEGAL */ #ifndef GRID_MATH_TRAITS_H #define GRID_MATH_TRAITS_H #include -NAMESPACE_BEGIN(Grid); +namespace Grid { + + // Forward declarations + template class iScalar; + template class iVector; + template class iMatrix; + + // These are the Grid tensors + template struct isGridTensor : public std::false_type { static constexpr bool notvalue = true; }; + template struct isGridTensor> : public std::true_type { static constexpr bool notvalue = false; }; + template struct isGridTensor> : public std::true_type { static constexpr bool notvalue = false; }; + template struct isGridTensor> : public std::true_type { static constexpr bool notvalue = false; }; ////////////////////////////////////////////////////////////////////////////////// // Want to recurse: GridTypeMapper >::scalar_type == ComplexD. @@ -40,258 +52,236 @@ NAMESPACE_BEGIN(Grid); // to study C++11's type_traits.h file. (std::enable_if >) // ////////////////////////////////////////////////////////////////////////////////// - -template class GridTypeMapper { -public: - typedef typename T::scalar_type scalar_type; - typedef typename T::vector_type vector_type; - typedef typename T::vector_typeD vector_typeD; - typedef typename T::tensor_reduced tensor_reduced; - typedef typename T::scalar_object scalar_object; - typedef typename T::Complexified Complexified; - typedef typename T::Realified Realified; - typedef typename T::DoublePrecision DoublePrecision; - enum { TensorLevel = T::TensorLevel }; -}; + + // This saves repeating common properties for supported Grid Scalar types + // TensorLevel How many nested grid tensors + // Rank Rank of the grid tensor + // count Total number of elements, i.e. product of dimensions + // Dimension(dim) Size of dimension dim + struct GridTypeMapper_Base { + static constexpr int TensorLevel = 0; + static constexpr int Rank = 0; + static constexpr std::size_t count = 1; + static constexpr int Dimension(int dim) { return 0; } + }; ////////////////////////////////////////////////////////////////////////////////// // Recursion stops with these template specialisations ////////////////////////////////////////////////////////////////////////////////// -template<> class GridTypeMapper { -public: - typedef RealF scalar_type; - typedef RealF vector_type; - typedef RealD vector_typeD; - typedef RealF tensor_reduced ; - typedef RealF scalar_object; - typedef ComplexF Complexified; - typedef RealF Realified; - typedef RealD DoublePrecision; - enum { TensorLevel = 0 }; -}; -template<> class GridTypeMapper { -public: - typedef RealD scalar_type; - typedef RealD vector_type; - typedef RealD vector_typeD; - typedef RealD tensor_reduced; - typedef RealD scalar_object; - typedef ComplexD Complexified; - typedef RealD Realified; - typedef RealD DoublePrecision; - enum { TensorLevel = 0 }; -}; -template<> class GridTypeMapper { -public: - typedef ComplexF scalar_type; - typedef ComplexF vector_type; - typedef ComplexD vector_typeD; - typedef ComplexF tensor_reduced; - typedef ComplexF scalar_object; - typedef ComplexF Complexified; - typedef RealF Realified; - typedef ComplexD DoublePrecision; - enum { TensorLevel = 0 }; -}; -template<> class GridTypeMapper { -public: - typedef ComplexD scalar_type; - typedef ComplexD vector_type; - typedef ComplexD vector_typeD; - typedef ComplexD tensor_reduced; - typedef ComplexD scalar_object; - typedef ComplexD Complexified; - typedef RealD Realified; - typedef ComplexD DoublePrecision; - enum { TensorLevel = 0 }; -}; -template<> class GridTypeMapper { -public: - typedef Integer scalar_type; - typedef Integer vector_type; - typedef Integer vector_typeD; - typedef Integer tensor_reduced; - typedef Integer scalar_object; - typedef void Complexified; - typedef void Realified; - typedef void DoublePrecision; - enum { TensorLevel = 0 }; -}; -template<> class GridTypeMapper { -public: - typedef RealF scalar_type; - typedef vRealF vector_type; - typedef vRealD vector_typeD; - typedef vRealF tensor_reduced; - typedef RealF scalar_object; - typedef vComplexF Complexified; - typedef vRealF Realified; - typedef vRealD DoublePrecision; - enum { TensorLevel = 0 }; -}; -template<> class GridTypeMapper { -public: - typedef RealD scalar_type; - typedef vRealD vector_type; - typedef vRealD vector_typeD; - typedef vRealD tensor_reduced; - typedef RealD scalar_object; - typedef vComplexD Complexified; - typedef vRealD Realified; - typedef vRealD DoublePrecision; - enum { TensorLevel = 0 }; -}; -template<> class GridTypeMapper { -public: - typedef ComplexF scalar_type; - typedef vComplexH vector_type; - typedef vComplexD vector_typeD; - typedef vComplexH tensor_reduced; - typedef ComplexF scalar_object; - typedef vComplexH Complexified; - typedef vRealH Realified; - typedef vComplexD DoublePrecision; - enum { TensorLevel = 0 }; -}; -template<> class GridTypeMapper { -public: - typedef ComplexF scalar_type; - typedef vComplexF vector_type; - typedef vComplexD vector_typeD; - typedef vComplexF tensor_reduced; - typedef ComplexF scalar_object; - typedef vComplexF Complexified; - typedef vRealF Realified; - typedef vComplexD DoublePrecision; - enum { TensorLevel = 0 }; -}; -template<> class GridTypeMapper { -public: - typedef ComplexD scalar_type; - typedef vComplexD vector_type; - typedef vComplexD vector_typeD; - typedef vComplexD tensor_reduced; - typedef ComplexD scalar_object; - typedef vComplexD Complexified; - typedef vRealD Realified; - typedef vComplexD DoublePrecision; - enum { TensorLevel = 0 }; -}; -template<> class GridTypeMapper { -public: - typedef Integer scalar_type; - typedef vInteger vector_type; - typedef vInteger vector_typeD; - typedef vInteger tensor_reduced; - typedef Integer scalar_object; - typedef void Complexified; - typedef void Realified; - typedef void DoublePrecision; - enum { TensorLevel = 0 }; -}; + template struct GridTypeMapper {}; -// First some of my own traits -template struct isGridTensor { - static const bool value = true; - static const bool notvalue = false; -}; -template<> struct isGridTensor { - static const bool value = false; - static const bool notvalue = true; -}; -template<> struct isGridTensor { - static const bool value = false; - static const bool notvalue = true; -}; -template<> struct isGridTensor { - static const bool value = false; - static const bool notvalue = true; -}; -template<> struct isGridTensor { - static const bool value = false; - static const bool notvalue = true; -}; -template<> struct isGridTensor { - static const bool value = false; - static const bool notvalue = true; -}; -template<> struct isGridTensor { - static const bool value = false; - static const bool notvalue = true; -}; -template<> struct isGridTensor { - static const bool value = false; - static const bool notvalue = true; -}; -template<> struct isGridTensor { - static const bool value = false; - static const bool notvalue = true; -}; -template<> struct isGridTensor { - static const bool value = false; - static const bool notvalue = true; -}; -template<> struct isGridTensor { - static const bool value = false; - static const bool notvalue = true; -}; -template<> struct isGridTensor { - static const bool value = false; - static const bool notvalue = true; -}; + template<> struct GridTypeMapper : public GridTypeMapper_Base { + typedef RealF scalar_type; + typedef RealF vector_type; + typedef RealD vector_typeD; + typedef RealF tensor_reduced ; + typedef RealF scalar_object; + typedef ComplexF Complexified; + typedef RealF Realified; + typedef RealD DoublePrecision; + }; + template<> struct GridTypeMapper : public GridTypeMapper_Base { + typedef RealD scalar_type; + typedef RealD vector_type; + typedef RealD vector_typeD; + typedef RealD tensor_reduced; + typedef RealD scalar_object; + typedef ComplexD Complexified; + typedef RealD Realified; + typedef RealD DoublePrecision; + }; + template<> struct GridTypeMapper : public GridTypeMapper_Base { + typedef ComplexF scalar_type; + typedef ComplexF vector_type; + typedef ComplexD vector_typeD; + typedef ComplexF tensor_reduced; + typedef ComplexF scalar_object; + typedef ComplexF Complexified; + typedef RealF Realified; + typedef ComplexD DoublePrecision; + }; + template<> struct GridTypeMapper : public GridTypeMapper_Base { + typedef ComplexD scalar_type; + typedef ComplexD vector_type; + typedef ComplexD vector_typeD; + typedef ComplexD tensor_reduced; + typedef ComplexD scalar_object; + typedef ComplexD Complexified; + typedef RealD Realified; + typedef ComplexD DoublePrecision; + }; + template<> struct GridTypeMapper : public GridTypeMapper_Base { + typedef Integer scalar_type; + typedef Integer vector_type; + typedef Integer vector_typeD; + typedef Integer tensor_reduced; + typedef Integer scalar_object; + typedef void Complexified; + typedef void Realified; + typedef void DoublePrecision; + }; -// Match the index -template struct matchGridTensorIndex { - static const bool value = (Level==T::TensorLevel); - static const bool notvalue = (Level!=T::TensorLevel); -}; -// What is the vtype -template struct isComplex { - static const bool value = false; -}; -template<> struct isComplex { - static const bool value = true; -}; -template<> struct isComplex { - static const bool value = true; -}; + template<> struct GridTypeMapper : public GridTypeMapper_Base { + typedef RealF scalar_type; + typedef vRealF vector_type; + typedef vRealD vector_typeD; + typedef vRealF tensor_reduced; + typedef RealF scalar_object; + typedef vComplexF Complexified; + typedef vRealF Realified; + typedef vRealD DoublePrecision; + }; + template<> struct GridTypeMapper : public GridTypeMapper_Base { + typedef RealD scalar_type; + typedef vRealD vector_type; + typedef vRealD vector_typeD; + typedef vRealD tensor_reduced; + typedef RealD scalar_object; + typedef vComplexD Complexified; + typedef vRealD Realified; + typedef vRealD DoublePrecision; + }; + template<> struct GridTypeMapper : public GridTypeMapper_Base { + // Fixme this is incomplete until Grid supports fp16 or bfp16 arithmetic types + typedef RealF scalar_type; + typedef vRealH vector_type; + typedef vRealD vector_typeD; + typedef vRealH tensor_reduced; + typedef RealF scalar_object; + typedef vComplexH Complexified; + typedef vRealH Realified; + typedef vRealD DoublePrecision; + }; + template<> struct GridTypeMapper : public GridTypeMapper_Base { + // Fixme this is incomplete until Grid supports fp16 or bfp16 arithmetic types + typedef ComplexF scalar_type; + typedef vComplexH vector_type; + typedef vComplexD vector_typeD; + typedef vComplexH tensor_reduced; + typedef ComplexF scalar_object; + typedef vComplexH Complexified; + typedef vRealH Realified; + typedef vComplexD DoublePrecision; + }; + template<> struct GridTypeMapper : public GridTypeMapper_Base { + typedef ComplexF scalar_type; + typedef vComplexF vector_type; + typedef vComplexD vector_typeD; + typedef vComplexF tensor_reduced; + typedef ComplexF scalar_object; + typedef vComplexF Complexified; + typedef vRealF Realified; + typedef vComplexD DoublePrecision; + }; + template<> struct GridTypeMapper : public GridTypeMapper_Base { + typedef ComplexD scalar_type; + typedef vComplexD vector_type; + typedef vComplexD vector_typeD; + typedef vComplexD tensor_reduced; + typedef ComplexD scalar_object; + typedef vComplexD Complexified; + typedef vRealD Realified; + typedef vComplexD DoublePrecision; + }; + template<> struct GridTypeMapper : public GridTypeMapper_Base { + typedef Integer scalar_type; + typedef vInteger vector_type; + typedef vInteger vector_typeD; + typedef vInteger tensor_reduced; + typedef Integer scalar_object; + typedef void Complexified; + typedef void Realified; + typedef void DoublePrecision; + }; -//Get the SIMD vector type from a Grid tensor or Lattice -template -struct getVectorType{ - typedef T type; -}; +#define GridTypeMapper_RepeatedTypes \ + using BaseTraits = GridTypeMapper; \ + using scalar_type = typename BaseTraits::scalar_type; \ + using vector_type = typename BaseTraits::vector_type; \ + using vector_typeD = typename BaseTraits::vector_typeD; \ + static constexpr int TensorLevel = BaseTraits::TensorLevel + 1 + + template struct GridTypeMapper> { + GridTypeMapper_RepeatedTypes; + using tensor_reduced = iScalar; + using scalar_object = iScalar; + using Complexified = iScalar; + using Realified = iScalar; + using DoublePrecision = iScalar; + static constexpr int Rank = BaseTraits::Rank + 1; + static constexpr std::size_t count = BaseTraits::count; + static constexpr int Dimension(int dim) { + return ( dim == 0 ) ? 1 : BaseTraits::Dimension(dim - 1); } + }; + + template struct GridTypeMapper> { + GridTypeMapper_RepeatedTypes; + using tensor_reduced = iScalar; + using scalar_object = iVector; + using Complexified = iVector; + using Realified = iVector; + using DoublePrecision = iVector; + static constexpr int Rank = BaseTraits::Rank + 1; + static constexpr std::size_t count = BaseTraits::count * N; + static constexpr int Dimension(int dim) { + return ( dim == 0 ) ? N : BaseTraits::Dimension(dim - 1); } + }; + + template struct GridTypeMapper> { + GridTypeMapper_RepeatedTypes; + using tensor_reduced = iScalar; + using scalar_object = iMatrix; + using Complexified = iMatrix; + using Realified = iMatrix; + using DoublePrecision = iMatrix; + static constexpr int Rank = BaseTraits::Rank + 2; + static constexpr std::size_t count = BaseTraits::count * N * N; + static constexpr int Dimension(int dim) { + return ( dim == 0 || dim == 1 ) ? N : BaseTraits::Dimension(dim - 2); } + }; + + // Match the index + template struct matchGridTensorIndex { + static const bool value = (Level==T::TensorLevel); + static const bool notvalue = (Level!=T::TensorLevel); + }; + // What is the vtype + template struct isComplex { + static const bool value = false; + }; + template<> struct isComplex { + static const bool value = true; + }; + template<> struct isComplex { + static const bool value = true; + }; + + //Get the SIMD vector type from a Grid tensor or Lattice + template + struct getVectorType{ + typedef T type; + }; -//Query if a tensor or Lattice is SIMD vector or scalar -template -class isSIMDvectorized{ - template - static typename std::enable_if< - !std::is_same< typename GridTypeMapper::type>::scalar_type, - typename GridTypeMapper::type>::vector_type>::value, - char>::type test(void *); + //Query whether a tensor or Lattice is SIMD vector or scalar + template struct isSIMDvectorized : public std::false_type {}; + template struct isSIMDvectorized::type>::scalar_type, + typename GridTypeMapper::type>::vector_type>::value, void>::type> + : public std::true_type {}; - template static double test(...); - -public: - enum {value = sizeof(test(0)) == sizeof(char) }; -}; - -//Get the precision of a Lattice, tensor or scalar type in units of sizeof(float) -template -class getPrecision{ -public: - //get the vector_obj (i.e. a grid Tensor) if its a Lattice, do nothing otherwise (i.e. if fundamental or grid Tensor) - typedef typename getVectorType::type vector_obj; - typedef typename GridTypeMapper::scalar_type scalar_type; //get the associated scalar type. Works on fundamental and tensor types - typedef typename GridTypeMapper::Realified real_scalar_type; //remove any std::complex wrapper, should get us to the fundamental type - - enum { value = sizeof(real_scalar_type)/sizeof(float) }; -}; - -NAMESPACE_END(Grid); + //Get the precision of a Lattice, tensor or scalar type in units of sizeof(float) + template + class getPrecision{ + public: + //get the vector_obj (i.e. a grid Tensor) if its a Lattice, do nothing otherwise (i.e. if fundamental or grid Tensor) + typedef typename getVectorType::type vector_obj; + typedef typename GridTypeMapper::scalar_type scalar_type; //get the associated scalar type. Works on fundamental and tensor types + typedef typename GridTypeMapper::Realified real_scalar_type; //remove any std::complex wrapper, should get us to the fundamental type + enum { value = sizeof(real_scalar_type)/sizeof(float) }; + }; +} #endif diff --git a/Grid/util/Init.cc b/Grid/util/Init.cc index b88eaba4..48250e6a 100644 --- a/Grid/util/Init.cc +++ b/Grid/util/Init.cc @@ -272,6 +272,11 @@ void GridBanner(void) std::cout << "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the"< +Author: Guido Cossu + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License along +with this program; if not, write to the Free Software Foundation, Inc., +51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +See the full license in the file "LICENSE" in the top level distribution +directory +*************************************************************************************/ +/* END LEGAL */ +#include + +int main(int argc, char **argv) { + using namespace Grid; + using namespace Grid::QCD; + + Grid_init(&argc, &argv); + int threads = GridThread::GetThreads(); + // 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; + + // Typedefs to simplify notation + typedef WilsonImplR FermionImplPolicy; + typedef MobiusFermionR FermionAction; + typedef typename FermionAction::FermionField FermionField; + + typedef Grid::XmlReader Serialiser; + + //:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: + IntegratorParameters MD; + // typedef GenericHMCRunner HMCWrapper; + // MD.name = std::string("Leap Frog"); + // typedef GenericHMCRunner HMCWrapper; + // MD.name = std::string("Force Gradient"); + typedef GenericHMCRunner HMCWrapper; + MD.name = std::string("MinimumNorm2"); + MD.MDsteps = 20; + MD.trajL = 1.0; + + HMCparameters HMCparams; + HMCparams.StartTrajectory = 0; + HMCparams.Trajectories = 200; + HMCparams.NoMetropolisUntil= 20; + // "[HotStart, ColdStart, TepidStart, CheckpointStart]\n"; + HMCparams.StartingType =std::string("ColdStart"); + HMCparams.MD = MD; + HMCWrapper TheHMC(HMCparams); + + // Grid from the command line arguments --grid and --mpi + TheHMC.Resources.AddFourDimGrid("gauge"); // use default simd lanes decomposition + + CheckpointerParameters CPparams; + CPparams.config_prefix = "ckpoint_EODWF_lat"; + CPparams.rng_prefix = "ckpoint_EODWF_rng"; + CPparams.saveInterval = 10; + CPparams.format = "IEEE64BIG"; + TheHMC.Resources.LoadNerscCheckpointer(CPparams); + + RNGModuleParameters RNGpar; + RNGpar.serial_seeds = "1 2 3 4 5"; + RNGpar.parallel_seeds = "6 7 8 9 10"; + TheHMC.Resources.SetRNGSeeds(RNGpar); + + // Construct observables + // here there is too much indirection + typedef PlaquetteMod PlaqObs; + TheHMC.Resources.AddObservable(); + ////////////////////////////////////////////// + + const int Ls = 16; + Real beta = 2.13; + Real light_mass = 0.01; + Real strange_mass = 0.04; + Real pv_mass = 1.0; + RealD M5 = 1.8; + RealD b = 1.0; // Scale factor two + RealD c = 0.0; + + OneFlavourRationalParams OFRp; + OFRp.lo = 1.0e-2; + OFRp.hi = 64; + OFRp.MaxIter = 10000; + OFRp.tolerance= 1.0e-10; + OFRp.degree = 14; + OFRp.precision= 40; + + std::vector hasenbusch({ 0.1 }); + + auto GridPtr = TheHMC.Resources.GetCartesian(); + auto GridRBPtr = TheHMC.Resources.GetRBCartesian(); + auto FGrid = SpaceTimeGrid::makeFiveDimGrid(Ls,GridPtr); + auto FrbGrid = SpaceTimeGrid::makeFiveDimRedBlackGrid(Ls,GridPtr); + + IwasakiGaugeActionR GaugeAction(beta); + + // temporarily need a gauge field + LatticeGaugeField U(GridPtr); + + // These lines are unecessary if BC are all periodic + std::vector boundary = {1,1,1,-1}; + FermionAction::ImplParams Params(boundary); + + double StoppingCondition = 1e-10; + double MaxCGIterations = 30000; + ConjugateGradient CG(StoppingCondition,MaxCGIterations); + + //////////////////////////////////// + // Collect actions + //////////////////////////////////// + ActionLevel Level1(1); + ActionLevel Level2(4); + + //////////////////////////////////// + // Strange action + //////////////////////////////////// + + // FermionAction StrangeOp(U,*FGrid,*FrbGrid,*GridPtr,*GridRBPtr,light_mass,M5,b,c, Params); + // DomainWallEOFAFermionR Strange_Op_L(Umu, *FGrid, *FrbGrid, *UGrid, *UrbGrid, mf, mf, mb, shift_L, pm, M5); + // DomainWallEOFAFermionR Strange_Op_R(Umu, *FGrid, *FrbGrid, *UGrid, *UrbGrid, mb, mf, mb, shift_R, pm, M5); + // ExactOneFlavourRatioPseudoFermionAction EOFA(Strange_Op_L,Strange_Op_R,CG,ofp, false); + + FermionAction StrangeOp (U,*FGrid,*FrbGrid,*GridPtr,*GridRBPtr,strange_mass,M5,b,c, Params); + FermionAction StrangePauliVillarsOp(U,*FGrid,*FrbGrid,*GridPtr,*GridRBPtr,pv_mass, M5,b,c, Params); + + // OneFlavourEvenOddRatioRationalPseudoFermionAction StrangePseudoFermion(StrangePauliVillarsOp,StrangeOp,OFRp); + OneFlavourRatioRationalPseudoFermionAction StrangePseudoFermion(StrangePauliVillarsOp,StrangeOp,OFRp); + // TwoFlavourRationalTesterPseudoFermionAction StrangePseudoFermion1F(StrangeOp,OFRp); + // TwoFlavourPseudoFermionAction StrangePseudoFermion2F(StrangeOp,CG,CG); + // Level1.push_back(&StrangePseudoFermion2F); + // Level1.push_back(&StrangePseudoFermion); + + //////////////////////////////////// + // up down action + //////////////////////////////////// + std::vector light_den; + std::vector light_num; + + int n_hasenbusch = hasenbusch.size(); + light_den.push_back(light_mass); + for(int h=0;h Numerators; + std::vector Denominators; + std::vector *> Quotients; + + for(int h=0;h(*Numerators[h],*Denominators[h],CG,CG)); + } + + for(int h=0;h +Author: Guido Cossu +Author: David Murphy + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License along +with this program; if not, write to the Free Software Foundation, Inc., +51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +See the full license in the file "LICENSE" in the top level distribution +directory +*************************************************************************************/ +/* END LEGAL */ +#include + +#define MIXED_PRECISION + +namespace Grid{ + namespace QCD{ + + /* + * Need a plan for gauge field update for mixed precision in HMC (2x speed up) + * -- Store the single prec action operator. + * -- Clone the gauge field from the operator function argument. + * -- Build the mixed precision operator dynamically from the passed operator and single prec clone. + */ + + template + class MixedPrecisionConjugateGradientOperatorFunction : public OperatorFunction { + public: + typedef typename FermionOperatorD::FermionField FieldD; + typedef typename FermionOperatorF::FermionField FieldF; + + RealD Tolerance; + RealD InnerTolerance; //Initial tolerance for inner CG. Defaults to Tolerance but can be changed + Integer MaxInnerIterations; + Integer MaxOuterIterations; + GridBase* SinglePrecGrid4; //Grid for single-precision fields + GridBase* SinglePrecGrid5; //Grid for single-precision fields + RealD OuterLoopNormMult; //Stop the outer loop and move to a final double prec solve when the residual is OuterLoopNormMult * Tolerance + + FermionOperatorF &FermOpF; + FermionOperatorD &FermOpD;; + SchurOperatorF &LinOpF; + SchurOperatorD &LinOpD; + + Integer TotalInnerIterations; //Number of inner CG iterations + Integer TotalOuterIterations; //Number of restarts + Integer TotalFinalStepIterations; //Number of CG iterations in final patch-up step + + MixedPrecisionConjugateGradientOperatorFunction(RealD tol, + Integer maxinnerit, + Integer maxouterit, + GridBase* _sp_grid4, + GridBase* _sp_grid5, + FermionOperatorF &_FermOpF, + FermionOperatorD &_FermOpD, + SchurOperatorF &_LinOpF, + SchurOperatorD &_LinOpD): + LinOpF(_LinOpF), + LinOpD(_LinOpD), + FermOpF(_FermOpF), + FermOpD(_FermOpD), + Tolerance(tol), + InnerTolerance(tol), + MaxInnerIterations(maxinnerit), + MaxOuterIterations(maxouterit), + SinglePrecGrid4(_sp_grid4), + SinglePrecGrid5(_sp_grid5), + OuterLoopNormMult(100.) + { + /* Debugging instances of objects; references are stored + std::cout << GridLogMessage << " Mixed precision CG wrapper LinOpF " < &LinOpU, const FieldD &src, FieldD &psi) { + + std::cout << GridLogMessage << " Mixed precision CG wrapper operator() "<(&LinOpU); + + // std::cout << GridLogMessage << " Mixed precision CG wrapper operator() FermOpU " <_Mat)<_Mat)==&(LinOpD._Mat)); + + //////////////////////////////////////////////////////////////////////////////////// + // Must snarf a single precision copy of the gauge field in Linop_d argument + //////////////////////////////////////////////////////////////////////////////////// + typedef typename FermionOperatorF::GaugeField GaugeFieldF; + typedef typename FermionOperatorF::GaugeLinkField GaugeLinkFieldF; + typedef typename FermionOperatorD::GaugeField GaugeFieldD; + typedef typename FermionOperatorD::GaugeLinkField GaugeLinkFieldD; + + GridBase * GridPtrF = SinglePrecGrid4; + GridBase * GridPtrD = FermOpD.Umu._grid; + GaugeFieldF U_f (GridPtrF); + GaugeLinkFieldF Umu_f(GridPtrF); + // std::cout << " Dim gauge field "<Nd()<Nd()<(FermOpD.Umu, mu); + precisionChange(Umu_f,Umu_d); + PokeIndex(FermOpF.Umu, Umu_f, mu); + } + pickCheckerboard(Even,FermOpF.UmuEven,FermOpF.Umu); + pickCheckerboard(Odd ,FermOpF.UmuOdd ,FermOpF.Umu); + + //////////////////////////////////////////////////////////////////////////////////// + // Could test to make sure that LinOpF and LinOpD agree to single prec? + //////////////////////////////////////////////////////////////////////////////////// + /* + GridBase *Fgrid = psi._grid; + FieldD tmp2(Fgrid); + FieldD tmp1(Fgrid); + LinOpU.Op(src,tmp1); + LinOpD.Op(src,tmp2); + std::cout << " Double gauge field "<< norm2(FermOpD.Umu)< MPCG(Tolerance,MaxInnerIterations,MaxOuterIterations,SinglePrecGrid5,LinOpF,LinOpD); + std::cout << GridLogMessage << "Calling mixed precision Conjugate Gradient" < HMCWrapper; + // MD.name = std::string("Leap Frog"); + typedef GenericHMCRunner HMCWrapper; + MD.name = std::string("Force Gradient"); + // typedef GenericHMCRunner HMCWrapper; + // MD.name = std::string("MinimumNorm2"); + MD.MDsteps = 6; + MD.trajL = 1.0; + + HMCparameters HMCparams; + HMCparams.StartTrajectory = 590; + HMCparams.Trajectories = 1000; + HMCparams.NoMetropolisUntil= 0; + // "[HotStart, ColdStart, TepidStart, CheckpointStart]\n"; + // HMCparams.StartingType =std::string("ColdStart"); + HMCparams.StartingType =std::string("CheckpointStart"); + HMCparams.MD = MD; + HMCWrapper TheHMC(HMCparams); + + // Grid from the command line arguments --grid and --mpi + TheHMC.Resources.AddFourDimGrid("gauge"); // use default simd lanes decomposition + + CheckpointerParameters CPparams; + CPparams.config_prefix = "ckpoint_EODWF_lat"; + CPparams.rng_prefix = "ckpoint_EODWF_rng"; + CPparams.saveInterval = 10; + CPparams.format = "IEEE64BIG"; + TheHMC.Resources.LoadNerscCheckpointer(CPparams); + + RNGModuleParameters RNGpar; + RNGpar.serial_seeds = "1 2 3 4 5"; + RNGpar.parallel_seeds = "6 7 8 9 10"; + TheHMC.Resources.SetRNGSeeds(RNGpar); + + // Construct observables + // here there is too much indirection + typedef PlaquetteMod PlaqObs; + TheHMC.Resources.AddObservable(); + ////////////////////////////////////////////// + + const int Ls = 16; + Real beta = 2.13; + Real light_mass = 0.01; + Real strange_mass = 0.04; + Real pv_mass = 1.0; + RealD M5 = 1.8; + RealD b = 1.0; + RealD c = 0.0; + + std::vector hasenbusch({ 0.1, 0.3, 0.6 }); + + auto GridPtr = TheHMC.Resources.GetCartesian(); + auto GridRBPtr = TheHMC.Resources.GetRBCartesian(); + auto FGrid = SpaceTimeGrid::makeFiveDimGrid(Ls,GridPtr); + auto FrbGrid = SpaceTimeGrid::makeFiveDimRedBlackGrid(Ls,GridPtr); + + std::vector latt = GridDefaultLatt(); + std::vector mpi = GridDefaultMpi(); + std::vector simdF = GridDefaultSimd(Nd,vComplexF::Nsimd()); + std::vector simdD = GridDefaultSimd(Nd,vComplexD::Nsimd()); + auto GridPtrF = SpaceTimeGrid::makeFourDimGrid(latt,simdF,mpi); + auto GridRBPtrF = SpaceTimeGrid::makeFourDimRedBlackGrid(GridPtrF); + auto FGridF = SpaceTimeGrid::makeFiveDimGrid(Ls,GridPtrF); + auto FrbGridF = SpaceTimeGrid::makeFiveDimRedBlackGrid(Ls,GridPtrF); + + IwasakiGaugeActionR GaugeAction(beta); + + // temporarily need a gauge field + LatticeGaugeField U(GridPtr); + LatticeGaugeFieldF UF(GridPtrF); + + // These lines are unecessary if BC are all periodic + std::vector boundary = {1,1,1,-1}; + FermionAction::ImplParams Params(boundary); + FermionActionF::ImplParams ParamsF(boundary); + + double ActionStoppingCondition = 1e-10; + double DerivativeStoppingCondition = 1e-6; + double MaxCGIterations = 30000; + + //////////////////////////////////// + // Collect actions + //////////////////////////////////// + ActionLevel Level1(1); + ActionLevel Level2(8); + + //////////////////////////////////// + // Strange action + //////////////////////////////////// + typedef SchurDiagMooeeOperator LinearOperatorF; + typedef SchurDiagMooeeOperator LinearOperatorD; + typedef SchurDiagMooeeOperator LinearOperatorEOFAF; + typedef SchurDiagMooeeOperator LinearOperatorEOFAD; + + typedef MixedPrecisionConjugateGradientOperatorFunction MxPCG; + typedef MixedPrecisionConjugateGradientOperatorFunction MxPCG_EOFA; + + // DJM: setup for EOFA ratio (Mobius) + OneFlavourRationalParams OFRp; + OFRp.lo = 0.1; + OFRp.hi = 25.0; + OFRp.MaxIter = 10000; + OFRp.tolerance= 1.0e-9; + OFRp.degree = 14; + OFRp.precision= 50; + + + MobiusEOFAFermionR Strange_Op_L (U , *FGrid , *FrbGrid , *GridPtr , *GridRBPtr , strange_mass, strange_mass, pv_mass, 0.0, -1, M5, b, c); + MobiusEOFAFermionF Strange_Op_LF(UF, *FGridF, *FrbGridF, *GridPtrF, *GridRBPtrF, strange_mass, strange_mass, pv_mass, 0.0, -1, M5, b, c); + MobiusEOFAFermionR Strange_Op_R (U , *FGrid , *FrbGrid , *GridPtr , *GridRBPtr , pv_mass, strange_mass, pv_mass, -1.0, 1, M5, b, c); + MobiusEOFAFermionF Strange_Op_RF(UF, *FGridF, *FrbGridF, *GridPtrF, *GridRBPtrF, pv_mass, strange_mass, pv_mass, -1.0, 1, M5, b, c); + + ConjugateGradient ActionCG(ActionStoppingCondition,MaxCGIterations); + ConjugateGradient DerivativeCG(DerivativeStoppingCondition,MaxCGIterations); +#ifdef MIXED_PRECISION + const int MX_inner = 1000; + // Mixed precision EOFA + LinearOperatorEOFAD Strange_LinOp_L (Strange_Op_L); + LinearOperatorEOFAD Strange_LinOp_R (Strange_Op_R); + LinearOperatorEOFAF Strange_LinOp_LF(Strange_Op_LF); + LinearOperatorEOFAF Strange_LinOp_RF(Strange_Op_RF); + + MxPCG_EOFA ActionCGL(ActionStoppingCondition, + MX_inner, + MaxCGIterations, + GridPtrF, + FrbGridF, + Strange_Op_LF,Strange_Op_L, + Strange_LinOp_LF,Strange_LinOp_L); + + MxPCG_EOFA DerivativeCGL(DerivativeStoppingCondition, + MX_inner, + MaxCGIterations, + GridPtrF, + FrbGridF, + Strange_Op_LF,Strange_Op_L, + Strange_LinOp_LF,Strange_LinOp_L); + + MxPCG_EOFA ActionCGR(ActionStoppingCondition, + MX_inner, + MaxCGIterations, + GridPtrF, + FrbGridF, + Strange_Op_RF,Strange_Op_R, + Strange_LinOp_RF,Strange_LinOp_R); + + MxPCG_EOFA DerivativeCGR(DerivativeStoppingCondition, + MX_inner, + MaxCGIterations, + GridPtrF, + FrbGridF, + Strange_Op_RF,Strange_Op_R, + Strange_LinOp_RF,Strange_LinOp_R); + + ExactOneFlavourRatioPseudoFermionAction + EOFA(Strange_Op_L, Strange_Op_R, + ActionCG, + ActionCGL, ActionCGR, + DerivativeCGL, DerivativeCGR, + OFRp, true); +#else + ExactOneFlavourRatioPseudoFermionAction + EOFA(Strange_Op_L, Strange_Op_R, + ActionCG, ActionCG, + DerivativeCG, DerivativeCG, + OFRp, true); +#endif + Level1.push_back(&EOFA); + + //////////////////////////////////// + // up down action + //////////////////////////////////// + std::vector light_den; + std::vector light_num; + + int n_hasenbusch = hasenbusch.size(); + light_den.push_back(light_mass); + for(int h=0;h Numerators; + std::vector Denominators; + std::vector *> Quotients; + std::vector ActionMPCG; + std::vector MPCG; + std::vector DenominatorsF; + std::vector LinOpD; + std::vector LinOpF; + + for(int h=0;h(*Numerators[h],*Denominators[h],*MPCG[h],*ActionMPCG[h],ActionCG)); +#else + //////////////////////////////////////////////////////////////////////////// + // Standard CG for 2f force + //////////////////////////////////////////////////////////////////////////// + Quotients.push_back (new TwoFlavourEvenOddRatioPseudoFermionAction(*Numerators[h],*Denominators[h],DerivativeCG,ActionCG)); +#endif + + } + + for(int h=0;h +Author: Guido Cossu + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License along +with this program; if not, write to the Free Software Foundation, Inc., +51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +See the full license in the file "LICENSE" in the top level distribution +directory +*************************************************************************************/ +/* END LEGAL */ +#include + +int main(int argc, char **argv) { + using namespace Grid; + using namespace Grid::QCD; + + Grid_init(&argc, &argv); + int threads = GridThread::GetThreads(); + // 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; + + // Typedefs to simplify notation + typedef WilsonImplR FermionImplPolicy; + typedef MobiusFermionR FermionAction; + typedef typename FermionAction::FermionField FermionField; + + typedef Grid::XmlReader Serialiser; + + //:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: + IntegratorParameters MD; + // typedef GenericHMCRunner HMCWrapper; + // MD.name = std::string("Leap Frog"); + // typedef GenericHMCRunner HMCWrapper; + // MD.name = std::string("Force Gradient"); + typedef GenericHMCRunner HMCWrapper; + MD.name = std::string("MinimumNorm2"); + MD.MDsteps = 20; + MD.trajL = 1.0; + + HMCparameters HMCparams; + HMCparams.StartTrajectory = 30; + HMCparams.Trajectories = 200; + HMCparams.NoMetropolisUntil= 0; + // "[HotStart, ColdStart, TepidStart, CheckpointStart]\n"; + // HMCparams.StartingType =std::string("ColdStart"); + HMCparams.StartingType =std::string("CheckpointStart"); + HMCparams.MD = MD; + HMCWrapper TheHMC(HMCparams); + + // Grid from the command line arguments --grid and --mpi + TheHMC.Resources.AddFourDimGrid("gauge"); // use default simd lanes decomposition + + CheckpointerParameters CPparams; + CPparams.config_prefix = "ckpoint_EODWF_lat"; + CPparams.rng_prefix = "ckpoint_EODWF_rng"; + CPparams.saveInterval = 10; + CPparams.format = "IEEE64BIG"; + TheHMC.Resources.LoadNerscCheckpointer(CPparams); + + RNGModuleParameters RNGpar; + RNGpar.serial_seeds = "1 2 3 4 5"; + RNGpar.parallel_seeds = "6 7 8 9 10"; + TheHMC.Resources.SetRNGSeeds(RNGpar); + + // Construct observables + // here there is too much indirection + typedef PlaquetteMod PlaqObs; + TheHMC.Resources.AddObservable(); + ////////////////////////////////////////////// + + const int Ls = 16; + Real beta = 2.13; + Real light_mass = 0.01; + Real strange_mass = 0.04; + Real pv_mass = 1.0; + RealD M5 = 1.8; + RealD b = 1.0; + RealD c = 0.0; + + // FIXME: + // Same in MC and MD + // Need to mix precision too + OneFlavourRationalParams OFRp; + OFRp.lo = 4.0e-3; + OFRp.hi = 30.0; + OFRp.MaxIter = 10000; + OFRp.tolerance= 1.0e-10; + OFRp.degree = 16; + OFRp.precision= 50; + + std::vector hasenbusch({ 0.1 }); + + auto GridPtr = TheHMC.Resources.GetCartesian(); + auto GridRBPtr = TheHMC.Resources.GetRBCartesian(); + auto FGrid = SpaceTimeGrid::makeFiveDimGrid(Ls,GridPtr); + auto FrbGrid = SpaceTimeGrid::makeFiveDimRedBlackGrid(Ls,GridPtr); + + IwasakiGaugeActionR GaugeAction(beta); + + // temporarily need a gauge field + LatticeGaugeField U(GridPtr); + + // These lines are unecessary if BC are all periodic + std::vector boundary = {1,1,1,-1}; + FermionAction::ImplParams Params(boundary); + + double StoppingCondition = 1e-10; + double MaxCGIterations = 30000; + ConjugateGradient CG(StoppingCondition,MaxCGIterations); + + //////////////////////////////////// + // Collect actions + //////////////////////////////////// + ActionLevel Level1(1); + ActionLevel Level2(4); + + //////////////////////////////////// + // Strange action + //////////////////////////////////// + + // FermionAction StrangeOp(U,*FGrid,*FrbGrid,*GridPtr,*GridRBPtr,light_mass,M5,b,c, Params); + // DomainWallEOFAFermionR Strange_Op_L(Umu, *FGrid, *FrbGrid, *UGrid, *UrbGrid, mf, mf, mb, shift_L, pm, M5); + // DomainWallEOFAFermionR Strange_Op_R(Umu, *FGrid, *FrbGrid, *UGrid, *UrbGrid, mb, mf, mb, shift_R, pm, M5); + // ExactOneFlavourRatioPseudoFermionAction EOFA(Strange_Op_L,Strange_Op_R,CG,ofp, false); + + FermionAction StrangeOp (U,*FGrid,*FrbGrid,*GridPtr,*GridRBPtr,strange_mass,M5,b,c, Params); + FermionAction StrangePauliVillarsOp(U,*FGrid,*FrbGrid,*GridPtr,*GridRBPtr,pv_mass, M5,b,c, Params); + + OneFlavourEvenOddRatioRationalPseudoFermionAction StrangePseudoFermion(StrangePauliVillarsOp,StrangeOp,OFRp); + Level1.push_back(&StrangePseudoFermion); + + //////////////////////////////////// + // up down action + //////////////////////////////////// + std::vector light_den; + std::vector light_num; + + int n_hasenbusch = hasenbusch.size(); + light_den.push_back(light_mass); + for(int h=0;h Numerators; + std::vector Denominators; + std::vector *> Quotients; + + for(int h=0;h(*Numerators[h],*Denominators[h],CG,CG)); + } + + for(int h=0;h 500s -> 160s and 20 traj per hour on 16^3. + +- Use mixed precision CG in HMC +- SchurRedBlack.h: stop use of operator function; use LinearOperator or similar instead. +- Or make an OperatorFunction for mixed precision as a wrapper + +******************************************************************** +* Signed off 2+1f HMC with Hasenbush and strange RHMC 16^3 x 32 DWF Ls=16 Plaquette 0.5883 ish +* Signed off 2+1f HMC with Hasenbush and strange EOFA 16^3 x 32 DWF Ls=16 Plaquette 0.5883 ish +* Wilson plaquette cross checked against CPS and literature GwilsonFnone +******************************************************************** + +******************************************************************** +* RHMC: Timesteps & eigenranges matched from previous CPS 16^3 x 32 runs: +******************************************************************** + +**** +Strange (m=0.04) has eigenspan +**** +16^3 done as 1+1+1 with separate PV's. +/dirac1/archive/QCDOC/host/QCDDWF/DWF/2+1f/16nt32/IWASAKI/b2.13/ls16/M1_8/ms0.04/mu0.01/rhmc_multitimescale/evol5/work +**** +2+1f 16^3 - [ 4e^-4, 2.42 ] for strange + +**** +24^3 done as 1+1+1 at strange, and single quotient https://arxiv.org/pdf/0804.0473.pdf Eq 83, +**** +double lambda_low = 4.0000000000000002e-04 <- strange +double lambda_low = 1.0000000000000000e-02 <- pauli villars +And high = 2.5 + +Array bsn_mass[3] = { +double bsn_mass[0] = 1.0000000000000000e+00 +double bsn_mass[1] = 1.0000000000000000e+00 +double bsn_mass[2] = 1.0000000000000000e+00 +} +Array frm_mass[3] = { +double frm_mass[0] = 4.0000000000000001e-02 +double frm_mass[1] = 4.0000000000000001e-02 +double frm_mass[2] = 4.0000000000000001e-02 +} + +*** +32^3 +/dirac1/archive/QCDOC/host/QCDDWF/DWF/2+1f/32nt64/IWASAKI/b2.25/ls16/M1_8/ms0.03/mu0.004/evol6/work +*** +Similar det scheme +double lambda_low = 4.0000000000000002e-04 +double lambda_low = 1.0000000000000000e-02 + +Array bsn_mass[3] = { +double bsn_mass[0] = 1.0000000000000000e+00 +double bsn_mass[1] = 1.0000000000000000e+00 +double bsn_mass[2] = 1.0000000000000000e+00 +} +Array frm_mass[3] = { +double frm_mass[0] = 3.0000000000000002e-02 +double frm_mass[1] = 3.0000000000000002e-02 +double frm_mass[2] = 3.0000000000000002e-02 +} + +******************************************************************** +* Grid: Power method bounds check +******************************************************************** +- Finding largest eigenvalue approx 25 not 2.5 +- Conventions: + +Grid MpcDagMpc based on: + + (Moo-Moe Mee^-1 Meo)^dag(Moo-Moe Mee^-1 Meo) + +- with Moo = 5-M5 = 3.2 +- CPS use(d) Moo = 1 +- Eigenrange in Grid is 3.2^2 rescaled so factor of 10 accounted for + diff --git a/Hadrons/A2AMatrix.hpp b/Hadrons/A2AMatrix.hpp index 138b8eb5..744077e3 100644 --- a/Hadrons/A2AMatrix.hpp +++ b/Hadrons/A2AMatrix.hpp @@ -4,7 +4,7 @@ Grid physics library, www.github.com/paboyle/Grid Source file: Hadrons/A2AMatrix.hpp -Copyright (C) 2015-2018 +Copyright (C) 2015-2019 Author: Antonin Portelli Author: Peter Boyle diff --git a/Hadrons/A2AVectors.hpp b/Hadrons/A2AVectors.hpp index 99082fb5..7cbd19ef 100644 --- a/Hadrons/A2AVectors.hpp +++ b/Hadrons/A2AVectors.hpp @@ -4,7 +4,7 @@ Grid physics library, www.github.com/paboyle/Grid Source file: Hadrons/A2AVectors.hpp -Copyright (C) 2015-2018 +Copyright (C) 2015-2019 Author: Antonin Portelli Author: fionnoh diff --git a/Hadrons/Application.cc b/Hadrons/Application.cc index 7c370b7c..e4264f84 100644 --- a/Hadrons/Application.cc +++ b/Hadrons/Application.cc @@ -4,7 +4,7 @@ Grid physics library, www.github.com/paboyle/Grid Source file: Hadrons/Application.cc -Copyright (C) 2015-2018 +Copyright (C) 2015-2019 Author: Antonin Portelli @@ -31,7 +31,7 @@ See the full license in the file "LICENSE" in the top level distribution directo #include using namespace Grid; - +using namespace QCD; using namespace Hadrons; #define BIG_SEP "================" @@ -48,28 +48,32 @@ Application::Application(void) { initLogger(); auto dim = GridDefaultLatt(), mpi = GridDefaultMpi(), loc(dim); - locVol_ = 1; - for (unsigned int d = 0; d < dim.size(); ++d) + + if (dim.size()) { - loc[d] /= mpi[d]; - locVol_ *= loc[d]; + locVol_ = 1; + for (unsigned int d = 0; d < dim.size(); ++d) + { + loc[d] /= mpi[d]; + locVol_ *= loc[d]; + } + LOG(Message) << "====== HADRONS APPLICATION INITIALISATION ======" << std::endl; + LOG(Message) << "** Dimensions" << std::endl; + LOG(Message) << "Global lattice: " << dim << std::endl; + LOG(Message) << "MPI partition : " << mpi << std::endl; + LOG(Message) << "Local lattice : " << loc << std::endl; + LOG(Message) << std::endl; + LOG(Message) << "** Default parameters (and associated C macros)" << std::endl; + LOG(Message) << "ASCII output precision : " << MACOUT(DEFAULT_ASCII_PREC) << std::endl; + LOG(Message) << "Fermion implementation : " << MACOUTS(FIMPLBASE) << std::endl; + LOG(Message) << "z-Fermion implementation: " << MACOUTS(ZFIMPLBASE) << std::endl; + LOG(Message) << "Scalar implementation : " << MACOUTS(SIMPLBASE) << std::endl; + LOG(Message) << "Gauge implementation : " << MACOUTS(GIMPLBASE) << std::endl; + LOG(Message) << "Eigenvector base size : " + << MACOUT(HADRONS_DEFAULT_LANCZOS_NBASIS) << std::endl; + LOG(Message) << "Schur decomposition : " << MACOUTS(HADRONS_DEFAULT_SCHUR) << std::endl; + LOG(Message) << std::endl; } - LOG(Message) << "====== HADRONS APPLICATION INITIALISATION ======" << std::endl; - LOG(Message) << "** Dimensions" << std::endl; - LOG(Message) << "Global lattice: " << dim << std::endl; - LOG(Message) << "MPI partition : " << mpi << std::endl; - LOG(Message) << "Local lattice : " << loc << std::endl; - LOG(Message) << std::endl; - LOG(Message) << "** Default parameters (and associated C macros)" << std::endl; - LOG(Message) << "ASCII output precision : " << MACOUT(DEFAULT_ASCII_PREC) << std::endl; - LOG(Message) << "Fermion implementation : " << MACOUTS(FIMPLBASE) << std::endl; - LOG(Message) << "z-Fermion implementation: " << MACOUTS(ZFIMPLBASE) << std::endl; - LOG(Message) << "Scalar implementation : " << MACOUTS(SIMPLBASE) << std::endl; - LOG(Message) << "Gauge implementation : " << MACOUTS(GIMPLBASE) << std::endl; - LOG(Message) << "Eigenvector base size : " - << MACOUT(HADRONS_DEFAULT_LANCZOS_NBASIS) << std::endl; - LOG(Message) << "Schur decomposition : " << MACOUTS(HADRONS_DEFAULT_SCHUR) << std::endl; - LOG(Message) << std::endl; } Application::Application(const Application::GlobalPar &par) @@ -114,7 +118,22 @@ void Application::run(void) vm().setRunId(getPar().runId); vm().printContent(); env().printContent(); - schedule(); + if (getPar().saveSchedule or getPar().scheduleFile.empty()) + { + schedule(); + if (getPar().saveSchedule) + { + std::string filename; + + filename = (getPar().scheduleFile.empty()) ? + "hadrons.sched" : getPar().scheduleFile; + saveSchedule(filename); + } + } + else + { + loadSchedule(getPar().scheduleFile); + } printSchedule(); if (!getPar().graphFile.empty()) { @@ -161,29 +180,30 @@ void Application::parseParameterFile(const std::string parameterFileName) pop(reader); } -void Application::saveParameterFile(const std::string parameterFileName) +void Application::saveParameterFile(const std::string parameterFileName, unsigned int prec) { LOG(Message) << "Saving application to '" << parameterFileName << "'..." << std::endl; if (env().getGrid()->IsBoss()) { - XmlWriter writer(parameterFileName); - ObjectId id; - const unsigned int nMod = vm().getNModule(); - - write(writer, "parameters", getPar()); - push(writer, "modules"); - for (unsigned int i = 0; i < nMod; ++i) - { - push(writer, "module"); - id.name = vm().getModuleName(i); - id.type = vm().getModule(i)->getRegisteredName(); - write(writer, "id", id); - vm().getModule(i)->saveParameters(writer, "options"); + XmlWriter writer(parameterFileName); + writer.setPrecision(prec); + ObjectId id; + const unsigned int nMod = vm().getNModule(); + + write(writer, "parameters", getPar()); + push(writer, "modules"); + for (unsigned int i = 0; i < nMod; ++i) + { + push(writer, "module"); + id.name = vm().getModuleName(i); + id.type = vm().getModule(i)->getRegisteredName(); + write(writer, "id", id); + vm().getModule(i)->saveParameters(writer, "options"); + pop(writer); + } + pop(writer); pop(writer); } - pop(writer); - pop(writer); -} } // schedule computation //////////////////////////////////////////////////////// @@ -202,20 +222,20 @@ void Application::saveSchedule(const std::string filename) << std::endl; if (env().getGrid()->IsBoss()) { - TextWriter writer(filename); - std::vector program; - - if (!scheduled_) - { + TextWriter writer(filename); + std::vector program; + + if (!scheduled_) + { HADRONS_ERROR(Definition, "Computation not scheduled"); - } + } - for (auto address: program_) - { - program.push_back(vm().getModuleName(address)); + for (auto address: program_) + { + program.push_back(vm().getModuleName(address)); + } + write(writer, "schedule", program); } - write(writer, "schedule", program); -} } void Application::loadSchedule(const std::string filename) diff --git a/Hadrons/Application.hpp b/Hadrons/Application.hpp index 3578c919..36179c5f 100644 --- a/Hadrons/Application.hpp +++ b/Hadrons/Application.hpp @@ -4,7 +4,7 @@ Grid physics library, www.github.com/paboyle/Grid Source file: Hadrons/Application.hpp -Copyright (C) 2015-2018 +Copyright (C) 2015-2019 Author: Antonin Portelli @@ -57,6 +57,8 @@ public: VirtualMachine::GeneticPar, genetic, std::string, runId, std::string, graphFile, + std::string, scheduleFile, + bool, saveSchedule, int, parallelWriteMaxRetry); GlobalPar(void): parallelWriteMaxRetry{-1} {} }; @@ -79,7 +81,7 @@ public: void run(void); // XML parameter file I/O void parseParameterFile(const std::string parameterFileName); - void saveParameterFile(const std::string parameterFileName); + void saveParameterFile(const std::string parameterFileName, unsigned int prec=15); // schedule computation void schedule(void); void saveSchedule(const std::string filename); diff --git a/Hadrons/Modules/MScalar/ScalarVP.cc b/Hadrons/Archive/Modules/ScalarVP.cc similarity index 99% rename from Hadrons/Modules/MScalar/ScalarVP.cc rename to Hadrons/Archive/Modules/ScalarVP.cc index 9b56d22b..f4f7e59b 100644 --- a/Hadrons/Modules/MScalar/ScalarVP.cc +++ b/Hadrons/Archive/Modules/ScalarVP.cc @@ -2,9 +2,9 @@ Grid physics library, www.github.com/paboyle/Grid -Source file: Hadrons/Modules/MScalar/ScalarVP.cc +Source file: Hadrons/Archive/Modules/ScalarVP.cc -Copyright (C) 2015-2018 +Copyright (C) 2015-2019 Author: Antonin Portelli Author: James Harrison diff --git a/Hadrons/Modules/MScalar/ScalarVP.hpp b/Hadrons/Archive/Modules/ScalarVP.hpp similarity index 98% rename from Hadrons/Modules/MScalar/ScalarVP.hpp rename to Hadrons/Archive/Modules/ScalarVP.hpp index 3cd01249..310299a1 100644 --- a/Hadrons/Modules/MScalar/ScalarVP.hpp +++ b/Hadrons/Archive/Modules/ScalarVP.hpp @@ -2,9 +2,9 @@ Grid physics library, www.github.com/paboyle/Grid -Source file: Hadrons/Modules/MScalar/ScalarVP.hpp +Source file: Hadrons/Archive/Modules/ScalarVP.hpp -Copyright (C) 2015-2018 +Copyright (C) 2015-2019 Author: Antonin Portelli Author: James Harrison diff --git a/Hadrons/Modules/MUtilities/TestSeqConserved.cc b/Hadrons/Archive/Modules/TestSeqConserved.cc similarity index 93% rename from Hadrons/Modules/MUtilities/TestSeqConserved.cc rename to Hadrons/Archive/Modules/TestSeqConserved.cc index e15eea2a..46227b99 100644 --- a/Hadrons/Modules/MUtilities/TestSeqConserved.cc +++ b/Hadrons/Archive/Modules/TestSeqConserved.cc @@ -2,9 +2,9 @@ Grid physics library, www.github.com/paboyle/Grid -Source file: Hadrons/Modules/MUtilities/TestSeqConserved.cc +Source file: Hadrons/Archive/Modules/TestSeqConserved.cc -Copyright (C) 2015-2018 +Copyright (C) 2015-2019 Author: Antonin Portelli diff --git a/Hadrons/Modules/MUtilities/TestSeqConserved.hpp b/Hadrons/Archive/Modules/TestSeqConserved.hpp similarity index 98% rename from Hadrons/Modules/MUtilities/TestSeqConserved.hpp rename to Hadrons/Archive/Modules/TestSeqConserved.hpp index c1c84105..fde8cfcd 100644 --- a/Hadrons/Modules/MUtilities/TestSeqConserved.hpp +++ b/Hadrons/Archive/Modules/TestSeqConserved.hpp @@ -2,9 +2,9 @@ Grid physics library, www.github.com/paboyle/Grid -Source file: Hadrons/Modules/MUtilities/TestSeqConserved.hpp +Source file: Hadrons/Archive/Modules/TestSeqConserved.hpp -Copyright (C) 2015-2018 +Copyright (C) 2015-2019 Author: Antonin Portelli Author: Lanny91 diff --git a/Hadrons/Modules/MUtilities/TestSeqGamma.cc b/Hadrons/Archive/Modules/TestSeqGamma.cc similarity index 94% rename from Hadrons/Modules/MUtilities/TestSeqGamma.cc rename to Hadrons/Archive/Modules/TestSeqGamma.cc index db9c824d..e52d0ade 100644 --- a/Hadrons/Modules/MUtilities/TestSeqGamma.cc +++ b/Hadrons/Archive/Modules/TestSeqGamma.cc @@ -2,9 +2,9 @@ Grid physics library, www.github.com/paboyle/Grid -Source file: Hadrons/Modules/MUtilities/TestSeqGamma.cc +Source file: Hadrons/Archive/Modules/TestSeqGamma.cc -Copyright (C) 2015-2018 +Copyright (C) 2015-2019 Author: Antonin Portelli diff --git a/Hadrons/Modules/MUtilities/TestSeqGamma.hpp b/Hadrons/Archive/Modules/TestSeqGamma.hpp similarity index 98% rename from Hadrons/Modules/MUtilities/TestSeqGamma.hpp rename to Hadrons/Archive/Modules/TestSeqGamma.hpp index 728dda05..3e1cdb6c 100644 --- a/Hadrons/Modules/MUtilities/TestSeqGamma.hpp +++ b/Hadrons/Archive/Modules/TestSeqGamma.hpp @@ -2,9 +2,9 @@ Grid physics library, www.github.com/paboyle/Grid -Source file: Hadrons/Modules/MUtilities/TestSeqGamma.hpp +Source file: Hadrons/Archive/Modules/TestSeqGamma.hpp -Copyright (C) 2015-2018 +Copyright (C) 2015-2019 Author: Antonin Portelli Author: Lanny91 diff --git a/Hadrons/Modules/MScalar/VPCounterTerms.cc b/Hadrons/Archive/Modules/VPCounterTerms.cc similarity index 99% rename from Hadrons/Modules/MScalar/VPCounterTerms.cc rename to Hadrons/Archive/Modules/VPCounterTerms.cc index 45956932..c324ed5e 100644 --- a/Hadrons/Modules/MScalar/VPCounterTerms.cc +++ b/Hadrons/Archive/Modules/VPCounterTerms.cc @@ -2,9 +2,9 @@ Grid physics library, www.github.com/paboyle/Grid -Source file: Hadrons/Modules/MScalar/VPCounterTerms.cc +Source file: Hadrons/Archive/Modules/VPCounterTerms.cc -Copyright (C) 2015-2018 +Copyright (C) 2015-2019 Author: Antonin Portelli Author: James Harrison diff --git a/Hadrons/Modules/MScalar/VPCounterTerms.hpp b/Hadrons/Archive/Modules/VPCounterTerms.hpp similarity index 97% rename from Hadrons/Modules/MScalar/VPCounterTerms.hpp rename to Hadrons/Archive/Modules/VPCounterTerms.hpp index 8bbc3e20..d8e6cc9a 100644 --- a/Hadrons/Modules/MScalar/VPCounterTerms.hpp +++ b/Hadrons/Archive/Modules/VPCounterTerms.hpp @@ -2,9 +2,9 @@ Grid physics library, www.github.com/paboyle/Grid -Source file: Hadrons/Modules/MScalar/VPCounterTerms.hpp +Source file: Hadrons/Archive/Modules/VPCounterTerms.hpp -Copyright (C) 2015-2018 +Copyright (C) 2015-2019 Author: Antonin Portelli Author: James Harrison diff --git a/Hadrons/Modules/MContraction/WardIdentity.cc b/Hadrons/Archive/Modules/WardIdentity.cc similarity index 93% rename from Hadrons/Modules/MContraction/WardIdentity.cc rename to Hadrons/Archive/Modules/WardIdentity.cc index 98c06d12..07e5b222 100644 --- a/Hadrons/Modules/MContraction/WardIdentity.cc +++ b/Hadrons/Archive/Modules/WardIdentity.cc @@ -2,9 +2,9 @@ Grid physics library, www.github.com/paboyle/Grid -Source file: Hadrons/Modules/MContraction/WardIdentity.cc +Source file: Hadrons/Archive/Modules/WardIdentity.cc -Copyright (C) 2015-2018 +Copyright (C) 2015-2019 Author: Antonin Portelli diff --git a/Hadrons/Modules/MContraction/WardIdentity.hpp b/Hadrons/Archive/Modules/WardIdentity.hpp similarity index 98% rename from Hadrons/Modules/MContraction/WardIdentity.hpp rename to Hadrons/Archive/Modules/WardIdentity.hpp index 8f27900e..e7732fc0 100644 --- a/Hadrons/Modules/MContraction/WardIdentity.hpp +++ b/Hadrons/Archive/Modules/WardIdentity.hpp @@ -2,9 +2,9 @@ Grid physics library, www.github.com/paboyle/Grid -Source file: Hadrons/Modules/MContraction/WardIdentity.hpp +Source file: Hadrons/Archive/Modules/WardIdentity.hpp -Copyright (C) 2015-2018 +Copyright (C) 2015-2019 Author: Antonin Portelli Author: Lanny91 diff --git a/Hadrons/Modules/MContraction/WeakHamiltonian.hpp b/Hadrons/Archive/Modules/WeakHamiltonian.hpp similarity index 97% rename from Hadrons/Modules/MContraction/WeakHamiltonian.hpp rename to Hadrons/Archive/Modules/WeakHamiltonian.hpp index 824dc780..d047a5fb 100644 --- a/Hadrons/Modules/MContraction/WeakHamiltonian.hpp +++ b/Hadrons/Archive/Modules/WeakHamiltonian.hpp @@ -2,9 +2,9 @@ Grid physics library, www.github.com/paboyle/Grid -Source file: Hadrons/Modules/MContraction/WeakHamiltonian.hpp +Source file: Hadrons/Archive/Modules/WeakHamiltonian.hpp -Copyright (C) 2015-2018 +Copyright (C) 2015-2019 Author: Antonin Portelli Author: Lanny91 diff --git a/Hadrons/Modules/MContraction/WeakHamiltonianEye.cc b/Hadrons/Archive/Modules/WeakHamiltonianEye.cc similarity index 98% rename from Hadrons/Modules/MContraction/WeakHamiltonianEye.cc rename to Hadrons/Archive/Modules/WeakHamiltonianEye.cc index 2183d992..df4d494c 100644 --- a/Hadrons/Modules/MContraction/WeakHamiltonianEye.cc +++ b/Hadrons/Archive/Modules/WeakHamiltonianEye.cc @@ -2,9 +2,9 @@ Grid physics library, www.github.com/paboyle/Grid -Source file: Hadrons/Modules/MContraction/WeakHamiltonianEye.cc +Source file: Hadrons/Archive/Modules/WeakHamiltonianEye.cc -Copyright (C) 2015-2018 +Copyright (C) 2015-2019 Author: Antonin Portelli Author: Lanny91 diff --git a/Hadrons/Modules/MContraction/WeakHamiltonianEye.hpp b/Hadrons/Archive/Modules/WeakHamiltonianEye.hpp similarity index 95% rename from Hadrons/Modules/MContraction/WeakHamiltonianEye.hpp rename to Hadrons/Archive/Modules/WeakHamiltonianEye.hpp index 37d37022..9d8db9a6 100644 --- a/Hadrons/Modules/MContraction/WeakHamiltonianEye.hpp +++ b/Hadrons/Archive/Modules/WeakHamiltonianEye.hpp @@ -2,9 +2,9 @@ Grid physics library, www.github.com/paboyle/Grid -Source file: Hadrons/Modules/MContraction/WeakHamiltonianEye.hpp +Source file: Hadrons/Archive/Modules/WeakHamiltonianEye.hpp -Copyright (C) 2015-2018 +Copyright (C) 2015-2019 Author: Antonin Portelli Author: Lanny91 diff --git a/Hadrons/Modules/MContraction/WeakHamiltonianNonEye.cc b/Hadrons/Archive/Modules/WeakHamiltonianNonEye.cc similarity index 98% rename from Hadrons/Modules/MContraction/WeakHamiltonianNonEye.cc rename to Hadrons/Archive/Modules/WeakHamiltonianNonEye.cc index 5c1d8a1c..3b5ab2e9 100644 --- a/Hadrons/Modules/MContraction/WeakHamiltonianNonEye.cc +++ b/Hadrons/Archive/Modules/WeakHamiltonianNonEye.cc @@ -2,9 +2,9 @@ Grid physics library, www.github.com/paboyle/Grid -Source file: Hadrons/Modules/MContraction/WeakHamiltonianNonEye.cc +Source file: Hadrons/Archive/Modules/WeakHamiltonianNonEye.cc -Copyright (C) 2015-2018 +Copyright (C) 2015-2019 Author: Antonin Portelli Author: Lanny91 diff --git a/Hadrons/Modules/MContraction/WeakHamiltonianNonEye.hpp b/Hadrons/Archive/Modules/WeakHamiltonianNonEye.hpp similarity index 95% rename from Hadrons/Modules/MContraction/WeakHamiltonianNonEye.hpp rename to Hadrons/Archive/Modules/WeakHamiltonianNonEye.hpp index 19c0ebaa..ce74642e 100644 --- a/Hadrons/Modules/MContraction/WeakHamiltonianNonEye.hpp +++ b/Hadrons/Archive/Modules/WeakHamiltonianNonEye.hpp @@ -2,9 +2,9 @@ Grid physics library, www.github.com/paboyle/Grid -Source file: Hadrons/Modules/MContraction/WeakHamiltonianNonEye.hpp +Source file: Hadrons/Archive/Modules/WeakHamiltonianNonEye.hpp -Copyright (C) 2015-2018 +Copyright (C) 2015-2019 Author: Antonin Portelli Author: Lanny91 diff --git a/Hadrons/Modules/MContraction/WeakNeutral4ptDisc.cc b/Hadrons/Archive/Modules/WeakNeutral4ptDisc.cc similarity index 98% rename from Hadrons/Modules/MContraction/WeakNeutral4ptDisc.cc rename to Hadrons/Archive/Modules/WeakNeutral4ptDisc.cc index 2273dd3d..52fce3f6 100644 --- a/Hadrons/Modules/MContraction/WeakNeutral4ptDisc.cc +++ b/Hadrons/Archive/Modules/WeakNeutral4ptDisc.cc @@ -2,9 +2,9 @@ Grid physics library, www.github.com/paboyle/Grid -Source file: Hadrons/Modules/MContraction/WeakNeutral4ptDisc.cc +Source file: Hadrons/Archive/Modules/WeakNeutral4ptDisc.cc -Copyright (C) 2015-2018 +Copyright (C) 2015-2019 Author: Antonin Portelli Author: Lanny91 diff --git a/Hadrons/Modules/MContraction/WeakNeutral4ptDisc.hpp b/Hadrons/Archive/Modules/WeakNeutral4ptDisc.hpp similarity index 95% rename from Hadrons/Modules/MContraction/WeakNeutral4ptDisc.hpp rename to Hadrons/Archive/Modules/WeakNeutral4ptDisc.hpp index 3e20633f..7a1d1451 100644 --- a/Hadrons/Modules/MContraction/WeakNeutral4ptDisc.hpp +++ b/Hadrons/Archive/Modules/WeakNeutral4ptDisc.hpp @@ -2,9 +2,9 @@ Grid physics library, www.github.com/paboyle/Grid -Source file: Hadrons/Modules/MContraction/WeakNeutral4ptDisc.hpp +Source file: Hadrons/Archive/Modules/WeakNeutral4ptDisc.hpp -Copyright (C) 2015-2018 +Copyright (C) 2015-2019 Author: Antonin Portelli Author: Lanny91 diff --git a/Hadrons/DilutedNoise.hpp b/Hadrons/DilutedNoise.hpp index 3867d763..cd0c3c60 100644 --- a/Hadrons/DilutedNoise.hpp +++ b/Hadrons/DilutedNoise.hpp @@ -4,10 +4,11 @@ Grid physics library, www.github.com/paboyle/Grid Source file: Hadrons/DilutedNoise.hpp -Copyright (C) 2015-2018 +Copyright (C) 2015-2019 Author: Antonin Portelli Author: Vera Guelpers +Author: Vera Guelpers This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by diff --git a/Hadrons/DiskVector.hpp b/Hadrons/DiskVector.hpp index 70a00b16..3a8d0696 100644 --- a/Hadrons/DiskVector.hpp +++ b/Hadrons/DiskVector.hpp @@ -4,7 +4,7 @@ Grid physics library, www.github.com/paboyle/Grid Source file: Hadrons/DiskVector.hpp -Copyright (C) 2015-2018 +Copyright (C) 2015-2019 Author: Antonin Portelli @@ -395,12 +395,26 @@ void DiskVectorBase::cacheInsert(const unsigned int i, const T &obj) const auto &freeInd = *freePtr_; auto &loads = *loadsPtr_; - evict(); - index[i] = freeInd.top(); - freeInd.pop(); - cache[index.at(i)] = obj; - loads.push_back(i); - modified[index.at(i)] = false; + // cache miss, evict and store + if (index.find(i) == index.end()) + { + evict(); + index[i] = freeInd.top(); + freeInd.pop(); + cache[index.at(i)] = obj; + loads.push_back(i); + modified[index.at(i)] = false; + } + // cache hit, modify current value + else + { + auto pos = std::find(loads.begin(), loads.end(), i); + + cache[index.at(i)] = obj; + modified[index.at(i)] = true; + loads.erase(pos); + loads.push_back(i); + } #ifdef DV_DEBUG std::string msg; diff --git a/Hadrons/EigenPack.hpp b/Hadrons/EigenPack.hpp index 0ce44e37..2e7c62c9 100644 --- a/Hadrons/EigenPack.hpp +++ b/Hadrons/EigenPack.hpp @@ -4,7 +4,7 @@ Grid physics library, www.github.com/paboyle/Grid Source file: Hadrons/EigenPack.hpp -Copyright (C) 2015-2018 +Copyright (C) 2015-2019 Author: Antonin Portelli @@ -308,7 +308,9 @@ template { public: - typedef CoarseF CoarseField; + typedef CoarseF CoarseField; + typedef CoarseFIo CoarseFieldIo; +public: std::vector evecCoarse; std::vector evalCoarse; public: diff --git a/Hadrons/Environment.cc b/Hadrons/Environment.cc index 507a306f..2287a7fd 100644 --- a/Hadrons/Environment.cc +++ b/Hadrons/Environment.cc @@ -4,7 +4,7 @@ Grid physics library, www.github.com/paboyle/Grid Source file: Hadrons/Environment.cc -Copyright (C) 2015-2018 +Copyright (C) 2015-2019 Author: Antonin Portelli @@ -45,13 +45,11 @@ Environment::Environment(void) { dim_ = GridDefaultLatt().toVector(); nd_ = dim_.size(); - createGrid(1); vol_ = 1.; for (auto d: dim_) { vol_ *= d; } - rng4d_.reset(new GridParallelRNG(getGrid())); } // grids /////////////////////////////////////////////////////////////////////// @@ -76,8 +74,13 @@ double Environment::getVolume(void) const } // random number generator ///////////////////////////////////////////////////// -GridParallelRNG * Environment::get4dRng(void) const +GridParallelRNG * Environment::get4dRng(void) { + if (rng4d_ == nullptr) + { + rng4d_.reset(new GridParallelRNG(getGrid())); + } + return rng4d_.get(); } diff --git a/Hadrons/Environment.hpp b/Hadrons/Environment.hpp index 9841d665..24f6b31e 100644 --- a/Hadrons/Environment.hpp +++ b/Hadrons/Environment.hpp @@ -4,7 +4,7 @@ Grid physics library, www.github.com/paboyle/Grid Source file: Hadrons/Environment.hpp -Copyright (C) 2015-2018 +Copyright (C) 2015-2019 Author: Antonin Portelli @@ -113,7 +113,7 @@ public: unsigned int getNd(void) const; double getVolume(void) const; // random number generator - GridParallelRNG * get4dRng(void) const; + GridParallelRNG * get4dRng(void); // general memory management void addObject(const std::string name, const int moduleAddress = -1); @@ -182,7 +182,7 @@ private: std::map gridCoarse5d_; unsigned int nd_; // random number generator - RngPt rng4d_; + RngPt rng4d_{nullptr}; // object store std::vector object_; std::map objectAddress_; diff --git a/Hadrons/Exceptions.cc b/Hadrons/Exceptions.cc index c9800610..bb489cdf 100644 --- a/Hadrons/Exceptions.cc +++ b/Hadrons/Exceptions.cc @@ -4,7 +4,7 @@ Grid physics library, www.github.com/paboyle/Grid Source file: Hadrons/Exceptions.cc -Copyright (C) 2015-2018 +Copyright (C) 2015-2019 Author: Antonin Portelli diff --git a/Hadrons/Exceptions.hpp b/Hadrons/Exceptions.hpp index 2a8b0f8c..9974e33d 100644 --- a/Hadrons/Exceptions.hpp +++ b/Hadrons/Exceptions.hpp @@ -4,7 +4,7 @@ Grid physics library, www.github.com/paboyle/Grid Source file: Hadrons/Exceptions.hpp -Copyright (C) 2015-2018 +Copyright (C) 2015-2019 Author: Antonin Portelli diff --git a/Hadrons/Factory.hpp b/Hadrons/Factory.hpp index 8a3c20ba..cfb609e9 100644 --- a/Hadrons/Factory.hpp +++ b/Hadrons/Factory.hpp @@ -4,7 +4,7 @@ Grid physics library, www.github.com/paboyle/Grid Source file: Hadrons/Factory.hpp -Copyright (C) 2015-2018 +Copyright (C) 2015-2019 Author: Antonin Portelli diff --git a/Hadrons/GeneticScheduler.hpp b/Hadrons/GeneticScheduler.hpp index 9025641b..178b8301 100644 --- a/Hadrons/GeneticScheduler.hpp +++ b/Hadrons/GeneticScheduler.hpp @@ -4,7 +4,7 @@ Grid physics library, www.github.com/paboyle/Grid Source file: Hadrons/GeneticScheduler.hpp -Copyright (C) 2015-2018 +Copyright (C) 2015-2019 Author: Antonin Portelli diff --git a/Hadrons/Global.cc b/Hadrons/Global.cc index ac8ac7f5..d74d10d2 100644 --- a/Hadrons/Global.cc +++ b/Hadrons/Global.cc @@ -4,7 +4,7 @@ Grid physics library, www.github.com/paboyle/Grid Source file: Hadrons/Global.cc -Copyright (C) 2015-2018 +Copyright (C) 2015-2019 Author: Antonin Portelli diff --git a/Hadrons/Global.hpp b/Hadrons/Global.hpp index 9f8d9c2c..9b592721 100644 --- a/Hadrons/Global.hpp +++ b/Hadrons/Global.hpp @@ -4,7 +4,7 @@ Grid physics library, www.github.com/paboyle/Grid Source file: Hadrons/Global.hpp -Copyright (C) 2015-2018 +Copyright (C) 2015-2019 Author: Antonin Portelli Author: Lanny91 @@ -44,6 +44,8 @@ See the full license in the file "LICENSE" in the top level distribution directo #define DEFAULT_ASCII_PREC 16 #endif +#define ARG(...) __VA_ARGS__ + /* the 'using Grid::operator<<;' statement prevents a very nasty compilation * error with GCC 5 (clang & GCC 6 compile fine without it). */ @@ -100,15 +102,17 @@ BEGIN_HADRONS_NAMESPACE typedef typename Impl::Field ScalarField##suffix;\ typedef typename Impl::PropagatorField PropagatorField##suffix;\ typedef typename Impl::SitePropagator::scalar_object SitePropagator##suffix;\ -typedef std::vector SlicedPropagator##suffix; +typedef typename Impl::ComplexField ComplexField##suffix;\ +typedef std::vector SlicedPropagator##suffix;\ +typedef std::vector SlicedComplex##suffix; #define FERM_TYPE_ALIASES(FImpl, suffix)\ BASIC_TYPE_ALIASES(FImpl, suffix);\ -typedef FermionOperator FMat##suffix;\ -typedef typename FImpl::FermionField FermionField##suffix;\ -typedef typename FImpl::GaugeField GaugeField##suffix;\ -typedef typename FImpl::DoubledGaugeField DoubledGaugeField##suffix;\ -typedef typename FImpl::ComplexField ComplexField##suffix; +typedef FermionOperator FMat##suffix;\ +typedef typename FImpl::FermionField FermionField##suffix;\ +typedef typename FImpl::GaugeField GaugeField##suffix;\ +typedef typename FImpl::DoubledGaugeField DoubledGaugeField##suffix;\ +typedef Lattice> SpinMatrixField##suffix; #define GAUGE_TYPE_ALIASES(GImpl, suffix)\ typedef typename GImpl::GaugeField GaugeField##suffix; @@ -262,6 +266,15 @@ void tokenReplace(std::string &str, const std::string token, } } +// generic correlator class +template +struct Correlator: Serializable +{ + GRID_SERIALIZABLE_CLASS_MEMBERS(ARG(Correlator), + Metadata, info, + std::vector, corr); +}; + END_HADRONS_NAMESPACE #include diff --git a/Hadrons/Graph.hpp b/Hadrons/Graph.hpp index 10e3bc60..65c74106 100644 --- a/Hadrons/Graph.hpp +++ b/Hadrons/Graph.hpp @@ -4,7 +4,7 @@ Grid physics library, www.github.com/paboyle/Grid Source file: Hadrons/Graph.hpp -Copyright (C) 2015-2018 +Copyright (C) 2015-2019 Author: Antonin Portelli diff --git a/Hadrons/Module.cc b/Hadrons/Module.cc index c72f8acb..8e332d5a 100644 --- a/Hadrons/Module.cc +++ b/Hadrons/Module.cc @@ -4,7 +4,7 @@ Grid physics library, www.github.com/paboyle/Grid Source file: Hadrons/Module.cc -Copyright (C) 2015-2018 +Copyright (C) 2015-2019 Author: Antonin Portelli diff --git a/Hadrons/Module.hpp b/Hadrons/Module.hpp index 8d59d06c..95db9511 100644 --- a/Hadrons/Module.hpp +++ b/Hadrons/Module.hpp @@ -4,7 +4,7 @@ Grid physics library, www.github.com/paboyle/Grid Source file: Hadrons/Module.hpp -Copyright (C) 2015-2018 +Copyright (C) 2015-2019 Author: Antonin Portelli @@ -65,7 +65,6 @@ static ns##mod##ModuleRegistrar ns##mod##ModuleRegistrarInstance; extern template class base;\ MODULE_REGISTER(mod, ARG(base), ns); -#define ARG(...) __VA_ARGS__ #define HADRONS_MACRO_REDIRECT_12(arg1, arg2, macro, ...) macro #define HADRONS_MACRO_REDIRECT_23(arg1, arg2, arg3, macro, ...) macro @@ -78,6 +77,15 @@ env().template getGrid(Ls) #define envGetGrid(...)\ HADRONS_MACRO_REDIRECT_12(__VA_ARGS__, envGetGrid5, envGetGrid4)(__VA_ARGS__) +#define envGetCoarseGrid4(latticeType, blockSize)\ +env().template getCoarseGrid(blockSize) + +#define envGetCoarseGrid5(latticeType, blockSize, Ls)\ +env().template getCoarseGrid(blockSize, Ls) + +#define envGetCoarseGrid(...)\ +HADRONS_MACRO_REDIRECT_23(__VA_ARGS__, envGetCoarseGrid5, envGetCoarseGrid4)(__VA_ARGS__) + #define envGetRbGrid4(latticeType)\ env().template getRbGrid() diff --git a/Hadrons/ModuleFactory.hpp b/Hadrons/ModuleFactory.hpp index 7dcbac75..4cb39983 100644 --- a/Hadrons/ModuleFactory.hpp +++ b/Hadrons/ModuleFactory.hpp @@ -4,7 +4,7 @@ Grid physics library, www.github.com/paboyle/Grid Source file: Hadrons/ModuleFactory.hpp -Copyright (C) 2015-2018 +Copyright (C) 2015-2019 Author: Antonin Portelli diff --git a/Hadrons/Modules.hpp b/Hadrons/Modules.hpp index 787fecea..898cb532 100644 --- a/Hadrons/Modules.hpp +++ b/Hadrons/Modules.hpp @@ -1,17 +1,18 @@ +#include #include #include +#include #include #include -#include -#include #include -#include #include -#include -#include +#include +#include #include #include +#include #include +#include #include #include #include @@ -21,28 +22,23 @@ #include #include #include +#include #include #include #include -#include #include #include #include -#include #include #include #include #include +#include #include #include #include #include -#include -#include -#include #include -#include -#include #include #include #include @@ -56,7 +52,6 @@ #include #include #include -#include #include #include #include diff --git a/Hadrons/Modules/MAction/DWF.cc b/Hadrons/Modules/MAction/DWF.cc index 38d25cb9..1cb89602 100644 --- a/Hadrons/Modules/MAction/DWF.cc +++ b/Hadrons/Modules/MAction/DWF.cc @@ -4,7 +4,7 @@ Grid physics library, www.github.com/paboyle/Grid Source file: Hadrons/Modules/MAction/DWF.cc -Copyright (C) 2015-2018 +Copyright (C) 2015-2019 Author: Antonin Portelli diff --git a/Hadrons/Modules/MAction/DWF.hpp b/Hadrons/Modules/MAction/DWF.hpp index a7104b42..21024a4f 100644 --- a/Hadrons/Modules/MAction/DWF.hpp +++ b/Hadrons/Modules/MAction/DWF.hpp @@ -4,7 +4,7 @@ Grid physics library, www.github.com/paboyle/Grid Source file: Hadrons/Modules/MAction/DWF.hpp -Copyright (C) 2015-2018 +Copyright (C) 2015-2019 Author: Antonin Portelli Author: Lanny91 @@ -112,8 +112,6 @@ void TDWF::setup(void) << par().mass << ", M5= " << par().M5 << " and Ls= " << par().Ls << " using gauge field '" << par().gauge << "'" << std::endl; - LOG(Message) << "Fermion boundary conditions: " << par().boundary - << std::endl; auto &U = envGet(GaugeField, par().gauge); auto &g4 = *envGetGrid(FermionField); @@ -121,8 +119,26 @@ void TDWF::setup(void) auto &g5 = *envGetGrid(FermionField, par().Ls); auto &grb5 = *envGetRbGrid(FermionField, par().Ls); typename DomainWallFermion::ImplParams implParams; - implParams.boundary_phases = strToVec(par().boundary); - implParams.twist_n_2pi_L = strToVec(par().twist); + if (!par().boundary.empty()) + { + implParams.boundary_phases = strToVec(par().boundary); + } + if (!par().twist.empty()) + { + implParams.twist_n_2pi_L = strToVec(par().twist); + } + LOG(Message) << "Fermion boundary conditions: " << implParams.boundary_phases + << std::endl; + LOG(Message) << "Twists: " << implParams.twist_n_2pi_L + << std::endl; + if (implParams.boundary_phases.size() != env().getNd()) + { + HADRONS_ERROR(Size, "Wrong number of boundary phase"); + } + if (implParams.twist_n_2pi_L.size() != env().getNd()) + { + HADRONS_ERROR(Size, "Wrong number of twist"); + } envCreateDerived(FMat, DomainWallFermion, getName(), par().Ls, U, g5, grb5, g4, grb4, par().mass, par().M5, implParams); } diff --git a/Hadrons/Modules/MAction/MobiusDWF.cc b/Hadrons/Modules/MAction/MobiusDWF.cc index 879452d8..00819632 100644 --- a/Hadrons/Modules/MAction/MobiusDWF.cc +++ b/Hadrons/Modules/MAction/MobiusDWF.cc @@ -4,7 +4,7 @@ Grid physics library, www.github.com/paboyle/Grid Source file: Hadrons/Modules/MAction/MobiusDWF.cc -Copyright (C) 2015-2018 +Copyright (C) 2015-2019 Author: Antonin Portelli diff --git a/Hadrons/Modules/MAction/MobiusDWF.hpp b/Hadrons/Modules/MAction/MobiusDWF.hpp index 0ba9c4c3..3ce02b91 100644 --- a/Hadrons/Modules/MAction/MobiusDWF.hpp +++ b/Hadrons/Modules/MAction/MobiusDWF.hpp @@ -4,7 +4,7 @@ Grid physics library, www.github.com/paboyle/Grid Source file: Hadrons/Modules/MAction/MobiusDWF.hpp -Copyright (C) 2015-2018 +Copyright (C) 2015-2019 Author: Antonin Portelli @@ -112,17 +112,33 @@ void TMobiusDWF::setup(void) << ", b= " << par().b << ", c= " << par().c << " using gauge field '" << par().gauge << "'" << std::endl; - LOG(Message) << "Fermion boundary conditions: " << par().boundary - << std::endl; - + auto &U = envGet(GaugeField, par().gauge); auto &g4 = *envGetGrid(FermionField); auto &grb4 = *envGetRbGrid(FermionField); auto &g5 = *envGetGrid(FermionField, par().Ls); auto &grb5 = *envGetRbGrid(FermionField, par().Ls); typename MobiusFermion::ImplParams implParams; - implParams.boundary_phases = strToVec(par().boundary); - implParams.twist_n_2pi_L = strToVec(par().twist); + if (!par().boundary.empty()) + { + implParams.boundary_phases = strToVec(par().boundary); + } + if (!par().twist.empty()) + { + implParams.twist_n_2pi_L = strToVec(par().twist); + } + LOG(Message) << "Fermion boundary conditions: " << implParams.boundary_phases + << std::endl; + LOG(Message) << "Twists: " << implParams.twist_n_2pi_L + << std::endl; + if (implParams.boundary_phases.size() != env().getNd()) + { + HADRONS_ERROR(Size, "Wrong number of boundary phase"); + } + if (implParams.twist_n_2pi_L.size() != env().getNd()) + { + HADRONS_ERROR(Size, "Wrong number of twist"); + } envCreateDerived(FMat, MobiusFermion, getName(), par().Ls, U, g5, grb5, g4, grb4, par().mass, par().M5, par().b, par().c, implParams); diff --git a/Hadrons/Modules/MAction/ScaledDWF.cc b/Hadrons/Modules/MAction/ScaledDWF.cc index 7008bf5d..81b254b1 100644 --- a/Hadrons/Modules/MAction/ScaledDWF.cc +++ b/Hadrons/Modules/MAction/ScaledDWF.cc @@ -4,7 +4,7 @@ Grid physics library, www.github.com/paboyle/Grid Source file: Hadrons/Modules/MAction/ScaledDWF.cc -Copyright (C) 2015-2018 +Copyright (C) 2015-2019 Author: Antonin Portelli diff --git a/Hadrons/Modules/MAction/ScaledDWF.hpp b/Hadrons/Modules/MAction/ScaledDWF.hpp index 3b8066e6..3e052225 100644 --- a/Hadrons/Modules/MAction/ScaledDWF.hpp +++ b/Hadrons/Modules/MAction/ScaledDWF.hpp @@ -4,7 +4,7 @@ Grid physics library, www.github.com/paboyle/Grid Source file: Hadrons/Modules/MAction/ScaledDWF.hpp -Copyright (C) 2015-2018 +Copyright (C) 2015-2019 Author: Antonin Portelli @@ -111,8 +111,6 @@ void TScaledDWF::setup(void) << ", scale= " << par().scale << " using gauge field '" << par().gauge << "'" << std::endl; - LOG(Message) << "Fermion boundary conditions: " << par().boundary - << std::endl; auto &U = envGet(GaugeField, par().gauge); auto &g4 = *envGetGrid(FermionField); @@ -120,8 +118,26 @@ void TScaledDWF::setup(void) auto &g5 = *envGetGrid(FermionField, par().Ls); auto &grb5 = *envGetRbGrid(FermionField, par().Ls); typename ScaledShamirFermion::ImplParams implParams; - implParams.boundary_phases = strToVec(par().boundary); - implParams.twist_n_2pi_L = strToVec(par().twist); + if (!par().boundary.empty()) + { + implParams.boundary_phases = strToVec(par().boundary); + } + if (!par().twist.empty()) + { + implParams.twist_n_2pi_L = strToVec(par().twist); + } + LOG(Message) << "Fermion boundary conditions: " << implParams.boundary_phases + << std::endl; + LOG(Message) << "Twists: " << implParams.twist_n_2pi_L + << std::endl; + if (implParams.boundary_phases.size() != env().getNd()) + { + HADRONS_ERROR(Size, "Wrong number of boundary phase"); + } + if (implParams.twist_n_2pi_L.size() != env().getNd()) + { + HADRONS_ERROR(Size, "Wrong number of twist"); + } envCreateDerived(FMat, ScaledShamirFermion, getName(), par().Ls, U, g5, grb5, g4, grb4, par().mass, par().M5, par().scale, implParams); diff --git a/Hadrons/Modules/MAction/Wilson.cc b/Hadrons/Modules/MAction/Wilson.cc index 1e801ed6..8d0f8b2f 100644 --- a/Hadrons/Modules/MAction/Wilson.cc +++ b/Hadrons/Modules/MAction/Wilson.cc @@ -4,7 +4,7 @@ Grid physics library, www.github.com/paboyle/Grid Source file: Hadrons/Modules/MAction/Wilson.cc -Copyright (C) 2015-2018 +Copyright (C) 2015-2019 Author: Antonin Portelli diff --git a/Hadrons/Modules/MAction/Wilson.hpp b/Hadrons/Modules/MAction/Wilson.hpp index b5e53837..11df89c3 100644 --- a/Hadrons/Modules/MAction/Wilson.hpp +++ b/Hadrons/Modules/MAction/Wilson.hpp @@ -4,7 +4,7 @@ Grid physics library, www.github.com/paboyle/Grid Source file: Hadrons/Modules/MAction/Wilson.hpp -Copyright (C) 2015-2018 +Copyright (C) 2015-2019 Author: Antonin Portelli Author: Lanny91 @@ -109,15 +109,31 @@ void TWilson::setup(void) { LOG(Message) << "Setting up Wilson fermion matrix with m= " << par().mass << " using gauge field '" << par().gauge << "'" << std::endl; - LOG(Message) << "Fermion boundary conditions: " << par().boundary - << std::endl; auto &U = envGet(GaugeField, par().gauge); auto &grid = *envGetGrid(FermionField); auto &gridRb = *envGetRbGrid(FermionField); typename WilsonFermion::ImplParams implParams; - implParams.boundary_phases = strToVec(par().boundary); - implParams.twist_n_2pi_L = strToVec(par().twist); + if (!par().boundary.empty()) + { + implParams.boundary_phases = strToVec(par().boundary); + } + if (!par().twist.empty()) + { + implParams.twist_n_2pi_L = strToVec(par().twist); + } + LOG(Message) << "Fermion boundary conditions: " << implParams.boundary_phases + << std::endl; + LOG(Message) << "Twists: " << implParams.twist_n_2pi_L + << std::endl; + if (implParams.boundary_phases.size() != env().getNd()) + { + HADRONS_ERROR(Size, "Wrong number of boundary phase"); + } + if (implParams.twist_n_2pi_L.size() != env().getNd()) + { + HADRONS_ERROR(Size, "Wrong number of twist"); + } envCreateDerived(FMat, WilsonFermion, getName(), 1, U, grid, gridRb, par().mass, implParams); } diff --git a/Hadrons/Modules/MAction/WilsonClover.cc b/Hadrons/Modules/MAction/WilsonClover.cc index eed1582c..95f5abe6 100644 --- a/Hadrons/Modules/MAction/WilsonClover.cc +++ b/Hadrons/Modules/MAction/WilsonClover.cc @@ -4,7 +4,7 @@ Grid physics library, www.github.com/paboyle/Grid Source file: Hadrons/Modules/MAction/WilsonClover.cc -Copyright (C) 2015-2018 +Copyright (C) 2015-2019 Author: Antonin Portelli diff --git a/Hadrons/Modules/MAction/WilsonClover.hpp b/Hadrons/Modules/MAction/WilsonClover.hpp index ad301380..d80bccdf 100644 --- a/Hadrons/Modules/MAction/WilsonClover.hpp +++ b/Hadrons/Modules/MAction/WilsonClover.hpp @@ -4,7 +4,7 @@ Grid physics library, www.github.com/paboyle/Grid Source file: Hadrons/Modules/MAction/WilsonClover.hpp -Copyright (C) 2015-2018 +Copyright (C) 2015-2019 Author: Antonin Portelli Author: Guido Cossu @@ -112,17 +112,34 @@ void TWilsonClover::setup(void) { LOG(Message) << "Setting up Wilson clover fermion matrix with m= " << par().mass << " using gauge field '" << par().gauge << "'" << std::endl; - LOG(Message) << "Fermion boundary conditions: " << par().boundary - << std::endl; LOG(Message) << "Clover term csw_r: " << par().csw_r << " csw_t: " << par().csw_t << std::endl; + auto &U = envGet(GaugeField, par().gauge); auto &grid = *envGetGrid(FermionField); auto &gridRb = *envGetRbGrid(FermionField); typename WilsonCloverFermion::ImplParams implParams; - implParams.boundary_phases = strToVec(par().boundary); - implParams.twist_n_2pi_L = strToVec(par().twist); + if (!par().boundary.empty()) + { + implParams.boundary_phases = strToVec(par().boundary); + } + if (!par().twist.empty()) + { + implParams.twist_n_2pi_L = strToVec(par().twist); + } + LOG(Message) << "Fermion boundary conditions: " << implParams.boundary_phases + << std::endl; + LOG(Message) << "Twists: " << implParams.twist_n_2pi_L + << std::endl; + if (implParams.boundary_phases.size() != env().getNd()) + { + HADRONS_ERROR(Size, "Wrong number of boundary phase"); + } + if (implParams.twist_n_2pi_L.size() != env().getNd()) + { + HADRONS_ERROR(Size, "Wrong number of twist"); + } envCreateDerived(FMat, WilsonCloverFermion, getName(), 1, U, grid, gridRb, par().mass, par().csw_r, par().csw_t, par().clover_anisotropy, implParams); diff --git a/Hadrons/Modules/MAction/ZMobiusDWF.cc b/Hadrons/Modules/MAction/ZMobiusDWF.cc index 609b76cc..778db139 100644 --- a/Hadrons/Modules/MAction/ZMobiusDWF.cc +++ b/Hadrons/Modules/MAction/ZMobiusDWF.cc @@ -4,7 +4,7 @@ Grid physics library, www.github.com/paboyle/Grid Source file: Hadrons/Modules/MAction/ZMobiusDWF.cc -Copyright (C) 2015-2018 +Copyright (C) 2015-2019 Author: Antonin Portelli diff --git a/Hadrons/Modules/MAction/ZMobiusDWF.hpp b/Hadrons/Modules/MAction/ZMobiusDWF.hpp index 7ded1254..62bd1651 100644 --- a/Hadrons/Modules/MAction/ZMobiusDWF.hpp +++ b/Hadrons/Modules/MAction/ZMobiusDWF.hpp @@ -4,7 +4,7 @@ Grid physics library, www.github.com/paboyle/Grid Source file: Hadrons/Modules/MAction/ZMobiusDWF.hpp -Copyright (C) 2015-2018 +Copyright (C) 2015-2019 Author: Antonin Portelli @@ -118,10 +118,7 @@ void TZMobiusDWF::setup(void) { LOG(Message) << " omega[" << i << "]= " << par().omega[i] << std::endl; } - LOG(Message) << "Fermion boundary conditions: " << par().boundary - << std::endl; - env().createGrid(par().Ls); auto &U = envGet(GaugeField, par().gauge); auto &g4 = *envGetGrid(FermionField); auto &grb4 = *envGetRbGrid(FermionField); @@ -129,9 +126,27 @@ void TZMobiusDWF::setup(void) auto &grb5 = *envGetRbGrid(FermionField, par().Ls); auto omega = par().omega; typename ZMobiusFermion::ImplParams implParams; - implParams.boundary_phases = strToVec(par().boundary); - implParams.twist_n_2pi_L = strToVec(par().twist); + + if (!par().boundary.empty()) + { + implParams.boundary_phases = strToVec(par().boundary); + } + if (!par().twist.empty()) + { + implParams.twist_n_2pi_L = strToVec(par().twist); + } + LOG(Message) << "Fermion boundary conditions: " << implParams.boundary_phases << std::endl; + LOG(Message) << "Twists: " << implParams.twist_n_2pi_L << std::endl; + if (implParams.boundary_phases.size() != env().getNd()) + { + HADRONS_ERROR(Size, "Wrong number of boundary phase"); + } + if (implParams.twist_n_2pi_L.size() != env().getNd()) + { + HADRONS_ERROR(Size, "Wrong number of twist"); + } + assert(par().Ls==omega.size()); int Ls=par().Ls; std::vector _omega(Ls); @@ -142,17 +157,6 @@ void TZMobiusDWF::setup(void) U, g5, grb5, g4, grb4, par().mass, par().M5, _omega, par().b, par().c, implParams); - - /* - ZMobiusFermion(GaugeField &_Umu, - GridCartesian &FiveDimGrid, - GridRedBlackCartesian &FiveDimRedBlackGrid, - GridCartesian &FourDimGrid, - GridRedBlackCartesian &FourDimRedBlackGrid, - RealD _mass,RealD _M5, - std::vector &gamma, RealD b,RealD c,const ImplParams &p= ImplParams()) : - */ - } // execution /////////////////////////////////////////////////////////////////// diff --git a/Hadrons/Modules/MContraction/A2AAslashField.cc b/Hadrons/Modules/MContraction/A2AAslashField.cc index 65c49198..47c39cca 100644 --- a/Hadrons/Modules/MContraction/A2AAslashField.cc +++ b/Hadrons/Modules/MContraction/A2AAslashField.cc @@ -4,7 +4,7 @@ Grid physics library, www.github.com/paboyle/Grid Source file: Hadrons/Modules/MContraction/A2AAslashField.cc -Copyright (C) 2015-2018 +Copyright (C) 2015-2019 Author: Antonin Portelli diff --git a/Hadrons/Modules/MContraction/A2AAslashField.hpp b/Hadrons/Modules/MContraction/A2AAslashField.hpp index 8b99692b..520df0de 100644 --- a/Hadrons/Modules/MContraction/A2AAslashField.hpp +++ b/Hadrons/Modules/MContraction/A2AAslashField.hpp @@ -4,7 +4,7 @@ Grid physics library, www.github.com/paboyle/Grid Source file: Hadrons/Modules/MContraction/A2AAslashField.hpp -Copyright (C) 2015-2018 +Copyright (C) 2015-2019 Author: Antonin Portelli diff --git a/Hadrons/Modules/MLoop/NoiseLoop.cc b/Hadrons/Modules/MContraction/A2ALoop.cc similarity index 83% rename from Hadrons/Modules/MLoop/NoiseLoop.cc rename to Hadrons/Modules/MContraction/A2ALoop.cc index a21372fb..3dfcd66d 100644 --- a/Hadrons/Modules/MLoop/NoiseLoop.cc +++ b/Hadrons/Modules/MContraction/A2ALoop.cc @@ -2,9 +2,9 @@ Grid physics library, www.github.com/paboyle/Grid -Source file: Hadrons/Modules/MLoop/NoiseLoop.cc +Source file: Hadrons/Modules/MContraction/A2ALoop.cc -Copyright (C) 2015-2018 +Copyright (C) 2015-2019 Author: Antonin Portelli @@ -25,11 +25,10 @@ with this program; if not, write to the Free Software Foundation, Inc., See the full license in the file "LICENSE" in the top level distribution directory *************************************************************************************/ /* END LEGAL */ -#include +#include using namespace Grid; using namespace Hadrons; -using namespace MLoop; - -template class Grid::Hadrons::MLoop::TNoiseLoop; +using namespace MContraction; +template class Grid::Hadrons::MContraction::TA2ALoop; diff --git a/Hadrons/Modules/MLoop/NoiseLoop.hpp b/Hadrons/Modules/MContraction/A2ALoop.hpp similarity index 63% rename from Hadrons/Modules/MLoop/NoiseLoop.hpp rename to Hadrons/Modules/MContraction/A2ALoop.hpp index 8da172d4..7e7ffac0 100644 --- a/Hadrons/Modules/MLoop/NoiseLoop.hpp +++ b/Hadrons/Modules/MContraction/A2ALoop.hpp @@ -2,12 +2,11 @@ Grid physics library, www.github.com/paboyle/Grid -Source file: Hadrons/Modules/MLoop/NoiseLoop.hpp +Source file: Hadrons/Modules/MContraction/A2ALoop.hpp -Copyright (C) 2015-2018 +Copyright (C) 2015-2019 Author: Antonin Portelli -Author: Lanny91 This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -26,9 +25,8 @@ with this program; if not, write to the Free Software Foundation, Inc., See the full license in the file "LICENSE" in the top level distribution directory *************************************************************************************/ /* END LEGAL */ - -#ifndef Hadrons_MLoop_NoiseLoop_hpp_ -#define Hadrons_MLoop_NoiseLoop_hpp_ +#ifndef Hadrons_MContraction_A2ALoop_hpp_ +#define Hadrons_MContraction_A2ALoop_hpp_ #include #include @@ -36,74 +34,60 @@ See the full license in the file "LICENSE" in the top level distribution directo BEGIN_HADRONS_NAMESPACE -/* - - Noise loop propagator - ----------------------------- - * loop_x = q_x * adj(eta_x) - - * options: - - q = Result of inversion on noise source. - - eta = noise source. - - */ - - /****************************************************************************** - * NoiseLoop * + * From closed loop from all-to-all vectors * ******************************************************************************/ -BEGIN_MODULE_NAMESPACE(MLoop) +BEGIN_MODULE_NAMESPACE(MContraction) -class NoiseLoopPar: Serializable +class A2ALoopPar: Serializable { public: - GRID_SERIALIZABLE_CLASS_MEMBERS(NoiseLoopPar, - std::string, q, - std::string, eta); + GRID_SERIALIZABLE_CLASS_MEMBERS(A2ALoopPar, + std::string, left, + std::string, right); }; template -class TNoiseLoop: public Module +class TA2ALoop: public Module { public: FERM_TYPE_ALIASES(FImpl,); public: // constructor - TNoiseLoop(const std::string name); + TA2ALoop(const std::string name); // destructor - virtual ~TNoiseLoop(void) {}; + virtual ~TA2ALoop(void) {}; // dependency relation virtual std::vector getInput(void); virtual std::vector getOutput(void); -protected: // setup virtual void setup(void); // execution virtual void execute(void); }; -MODULE_REGISTER_TMP(NoiseLoop, TNoiseLoop, MLoop); +MODULE_REGISTER_TMP(A2ALoop, TA2ALoop, MContraction); /****************************************************************************** - * TNoiseLoop implementation * + * TA2ALoop implementation * ******************************************************************************/ // constructor ///////////////////////////////////////////////////////////////// template -TNoiseLoop::TNoiseLoop(const std::string name) -: Module(name) +TA2ALoop::TA2ALoop(const std::string name) +: Module(name) {} // dependencies/products /////////////////////////////////////////////////////// template -std::vector TNoiseLoop::getInput(void) +std::vector TA2ALoop::getInput(void) { - std::vector in = {par().q, par().eta}; + std::vector in = {par().left, par().right}; return in; } template -std::vector TNoiseLoop::getOutput(void) +std::vector TA2ALoop::getOutput(void) { std::vector out = {getName()}; @@ -112,23 +96,28 @@ std::vector TNoiseLoop::getOutput(void) // setup /////////////////////////////////////////////////////////////////////// template -void TNoiseLoop::setup(void) +void TA2ALoop::setup(void) { envCreateLat(PropagatorField, getName()); } // execution /////////////////////////////////////////////////////////////////// template -void TNoiseLoop::execute(void) +void TA2ALoop::execute(void) { - auto &loop = envGet(PropagatorField, getName()); - auto &q = envGet(PropagatorField, par().q); - auto &eta = envGet(PropagatorField, par().eta); - loop = q*adj(eta); + auto &loop = envGet(PropagatorField, getName()); + auto &left = envGet(std::vector, par().left); + auto &right = envGet(std::vector, par().right); + + loop = zero; + for (unsigned int i = 0; i < left.size(); ++i) + { + loop += outerProduct(left[i], right[i]); + } } END_MODULE_NAMESPACE END_HADRONS_NAMESPACE -#endif // Hadrons_MLoop_NoiseLoop_hpp_ +#endif // Hadrons_MContraction_A2ALoop_hpp_ diff --git a/Hadrons/Modules/MContraction/A2AMesonField.cc b/Hadrons/Modules/MContraction/A2AMesonField.cc index c71f8ef2..0b4f79a9 100644 --- a/Hadrons/Modules/MContraction/A2AMesonField.cc +++ b/Hadrons/Modules/MContraction/A2AMesonField.cc @@ -4,7 +4,7 @@ Grid physics library, www.github.com/paboyle/Grid Source file: Hadrons/Modules/MContraction/A2AMesonField.cc -Copyright (C) 2015-2018 +Copyright (C) 2015-2019 Author: Antonin Portelli Author: paboyle diff --git a/Hadrons/Modules/MContraction/A2AMesonField.hpp b/Hadrons/Modules/MContraction/A2AMesonField.hpp index 4d35d1ef..d3f90959 100644 --- a/Hadrons/Modules/MContraction/A2AMesonField.hpp +++ b/Hadrons/Modules/MContraction/A2AMesonField.hpp @@ -4,7 +4,7 @@ Grid physics library, www.github.com/paboyle/Grid Source file: Hadrons/Modules/MContraction/A2AMesonField.hpp -Copyright (C) 2015-2018 +Copyright (C) 2015-2019 Author: Antonin Portelli Author: Peter Boyle diff --git a/Hadrons/Modules/MContraction/Baryon.cc b/Hadrons/Modules/MContraction/Baryon.cc index f597a858..84e0f984 100644 --- a/Hadrons/Modules/MContraction/Baryon.cc +++ b/Hadrons/Modules/MContraction/Baryon.cc @@ -4,7 +4,7 @@ Grid physics library, www.github.com/paboyle/Grid Source file: Hadrons/Modules/MContraction/Baryon.cc -Copyright (C) 2015-2018 +Copyright (C) 2015-2019 Author: Antonin Portelli diff --git a/Hadrons/Modules/MContraction/Baryon.hpp b/Hadrons/Modules/MContraction/Baryon.hpp index 01db09e0..fc78ab80 100644 --- a/Hadrons/Modules/MContraction/Baryon.hpp +++ b/Hadrons/Modules/MContraction/Baryon.hpp @@ -4,7 +4,7 @@ Grid physics library, www.github.com/paboyle/Grid Source file: Hadrons/Modules/MContraction/Baryon.hpp -Copyright (C) 2015-2018 +Copyright (C) 2015-2019 Author: Antonin Portelli Author: Lanny91 diff --git a/Hadrons/Modules/MContraction/DiscLoop.cc b/Hadrons/Modules/MContraction/DiscLoop.cc index fa4cd235..659593c6 100644 --- a/Hadrons/Modules/MContraction/DiscLoop.cc +++ b/Hadrons/Modules/MContraction/DiscLoop.cc @@ -4,7 +4,7 @@ Grid physics library, www.github.com/paboyle/Grid Source file: Hadrons/Modules/MContraction/DiscLoop.cc -Copyright (C) 2015-2018 +Copyright (C) 2015-2019 Author: Antonin Portelli diff --git a/Hadrons/Modules/MContraction/DiscLoop.hpp b/Hadrons/Modules/MContraction/DiscLoop.hpp index f8b88eb2..b28cc742 100644 --- a/Hadrons/Modules/MContraction/DiscLoop.hpp +++ b/Hadrons/Modules/MContraction/DiscLoop.hpp @@ -4,7 +4,7 @@ Grid physics library, www.github.com/paboyle/Grid Source file: Hadrons/Modules/MContraction/DiscLoop.hpp -Copyright (C) 2015-2018 +Copyright (C) 2015-2019 Author: Antonin Portelli Author: Lanny91 diff --git a/Hadrons/Modules/MContraction/Gamma3pt.cc b/Hadrons/Modules/MContraction/Gamma3pt.cc index ca1ca441..044d7c65 100644 --- a/Hadrons/Modules/MContraction/Gamma3pt.cc +++ b/Hadrons/Modules/MContraction/Gamma3pt.cc @@ -4,7 +4,7 @@ Grid physics library, www.github.com/paboyle/Grid Source file: Hadrons/Modules/MContraction/Gamma3pt.cc -Copyright (C) 2015-2018 +Copyright (C) 2015-2019 Author: Antonin Portelli diff --git a/Hadrons/Modules/MContraction/Gamma3pt.hpp b/Hadrons/Modules/MContraction/Gamma3pt.hpp index 2a0da43a..d36e184b 100644 --- a/Hadrons/Modules/MContraction/Gamma3pt.hpp +++ b/Hadrons/Modules/MContraction/Gamma3pt.hpp @@ -4,7 +4,7 @@ Grid physics library, www.github.com/paboyle/Grid Source file: Hadrons/Modules/MContraction/Gamma3pt.hpp -Copyright (C) 2015-2018 +Copyright (C) 2015-2019 Author: Antonin Portelli Author: Lanny91 diff --git a/Hadrons/Modules/MContraction/Meson.cc b/Hadrons/Modules/MContraction/Meson.cc index 7fac7e95..ddb7c3ae 100644 --- a/Hadrons/Modules/MContraction/Meson.cc +++ b/Hadrons/Modules/MContraction/Meson.cc @@ -4,7 +4,7 @@ Grid physics library, www.github.com/paboyle/Grid Source file: Hadrons/Modules/MContraction/Meson.cc -Copyright (C) 2015-2018 +Copyright (C) 2015-2019 Author: Antonin Portelli diff --git a/Hadrons/Modules/MContraction/Meson.hpp b/Hadrons/Modules/MContraction/Meson.hpp index 514a6bb9..ee923341 100644 --- a/Hadrons/Modules/MContraction/Meson.hpp +++ b/Hadrons/Modules/MContraction/Meson.hpp @@ -4,7 +4,7 @@ Grid physics library, www.github.com/paboyle/Grid Source file: Hadrons/Modules/MContraction/Meson.hpp -Copyright (C) 2015-2018 +Copyright (C) 2015-2019 Author: Antonin Portelli Author: Lanny91 diff --git a/Hadrons/Modules/MContraction/WeakEye3pt.cc b/Hadrons/Modules/MContraction/WeakEye3pt.cc new file mode 100644 index 00000000..4942bbe4 --- /dev/null +++ b/Hadrons/Modules/MContraction/WeakEye3pt.cc @@ -0,0 +1,34 @@ +/************************************************************************************* + +Grid physics library, www.github.com/paboyle/Grid + +Source file: Hadrons/Modules/MContraction/WeakEye3pt.cc + +Copyright (C) 2015-2019 + +Author: Antonin Portelli + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License along +with this program; if not, write to the Free Software Foundation, Inc., +51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +See the full license in the file "LICENSE" in the top level distribution directory +*************************************************************************************/ +/* END LEGAL */ +#include + +using namespace Grid; +using namespace Hadrons; +using namespace MContraction; + +template class Grid::Hadrons::MContraction::TWeakEye3pt; diff --git a/Hadrons/Modules/MContraction/WeakEye3pt.hpp b/Hadrons/Modules/MContraction/WeakEye3pt.hpp new file mode 100644 index 00000000..ea7ff529 --- /dev/null +++ b/Hadrons/Modules/MContraction/WeakEye3pt.hpp @@ -0,0 +1,200 @@ +/************************************************************************************* + +Grid physics library, www.github.com/paboyle/Grid + +Source file: Hadrons/Modules/MContraction/WeakEye3pt.hpp + +Copyright (C) 2015-2019 + +Author: Antonin Portelli +Author: Lanny91 + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License along +with this program; if not, write to the Free Software Foundation, Inc., +51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +See the full license in the file "LICENSE" in the top level distribution directory +*************************************************************************************/ +/* END LEGAL */ +#ifndef Hadrons_MContraction_WeakEye3pt_hpp_ +#define Hadrons_MContraction_WeakEye3pt_hpp_ + +#include +#include +#include + +BEGIN_HADRONS_NAMESPACE + +/* + * Weak Hamiltonian meson 3-pt diagrams, eye topologies. + * + * Schematics: loop | + * /-<-¬ | + * / \ | qbl G qbr + * \ / | /----<------*------<----¬ + * qbl \ / qbr | / /-*-¬ \ + * /-----<-----* *-----<----¬ | / / G \ \ + * gIn * G G * gOut | gIn * \ / loop * gOut + * \ / | \ \->-/ / + * \ / | \ / + * \---------->---------/ | \----------->----------/ + * qs | qs + * | + * one trace | two traces + * + * one trace : tr(qbr*gOut*qs*adj(gIn)*g5*adj(qbl)*g5*G*loop*G) + * two traces: tr(qbr*gOut*qs*adj(gIn)*g5*adj(qbl)*g5*G)*tr(loop*G) + * + */ + +BEGIN_MODULE_NAMESPACE(MContraction) + +class WeakEye3ptPar: Serializable +{ +public: + GRID_SERIALIZABLE_CLASS_MEMBERS(WeakEye3ptPar, + std::string, qBarLeft, + std::string, qBarRight, + std::string, qSpectator, + std::string, loop, + unsigned int, tOut, + Gamma::Algebra, gammaIn, + Gamma::Algebra, gammaOut, + std::string, output); +}; + +template +class TWeakEye3pt: public Module +{ +public: + FERM_TYPE_ALIASES(FImpl,); + class Metadata: Serializable + { + public: + GRID_SERIALIZABLE_CLASS_MEMBERS(Metadata, + Gamma::Algebra, in, + Gamma::Algebra, out, + Gamma::Algebra, op, + unsigned int, trace); + }; + typedef Correlator Result; +public: + // constructor + TWeakEye3pt(const std::string name); + // destructor + virtual ~TWeakEye3pt(void) {}; + // dependency relation + virtual std::vector getInput(void); + virtual std::vector getOutput(void); + // setup + virtual void setup(void); + // execution + virtual void execute(void); +}; + +MODULE_REGISTER_TMP(WeakEye3pt, TWeakEye3pt, MContraction); + +/****************************************************************************** + * TWeakEye3pt implementation * + ******************************************************************************/ +// constructor ///////////////////////////////////////////////////////////////// +template +TWeakEye3pt::TWeakEye3pt(const std::string name) +: Module(name) +{} + +// dependencies/products /////////////////////////////////////////////////////// +template +std::vector TWeakEye3pt::getInput(void) +{ + std::vector in = {par().qBarLeft, par().qBarRight, + par().qSpectator, par().loop}; + + return in; +} + +template +std::vector TWeakEye3pt::getOutput(void) +{ + std::vector out = {}; + + return out; +} + +// setup /////////////////////////////////////////////////////////////////////// +template +void TWeakEye3pt::setup(void) +{ + envTmpLat(ComplexField, "corr"); +} + +// execution /////////////////////////////////////////////////////////////////// +template +void TWeakEye3pt::execute(void) +{ + LOG(Message) << "Computing mesonic weak 3pt contractions, eye topologies" << std::endl; + LOG(Message) << "gIn : " << par().gammaIn << std::endl; + LOG(Message) << "gOut: " << par().gammaIn << std::endl; + LOG(Message) << "tOut: " << par().tOut << std::endl; + LOG(Message) << "qbl : " << par().qBarLeft << std::endl; + LOG(Message) << "qbr : " << par().qBarRight << std::endl; + LOG(Message) << "qs : " << par().qSpectator << std::endl; + LOG(Message) << "loop: " << par().loop << std::endl; + + std::vector result; + Result r; + auto &qbl = envGet(PropagatorField, par().qBarLeft); + auto &qbr = envGet(PropagatorField, par().qBarRight); + auto &loop = envGet(PropagatorField, par().loop); + auto &qs = envGet(SlicedPropagator, par().qSpectator); + auto qst = qs[par().tOut]; + Gamma gIn(par().gammaIn), gOut(par().gammaOut); + Gamma g5(Gamma::Algebra::Gamma5); + + envGetTmp(ComplexField, corr); + r.info.in = par().gammaIn; + r.info.out = par().gammaOut; + for (auto &G: Gamma::gall) + { + SlicedComplex buf; + + r.info.op = G.g; + // one trace + corr = trace(qbr*gOut*qst*adj(gIn)*g5*adj(qbl)*g5*G*loop*G); + sliceSum(corr, buf, Tp); + r.corr.clear(); + for (unsigned int t = 0; t < buf.size(); ++t) + { + r.corr.push_back(TensorRemove(buf[t])); + } + r.info.trace = 1; + result.push_back(r); + // two traces + corr = trace(qbr*gOut*qst*adj(gIn)*g5*adj(qbl)*g5*G)*trace(loop*G); + sliceSum(corr, buf, Tp); + r.corr.clear(); + for (unsigned int t = 0; t < buf.size(); ++t) + { + r.corr.push_back(TensorRemove(buf[t])); + } + r.info.trace = 2; + result.push_back(r); + } + saveResult(par().output, "weakEye3pt", result); +} + +END_MODULE_NAMESPACE + +END_HADRONS_NAMESPACE + +#endif // Hadrons_MContraction_WeakEye3pt_hpp_ diff --git a/Hadrons/Modules/MScalarSUN/ShiftProbe.cc b/Hadrons/Modules/MContraction/WeakMesonDecayKl2.cc similarity index 68% rename from Hadrons/Modules/MScalarSUN/ShiftProbe.cc rename to Hadrons/Modules/MContraction/WeakMesonDecayKl2.cc index 83454941..78f1a6ae 100644 --- a/Hadrons/Modules/MScalarSUN/ShiftProbe.cc +++ b/Hadrons/Modules/MContraction/WeakMesonDecayKl2.cc @@ -2,11 +2,12 @@ Grid physics library, www.github.com/paboyle/Grid -Source file: Hadrons/Modules/MScalarSUN/ShiftProbe.cc +Source file: Hadrons/Modules/MContraction/WeakMesonDecayKl2.cc Copyright (C) 2015-2018 Author: Antonin Portelli +Author: Vera Guelpers This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -25,15 +26,11 @@ with this program; if not, write to the Free Software Foundation, Inc., See the full license in the file "LICENSE" in the top level distribution directory *************************************************************************************/ /* END LEGAL */ -#include +#include using namespace Grid; using namespace Hadrons; -using namespace MScalarSUN; +using namespace MContraction; -template class Grid::Hadrons::MScalarSUN::TShiftProbe>; -template class Grid::Hadrons::MScalarSUN::TShiftProbe>; -template class Grid::Hadrons::MScalarSUN::TShiftProbe>; -template class Grid::Hadrons::MScalarSUN::TShiftProbe>; -template class Grid::Hadrons::MScalarSUN::TShiftProbe>; +template class Grid::Hadrons::MContraction::TWeakMesonDecayKl2; diff --git a/Hadrons/Modules/MContraction/WeakMesonDecayKl2.hpp b/Hadrons/Modules/MContraction/WeakMesonDecayKl2.hpp new file mode 100644 index 00000000..d7a45108 --- /dev/null +++ b/Hadrons/Modules/MContraction/WeakMesonDecayKl2.hpp @@ -0,0 +1,185 @@ +/************************************************************************************* + +Grid physics library, www.github.com/paboyle/Grid + +Source file: Hadrons/Modules/MContraction/WeakMesonDecayKl2.hpp + +Copyright (C) 2015-2018 + +Author: Antonin Portelli +Author: Vera Guelpers + + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License along +with this program; if not, write to the Free Software Foundation, Inc., +51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +See the full license in the file "LICENSE" in the top level distribution directory +*************************************************************************************/ +/* END LEGAL */ + +#ifndef Hadrons_MContraction_WeakMesonDecayKl2_hpp_ +#define Hadrons_MContraction_WeakMesonDecayKl2_hpp_ + +#include +#include +#include + +BEGIN_HADRONS_NAMESPACE + +/* +* Kl2 contraction +* ----------------------------- +* +* contraction for Kl2 decay, including the lepton +* +* trace(q1*adj(q2)*g5*gL[mu]) * (gL[mu] * lepton)_{a,b} +* +* with open spinor indices (a,b) for the lepton part +* +* q1 lepton +* /------------\ /------------ +* / \ / +* / \H_W/ +* g_5 * * * +* \ / +* \ / +* \____________/ +* q2 +* +* * options: +* - q1: input propagator 1 (string) +* - q2: input propagator 2 (string) +* - lepton: input lepton (string) +*/ + +/****************************************************************************** + * TWeakMesonDecayKl2 * + ******************************************************************************/ +BEGIN_MODULE_NAMESPACE(MContraction) + +class WeakMesonDecayKl2Par: Serializable +{ +public: + GRID_SERIALIZABLE_CLASS_MEMBERS(WeakMesonDecayKl2Par, + std::string, q1, + std::string, q2, + std::string, lepton, + std::string, output); +}; + +template +class TWeakMesonDecayKl2: public Module +{ +public: + FERM_TYPE_ALIASES(FImpl,); + typedef typename SpinMatrixField::vector_object::scalar_object SpinMatrix; + class Result: Serializable + { + public: + GRID_SERIALIZABLE_CLASS_MEMBERS(Result, + std::vector, corr); + }; +public: + // constructor + TWeakMesonDecayKl2(const std::string name); + // destructor + virtual ~TWeakMesonDecayKl2(void) {}; + // dependencies/products + virtual std::vector getInput(void); + virtual std::vector getOutput(void); +protected: + // execution + virtual void setup(void); + // execution + virtual void execute(void); +}; + +MODULE_REGISTER_TMP(WeakMesonDecayKl2, TWeakMesonDecayKl2, MContraction); + +/****************************************************************************** + * TWeakMesonDecayKl2 implementation * + ******************************************************************************/ +// constructor ///////////////////////////////////////////////////////////////// +template +TWeakMesonDecayKl2::TWeakMesonDecayKl2(const std::string name) +: Module(name) +{} + +// dependencies/products /////////////////////////////////////////////////////// +template +std::vector TWeakMesonDecayKl2::getInput(void) +{ + std::vector input = {par().q1, par().q2, par().lepton}; + + return input; +} + +template +std::vector TWeakMesonDecayKl2::getOutput(void) +{ + std::vector output = {}; + + return output; +} + +// setup //////////////////////////////////////////////////////////////////////// +template +void TWeakMesonDecayKl2::setup(void) +{ + envTmpLat(ComplexField, "c"); + envTmpLat(PropagatorField, "prop_buf"); + envCreateLat(PropagatorField, getName()); + envTmpLat(SpinMatrixField, "buf"); +} + +// execution /////////////////////////////////////////////////////////////////// +template +void TWeakMesonDecayKl2::execute(void) +{ + LOG(Message) << "Computing QED Kl2 contractions '" << getName() << "' using" + << " quarks '" << par().q1 << "' and '" << par().q2 << "' and" + << "lepton '" << par().lepton << "'" << std::endl; + + Gamma g5(Gamma::Algebra::Gamma5); + int nt = env().getDim(Tp); + std::vector res_summed; + Result r; + + auto &res = envGet(PropagatorField, getName()); res = zero; + auto &q1 = envGet(PropagatorField, par().q1); + auto &q2 = envGet(PropagatorField, par().q2); + auto &lepton = envGet(PropagatorField, par().lepton); + envGetTmp(SpinMatrixField, buf); + envGetTmp(ComplexField, c); + envGetTmp(PropagatorField, prop_buf); + + for (unsigned int mu = 0; mu < 4; ++mu) + { + c = zero; + //hadronic part: trace(q1*adj(q2)*g5*gL[mu]) + c = trace(q1*adj(q2)*g5*GammaL(Gamma::gmu[mu])); + prop_buf = 1.; + //multiply lepton part + res += c * prop_buf * GammaL(Gamma::gmu[mu]) * lepton; + } + buf = peekColour(res, 0, 0); + sliceSum(buf, r.corr, Tp); + saveResult(par().output, "weakdecay", r); +} + +END_MODULE_NAMESPACE + +END_HADRONS_NAMESPACE + +#endif // Hadrons_MContraction_WeakMesonDecayKl2_hpp_ diff --git a/Hadrons/Modules/MContraction/WeakNonEye3pt.cc b/Hadrons/Modules/MContraction/WeakNonEye3pt.cc new file mode 100644 index 00000000..59ada976 --- /dev/null +++ b/Hadrons/Modules/MContraction/WeakNonEye3pt.cc @@ -0,0 +1,34 @@ +/************************************************************************************* + +Grid physics library, www.github.com/paboyle/Grid + +Source file: Hadrons/Modules/MContraction/WeakNonEye3pt.cc + +Copyright (C) 2015-2019 + +Author: Antonin Portelli + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License along +with this program; if not, write to the Free Software Foundation, Inc., +51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +See the full license in the file "LICENSE" in the top level distribution directory +*************************************************************************************/ +/* END LEGAL */ +#include + +using namespace Grid; +using namespace Hadrons; +using namespace MContraction; + +template class Grid::Hadrons::MContraction::TWeakNonEye3pt; diff --git a/Hadrons/Modules/MContraction/WeakNonEye3pt.hpp b/Hadrons/Modules/MContraction/WeakNonEye3pt.hpp new file mode 100644 index 00000000..08a1188b --- /dev/null +++ b/Hadrons/Modules/MContraction/WeakNonEye3pt.hpp @@ -0,0 +1,198 @@ +/************************************************************************************* + +Grid physics library, www.github.com/paboyle/Grid + +Source file: Hadrons/Modules/MContraction/WeakNonEye3pt.hpp + +Copyright (C) 2015-2019 + +Author: Antonin Portelli +Author: Lanny91 + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License along +with this program; if not, write to the Free Software Foundation, Inc., +51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +See the full license in the file "LICENSE" in the top level distribution directory +*************************************************************************************/ +/* END LEGAL */ +#ifndef Hadrons_MContraction_WeakNonEye3pt_hpp_ +#define Hadrons_MContraction_WeakNonEye3pt_hpp_ + +#include +#include +#include + +BEGIN_HADRONS_NAMESPACE + +/* + * Weak Hamiltonian meson 3-pt diagrams, non-eye topologies. + * + * Schematic: + * qbl qbr | qbl qbr + * /--<--¬ /--<--¬ | /--<--¬ /--<--¬ + * / \ / \ | / \ / \ + * / \ / \ | / \ / \ + * / \ / \ | / \ / \ + * gIn * * G * gOut | gIn * G * * G * gOut + * \ * G | | \ / \ / + * \ / \ / | \ / \ / + * \ / \ / | \ / \ / + * \ / \ / | \-->--/ \-->--/ + * \-->--/ \-->--/ | ql qr + * ql qr | + * one trace | two traces + * + * one trace : tr(ql*adj(gIn)*g5*adj(qbl)*g5*G*qbr*gOut*g5*adj(qr)*g5*G) + * two traces: tr(ql*adj(gIn)*g5*adj(qbl)*g5*G)*tr(qbr*gOut*g5*adj(qr)*g5*G) + * + */ + +BEGIN_MODULE_NAMESPACE(MContraction) + +class WeakNonEye3ptPar: Serializable +{ +public: + GRID_SERIALIZABLE_CLASS_MEMBERS(WeakNonEye3ptPar, + std::string, qLeft, + std::string, qBarLeft, + std::string, qRight, + std::string, qBarRight, + Gamma::Algebra, gammaIn, + Gamma::Algebra, gammaOut, + std::string, output); +}; + +template +class TWeakNonEye3pt: public Module +{ +public: + FERM_TYPE_ALIASES(FImpl,); + class Metadata: Serializable + { + public: + GRID_SERIALIZABLE_CLASS_MEMBERS(Metadata, + Gamma::Algebra, in, + Gamma::Algebra, out, + Gamma::Algebra, op, + unsigned int, trace); + }; + typedef Correlator Result; +public: + // constructor + TWeakNonEye3pt(const std::string name); + // destructor + virtual ~TWeakNonEye3pt(void) {}; + // dependency relation + virtual std::vector getInput(void); + virtual std::vector getOutput(void); + // setup + virtual void setup(void); + // execution + virtual void execute(void); +}; + +MODULE_REGISTER_TMP(WeakNonEye3pt, TWeakNonEye3pt, MContraction); + +/****************************************************************************** + * TWeakNonEye3pt implementation * + ******************************************************************************/ +// constructor ///////////////////////////////////////////////////////////////// +template +TWeakNonEye3pt::TWeakNonEye3pt(const std::string name) +: Module(name) +{} + +// dependencies/products /////////////////////////////////////////////////////// +template +std::vector TWeakNonEye3pt::getInput(void) +{ + std::vector in = {par().qLeft, par().qBarLeft, + par().qRight, par().qBarRight}; + + return in; +} + +template +std::vector TWeakNonEye3pt::getOutput(void) +{ + std::vector out = {}; + + return out; +} + +// setup /////////////////////////////////////////////////////////////////////// +template +void TWeakNonEye3pt::setup(void) +{ + envTmpLat(ComplexField, "corr"); +} + +// execution /////////////////////////////////////////////////////////////////// +template +void TWeakNonEye3pt::execute(void) +{ + LOG(Message) << "Computing mesonic weak 3pt contractions, non-eye topologies" << std::endl; + LOG(Message) << "gIn : " << par().gammaIn << std::endl; + LOG(Message) << "gOut: " << par().gammaIn << std::endl; + LOG(Message) << "ql : " << par().qLeft << std::endl; + LOG(Message) << "qbl : " << par().qBarLeft << std::endl; + LOG(Message) << "qr : " << par().qRight << std::endl; + LOG(Message) << "qbr : " << par().qBarRight << std::endl; + + std::vector result; + Result r; + auto &ql = envGet(PropagatorField, par().qLeft); + auto &qbl = envGet(PropagatorField, par().qBarLeft); + auto &qr = envGet(PropagatorField, par().qRight); + auto &qbr = envGet(PropagatorField, par().qBarRight); + Gamma gIn(par().gammaIn), gOut(par().gammaOut); + Gamma g5(Gamma::Algebra::Gamma5); + + envGetTmp(ComplexField, corr); + r.info.in = par().gammaIn; + r.info.out = par().gammaOut; + for (auto &G: Gamma::gall) + { + SlicedComplex buf; + + r.info.op = G.g; + // one trace + corr = trace(ql*adj(gIn)*g5*adj(qbl)*g5*G*qbr*gOut*g5*adj(qr)*g5*G); + sliceSum(corr, buf, Tp); + r.corr.clear(); + for (unsigned int t = 0; t < buf.size(); ++t) + { + r.corr.push_back(TensorRemove(buf[t])); + } + r.info.trace = 1; + result.push_back(r); + // two traces + corr = trace(ql*adj(gIn)*g5*adj(qbl)*g5*G)*trace(qbr*gOut*g5*adj(qr)*g5*G); + sliceSum(corr, buf, Tp); + r.corr.clear(); + for (unsigned int t = 0; t < buf.size(); ++t) + { + r.corr.push_back(TensorRemove(buf[t])); + } + r.info.trace = 2; + result.push_back(r); + } + saveResult(par().output, "weakNonEye3pt", result); +} + +END_MODULE_NAMESPACE + +END_HADRONS_NAMESPACE + +#endif // Hadrons_MContraction_WeakNonEye3pt_hpp_ diff --git a/Hadrons/Modules/MFermion/EMLepton.cc b/Hadrons/Modules/MFermion/EMLepton.cc new file mode 100644 index 00000000..891a6286 --- /dev/null +++ b/Hadrons/Modules/MFermion/EMLepton.cc @@ -0,0 +1,35 @@ +/************************************************************************************* + +Grid physics library, www.github.com/paboyle/Grid + +Source file: Hadrons/Modules/MFermion/EMLepton.cc + +Copyright (C) 2015-2019 + +Author: Vera Guelpers + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License along +with this program; if not, write to the Free Software Foundation, Inc., +51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +See the full license in the file "LICENSE" in the top level distribution directory +*************************************************************************************/ +/* END LEGAL */ +#include + +using namespace Grid; +using namespace Hadrons; +using namespace MFermion; + +template class Grid::Hadrons::MFermion::TEMLepton; + diff --git a/Hadrons/Modules/MFermion/EMLepton.hpp b/Hadrons/Modules/MFermion/EMLepton.hpp new file mode 100644 index 00000000..3fe544d3 --- /dev/null +++ b/Hadrons/Modules/MFermion/EMLepton.hpp @@ -0,0 +1,315 @@ +/************************************************************************************* + +Grid physics library, www.github.com/paboyle/Grid + +Source file: Hadrons/Modules/MFermion/EMLepton.hpp + +Copyright (C) 2015-2019 + +Author: Vera Guelpers + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License along +with this program; if not, write to the Free Software Foundation, Inc., +51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +See the full license in the file "LICENSE" in the top level distribution directory +*************************************************************************************/ +/* END LEGAL */ + + +#ifndef Hadrons_MFermion_EMLepton_hpp_ +#define Hadrons_MFermion_EMLepton_hpp_ + +#include +#include +#include + +BEGIN_HADRONS_NAMESPACE + +/******************************************************************************* +* +* Calculates a free lepton propagator with a sequential insertion of +* i*\gamma_mu A_mu with a photon field A_mu +* +* L(x) = \sum_y S(x,y) i*\gamma_mu*A_mu S(y,xl) \delta_{(tl-x0),dt} +* +* with a wall source for the lepton at tl +* +* In addition outputs the propagator without photon vertex +* +* L^{free}(x) = S(x,xl) \delta_{(tl-x0),dt} +* +* +* options: +* - action: fermion action used for propagator (string) +* - emField: photon field A_mu (string) +* - mass: input mass for the lepton propagator +* - boundary: boundary conditions for the lepton propagator, e.g. "1 1 1 -1" +* - twist: twisted boundary for lepton propagator, e.g. "0.0 0.0 0.0 0.5" +* - deltat: list of source-sink separations +* +*******************************************************************************/ + + +/****************************************************************************** + * EMLepton * + ******************************************************************************/ +BEGIN_MODULE_NAMESPACE(MFermion) + +class EMLeptonPar: Serializable +{ +public: + GRID_SERIALIZABLE_CLASS_MEMBERS(EMLeptonPar, + std::string, action, + std::string, emField, + double, mass, + std::string , boundary, + std::string, twist, + std::vector, deltat); +}; + +template +class TEMLepton: public Module +{ +public: + FERM_TYPE_ALIASES(FImpl,); +public: + typedef PhotonR::GaugeField EmField; +public: + // constructor + TEMLepton(const std::string name); + // destructor + virtual ~TEMLepton(void) {}; + // dependency relation + virtual std::vector getInput(void); + virtual std::vector getOutput(void); +protected: + // setup + virtual void setup(void); + // execution + virtual void execute(void); +private: + unsigned int Ls_; +}; + +MODULE_REGISTER_TMP(EMLepton, TEMLepton, MFermion); + +/****************************************************************************** + * TEMLepton implementation * + ******************************************************************************/ +// constructor ///////////////////////////////////////////////////////////////// +template +TEMLepton::TEMLepton(const std::string name) +: Module(name) +{} + +// dependencies/products /////////////////////////////////////////////////////// +template +std::vector TEMLepton::getInput(void) +{ + std::vector in = {par().action, par().emField}; + + return in; +} + +template +std::vector TEMLepton::getOutput(void) +{ + std::vector out = {}; + for(int i=0; i +void TEMLepton::setup(void) +{ + Ls_ = env().getObjectLs(par().action); + for(int i=0; i>, "tlat",1, envGetGrid(LatticeComplex)); + +} + +// execution /////////////////////////////////////////////////////////////////// +template +void TEMLepton::execute(void) +{ + LOG(Message) << "Computing free fermion propagator '" << getName() << "'" + << std::endl; + + auto &mat = envGet(FMat, par().action); + RealD mass = par().mass; + Complex ci(0.0,1.0); + + envGetTmp(FermionField, source); + envGetTmp(FermionField, sol); + envGetTmp(FermionField, tmp); + LOG(Message) << "Calculating a lepton Propagator with sequential Aslash insertion with lepton mass " + << mass << " using the action '" << par().action + << "' for fixed source-sink separation of " << par().deltat << std::endl; + + envGetTmp(Lattice>, tlat); + LatticeCoordinate(tlat, Tp); + + + std::vector twist = strToVec(par().twist); + if(twist.size() != Nd) + { + HADRONS_ERROR(Size, "number of twist angles does not match number of dimensions"); + } + std::vector boundary = strToVec(par().boundary); + if(boundary.size() != Nd) + { + HADRONS_ERROR(Size, "number of boundary conditions does not match number of dimensions"); + } + + auto &stoch_photon = envGet(EmField, par().emField); + unsigned int nt = env().getDim(Tp); + + envGetTmp(PropagatorField, proptmp); + envGetTmp(PropagatorField, freetmp); + envGetTmp(PropagatorField, sourcetmp); + + std::vector position; + SitePropagator id; + id = 1.; + + unsigned int tl=0; + + //wallsource at tl + sourcetmp = 1.; + sourcetmp = where((tlat == tl), sourcetmp, 0.*sourcetmp); + + //free propagator from pt source + for (unsigned int s = 0; s < Ns; ++s) + { + LOG(Message) << "Calculation for spin= " << s << std::endl; + if (Ls_ == 1) + { + PropToFerm(source, sourcetmp, s, 0); + } + else + { + PropToFerm(tmp, sourcetmp, s, 0); + // 5D source if action is 5d + mat.ImportPhysicalFermionSource(tmp, source); + } + sol = zero; + mat.FreePropagator(source,sol,mass,boundary,twist); + if (Ls_ == 1) + { + FermToProp(freetmp, sol, s, 0); + } + // create 4D propagators from 5D one if necessary + if (Ls_ > 1) + { + mat.ExportPhysicalFermionSolution(sol, tmp); + FermToProp(freetmp, tmp, s, 0); + } + } + + for(unsigned int dt=0;dt= nt-par().deltat[dt], boundary[Tp]*lep, lep); + } + + for(tl=0;tl(stoch_photon, mu) * (gmu * proptmp ); + } + + proptmp = zero; + + //sequential propagator from i*Aslash*S + LOG(Message) << "Sequential propagator for t= " << tl << std::endl; + for (unsigned int s = 0; s < Ns; ++s) + { + LOG(Message) << "Calculation for spin= " << s << std::endl; + if (Ls_ == 1) + { + PropToFerm(source, sourcetmp, s, 0); + } + else + { + PropToFerm(tmp, sourcetmp, s, 0); + // 5D source if action is 5d + mat.ImportPhysicalFermionSource(tmp, source); + } + sol = zero; + mat.FreePropagator(source,sol,mass,boundary,twist); + if (Ls_ == 1) + { + FermToProp(proptmp, sol, s, 0); + } + // create 4D propagators from 5D one if necessary + if (Ls_ > 1) + { + mat.ExportPhysicalFermionSolution(sol, tmp); + FermToProp(proptmp, tmp, s, 0); + } + } + // keep the result for the desired delta t + for(unsigned int dt=0;dt= nt-par().deltat[dt], boundary[Tp]*Aslashlep, Aslashlep); + } +} + +END_MODULE_NAMESPACE + +END_HADRONS_NAMESPACE + +#endif // Hadrons_MFermion_EMLepton_hpp_ diff --git a/Hadrons/Modules/MFermion/FreeProp.cc b/Hadrons/Modules/MFermion/FreeProp.cc index 1256f19c..e35afd2d 100644 --- a/Hadrons/Modules/MFermion/FreeProp.cc +++ b/Hadrons/Modules/MFermion/FreeProp.cc @@ -4,7 +4,7 @@ Grid physics library, www.github.com/paboyle/Grid Source file: Hadrons/Modules/MFermion/FreeProp.cc -Copyright (C) 2015-2018 +Copyright (C) 2015-2019 Author: Antonin Portelli Author: Vera Guelpers diff --git a/Hadrons/Modules/MFermion/FreeProp.hpp b/Hadrons/Modules/MFermion/FreeProp.hpp index eb7971f5..dcf77802 100644 --- a/Hadrons/Modules/MFermion/FreeProp.hpp +++ b/Hadrons/Modules/MFermion/FreeProp.hpp @@ -4,7 +4,7 @@ Grid physics library, www.github.com/paboyle/Grid Source file: Hadrons/Modules/MFermion/FreeProp.hpp -Copyright (C) 2015-2018 +Copyright (C) 2015-2019 Author: Antonin Portelli Author: Vera Guelpers @@ -49,6 +49,7 @@ public: std::string, source, std::string, action, double, mass, + std::string , boundary, std::string, twist); }; @@ -168,8 +169,16 @@ void TFreeProp::execute(void) } sol = Zero(); std::vector twist = strToVec(par().twist); - if(twist.size() != Nd) HADRONS_ERROR(Size, "number of twist angles does not match number of dimensions"); - mat.FreePropagator(source,sol,mass,twist); + if(twist.size() != Nd) + { + HADRONS_ERROR(Size, "number of twist angles does not match number of dimensions"); + } + std::vector boundary = strToVec(par().boundary); + if(boundary.size() != Nd) + { + HADRONS_ERROR(Size, "number of boundary conditions does not match number of dimensions"); + } + mat.FreePropagator(source,sol,mass,boundary,twist); FermToProp(prop, sol, s, c); // create 4D propagators from 5D one if necessary if (Ls_ > 1) diff --git a/Hadrons/Modules/MFermion/GaugeProp.cc b/Hadrons/Modules/MFermion/GaugeProp.cc index f3881e0f..23291714 100644 --- a/Hadrons/Modules/MFermion/GaugeProp.cc +++ b/Hadrons/Modules/MFermion/GaugeProp.cc @@ -4,7 +4,7 @@ Grid physics library, www.github.com/paboyle/Grid Source file: Hadrons/Modules/MFermion/GaugeProp.cc -Copyright (C) 2015-2018 +Copyright (C) 2015-2019 Author: Antonin Portelli diff --git a/Hadrons/Modules/MFermion/GaugeProp.hpp b/Hadrons/Modules/MFermion/GaugeProp.hpp index 90554607..a11274e6 100644 --- a/Hadrons/Modules/MFermion/GaugeProp.hpp +++ b/Hadrons/Modules/MFermion/GaugeProp.hpp @@ -4,7 +4,7 @@ Grid physics library, www.github.com/paboyle/Grid Source file: Hadrons/Modules/MFermion/GaugeProp.hpp -Copyright (C) 2015-2018 +Copyright (C) 2015-2019 Author: Antonin Portelli Author: Guido Cossu @@ -111,13 +111,18 @@ void TGaugeProp::setup(void) { Ls_ = env().getObjectLs(par().solver); envCreateLat(PropagatorField, getName()); - envTmpLat(FermionField, "source", Ls_); - envTmpLat(FermionField, "sol", Ls_); envTmpLat(FermionField, "tmp"); if (Ls_ > 1) { + envTmpLat(FermionField, "source", Ls_); + envTmpLat(FermionField, "sol", Ls_); envCreateLat(PropagatorField, getName() + "_5d", Ls_); } + else + { + envTmpLat(FermionField, "source"); + envTmpLat(FermionField, "sol"); + } } // execution /////////////////////////////////////////////////////////////////// diff --git a/Hadrons/Modules/MGauge/Electrify.cc b/Hadrons/Modules/MGauge/Electrify.cc index 1feea9ec..1ad98ab2 100644 --- a/Hadrons/Modules/MGauge/Electrify.cc +++ b/Hadrons/Modules/MGauge/Electrify.cc @@ -4,9 +4,11 @@ Grid physics library, www.github.com/paboyle/Grid Source file: Hadrons/Modules/MGauge/Electrify.cc -Copyright (C) 2015-2018 +Copyright (C) 2015-2019 +Author: Antonin Portelli Author: Vera Guelpers +Author: Vera Guelpers This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by diff --git a/Hadrons/Modules/MGauge/Electrify.hpp b/Hadrons/Modules/MGauge/Electrify.hpp index 58d65eba..4f34eef3 100644 --- a/Hadrons/Modules/MGauge/Electrify.hpp +++ b/Hadrons/Modules/MGauge/Electrify.hpp @@ -4,9 +4,11 @@ Grid physics library, www.github.com/paboyle/Grid Source file: Hadrons/Modules/MGauge/Electrify.hpp -Copyright (C) 2015-2018 +Copyright (C) 2015-2019 +Author: Antonin Portelli Author: Vera Guelpers +Author: Vera Guelpers This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by diff --git a/Hadrons/Modules/MGauge/FundtoHirep.cc b/Hadrons/Modules/MGauge/FundtoHirep.cc index 11b4aed5..f5b1385f 100644 --- a/Hadrons/Modules/MGauge/FundtoHirep.cc +++ b/Hadrons/Modules/MGauge/FundtoHirep.cc @@ -4,7 +4,7 @@ Grid physics library, www.github.com/paboyle/Grid Source file: Hadrons/Modules/MGauge/FundtoHirep.cc -Copyright (C) 2015-2018 +Copyright (C) 2015-2019 Author: Antonin Portelli Author: Guido Cossu diff --git a/Hadrons/Modules/MGauge/FundtoHirep.hpp b/Hadrons/Modules/MGauge/FundtoHirep.hpp index 893383d2..345520f4 100644 --- a/Hadrons/Modules/MGauge/FundtoHirep.hpp +++ b/Hadrons/Modules/MGauge/FundtoHirep.hpp @@ -4,7 +4,7 @@ Grid physics library, www.github.com/paboyle/Grid Source file: Hadrons/Modules/MGauge/FundtoHirep.hpp -Copyright (C) 2015-2018 +Copyright (C) 2015-2019 Author: Antonin Portelli Author: pretidav diff --git a/Hadrons/Modules/MGauge/GaugeFix.cc b/Hadrons/Modules/MGauge/GaugeFix.cc index 53aa16da..3a90ec36 100644 --- a/Hadrons/Modules/MGauge/GaugeFix.cc +++ b/Hadrons/Modules/MGauge/GaugeFix.cc @@ -4,7 +4,7 @@ Grid physics library, www.github.com/paboyle/Grid Source file: Hadrons/Modules/MGauge/GaugeFix.cc -Copyright (C) 2015-2018 +Copyright (C) 2015-2019 Author: Antonin Portelli Author: Peter Boyle diff --git a/Hadrons/Modules/MGauge/GaugeFix.hpp b/Hadrons/Modules/MGauge/GaugeFix.hpp index ece8c19d..f5ebb39f 100644 --- a/Hadrons/Modules/MGauge/GaugeFix.hpp +++ b/Hadrons/Modules/MGauge/GaugeFix.hpp @@ -4,9 +4,10 @@ Grid physics library, www.github.com/paboyle/Grid Source file: Hadrons/Modules/MGauge/GaugeFix.hpp -Copyright (C) 2015-2018 +Copyright (C) 2015-2019 Author: Antonin Portelli +Author: Nils Asmussen Author: Peter Boyle This program is free software; you can redistribute it and/or modify @@ -41,6 +42,8 @@ BEGIN_HADRONS_NAMESPACE ******************************************************************************/ BEGIN_MODULE_NAMESPACE(MGauge) +GRID_SERIALIZABLE_ENUM(Fix, undef, coulomb, Nd - 1, landau, -1); + class GaugeFixPar: Serializable { public: @@ -50,6 +53,7 @@ public: int, maxiter, Real, Omega_tol, Real, Phi_tol, + Fix, gaugeFix, bool, Fourier); }; @@ -58,6 +62,7 @@ class TGaugeFix: public Module { public: GAUGE_TYPE_ALIASES(GImpl,); + typedef typename GImpl::GaugeLinkField GaugeMat; public: // constructor TGaugeFix(const std::string name); @@ -94,7 +99,7 @@ std::vector TGaugeFix::getInput(void) template std::vector TGaugeFix::getOutput(void) { - std::vector out = {getName()}; + std::vector out = {getName(), getName()+"_xform"}; return out; } @@ -103,6 +108,7 @@ template void TGaugeFix::setup(void) { envCreateLat(GaugeField, getName()); + envCreateLat(GaugeMat, getName()+"_xform"); } @@ -112,19 +118,21 @@ void TGaugeFix::execute(void) //Loads the gauge and fixes it { std::cout << "executing" << std::endl; - LOG(Message) << "Fixing the Gauge" << std::endl; - LOG(Message) << par().gauge << std::endl; + LOG(Message) << "Fixing the Gauge " << par().gauge << " using " + << par().gaugeFix << " guage fixing. " << Nd - 1 << std::endl; auto &U = envGet(GaugeField, par().gauge); auto &Umu = envGet(GaugeField, getName()); + auto &xform = envGet(GaugeMat, getName()+"_xform"); LOG(Message) << "Gauge Field fetched" << std::endl; //do we allow maxiter etc to be user set? Real alpha = par().alpha; int maxiter = par().maxiter; Real Omega_tol = par().Omega_tol; Real Phi_tol = par().Phi_tol; + int gaugeFix = par().gaugeFix; bool Fourier = par().Fourier; - FourierAcceleratedGaugeFixer::SteepestDescentGaugeFix(U,alpha,maxiter,Omega_tol,Phi_tol,Fourier); Umu = U; + FourierAcceleratedGaugeFixer::SteepestDescentGaugeFix(Umu,xform,alpha,maxiter,Omega_tol,Phi_tol,Fourier,gaugeFix); LOG(Message) << "Gauge Fixed" << std::endl; } diff --git a/Hadrons/Modules/MGauge/Random.cc b/Hadrons/Modules/MGauge/Random.cc index 040cd91a..b5fa4b94 100644 --- a/Hadrons/Modules/MGauge/Random.cc +++ b/Hadrons/Modules/MGauge/Random.cc @@ -4,7 +4,7 @@ Grid physics library, www.github.com/paboyle/Grid Source file: Hadrons/Modules/MGauge/Random.cc -Copyright (C) 2015-2018 +Copyright (C) 2015-2019 Author: Antonin Portelli diff --git a/Hadrons/Modules/MGauge/Random.hpp b/Hadrons/Modules/MGauge/Random.hpp index 84b8dba0..358e3b79 100644 --- a/Hadrons/Modules/MGauge/Random.hpp +++ b/Hadrons/Modules/MGauge/Random.hpp @@ -4,7 +4,7 @@ Grid physics library, www.github.com/paboyle/Grid Source file: Hadrons/Modules/MGauge/Random.hpp -Copyright (C) 2015-2018 +Copyright (C) 2015-2019 Author: Antonin Portelli diff --git a/Hadrons/Modules/MGauge/StochEm.cc b/Hadrons/Modules/MGauge/StochEm.cc index 574387e4..3b718c9f 100644 --- a/Hadrons/Modules/MGauge/StochEm.cc +++ b/Hadrons/Modules/MGauge/StochEm.cc @@ -4,7 +4,7 @@ Grid physics library, www.github.com/paboyle/Grid Source file: Hadrons/Modules/MGauge/StochEm.cc -Copyright (C) 2015-2018 +Copyright (C) 2015-2019 Author: Antonin Portelli Author: James Harrison diff --git a/Hadrons/Modules/MGauge/StochEm.hpp b/Hadrons/Modules/MGauge/StochEm.hpp index b549387b..2b521b17 100644 --- a/Hadrons/Modules/MGauge/StochEm.hpp +++ b/Hadrons/Modules/MGauge/StochEm.hpp @@ -4,7 +4,7 @@ Grid physics library, www.github.com/paboyle/Grid Source file: Hadrons/Modules/MGauge/StochEm.hpp -Copyright (C) 2015-2018 +Copyright (C) 2015-2019 Author: Antonin Portelli Author: James Harrison diff --git a/Hadrons/Modules/MGauge/StoutSmearing.cc b/Hadrons/Modules/MGauge/StoutSmearing.cc index e7fb43d1..a17efb39 100644 --- a/Hadrons/Modules/MGauge/StoutSmearing.cc +++ b/Hadrons/Modules/MGauge/StoutSmearing.cc @@ -4,7 +4,7 @@ Grid physics library, www.github.com/paboyle/Grid Source file: Hadrons/Modules/MGauge/StoutSmearing.cc -Copyright (C) 2015-2018 +Copyright (C) 2015-2019 Author: Antonin Portelli diff --git a/Hadrons/Modules/MGauge/StoutSmearing.hpp b/Hadrons/Modules/MGauge/StoutSmearing.hpp index 973ac38d..661e0944 100644 --- a/Hadrons/Modules/MGauge/StoutSmearing.hpp +++ b/Hadrons/Modules/MGauge/StoutSmearing.hpp @@ -4,7 +4,7 @@ Grid physics library, www.github.com/paboyle/Grid Source file: Hadrons/Modules/MGauge/StoutSmearing.hpp -Copyright (C) 2015-2018 +Copyright (C) 2015-2019 Author: Antonin Portelli diff --git a/Hadrons/Modules/MGauge/Unit.cc b/Hadrons/Modules/MGauge/Unit.cc index 02ad7c0b..087132b5 100644 --- a/Hadrons/Modules/MGauge/Unit.cc +++ b/Hadrons/Modules/MGauge/Unit.cc @@ -4,7 +4,7 @@ Grid physics library, www.github.com/paboyle/Grid Source file: Hadrons/Modules/MGauge/Unit.cc -Copyright (C) 2015-2018 +Copyright (C) 2015-2019 Author: Antonin Portelli diff --git a/Hadrons/Modules/MGauge/Unit.hpp b/Hadrons/Modules/MGauge/Unit.hpp index f123f25b..ff0d116d 100644 --- a/Hadrons/Modules/MGauge/Unit.hpp +++ b/Hadrons/Modules/MGauge/Unit.hpp @@ -4,7 +4,7 @@ Grid physics library, www.github.com/paboyle/Grid Source file: Hadrons/Modules/MGauge/Unit.hpp -Copyright (C) 2015-2018 +Copyright (C) 2015-2019 Author: Antonin Portelli diff --git a/Hadrons/Modules/MGauge/UnitEm.cc b/Hadrons/Modules/MGauge/UnitEm.cc index 97da8224..d551e0fe 100644 --- a/Hadrons/Modules/MGauge/UnitEm.cc +++ b/Hadrons/Modules/MGauge/UnitEm.cc @@ -4,7 +4,7 @@ Grid physics library, www.github.com/paboyle/Grid Source file: Hadrons/Modules/MGauge/UnitEm.cc -Copyright (C) 2015-2018 +Copyright (C) 2015-2019 Author: Antonin Portelli Author: James Harrison diff --git a/Hadrons/Modules/MGauge/UnitEm.hpp b/Hadrons/Modules/MGauge/UnitEm.hpp index 725147b1..3277f211 100644 --- a/Hadrons/Modules/MGauge/UnitEm.hpp +++ b/Hadrons/Modules/MGauge/UnitEm.hpp @@ -4,7 +4,7 @@ Grid physics library, www.github.com/paboyle/Grid Source file: Hadrons/Modules/MGauge/UnitEm.hpp -Copyright (C) 2015-2018 +Copyright (C) 2015-2019 Author: Antonin Portelli Author: James Harrison diff --git a/Hadrons/Modules/MIO/LoadA2AVectors.cc b/Hadrons/Modules/MIO/LoadA2AVectors.cc index 7a40a6f5..ba1df2ad 100644 --- a/Hadrons/Modules/MIO/LoadA2AVectors.cc +++ b/Hadrons/Modules/MIO/LoadA2AVectors.cc @@ -4,7 +4,7 @@ Grid physics library, www.github.com/paboyle/Grid Source file: Hadrons/Modules/MIO/LoadA2AVectors.cc -Copyright (C) 2015-2018 +Copyright (C) 2015-2019 Author: Antonin Portelli diff --git a/Hadrons/Modules/MIO/LoadA2AVectors.hpp b/Hadrons/Modules/MIO/LoadA2AVectors.hpp index 5b194c16..997fc107 100644 --- a/Hadrons/Modules/MIO/LoadA2AVectors.hpp +++ b/Hadrons/Modules/MIO/LoadA2AVectors.hpp @@ -4,7 +4,7 @@ Grid physics library, www.github.com/paboyle/Grid Source file: Hadrons/Modules/MIO/LoadA2AVectors.hpp -Copyright (C) 2015-2018 +Copyright (C) 2015-2019 Author: Antonin Portelli diff --git a/Hadrons/Modules/MIO/LoadBinary.cc b/Hadrons/Modules/MIO/LoadBinary.cc index 3f1f4fba..48a909e2 100644 --- a/Hadrons/Modules/MIO/LoadBinary.cc +++ b/Hadrons/Modules/MIO/LoadBinary.cc @@ -4,7 +4,7 @@ Grid physics library, www.github.com/paboyle/Grid Source file: Hadrons/Modules/MIO/LoadBinary.cc -Copyright (C) 2015-2018 +Copyright (C) 2015-2019 Author: Antonin Portelli diff --git a/Hadrons/Modules/MIO/LoadBinary.hpp b/Hadrons/Modules/MIO/LoadBinary.hpp index ec5539b4..48dfccdc 100644 --- a/Hadrons/Modules/MIO/LoadBinary.hpp +++ b/Hadrons/Modules/MIO/LoadBinary.hpp @@ -4,7 +4,7 @@ Grid physics library, www.github.com/paboyle/Grid Source file: Hadrons/Modules/MIO/LoadBinary.hpp -Copyright (C) 2015-2018 +Copyright (C) 2015-2019 Author: Antonin Portelli diff --git a/Hadrons/Modules/MIO/LoadCoarseEigenPack.cc b/Hadrons/Modules/MIO/LoadCoarseEigenPack.cc index ac8f2c4a..22bc55a6 100644 --- a/Hadrons/Modules/MIO/LoadCoarseEigenPack.cc +++ b/Hadrons/Modules/MIO/LoadCoarseEigenPack.cc @@ -4,7 +4,7 @@ Grid physics library, www.github.com/paboyle/Grid Source file: Hadrons/Modules/MIO/LoadCoarseEigenPack.cc -Copyright (C) 2015-2018 +Copyright (C) 2015-2019 Author: Antonin Portelli @@ -32,4 +32,6 @@ using namespace Hadrons; using namespace MIO; template class Grid::Hadrons::MIO::TLoadCoarseEigenPack>; - +#ifdef GRID_DEFAULT_PRECISION_DOUBLE +template class Grid::Hadrons::MIO::TLoadCoarseEigenPack>; +#endif diff --git a/Hadrons/Modules/MIO/LoadCoarseEigenPack.hpp b/Hadrons/Modules/MIO/LoadCoarseEigenPack.hpp index 94c1ff40..521b4814 100644 --- a/Hadrons/Modules/MIO/LoadCoarseEigenPack.hpp +++ b/Hadrons/Modules/MIO/LoadCoarseEigenPack.hpp @@ -4,7 +4,7 @@ Grid physics library, www.github.com/paboyle/Grid Source file: Hadrons/Modules/MIO/LoadCoarseEigenPack.hpp -Copyright (C) 2015-2018 +Copyright (C) 2015-2019 Author: Antonin Portelli @@ -56,7 +56,11 @@ template class TLoadCoarseEigenPack: public Module { public: - typedef CoarseEigenPack BasePack; + typedef typename Pack::Field Field; + typedef typename Pack::FieldIo FieldIo; + typedef typename Pack::CoarseField CoarseField; + typedef typename Pack::CoarseFieldIo CoarseFieldIo; + typedef CoarseEigenPack BasePack; template using iImplScalar = iScalar>>; typedef iImplScalar SiteComplex; @@ -74,7 +78,12 @@ public: virtual void execute(void); }; -MODULE_REGISTER_TMP(LoadCoarseFermionEigenPack, ARG(TLoadCoarseEigenPack>), MIO); +MODULE_REGISTER_TMP(LoadCoarseFermionEigenPack, + ARG(TLoadCoarseEigenPack>), MIO); +#ifdef GRID_DEFAULT_PRECISION_DOUBLE +MODULE_REGISTER_TMP(LoadCoarseFermionEigenPackIo32, + ARG(TLoadCoarseEigenPack>), MIO); +#endif /****************************************************************************** * TLoadCoarseEigenPack implementation * @@ -106,18 +115,27 @@ std::vector TLoadCoarseEigenPack::getOutput(void) template void TLoadCoarseEigenPack::setup(void) { - env().createGrid(par().Ls); - env().createCoarseGrid(par().blockSize, par().Ls); + GridBase *gridIo = nullptr, *gridCoarseIo = nullptr; + + if (typeHash() != typeHash()) + { + gridIo = envGetRbGrid(FieldIo, par().Ls); + } + if (typeHash() != typeHash()) + { + gridCoarseIo = envGetCoarseGrid(CoarseFieldIo, par().blockSize, par().Ls); + } envCreateDerived(BasePack, Pack, getName(), par().Ls, par().sizeFine, - par().sizeCoarse, env().getRbGrid(par().Ls), - env().getCoarseGrid(par().blockSize, par().Ls)); + par().sizeCoarse, envGetRbGrid(Field, par().Ls), + envGetCoarseGrid(CoarseField, par().blockSize, par().Ls), + gridIo, gridCoarseIo); } // execution /////////////////////////////////////////////////////////////////// template void TLoadCoarseEigenPack::execute(void) { - auto cg = env().getCoarseGrid(par().blockSize, par().Ls); + auto cg = envGetCoarseGrid(CoarseField, par().blockSize, par().Ls); auto &epack = envGetDerived(BasePack, Pack, getName()); Lattice dummy(cg); diff --git a/Hadrons/Modules/MIO/LoadCosmHol.cc b/Hadrons/Modules/MIO/LoadCosmHol.cc index 9214165f..79dc6119 100644 --- a/Hadrons/Modules/MIO/LoadCosmHol.cc +++ b/Hadrons/Modules/MIO/LoadCosmHol.cc @@ -4,7 +4,7 @@ Grid physics library, www.github.com/paboyle/Grid Source file: Hadrons/Modules/MIO/LoadCosmHol.cc -Copyright (C) 2015-2018 +Copyright (C) 2015-2019 Author: Antonin Portelli diff --git a/Hadrons/Modules/MIO/LoadCosmHol.hpp b/Hadrons/Modules/MIO/LoadCosmHol.hpp index cd940309..a8faa608 100644 --- a/Hadrons/Modules/MIO/LoadCosmHol.hpp +++ b/Hadrons/Modules/MIO/LoadCosmHol.hpp @@ -4,7 +4,7 @@ Grid physics library, www.github.com/paboyle/Grid Source file: Hadrons/Modules/MIO/LoadCosmHol.hpp -Copyright (C) 2015-2018 +Copyright (C) 2015-2019 Author: Antonin Portelli diff --git a/Hadrons/Modules/MIO/LoadEigenPack.cc b/Hadrons/Modules/MIO/LoadEigenPack.cc index 28fdeb01..0750d265 100644 --- a/Hadrons/Modules/MIO/LoadEigenPack.cc +++ b/Hadrons/Modules/MIO/LoadEigenPack.cc @@ -4,7 +4,7 @@ Grid physics library, www.github.com/paboyle/Grid Source file: Hadrons/Modules/MIO/LoadEigenPack.cc -Copyright (C) 2015-2018 +Copyright (C) 2015-2019 Author: Antonin Portelli @@ -31,7 +31,7 @@ using namespace Grid; using namespace Hadrons; using namespace MIO; -template class Grid::Hadrons::MIO::TLoadEigenPack>; +template class Grid::Hadrons::MIO::TLoadEigenPack, GIMPL>; #ifdef GRID_DEFAULT_PRECISION_DOUBLE -template class Grid::Hadrons::MIO::TLoadEigenPack>; +template class Grid::Hadrons::MIO::TLoadEigenPack, GIMPL>; #endif diff --git a/Hadrons/Modules/MIO/LoadEigenPack.hpp b/Hadrons/Modules/MIO/LoadEigenPack.hpp index 016675c9..0d6036b8 100644 --- a/Hadrons/Modules/MIO/LoadEigenPack.hpp +++ b/Hadrons/Modules/MIO/LoadEigenPack.hpp @@ -4,7 +4,7 @@ Grid physics library, www.github.com/paboyle/Grid Source file: Hadrons/Modules/MIO/LoadEigenPack.hpp -Copyright (C) 2015-2018 +Copyright (C) 2015-2019 Author: Antonin Portelli @@ -47,16 +47,21 @@ public: std::string, filestem, bool, multiFile, unsigned int, size, - unsigned int, Ls); + unsigned int, Ls, + std::string, gaugeXform); }; -template +template class TLoadEigenPack: public Module { public: typedef typename Pack::Field Field; typedef typename Pack::FieldIo FieldIo; typedef BaseEigenPack BasePack; + +public: + GAUGE_TYPE_ALIASES(GImpl, ); + typedef typename GImpl::GaugeLinkField GaugeMat; public: // constructor TLoadEigenPack(const std::string name); @@ -71,31 +76,36 @@ public: virtual void execute(void); }; -MODULE_REGISTER_TMP(LoadFermionEigenPack, TLoadEigenPack>, MIO); +MODULE_REGISTER_TMP(LoadFermionEigenPack, ARG(TLoadEigenPack, GIMPL>), MIO); #ifdef GRID_DEFAULT_PRECISION_DOUBLE -MODULE_REGISTER_TMP(LoadFermionEigenPackIo32, ARG(TLoadEigenPack>), MIO); +MODULE_REGISTER_TMP(LoadFermionEigenPackIo32, ARG(TLoadEigenPack, GIMPL>), MIO); #endif /****************************************************************************** * TLoadEigenPack implementation * ******************************************************************************/ // constructor ///////////////////////////////////////////////////////////////// -template -TLoadEigenPack::TLoadEigenPack(const std::string name) +template +TLoadEigenPack::TLoadEigenPack(const std::string name) : Module(name) {} // dependencies/products /////////////////////////////////////////////////////// -template -std::vector TLoadEigenPack::getInput(void) +template +std::vector TLoadEigenPack::getInput(void) { std::vector in; + + if (!par().gaugeXform.empty()) + { + in = {par().gaugeXform}; + } return in; } -template -std::vector TLoadEigenPack::getOutput(void) +template +std::vector TLoadEigenPack::getOutput(void) { std::vector out = {getName()}; @@ -103,8 +113,8 @@ std::vector TLoadEigenPack::getOutput(void) } // setup /////////////////////////////////////////////////////////////////////// -template -void TLoadEigenPack::setup(void) +template +void TLoadEigenPack::setup(void) { GridBase *gridIo = nullptr; @@ -114,16 +124,64 @@ void TLoadEigenPack::setup(void) } envCreateDerived(BasePack, Pack, getName(), par().Ls, par().size, envGetRbGrid(Field, par().Ls), gridIo); + + if (!par().gaugeXform.empty()) + { + if (par().Ls > 1) + { + LOG(Message) << "Setup 5d GaugeMat for Ls = " << par().Ls << std::endl; + envTmp(GaugeMat, "tmpXform", par().Ls, envGetGrid5(Field, par().Ls)); + envTmp(GaugeMat, "tmpXformOdd", par().Ls, envGetRbGrid5(Field, par().Ls)); + } + else + { + LOG(Message) << "Setup 4d GaugeMat for Ls = " << par().Ls << std::endl; + envTmp(GaugeMat, "tmpXform", par().Ls, envGetGrid(Field)); + envTmp(GaugeMat, "tmpXformOdd", par().Ls, envGetRbGrid(Field)); + } + + } } // execution /////////////////////////////////////////////////////////////////// -template -void TLoadEigenPack::execute(void) +template +void TLoadEigenPack::execute(void) { auto &epack = envGetDerived(BasePack, Pack, getName()); epack.read(par().filestem, par().multiFile, vm().getTrajectory()); epack.eval.resize(par().size); + + if (!par().gaugeXform.empty()) + { + + LOG(Message) << "Applying gauge transformation to eigenvectors " << getName() + << " using " << par().gaugeXform << std::endl; + auto &xform = envGet(GaugeMat, par().gaugeXform); + envGetTmp(GaugeMat, tmpXform); + envGetTmp(GaugeMat, tmpXformOdd); + + if (par().Ls > 1) + { + LOG(Message) << "Creating 5d GaugeMat from " << par().gaugeXform << std::endl; + startTimer("5-d gauge transform creation"); + for (unsigned int j = 0; j < par().Ls; j++) + { + InsertSlice(xform, tmpXform, j, 0); + } + stopTimer("5-d gauge transform creation"); + } + + pickCheckerboard(Odd, tmpXformOdd, tmpXform); + startTimer("Transform application"); + for (unsigned int i = 0; i < par().size; i++) + { + LOG(Message) << "Applying gauge transformation to eigenvector i = " << i << "/" << par().size << std::endl; + epack.evec[i].checkerboard = Odd; + epack.evec[i] = tmpXformOdd * epack.evec[i]; + } + stopTimer("Transform application"); + } } END_MODULE_NAMESPACE diff --git a/Hadrons/Modules/MIO/LoadNersc.cc b/Hadrons/Modules/MIO/LoadNersc.cc index ce7276f9..c624ce31 100644 --- a/Hadrons/Modules/MIO/LoadNersc.cc +++ b/Hadrons/Modules/MIO/LoadNersc.cc @@ -4,7 +4,7 @@ Grid physics library, www.github.com/paboyle/Grid Source file: Hadrons/Modules/MIO/LoadNersc.cc -Copyright (C) 2015-2018 +Copyright (C) 2015-2019 Author: Antonin Portelli diff --git a/Hadrons/Modules/MIO/LoadNersc.hpp b/Hadrons/Modules/MIO/LoadNersc.hpp index c0e69511..facc2ecb 100644 --- a/Hadrons/Modules/MIO/LoadNersc.hpp +++ b/Hadrons/Modules/MIO/LoadNersc.hpp @@ -4,7 +4,7 @@ Grid physics library, www.github.com/paboyle/Grid Source file: Hadrons/Modules/MIO/LoadNersc.hpp -Copyright (C) 2015-2018 +Copyright (C) 2015-2019 Author: Antonin Portelli diff --git a/Hadrons/Modules/MNPR/Amputate.cc b/Hadrons/Modules/MNPR/Amputate.cc index ec7c5940..a8cb7eb6 100644 --- a/Hadrons/Modules/MNPR/Amputate.cc +++ b/Hadrons/Modules/MNPR/Amputate.cc @@ -4,7 +4,7 @@ Grid physics library, www.github.com/paboyle/Grid Source file: Hadrons/Modules/MNPR/Amputate.cc -Copyright (C) 2015-2018 +Copyright (C) 2015-2019 Author: Antonin Portelli Author: Peter Boyle diff --git a/Hadrons/Modules/MNPR/Amputate.hpp b/Hadrons/Modules/MNPR/Amputate.hpp index 93731bd6..88860d92 100644 --- a/Hadrons/Modules/MNPR/Amputate.hpp +++ b/Hadrons/Modules/MNPR/Amputate.hpp @@ -4,7 +4,7 @@ Grid physics library, www.github.com/paboyle/Grid Source file: Hadrons/Modules/MNPR/Amputate.hpp -Copyright (C) 2015-2018 +Copyright (C) 2015-2019 Author: Antonin Portelli Author: Julia Kettle J.R.Kettle-2@sms.ed.ac.uk diff --git a/Hadrons/Modules/MNPR/Bilinear.cc b/Hadrons/Modules/MNPR/Bilinear.cc index c5b38d37..82086d5a 100644 --- a/Hadrons/Modules/MNPR/Bilinear.cc +++ b/Hadrons/Modules/MNPR/Bilinear.cc @@ -4,7 +4,7 @@ Grid physics library, www.github.com/paboyle/Grid Source file: Hadrons/Modules/MNPR/Bilinear.cc -Copyright (C) 2015-2018 +Copyright (C) 2015-2019 Author: Antonin Portelli Author: Peter Boyle diff --git a/Hadrons/Modules/MNPR/Bilinear.hpp b/Hadrons/Modules/MNPR/Bilinear.hpp index e01837a6..444d42a0 100644 --- a/Hadrons/Modules/MNPR/Bilinear.hpp +++ b/Hadrons/Modules/MNPR/Bilinear.hpp @@ -4,7 +4,7 @@ Grid physics library, www.github.com/paboyle/Grid Source file: Hadrons/Modules/MNPR/Bilinear.hpp -Copyright (C) 2015-2018 +Copyright (C) 2015-2019 Author: Antonin Portelli Author: Julia Kettle J.R.Kettle-2@sms.ed.ac.uk diff --git a/Hadrons/Modules/MNPR/FourQuark.cc b/Hadrons/Modules/MNPR/FourQuark.cc index 1943c25b..20ed2d7d 100644 --- a/Hadrons/Modules/MNPR/FourQuark.cc +++ b/Hadrons/Modules/MNPR/FourQuark.cc @@ -4,7 +4,7 @@ Grid physics library, www.github.com/paboyle/Grid Source file: Hadrons/Modules/MNPR/FourQuark.cc -Copyright (C) 2015-2018 +Copyright (C) 2015-2019 Author: Antonin Portelli Author: Peter Boyle diff --git a/Hadrons/Modules/MNPR/FourQuark.hpp b/Hadrons/Modules/MNPR/FourQuark.hpp index 893a5f85..df8cbffe 100644 --- a/Hadrons/Modules/MNPR/FourQuark.hpp +++ b/Hadrons/Modules/MNPR/FourQuark.hpp @@ -4,7 +4,7 @@ Grid physics library, www.github.com/paboyle/Grid Source file: Hadrons/Modules/MNPR/FourQuark.hpp -Copyright (C) 2015-2018 +Copyright (C) 2015-2019 Author: Antonin Portelli Author: Julia Kettle J.R.Kettle-2@sms.ed.ac.uk diff --git a/Hadrons/Modules/MNoise/FullVolumeSpinColorDiagonal.cc b/Hadrons/Modules/MNoise/FullVolumeSpinColorDiagonal.cc index b909bf92..b58fdc9c 100644 --- a/Hadrons/Modules/MNoise/FullVolumeSpinColorDiagonal.cc +++ b/Hadrons/Modules/MNoise/FullVolumeSpinColorDiagonal.cc @@ -4,10 +4,11 @@ Grid physics library, www.github.com/paboyle/Grid Source file: Hadrons/Modules/MNoise/FullVolumeSpinColorDiagonal.cc -Copyright (C) 2015-2018 +Copyright (C) 2015-2019 Author: Antonin Portelli Author: Vera Guelpers +Author: Vera Guelpers This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by diff --git a/Hadrons/Modules/MNoise/FullVolumeSpinColorDiagonal.hpp b/Hadrons/Modules/MNoise/FullVolumeSpinColorDiagonal.hpp index 93990882..c7f3afa0 100644 --- a/Hadrons/Modules/MNoise/FullVolumeSpinColorDiagonal.hpp +++ b/Hadrons/Modules/MNoise/FullVolumeSpinColorDiagonal.hpp @@ -4,10 +4,11 @@ Grid physics library, www.github.com/paboyle/Grid Source file: Hadrons/Modules/MNoise/FullVolumeSpinColorDiagonal.hpp -Copyright (C) 2015-2018 +Copyright (C) 2015-2019 Author: Antonin Portelli Author: Vera Guelpers +Author: Vera Guelpers This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by diff --git a/Hadrons/Modules/MNoise/TimeDilutedSpinColorDiagonal.cc b/Hadrons/Modules/MNoise/TimeDilutedSpinColorDiagonal.cc index 52d2b62d..c680a44b 100644 --- a/Hadrons/Modules/MNoise/TimeDilutedSpinColorDiagonal.cc +++ b/Hadrons/Modules/MNoise/TimeDilutedSpinColorDiagonal.cc @@ -4,7 +4,7 @@ Grid physics library, www.github.com/paboyle/Grid Source file: Hadrons/Modules/MNoise/TimeDilutedSpinColorDiagonal.cc -Copyright (C) 2015-2018 +Copyright (C) 2015-2019 Author: Antonin Portelli diff --git a/Hadrons/Modules/MNoise/TimeDilutedSpinColorDiagonal.hpp b/Hadrons/Modules/MNoise/TimeDilutedSpinColorDiagonal.hpp index da634d6c..306efa10 100644 --- a/Hadrons/Modules/MNoise/TimeDilutedSpinColorDiagonal.hpp +++ b/Hadrons/Modules/MNoise/TimeDilutedSpinColorDiagonal.hpp @@ -4,7 +4,7 @@ Grid physics library, www.github.com/paboyle/Grid Source file: Hadrons/Modules/MNoise/TimeDilutedSpinColorDiagonal.hpp -Copyright (C) 2015-2018 +Copyright (C) 2015-2019 Author: Antonin Portelli diff --git a/Hadrons/Modules/MScalar/ChargedProp.cc b/Hadrons/Modules/MScalar/ChargedProp.cc index f56dfeda..cde5e3ba 100644 --- a/Hadrons/Modules/MScalar/ChargedProp.cc +++ b/Hadrons/Modules/MScalar/ChargedProp.cc @@ -4,7 +4,7 @@ Grid physics library, www.github.com/paboyle/Grid Source file: Hadrons/Modules/MScalar/ChargedProp.cc -Copyright (C) 2015-2018 +Copyright (C) 2015-2019 Author: Antonin Portelli Author: James Harrison diff --git a/Hadrons/Modules/MScalar/ChargedProp.hpp b/Hadrons/Modules/MScalar/ChargedProp.hpp index 443c38a6..ec7f641b 100644 --- a/Hadrons/Modules/MScalar/ChargedProp.hpp +++ b/Hadrons/Modules/MScalar/ChargedProp.hpp @@ -4,7 +4,7 @@ Grid physics library, www.github.com/paboyle/Grid Source file: Hadrons/Modules/MScalar/ChargedProp.hpp -Copyright (C) 2015-2018 +Copyright (C) 2015-2019 Author: Antonin Portelli Author: James Harrison diff --git a/Hadrons/Modules/MScalar/FreeProp.cc b/Hadrons/Modules/MScalar/FreeProp.cc index 4b25fbd0..cbae8219 100644 --- a/Hadrons/Modules/MScalar/FreeProp.cc +++ b/Hadrons/Modules/MScalar/FreeProp.cc @@ -4,7 +4,7 @@ Grid physics library, www.github.com/paboyle/Grid Source file: Hadrons/Modules/MScalar/FreeProp.cc -Copyright (C) 2015-2018 +Copyright (C) 2015-2019 Author: Antonin Portelli diff --git a/Hadrons/Modules/MScalar/FreeProp.hpp b/Hadrons/Modules/MScalar/FreeProp.hpp index 5ed6756d..68e8a8e6 100644 --- a/Hadrons/Modules/MScalar/FreeProp.hpp +++ b/Hadrons/Modules/MScalar/FreeProp.hpp @@ -4,7 +4,7 @@ Grid physics library, www.github.com/paboyle/Grid Source file: Hadrons/Modules/MScalar/FreeProp.hpp -Copyright (C) 2015-2018 +Copyright (C) 2015-2019 Author: Antonin Portelli diff --git a/Hadrons/Modules/MScalar/Scalar.hpp b/Hadrons/Modules/MScalar/Scalar.hpp index afdb1713..69ca47a7 100644 --- a/Hadrons/Modules/MScalar/Scalar.hpp +++ b/Hadrons/Modules/MScalar/Scalar.hpp @@ -4,7 +4,7 @@ Grid physics library, www.github.com/paboyle/Grid Source file: Hadrons/Modules/MScalar/Scalar.hpp -Copyright (C) 2015-2018 +Copyright (C) 2015-2019 Author: Antonin Portelli diff --git a/Hadrons/Modules/MScalarSUN/Div.cc b/Hadrons/Modules/MScalarSUN/Div.cc index c5d67579..9819a453 100644 --- a/Hadrons/Modules/MScalarSUN/Div.cc +++ b/Hadrons/Modules/MScalarSUN/Div.cc @@ -4,7 +4,7 @@ Grid physics library, www.github.com/paboyle/Grid Source file: Hadrons/Modules/MScalarSUN/Div.cc -Copyright (C) 2015-2018 +Copyright (C) 2015-2019 Author: Antonin Portelli diff --git a/Hadrons/Modules/MScalarSUN/Div.hpp b/Hadrons/Modules/MScalarSUN/Div.hpp index 9980d0f6..af68d696 100644 --- a/Hadrons/Modules/MScalarSUN/Div.hpp +++ b/Hadrons/Modules/MScalarSUN/Div.hpp @@ -4,7 +4,7 @@ Grid physics library, www.github.com/paboyle/Grid Source file: Hadrons/Modules/MScalarSUN/Div.hpp -Copyright (C) 2015-2018 +Copyright (C) 2015-2019 Author: Antonin Portelli diff --git a/Hadrons/Modules/MScalarSUN/EMT.cc b/Hadrons/Modules/MScalarSUN/EMT.cc index 08ba2a83..65859244 100644 --- a/Hadrons/Modules/MScalarSUN/EMT.cc +++ b/Hadrons/Modules/MScalarSUN/EMT.cc @@ -4,7 +4,7 @@ Grid physics library, www.github.com/paboyle/Grid Source file: Hadrons/Modules/MScalarSUN/EMT.cc -Copyright (C) 2015-2018 +Copyright (C) 2015-2019 Author: Antonin Portelli diff --git a/Hadrons/Modules/MScalarSUN/EMT.hpp b/Hadrons/Modules/MScalarSUN/EMT.hpp index c5fd10a5..bb6a5e7c 100644 --- a/Hadrons/Modules/MScalarSUN/EMT.hpp +++ b/Hadrons/Modules/MScalarSUN/EMT.hpp @@ -4,7 +4,7 @@ Grid physics library, www.github.com/paboyle/Grid Source file: Hadrons/Modules/MScalarSUN/EMT.hpp -Copyright (C) 2015-2018 +Copyright (C) 2015-2019 Author: Antonin Portelli diff --git a/Hadrons/Modules/MScalarSUN/Grad.cc b/Hadrons/Modules/MScalarSUN/Grad.cc index 15904af1..03160857 100644 --- a/Hadrons/Modules/MScalarSUN/Grad.cc +++ b/Hadrons/Modules/MScalarSUN/Grad.cc @@ -4,7 +4,7 @@ Grid physics library, www.github.com/paboyle/Grid Source file: Hadrons/Modules/MScalarSUN/Grad.cc -Copyright (C) 2015-2018 +Copyright (C) 2015-2019 Author: Antonin Portelli diff --git a/Hadrons/Modules/MScalarSUN/Grad.hpp b/Hadrons/Modules/MScalarSUN/Grad.hpp index 93a8ddda..a8b3911f 100644 --- a/Hadrons/Modules/MScalarSUN/Grad.hpp +++ b/Hadrons/Modules/MScalarSUN/Grad.hpp @@ -4,7 +4,7 @@ Grid physics library, www.github.com/paboyle/Grid Source file: Hadrons/Modules/MScalarSUN/Grad.hpp -Copyright (C) 2015-2018 +Copyright (C) 2015-2019 Author: Antonin Portelli diff --git a/Hadrons/Modules/MScalarSUN/ShiftProbe.hpp b/Hadrons/Modules/MScalarSUN/ShiftProbe.hpp deleted file mode 100644 index dcd56252..00000000 --- a/Hadrons/Modules/MScalarSUN/ShiftProbe.hpp +++ /dev/null @@ -1,177 +0,0 @@ -/************************************************************************************* - -Grid physics library, www.github.com/paboyle/Grid - -Source file: Hadrons/Modules/MScalarSUN/ShiftProbe.hpp - -Copyright (C) 2015-2018 - -Author: Antonin Portelli - -This program is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License along -with this program; if not, write to the Free Software Foundation, Inc., -51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - -See the full license in the file "LICENSE" in the top level distribution directory -*************************************************************************************/ -/* END LEGAL */ -#ifndef Hadrons_MScalarSUN_ShiftProbe_hpp_ -#define Hadrons_MScalarSUN_ShiftProbe_hpp_ - -#include -#include -#include -#include - -BEGIN_HADRONS_NAMESPACE - -/****************************************************************************** - * Ward identity phi^n probe with fields at different positions * - ******************************************************************************/ -BEGIN_MODULE_NAMESPACE(MScalarSUN) - -typedef std::pair ShiftPair; - -class ShiftProbePar: Serializable -{ -public: - GRID_SERIALIZABLE_CLASS_MEMBERS(ShiftProbePar, - std::string, field, - std::string, shifts, - std::string, output); -}; - -class ShiftProbeResult: Serializable -{ -public: - GRID_SERIALIZABLE_CLASS_MEMBERS(ShiftProbeResult, - std::string, shifts, - Complex, value); -}; - -template -class TShiftProbe: public Module -{ -public: - typedef typename SImpl::Field Field; - typedef typename SImpl::ComplexField ComplexField; -public: - // constructor - TShiftProbe(const std::string name); - // destructor - virtual ~TShiftProbe(void) {}; - // dependency relation - virtual std::vector getInput(void); - virtual std::vector getOutput(void); - // setup - virtual void setup(void); - // execution - virtual void execute(void); -}; - -MODULE_REGISTER_TMP(ShiftProbeSU2, TShiftProbe>, MScalarSUN); -MODULE_REGISTER_TMP(ShiftProbeSU3, TShiftProbe>, MScalarSUN); -MODULE_REGISTER_TMP(ShiftProbeSU4, TShiftProbe>, MScalarSUN); -MODULE_REGISTER_TMP(ShiftProbeSU5, TShiftProbe>, MScalarSUN); -MODULE_REGISTER_TMP(ShiftProbeSU6, TShiftProbe>, MScalarSUN); - -/****************************************************************************** - * TShiftProbe implementation * - ******************************************************************************/ -// constructor ///////////////////////////////////////////////////////////////// -template -TShiftProbe::TShiftProbe(const std::string name) -: Module(name) -{} - -// dependencies/products /////////////////////////////////////////////////////// -template -std::vector TShiftProbe::getInput(void) -{ - std::vector in = {par().field}; - - return in; -} - -template -std::vector TShiftProbe::getOutput(void) -{ - std::vector out = {getName()}; - - return out; -} - -// setup /////////////////////////////////////////////////////////////////////// -template -void TShiftProbe::setup(void) -{ - envTmpLat(Field, "acc"); - envCreateLat(ComplexField, getName()); -} - -// execution /////////////////////////////////////////////////////////////////// -template -void TShiftProbe::execute(void) -{ - LOG(Message) << "Creating shift probe for shifts " << par().shifts - << std::endl; - - std::vector shift; - double sign; - auto &phi = envGet(Field, par().field); - auto &probe = envGet(ComplexField, getName()); - - shift = strToVec(par().shifts); - if (shift.size() % 2 != 0) - { - HADRONS_ERROR(Size, "the number of shifts is odd"); - } - sign = (shift.size() % 4 == 0) ? 1. : -1.; - for (auto &s: shift) - { - if (s.first >= env().getNd()) - { - HADRONS_ERROR(Size, "dimension to large for shift <" - + std::to_string(s.first) + " " - + std::to_string(s.second) + ">" ); - } - } - envGetTmp(Field, acc); - acc = 1.; - for (unsigned int i = 0; i < shift.size(); ++i) - { - if (shift[i].second == 0) - { - acc *= phi; - } - else - { - acc *= Cshift(phi, shift[i].first, shift[i].second); - } - } - probe = sign*trace(acc); - if (!par().output.empty()) - { - ShiftProbeResult r; - - r.shifts = par().shifts; - r.value = TensorRemove(sum(probe)); - saveResult(par().output, "probe", r); - } -} - -END_MODULE_NAMESPACE - -END_HADRONS_NAMESPACE - -#endif // Hadrons_MScalarSUN_ShiftProbe_hpp_ diff --git a/Hadrons/Modules/MScalarSUN/StochFreeField.cc b/Hadrons/Modules/MScalarSUN/StochFreeField.cc index 70e8356d..7166d179 100644 --- a/Hadrons/Modules/MScalarSUN/StochFreeField.cc +++ b/Hadrons/Modules/MScalarSUN/StochFreeField.cc @@ -4,7 +4,7 @@ Grid physics library, www.github.com/paboyle/Grid Source file: Hadrons/Modules/MScalarSUN/StochFreeField.cc -Copyright (C) 2015-2018 +Copyright (C) 2015-2019 Author: Antonin Portelli diff --git a/Hadrons/Modules/MScalarSUN/StochFreeField.hpp b/Hadrons/Modules/MScalarSUN/StochFreeField.hpp index 5ab260d3..a66f010c 100644 --- a/Hadrons/Modules/MScalarSUN/StochFreeField.hpp +++ b/Hadrons/Modules/MScalarSUN/StochFreeField.hpp @@ -4,7 +4,7 @@ Grid physics library, www.github.com/paboyle/Grid Source file: Hadrons/Modules/MScalarSUN/StochFreeField.hpp -Copyright (C) 2015-2018 +Copyright (C) 2015-2019 Author: Antonin Portelli diff --git a/Hadrons/Modules/MScalarSUN/TrKinetic.cc b/Hadrons/Modules/MScalarSUN/TrKinetic.cc index f3823264..10ae8a39 100644 --- a/Hadrons/Modules/MScalarSUN/TrKinetic.cc +++ b/Hadrons/Modules/MScalarSUN/TrKinetic.cc @@ -4,7 +4,7 @@ Grid physics library, www.github.com/paboyle/Grid Source file: Hadrons/Modules/MScalarSUN/TrKinetic.cc -Copyright (C) 2015-2018 +Copyright (C) 2015-2019 Author: Antonin Portelli diff --git a/Hadrons/Modules/MScalarSUN/TrKinetic.hpp b/Hadrons/Modules/MScalarSUN/TrKinetic.hpp index a12df377..f26a0f91 100644 --- a/Hadrons/Modules/MScalarSUN/TrKinetic.hpp +++ b/Hadrons/Modules/MScalarSUN/TrKinetic.hpp @@ -4,7 +4,7 @@ Grid physics library, www.github.com/paboyle/Grid Source file: Hadrons/Modules/MScalarSUN/TrKinetic.hpp -Copyright (C) 2015-2018 +Copyright (C) 2015-2019 Author: Antonin Portelli diff --git a/Hadrons/Modules/MScalarSUN/TrMag.cc b/Hadrons/Modules/MScalarSUN/TrMag.cc index 88c8f547..45fbf1bf 100644 --- a/Hadrons/Modules/MScalarSUN/TrMag.cc +++ b/Hadrons/Modules/MScalarSUN/TrMag.cc @@ -4,7 +4,7 @@ Grid physics library, www.github.com/paboyle/Grid Source file: Hadrons/Modules/MScalarSUN/TrMag.cc -Copyright (C) 2015-2018 +Copyright (C) 2015-2019 Author: Antonin Portelli diff --git a/Hadrons/Modules/MScalarSUN/TrMag.hpp b/Hadrons/Modules/MScalarSUN/TrMag.hpp index b9602be3..84eb2231 100644 --- a/Hadrons/Modules/MScalarSUN/TrMag.hpp +++ b/Hadrons/Modules/MScalarSUN/TrMag.hpp @@ -4,7 +4,7 @@ Grid physics library, www.github.com/paboyle/Grid Source file: Hadrons/Modules/MScalarSUN/TrMag.hpp -Copyright (C) 2015-2018 +Copyright (C) 2015-2019 Author: Antonin Portelli diff --git a/Hadrons/Modules/MScalarSUN/TrPhi.cc b/Hadrons/Modules/MScalarSUN/TrPhi.cc index bb16f1bf..ee112f46 100644 --- a/Hadrons/Modules/MScalarSUN/TrPhi.cc +++ b/Hadrons/Modules/MScalarSUN/TrPhi.cc @@ -4,7 +4,7 @@ Grid physics library, www.github.com/paboyle/Grid Source file: Hadrons/Modules/MScalarSUN/TrPhi.cc -Copyright (C) 2015-2018 +Copyright (C) 2015-2019 Author: Antonin Portelli diff --git a/Hadrons/Modules/MScalarSUN/TrPhi.hpp b/Hadrons/Modules/MScalarSUN/TrPhi.hpp index ecc0b8d3..b92a1343 100644 --- a/Hadrons/Modules/MScalarSUN/TrPhi.hpp +++ b/Hadrons/Modules/MScalarSUN/TrPhi.hpp @@ -4,7 +4,7 @@ Grid physics library, www.github.com/paboyle/Grid Source file: Hadrons/Modules/MScalarSUN/TrPhi.hpp -Copyright (C) 2015-2018 +Copyright (C) 2015-2019 Author: Antonin Portelli diff --git a/Hadrons/Modules/MScalarSUN/TransProj.cc b/Hadrons/Modules/MScalarSUN/TransProj.cc index 47cfe876..e77f53fb 100644 --- a/Hadrons/Modules/MScalarSUN/TransProj.cc +++ b/Hadrons/Modules/MScalarSUN/TransProj.cc @@ -4,7 +4,7 @@ Grid physics library, www.github.com/paboyle/Grid Source file: Hadrons/Modules/MScalarSUN/TransProj.cc -Copyright (C) 2015-2018 +Copyright (C) 2015-2019 Author: Antonin Portelli diff --git a/Hadrons/Modules/MScalarSUN/TransProj.hpp b/Hadrons/Modules/MScalarSUN/TransProj.hpp index 59b7dc71..22ecfffb 100644 --- a/Hadrons/Modules/MScalarSUN/TransProj.hpp +++ b/Hadrons/Modules/MScalarSUN/TransProj.hpp @@ -4,7 +4,7 @@ Grid physics library, www.github.com/paboyle/Grid Source file: Hadrons/Modules/MScalarSUN/TransProj.hpp -Copyright (C) 2015-2018 +Copyright (C) 2015-2019 Author: Antonin Portelli diff --git a/Hadrons/Modules/MScalarSUN/TwoPoint.cc b/Hadrons/Modules/MScalarSUN/TwoPoint.cc index 9cb8b7ad..dd485515 100644 --- a/Hadrons/Modules/MScalarSUN/TwoPoint.cc +++ b/Hadrons/Modules/MScalarSUN/TwoPoint.cc @@ -4,7 +4,7 @@ Grid physics library, www.github.com/paboyle/Grid Source file: Hadrons/Modules/MScalarSUN/TwoPoint.cc -Copyright (C) 2015-2018 +Copyright (C) 2015-2019 Author: Antonin Portelli diff --git a/Hadrons/Modules/MScalarSUN/TwoPoint.hpp b/Hadrons/Modules/MScalarSUN/TwoPoint.hpp index df0d2cba..b22e38c9 100644 --- a/Hadrons/Modules/MScalarSUN/TwoPoint.hpp +++ b/Hadrons/Modules/MScalarSUN/TwoPoint.hpp @@ -4,7 +4,7 @@ Grid physics library, www.github.com/paboyle/Grid Source file: Hadrons/Modules/MScalarSUN/TwoPoint.hpp -Copyright (C) 2015-2018 +Copyright (C) 2015-2019 Author: Antonin Portelli diff --git a/Hadrons/Modules/MScalarSUN/TwoPointNPR.cc b/Hadrons/Modules/MScalarSUN/TwoPointNPR.cc index a7b4cd4f..b94d331f 100644 --- a/Hadrons/Modules/MScalarSUN/TwoPointNPR.cc +++ b/Hadrons/Modules/MScalarSUN/TwoPointNPR.cc @@ -4,7 +4,7 @@ Grid physics library, www.github.com/paboyle/Grid Source file: Hadrons/Modules/MScalarSUN/TwoPointNPR.cc -Copyright (C) 2015-2018 +Copyright (C) 2015-2019 Author: Antonin Portelli diff --git a/Hadrons/Modules/MScalarSUN/TwoPointNPR.hpp b/Hadrons/Modules/MScalarSUN/TwoPointNPR.hpp index 6a18f6cb..dd1e7215 100644 --- a/Hadrons/Modules/MScalarSUN/TwoPointNPR.hpp +++ b/Hadrons/Modules/MScalarSUN/TwoPointNPR.hpp @@ -4,7 +4,7 @@ Grid physics library, www.github.com/paboyle/Grid Source file: Hadrons/Modules/MScalarSUN/TwoPointNPR.hpp -Copyright (C) 2015-2018 +Copyright (C) 2015-2019 Author: Antonin Portelli diff --git a/Hadrons/Modules/MScalarSUN/Utils.hpp b/Hadrons/Modules/MScalarSUN/Utils.hpp index 7eba5900..869bc8e7 100644 --- a/Hadrons/Modules/MScalarSUN/Utils.hpp +++ b/Hadrons/Modules/MScalarSUN/Utils.hpp @@ -4,7 +4,7 @@ Grid physics library, www.github.com/paboyle/Grid Source file: Hadrons/Modules/MScalarSUN/Utils.hpp -Copyright (C) 2015-2018 +Copyright (C) 2015-2019 Author: Antonin Portelli diff --git a/Hadrons/Modules/MSink/Point.cc b/Hadrons/Modules/MSink/Point.cc index b1deaa64..333e56b1 100644 --- a/Hadrons/Modules/MSink/Point.cc +++ b/Hadrons/Modules/MSink/Point.cc @@ -4,7 +4,7 @@ Grid physics library, www.github.com/paboyle/Grid Source file: Hadrons/Modules/MSink/Point.cc -Copyright (C) 2015-2018 +Copyright (C) 2015-2019 Author: Antonin Portelli diff --git a/Hadrons/Modules/MSink/Point.hpp b/Hadrons/Modules/MSink/Point.hpp index 22346087..a8359eae 100644 --- a/Hadrons/Modules/MSink/Point.hpp +++ b/Hadrons/Modules/MSink/Point.hpp @@ -4,7 +4,7 @@ Grid physics library, www.github.com/paboyle/Grid Source file: Hadrons/Modules/MSink/Point.hpp -Copyright (C) 2015-2018 +Copyright (C) 2015-2019 Author: Antonin Portelli Author: Guido Cossu diff --git a/Hadrons/Modules/MSink/Smear.cc b/Hadrons/Modules/MSink/Smear.cc index aacceedf..b7a99025 100644 --- a/Hadrons/Modules/MSink/Smear.cc +++ b/Hadrons/Modules/MSink/Smear.cc @@ -4,7 +4,7 @@ Grid physics library, www.github.com/paboyle/Grid Source file: Hadrons/Modules/MSink/Smear.cc -Copyright (C) 2015-2018 +Copyright (C) 2015-2019 Author: Antonin Portelli diff --git a/Hadrons/Modules/MSink/Smear.hpp b/Hadrons/Modules/MSink/Smear.hpp index 59a8b9cd..47f91d3a 100644 --- a/Hadrons/Modules/MSink/Smear.hpp +++ b/Hadrons/Modules/MSink/Smear.hpp @@ -4,7 +4,7 @@ Grid physics library, www.github.com/paboyle/Grid Source file: Hadrons/Modules/MSink/Smear.hpp -Copyright (C) 2015-2018 +Copyright (C) 2015-2019 Author: Antonin Portelli Author: Lanny91 diff --git a/Hadrons/Modules/MSolver/A2AAslashVectors.cc b/Hadrons/Modules/MSolver/A2AAslashVectors.cc index 74e9f59f..d7e60db5 100644 --- a/Hadrons/Modules/MSolver/A2AAslashVectors.cc +++ b/Hadrons/Modules/MSolver/A2AAslashVectors.cc @@ -4,8 +4,9 @@ Grid physics library, www.github.com/paboyle/Grid Source file: Hadrons/Modules/MSolver/A2AAslashVectors.cc -Copyright (C) 2015-2018 +Copyright (C) 2015-2019 +Author: Antonin Portelli Author: Vera Guelpers This program is free software; you can redistribute it and/or modify diff --git a/Hadrons/Modules/MSolver/A2AAslashVectors.hpp b/Hadrons/Modules/MSolver/A2AAslashVectors.hpp index 8531c6ba..fa222228 100644 --- a/Hadrons/Modules/MSolver/A2AAslashVectors.hpp +++ b/Hadrons/Modules/MSolver/A2AAslashVectors.hpp @@ -4,8 +4,9 @@ Grid physics library, www.github.com/paboyle/Grid Source file: Hadrons/Modules/MSolver/A2AAslashVectors.hpp -Copyright (C) 2015-2018 +Copyright (C) 2015-2019 +Author: Antonin Portelli Author: Vera Guelpers This program is free software; you can redistribute it and/or modify diff --git a/Hadrons/Modules/MSolver/A2AVectors.cc b/Hadrons/Modules/MSolver/A2AVectors.cc index f5e9fd6c..c7d92006 100644 --- a/Hadrons/Modules/MSolver/A2AVectors.cc +++ b/Hadrons/Modules/MSolver/A2AVectors.cc @@ -4,7 +4,7 @@ Grid physics library, www.github.com/paboyle/Grid Source file: Hadrons/Modules/MSolver/A2AVectors.cc -Copyright (C) 2015-2018 +Copyright (C) 2015-2019 Author: Antonin Portelli Author: fionnoh diff --git a/Hadrons/Modules/MSolver/A2AVectors.hpp b/Hadrons/Modules/MSolver/A2AVectors.hpp index f9980ee3..0d419f85 100644 --- a/Hadrons/Modules/MSolver/A2AVectors.hpp +++ b/Hadrons/Modules/MSolver/A2AVectors.hpp @@ -4,7 +4,7 @@ Grid physics library, www.github.com/paboyle/Grid Source file: Hadrons/Modules/MSolver/A2AVectors.hpp -Copyright (C) 2015-2018 +Copyright (C) 2015-2019 Author: Antonin Portelli Author: fionnoh diff --git a/Hadrons/Modules/MSolver/Guesser.hpp b/Hadrons/Modules/MSolver/Guesser.hpp index 7063198d..9e2c68c3 100644 --- a/Hadrons/Modules/MSolver/Guesser.hpp +++ b/Hadrons/Modules/MSolver/Guesser.hpp @@ -4,7 +4,7 @@ Grid physics library, www.github.com/paboyle/Grid Source file: Hadrons/Modules/MSolver/Guesser.hpp -Copyright (C) 2015-2018 +Copyright (C) 2015-2019 Author: Antonin Portelli diff --git a/Hadrons/Modules/MSolver/LocalCoherenceLanczos.cc b/Hadrons/Modules/MSolver/LocalCoherenceLanczos.cc index dacc871f..38bea68e 100644 --- a/Hadrons/Modules/MSolver/LocalCoherenceLanczos.cc +++ b/Hadrons/Modules/MSolver/LocalCoherenceLanczos.cc @@ -4,7 +4,7 @@ Grid physics library, www.github.com/paboyle/Grid Source file: Hadrons/Modules/MSolver/LocalCoherenceLanczos.cc -Copyright (C) 2015-2018 +Copyright (C) 2015-2019 Author: Antonin Portelli diff --git a/Hadrons/Modules/MSolver/LocalCoherenceLanczos.hpp b/Hadrons/Modules/MSolver/LocalCoherenceLanczos.hpp index 492ff39e..72045313 100644 --- a/Hadrons/Modules/MSolver/LocalCoherenceLanczos.hpp +++ b/Hadrons/Modules/MSolver/LocalCoherenceLanczos.hpp @@ -4,7 +4,7 @@ Grid physics library, www.github.com/paboyle/Grid Source file: Hadrons/Modules/MSolver/LocalCoherenceLanczos.hpp -Copyright (C) 2015-2018 +Copyright (C) 2015-2019 Author: Antonin Portelli @@ -65,6 +65,10 @@ public: nBasis> LCL; typedef BaseFermionEigenPack BasePack; typedef CoarseFermionEigenPack CoarsePack; + typedef typename CoarsePack::Field Field; + typedef typename CoarsePack::FieldIo FieldIo; + typedef typename CoarsePack::CoarseField CoarseField; + typedef typename CoarsePack::CoarseFieldIo CoarseFieldIo; typedef HADRONS_DEFAULT_SCHUR_OP SchurFMat; public: // constructor @@ -123,21 +127,30 @@ void TLocalCoherenceLanczos::setup(void) unsigned int Ls = env().getObjectLs(par().action); auto blockSize = strToVec(par().blockSize); + GridBase *gridIo = nullptr, *gridCoarseIo = nullptr; - env().createCoarseGrid(blockSize, Ls); + if (typeHash() != typeHash()) + { + gridIo = envGetRbGrid(FieldIo, Ls); + } + if (typeHash() != typeHash()) + { + gridCoarseIo = envGetCoarseGrid(CoarseFieldIo, blockSize, Ls); + } - auto cg = env().getCoarseGrid(blockSize, Ls); + auto cg = envGetCoarseGrid(CoarseField, blockSize, Ls); int cNm = (par().doCoarse) ? par().coarseParams.Nm : 0; LOG(Message) << "Coarse grid: " << cg->GlobalDimensions() << std::endl; envCreateDerived(BasePack, CoarsePack, getName(), Ls, - par().fineParams.Nm, cNm, env().getRbGrid(Ls), cg); + par().fineParams.Nm, cNm, envGetRbGrid(Field, Ls), cg, + gridIo, gridCoarseIo); auto &epack = envGetDerived(BasePack, CoarsePack, getName()); envTmp(SchurFMat, "mat", Ls, envGet(FMat, par().action)); envGetTmp(SchurFMat, mat); - envTmp(LCL, "solver", Ls, env().getRbGrid(Ls), cg, mat, + envTmp(LCL, "solver", Ls, envGetRbGrid(Field, Ls), cg, mat, Odd, epack.evec, epack.evecCoarse, epack.eval, epack.evalCoarse); } diff --git a/Hadrons/Modules/MSolver/MixedPrecisionRBPrecCG.cc b/Hadrons/Modules/MSolver/MixedPrecisionRBPrecCG.cc index 36dc7c94..a5286af6 100644 --- a/Hadrons/Modules/MSolver/MixedPrecisionRBPrecCG.cc +++ b/Hadrons/Modules/MSolver/MixedPrecisionRBPrecCG.cc @@ -4,7 +4,7 @@ Grid physics library, www.github.com/paboyle/Grid Source file: Hadrons/Modules/MSolver/MixedPrecisionRBPrecCG.cc -Copyright (C) 2015-2018 +Copyright (C) 2015-2019 Author: Antonin Portelli diff --git a/Hadrons/Modules/MSolver/MixedPrecisionRBPrecCG.hpp b/Hadrons/Modules/MSolver/MixedPrecisionRBPrecCG.hpp index efc2ae2a..5a041c79 100644 --- a/Hadrons/Modules/MSolver/MixedPrecisionRBPrecCG.hpp +++ b/Hadrons/Modules/MSolver/MixedPrecisionRBPrecCG.hpp @@ -4,7 +4,7 @@ Grid physics library, www.github.com/paboyle/Grid Source file: Hadrons/Modules/MSolver/MixedPrecisionRBPrecCG.hpp -Copyright (C) 2015-2018 +Copyright (C) 2015-2019 Author: Antonin Portelli diff --git a/Hadrons/Modules/MSolver/RBPrecCG.cc b/Hadrons/Modules/MSolver/RBPrecCG.cc index 6d26532b..bf3b0868 100644 --- a/Hadrons/Modules/MSolver/RBPrecCG.cc +++ b/Hadrons/Modules/MSolver/RBPrecCG.cc @@ -4,7 +4,7 @@ Grid physics library, www.github.com/paboyle/Grid Source file: Hadrons/Modules/MSolver/RBPrecCG.cc -Copyright (C) 2015-2018 +Copyright (C) 2015-2019 Author: Antonin Portelli diff --git a/Hadrons/Modules/MSolver/RBPrecCG.hpp b/Hadrons/Modules/MSolver/RBPrecCG.hpp index 8c83c6a1..a1ef2f7f 100644 --- a/Hadrons/Modules/MSolver/RBPrecCG.hpp +++ b/Hadrons/Modules/MSolver/RBPrecCG.hpp @@ -4,7 +4,7 @@ Grid physics library, www.github.com/paboyle/Grid Source file: Hadrons/Modules/MSolver/RBPrecCG.hpp -Copyright (C) 2015-2018 +Copyright (C) 2015-2019 Author: Antonin Portelli Author: fionnoh diff --git a/Hadrons/Modules/MSource/Momentum.cc b/Hadrons/Modules/MSource/Momentum.cc index 9bcf65ae..ca72092f 100644 --- a/Hadrons/Modules/MSource/Momentum.cc +++ b/Hadrons/Modules/MSource/Momentum.cc @@ -4,7 +4,7 @@ Grid physics library, www.github.com/paboyle/Grid Source file: Hadrons/Modules/MSource/Momentum.cc -Copyright (C) 2015-2018 +Copyright (C) 2015-2019 Author: Antonin Portelli Author: Peter Boyle diff --git a/Hadrons/Modules/MSource/Momentum.hpp b/Hadrons/Modules/MSource/Momentum.hpp index 42cda57a..87a19fe5 100644 --- a/Hadrons/Modules/MSource/Momentum.hpp +++ b/Hadrons/Modules/MSource/Momentum.hpp @@ -4,7 +4,7 @@ Grid physics library, www.github.com/paboyle/Grid Source file: Hadrons/Modules/MSource/Momentum.hpp -Copyright (C) 2015-2018 +Copyright (C) 2015-2019 Author: Antonin Portelli Author: Peter Boyle diff --git a/Hadrons/Modules/MSource/Point.cc b/Hadrons/Modules/MSource/Point.cc index 43cea943..52fc9399 100644 --- a/Hadrons/Modules/MSource/Point.cc +++ b/Hadrons/Modules/MSource/Point.cc @@ -4,7 +4,7 @@ Grid physics library, www.github.com/paboyle/Grid Source file: Hadrons/Modules/MSource/Point.cc -Copyright (C) 2015-2018 +Copyright (C) 2015-2019 Author: Antonin Portelli diff --git a/Hadrons/Modules/MSource/Point.hpp b/Hadrons/Modules/MSource/Point.hpp index 0d81b34b..a33c5308 100644 --- a/Hadrons/Modules/MSource/Point.hpp +++ b/Hadrons/Modules/MSource/Point.hpp @@ -4,7 +4,7 @@ Grid physics library, www.github.com/paboyle/Grid Source file: Hadrons/Modules/MSource/Point.hpp -Copyright (C) 2015-2018 +Copyright (C) 2015-2019 Author: Antonin Portelli Author: Lanny91 diff --git a/Hadrons/Modules/MSource/SeqAslash.cc b/Hadrons/Modules/MSource/SeqAslash.cc new file mode 100644 index 00000000..6586f2f2 --- /dev/null +++ b/Hadrons/Modules/MSource/SeqAslash.cc @@ -0,0 +1,36 @@ +/************************************************************************************* + +Grid physics library, www.github.com/paboyle/Grid + +Source file: Hadrons/Modules/MSource/SeqAslash.cc + +Copyright (C) 2015-2018 + +Author: Antonin Portelli +Author: Vera Guelpers + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License along +with this program; if not, write to the Free Software Foundation, Inc., +51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +See the full license in the file "LICENSE" in the top level distribution directory +*************************************************************************************/ +/* END LEGAL */ +#include + +using namespace Grid; +using namespace Hadrons; +using namespace MSource; + +template class Grid::Hadrons::MSource::TSeqAslash; + diff --git a/Hadrons/Modules/MSource/SeqAslash.hpp b/Hadrons/Modules/MSource/SeqAslash.hpp new file mode 100644 index 00000000..a31051fd --- /dev/null +++ b/Hadrons/Modules/MSource/SeqAslash.hpp @@ -0,0 +1,186 @@ +/************************************************************************************* + +Grid physics library, www.github.com/paboyle/Grid + +Source file: Hadrons/Modules/MSource/SeqAslash.hpp + +Copyright (C) 2015-2018 + +Author: Antonin Portelli +Author: Lanny91 +Author: Vera Guelpers + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License along +with this program; if not, write to the Free Software Foundation, Inc., +51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +See the full license in the file "LICENSE" in the top level distribution directory +*************************************************************************************/ +/* END LEGAL */ + +#ifndef Hadrons_MSource_SeqAslash_hpp_ +#define Hadrons_MSource_SeqAslash_hpp_ + +#include +#include +#include + +BEGIN_HADRONS_NAMESPACE + +/* + + Sequential source + ----------------------------- + * src_x = q_x * theta(x_3 - tA) * theta(tB - x_3) * i * A_mu g_mu * exp(i x.mom) + + * options: + - q: input propagator (string) + - tA: begin timeslice (integer) + - tB: end timesilce (integer) + - emField: input photon field (string) + - mom: momentum insertion, space-separated float sequence (e.g ".1 .2 1. 0.") + + */ + +/****************************************************************************** + * SeqAslash * + ******************************************************************************/ +BEGIN_MODULE_NAMESPACE(MSource) + +class SeqAslashPar: Serializable +{ +public: + GRID_SERIALIZABLE_CLASS_MEMBERS(SeqAslashPar, + std::string, q, + unsigned int, tA, + unsigned int, tB, + std::string, emField, + std::string, mom); +}; + +template +class TSeqAslash: public Module +{ +public: + FERM_TYPE_ALIASES(FImpl,); +public: + typedef PhotonR::GaugeField EmField; +public: + // constructor + TSeqAslash(const std::string name); + // destructor + virtual ~TSeqAslash(void) {}; + // dependency relation + virtual std::vector getInput(void); + virtual std::vector getOutput(void); +protected: + // setup + virtual void setup(void); + // execution + virtual void execute(void); +private: + bool hasPhase_{false}; + std::string momphName_, tName_; +}; + +MODULE_REGISTER_TMP(SeqAslash, TSeqAslash, MSource); + +/****************************************************************************** + * TSeqAslash implementation * + ******************************************************************************/ +// constructor ///////////////////////////////////////////////////////////////// +template +TSeqAslash::TSeqAslash(const std::string name) +: Module(name) +, momphName_ (name + "_momph") +, tName_ (name + "_t") +{} + +// dependencies/products /////////////////////////////////////////////////////// +template +std::vector TSeqAslash::getInput(void) +{ + std::vector in = {par().q,par().emField}; + + return in; +} + +template +std::vector TSeqAslash::getOutput(void) +{ + std::vector out = {getName()}; + + return out; +} + +// setup /////////////////////////////////////////////////////////////////////// +template +void TSeqAslash::setup(void) +{ + envCreateLat(PropagatorField, getName()); + envCache(Lattice>, tName_, 1, envGetGrid(LatticeComplex)); + envCacheLat(LatticeComplex, momphName_); + envTmpLat(LatticeComplex, "coor"); +} + +// execution /////////////////////////////////////////////////////////////////// +template +void TSeqAslash::execute(void) +{ + if (par().tA == par().tB) + { + LOG(Message) << "Generating Aslash sequential source at t= " << par().tA + << " using the photon field " << par().emField << std::endl; + } + else + { + LOG(Message) << "Generating Aslash sequential source for " + << par().tA << " <= t <= " << par().tB + << " using the photon field " << par().emField << std::endl; + } + auto &src = envGet(PropagatorField, getName()); src=zero; + auto &q = envGet(PropagatorField, par().q); + auto &ph = envGet(LatticeComplex, momphName_); + auto &t = envGet(Lattice>, tName_); + + if (!hasPhase_) + { + Complex i(0.0,1.0); + std::vector p; + + envGetTmp(LatticeComplex, coor); + p = strToVec(par().mom); + ph = zero; + for(unsigned int mu = 0; mu < env().getNd(); mu++) + { + LatticeCoordinate(coor, mu); + ph = ph + (p[mu]/env().getDim(mu))*coor; + } + ph = exp((Real)(2*M_PI)*i*ph); + LatticeCoordinate(t, Tp); + hasPhase_ = true; + } + auto &stoch_photon = envGet(EmField, par().emField); + Complex ci(0.0,1.0); + for(unsigned int mu=0;mu<=3;mu++) + { + Gamma gmu(Gamma::gmu[mu]); + src = src + where((t >= par().tA) and (t <= par().tB), ci * PeekIndex(stoch_photon, mu) *ph*(gmu*q), 0.*q); + } +} + +END_MODULE_NAMESPACE + +END_HADRONS_NAMESPACE + +#endif // Hadrons_MSource_SeqAslash_hpp_ diff --git a/Hadrons/Modules/MSource/SeqConserved.cc b/Hadrons/Modules/MSource/SeqConserved.cc index 1802993b..fbef504f 100644 --- a/Hadrons/Modules/MSource/SeqConserved.cc +++ b/Hadrons/Modules/MSource/SeqConserved.cc @@ -4,7 +4,7 @@ Grid physics library, www.github.com/paboyle/Grid Source file: Hadrons/Modules/MSource/SeqConserved.cc -Copyright (C) 2015-2018 +Copyright (C) 2015-2019 Author: Antonin Portelli @@ -32,4 +32,4 @@ using namespace Hadrons; using namespace MSource; template class Grid::Hadrons::MSource::TSeqConserved; - +template class Grid::Hadrons::MSource::TSeqConserved; diff --git a/Hadrons/Modules/MSource/SeqConserved.hpp b/Hadrons/Modules/MSource/SeqConserved.hpp index 8e44e989..c8d5121d 100644 --- a/Hadrons/Modules/MSource/SeqConserved.hpp +++ b/Hadrons/Modules/MSource/SeqConserved.hpp @@ -4,7 +4,7 @@ Grid physics library, www.github.com/paboyle/Grid Source file: Hadrons/Modules/MSource/SeqConserved.hpp -Copyright (C) 2015-2018 +Copyright (C) 2015-2019 Author: Antonin Portelli Author: Lanny91 @@ -104,6 +104,7 @@ private: }; MODULE_REGISTER_TMP(SeqConserved, TSeqConserved, MSource); +MODULE_REGISTER_TMP(ZSeqConserved, TSeqConserved, MSource); /****************************************************************************** diff --git a/Hadrons/Modules/MSource/SeqGamma.cc b/Hadrons/Modules/MSource/SeqGamma.cc index 64d31478..c2ae2322 100644 --- a/Hadrons/Modules/MSource/SeqGamma.cc +++ b/Hadrons/Modules/MSource/SeqGamma.cc @@ -4,7 +4,7 @@ Grid physics library, www.github.com/paboyle/Grid Source file: Hadrons/Modules/MSource/SeqGamma.cc -Copyright (C) 2015-2018 +Copyright (C) 2015-2019 Author: Antonin Portelli @@ -32,4 +32,4 @@ using namespace Hadrons; using namespace MSource; template class Grid::Hadrons::MSource::TSeqGamma; - +template class Grid::Hadrons::MSource::TSeqGamma; diff --git a/Hadrons/Modules/MSource/SeqGamma.hpp b/Hadrons/Modules/MSource/SeqGamma.hpp index b8278142..4d125848 100644 --- a/Hadrons/Modules/MSource/SeqGamma.hpp +++ b/Hadrons/Modules/MSource/SeqGamma.hpp @@ -4,7 +4,7 @@ Grid physics library, www.github.com/paboyle/Grid Source file: Hadrons/Modules/MSource/SeqGamma.hpp -Copyright (C) 2015-2018 +Copyright (C) 2015-2019 Author: Antonin Portelli Author: Lanny91 @@ -91,6 +91,7 @@ private: }; MODULE_REGISTER_TMP(SeqGamma, TSeqGamma, MSource); +MODULE_REGISTER_TMP(ZSeqGamma, TSeqGamma, MSource); /****************************************************************************** * TSeqGamma implementation * diff --git a/Hadrons/Modules/MSource/Wall.cc b/Hadrons/Modules/MSource/Wall.cc index dbc46293..4b36145f 100644 --- a/Hadrons/Modules/MSource/Wall.cc +++ b/Hadrons/Modules/MSource/Wall.cc @@ -4,7 +4,7 @@ Grid physics library, www.github.com/paboyle/Grid Source file: Hadrons/Modules/MSource/Wall.cc -Copyright (C) 2015-2018 +Copyright (C) 2015-2019 Author: Antonin Portelli diff --git a/Hadrons/Modules/MSource/Wall.hpp b/Hadrons/Modules/MSource/Wall.hpp index 9ec0f391..ea26d6c9 100644 --- a/Hadrons/Modules/MSource/Wall.hpp +++ b/Hadrons/Modules/MSource/Wall.hpp @@ -4,7 +4,7 @@ Grid physics library, www.github.com/paboyle/Grid Source file: Hadrons/Modules/MSource/Wall.hpp -Copyright (C) 2015-2018 +Copyright (C) 2015-2019 Author: Antonin Portelli Author: Lanny91 @@ -119,6 +119,9 @@ template void TWall::setup(void) { envCreateLat(PropagatorField, getName()); + envCache(Lattice>, tName_, 1, envGetGrid(LatticeComplex)); + envCacheLat(LatticeComplex, momphName_); + envTmpLat(LatticeComplex, "coor"); } // execution /////////////////////////////////////////////////////////////////// diff --git a/Hadrons/Modules/MSource/Z2.cc b/Hadrons/Modules/MSource/Z2.cc index 2fc95532..bd63d02a 100644 --- a/Hadrons/Modules/MSource/Z2.cc +++ b/Hadrons/Modules/MSource/Z2.cc @@ -4,7 +4,7 @@ Grid physics library, www.github.com/paboyle/Grid Source file: Hadrons/Modules/MSource/Z2.cc -Copyright (C) 2015-2018 +Copyright (C) 2015-2019 Author: Antonin Portelli diff --git a/Hadrons/Modules/MSource/Z2.hpp b/Hadrons/Modules/MSource/Z2.hpp index e16114e0..f943072f 100644 --- a/Hadrons/Modules/MSource/Z2.hpp +++ b/Hadrons/Modules/MSource/Z2.hpp @@ -4,7 +4,7 @@ Grid physics library, www.github.com/paboyle/Grid Source file: Hadrons/Modules/MSource/Z2.hpp -Copyright (C) 2015-2018 +Copyright (C) 2015-2019 Author: Antonin Portelli diff --git a/Hadrons/Modules/MUtilities/PrecisionCast.cc b/Hadrons/Modules/MUtilities/PrecisionCast.cc index 556ededc..d1235070 100644 --- a/Hadrons/Modules/MUtilities/PrecisionCast.cc +++ b/Hadrons/Modules/MUtilities/PrecisionCast.cc @@ -4,7 +4,7 @@ Grid physics library, www.github.com/paboyle/Grid Source file: Hadrons/Modules/MUtilities/PrecisionCast.cc -Copyright (C) 2015-2018 +Copyright (C) 2015-2019 Author: Antonin Portelli diff --git a/Hadrons/Modules/MUtilities/PrecisionCast.hpp b/Hadrons/Modules/MUtilities/PrecisionCast.hpp index 39a5ff73..ce3321a1 100644 --- a/Hadrons/Modules/MUtilities/PrecisionCast.hpp +++ b/Hadrons/Modules/MUtilities/PrecisionCast.hpp @@ -4,7 +4,7 @@ Grid physics library, www.github.com/paboyle/Grid Source file: Hadrons/Modules/MUtilities/PrecisionCast.hpp -Copyright (C) 2015-2018 +Copyright (C) 2015-2019 Author: Antonin Portelli diff --git a/Hadrons/Modules/MUtilities/RandomVectors.cc b/Hadrons/Modules/MUtilities/RandomVectors.cc index eb3b9cad..9676ddc0 100644 --- a/Hadrons/Modules/MUtilities/RandomVectors.cc +++ b/Hadrons/Modules/MUtilities/RandomVectors.cc @@ -4,7 +4,7 @@ Grid physics library, www.github.com/paboyle/Grid Source file: Hadrons/Modules/MUtilities/RandomVectors.cc -Copyright (C) 2015-2018 +Copyright (C) 2015-2019 Author: Antonin Portelli diff --git a/Hadrons/Modules/MUtilities/RandomVectors.hpp b/Hadrons/Modules/MUtilities/RandomVectors.hpp index 65126eb7..9bb4bdce 100644 --- a/Hadrons/Modules/MUtilities/RandomVectors.hpp +++ b/Hadrons/Modules/MUtilities/RandomVectors.hpp @@ -4,7 +4,7 @@ Grid physics library, www.github.com/paboyle/Grid Source file: Hadrons/Modules/MUtilities/RandomVectors.hpp -Copyright (C) 2015-2018 +Copyright (C) 2015-2019 Author: Antonin Portelli @@ -31,6 +31,7 @@ See the full license in the file "LICENSE" in the top level distribution directo #include #include #include +#include BEGIN_HADRONS_NAMESPACE @@ -44,7 +45,9 @@ class RandomVectorsPar: Serializable public: GRID_SERIALIZABLE_CLASS_MEMBERS(RandomVectorsPar, unsigned int, size, - unsigned int, Ls); + unsigned int, Ls, + std::string, output, + bool, multiFile); }; template @@ -119,6 +122,11 @@ void TRandomVectors::execute(void) { random(rng4d(), vec[i]); } + // I/O if necessary + if (!par().output.empty()) + { + A2AVectorsIo::write(par().output, vec, par().multiFile, vm().getTrajectory()); + } } END_MODULE_NAMESPACE diff --git a/Hadrons/Solver.hpp b/Hadrons/Solver.hpp index adba9665..22af6309 100644 --- a/Hadrons/Solver.hpp +++ b/Hadrons/Solver.hpp @@ -4,7 +4,7 @@ Grid physics library, www.github.com/paboyle/Grid Source file: Hadrons/Solver.hpp -Copyright (C) 2015-2018 +Copyright (C) 2015-2019 Author: Antonin Portelli diff --git a/Hadrons/TimerArray.cc b/Hadrons/TimerArray.cc index 6f787f6d..caf72fc1 100644 --- a/Hadrons/TimerArray.cc +++ b/Hadrons/TimerArray.cc @@ -4,7 +4,7 @@ Grid physics library, www.github.com/paboyle/Grid Source file: Hadrons/TimerArray.cc -Copyright (C) 2015-2018 +Copyright (C) 2015-2019 Author: Antonin Portelli diff --git a/Hadrons/TimerArray.hpp b/Hadrons/TimerArray.hpp index 77cc2b8c..a4a5b3a4 100644 --- a/Hadrons/TimerArray.hpp +++ b/Hadrons/TimerArray.hpp @@ -4,7 +4,7 @@ Grid physics library, www.github.com/paboyle/Grid Source file: Hadrons/TimerArray.hpp -Copyright (C) 2015-2018 +Copyright (C) 2015-2019 Author: Antonin Portelli diff --git a/Hadrons/Utilities/Contractor.cc b/Hadrons/Utilities/Contractor.cc index 73150dd1..7e4b8b26 100644 --- a/Hadrons/Utilities/Contractor.cc +++ b/Hadrons/Utilities/Contractor.cc @@ -4,8 +4,9 @@ Grid physics library, www.github.com/paboyle/Grid Source file: Hadrons/Utilities/Contractor.cc -Copyright (C) 2015-2018 +Copyright (C) 2015-2019 +Author: Antonin Portelli This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by diff --git a/Hadrons/Utilities/Contractor.hpp b/Hadrons/Utilities/Contractor.hpp index 9640c7c8..decd13aa 100644 --- a/Hadrons/Utilities/Contractor.hpp +++ b/Hadrons/Utilities/Contractor.hpp @@ -1,3 +1,30 @@ +/************************************************************************************* + +Grid physics library, www.github.com/paboyle/Grid + +Source file: Hadrons/Utilities/Contractor.hpp + +Copyright (C) 2015-2019 + +Author: Antonin Portelli + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License along +with this program; if not, write to the Free Software Foundation, Inc., +51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +See the full license in the file "LICENSE" in the top level distribution directory +*************************************************************************************/ +/* END LEGAL */ #ifndef Hadrons_Contractor_hpp_ #define Hadrons_Contractor_hpp_ diff --git a/Hadrons/Utilities/ContractorBenchmark.cc b/Hadrons/Utilities/ContractorBenchmark.cc index b674f020..2035c33b 100644 --- a/Hadrons/Utilities/ContractorBenchmark.cc +++ b/Hadrons/Utilities/ContractorBenchmark.cc @@ -1,3 +1,30 @@ +/************************************************************************************* + +Grid physics library, www.github.com/paboyle/Grid + +Source file: Hadrons/Utilities/ContractorBenchmark.cc + +Copyright (C) 2015-2019 + +Author: Antonin Portelli + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License along +with this program; if not, write to the Free Software Foundation, Inc., +51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +See the full license in the file "LICENSE" in the top level distribution directory +*************************************************************************************/ +/* END LEGAL */ #include #include #ifdef USE_MKL diff --git a/Hadrons/Utilities/EigenPackCast.cc b/Hadrons/Utilities/EigenPackCast.cc index bb0d8d4e..09a9cc43 100644 --- a/Hadrons/Utilities/EigenPackCast.cc +++ b/Hadrons/Utilities/EigenPackCast.cc @@ -4,7 +4,7 @@ Grid physics library, www.github.com/paboyle/Grid Source file: Hadrons/Utilities/EigenPackCast.cc -Copyright (C) 2015-2018 +Copyright (C) 2015-2019 Author: Antonin Portelli diff --git a/Hadrons/Utilities/HadronsXmlRun.cc b/Hadrons/Utilities/HadronsXmlRun.cc index a78c8724..a81139af 100644 --- a/Hadrons/Utilities/HadronsXmlRun.cc +++ b/Hadrons/Utilities/HadronsXmlRun.cc @@ -4,7 +4,7 @@ Grid physics library, www.github.com/paboyle/Grid Source file: Hadrons/Utilities/HadronsXmlRun.cc -Copyright (C) 2015-2018 +Copyright (C) 2015-2019 Author: Antonin Portelli @@ -35,22 +35,15 @@ using namespace Hadrons; int main(int argc, char *argv[]) { // parse command line - std::string parameterFileName, scheduleFileName = ""; + std::string parameterFileName; if (argc < 2) { - std::cerr << "usage: " << argv[0] << " [] [Grid options]"; + std::cerr << "usage: " << argv[0] << " [Grid options]"; std::cerr << std::endl; std::exit(EXIT_FAILURE); } parameterFileName = argv[1]; - if (argc > 2) - { - if (argv[2][0] != '-') - { - scheduleFileName = argv[2]; - } - } // initialization Grid_init(&argc, &argv); @@ -58,14 +51,10 @@ int main(int argc, char *argv[]) // execution try { - Application application(parameterFileName); - - application.parseParameterFile(parameterFileName); - if (!scheduleFileName.empty()) - { - application.loadSchedule(scheduleFileName); - } - application.run(); + Application application(parameterFileName); + + application.parseParameterFile(parameterFileName); + application.run(); } catch (const std::exception& e) { diff --git a/Hadrons/Utilities/HadronsXmlValidate.cc b/Hadrons/Utilities/HadronsXmlValidate.cc new file mode 100644 index 00000000..73cf3139 --- /dev/null +++ b/Hadrons/Utilities/HadronsXmlValidate.cc @@ -0,0 +1,64 @@ +/************************************************************************************* + +Grid physics library, www.github.com/paboyle/Grid + +Source file: Hadrons/Utilities/HadronsXmlValidate.cc + +Copyright (C) 2015-2019 + +Author: Antonin Portelli + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License along +with this program; if not, write to the Free Software Foundation, Inc., +51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +See the full license in the file "LICENSE" in the top level distribution directory +*************************************************************************************/ +/* END LEGAL */ + +#include + +using namespace Grid; +using namespace QCD; +using namespace Hadrons; + +int main(int argc, char *argv[]) +{ + // parse command line + std::string parameterFileName; + + if (argc != 2) + { + std::cerr << "usage: " << argv[0] << " "; + std::cerr << std::endl; + std::exit(EXIT_FAILURE); + } + parameterFileName = argv[1]; + + try + { + Application application(parameterFileName); + + application.parseParameterFile(parameterFileName); + auto &vm = VirtualMachine::getInstance(); + vm.getModuleGraph(); + LOG(Message) << "Application valid (check XML warnings though)" + << std::endl; + } + catch (const std::exception& e) + { + Exceptions::abort(e); + } + + return EXIT_SUCCESS; +} diff --git a/Hadrons/Utilities/Makefile.am b/Hadrons/Utilities/Makefile.am index 4f324d6d..6c48d966 100644 --- a/Hadrons/Utilities/Makefile.am +++ b/Hadrons/Utilities/Makefile.am @@ -1,8 +1,11 @@ -bin_PROGRAMS = HadronsXmlRun HadronsFermionEP64To32 HadronsContractor HadronsContractorBenchmark +bin_PROGRAMS = HadronsXmlRun HadronsXmlValidate HadronsFermionEP64To32 HadronsContractor HadronsContractorBenchmark HadronsXmlRun_SOURCES = HadronsXmlRun.cc HadronsXmlRun_LDADD = ../libHadrons.a ../../Grid/libGrid.a +HadronsXmlValidate_SOURCES = HadronsXmlValidate.cc +HadronsXmlValidate_LDADD = ../libHadrons.a ../../Grid/libGrid.a + HadronsFermionEP64To32_SOURCES = EigenPackCast.cc HadronsFermionEP64To32_CXXFLAGS = $(AM_CXXFLAGS) -DFIN=WilsonImplD::FermionField -DFOUT=WilsonImplF::FermionField HadronsFermionEP64To32_LDADD = ../libHadrons.a ../../Grid/libGrid.a diff --git a/Hadrons/VirtualMachine.cc b/Hadrons/VirtualMachine.cc index 09a2694b..e09dfdee 100644 --- a/Hadrons/VirtualMachine.cc +++ b/Hadrons/VirtualMachine.cc @@ -4,7 +4,7 @@ Grid physics library, www.github.com/paboyle/Grid Source file: Hadrons/VirtualMachine.cc -Copyright (C) 2015-2018 +Copyright (C) 2015-2019 Author: Antonin Portelli @@ -601,11 +601,10 @@ VirtualMachine::Program VirtualMachine::schedule(const GeneticPar &par) Scheduler scheduler(graph, memPeak, gpar); gen = 0; scheduler.initPopulation(); - LOG(Iterative) << "Start: " << sizeString(scheduler.getMinValue()) - << std::endl; + LOG(Message) << "Start: " << sizeString(scheduler.getMinValue()) + << std::endl; do { - //LOG(Debug) << "Generation " << gen << ":" << std::endl; scheduler.nextGeneration(); if (gen != 0) { @@ -622,8 +621,8 @@ VirtualMachine::Program VirtualMachine::schedule(const GeneticPar &par) prevPeak = scheduler.getMinValue(); if (gen % 10 == 0) { - LOG(Iterative) << "Generation " << gen << ": " - << sizeString(scheduler.getMinValue()) << std::endl; + LOG(Message) << "Generation " << gen << ": " + << sizeString(scheduler.getMinValue()) << std::endl; } gen++; diff --git a/Hadrons/VirtualMachine.hpp b/Hadrons/VirtualMachine.hpp index 9d0357f5..dff72aa6 100644 --- a/Hadrons/VirtualMachine.hpp +++ b/Hadrons/VirtualMachine.hpp @@ -4,7 +4,7 @@ Grid physics library, www.github.com/paboyle/Grid Source file: Hadrons/VirtualMachine.hpp -Copyright (C) 2015-2018 +Copyright (C) 2015-2019 Author: Antonin Portelli diff --git a/Hadrons/modules.inc b/Hadrons/modules.inc index 88cfea88..3b9e6563 100644 --- a/Hadrons/modules.inc +++ b/Hadrons/modules.inc @@ -1,21 +1,23 @@ modules_cc =\ - Modules/MContraction/WeakHamiltonianEye.cc \ Modules/MContraction/Baryon.cc \ Modules/MContraction/Meson.cc \ - Modules/MContraction/WeakNeutral4ptDisc.cc \ - Modules/MContraction/WeakHamiltonianNonEye.cc \ + Modules/MContraction/WeakMesonDecayKl2.cc \ + Modules/MContraction/WeakEye3pt.cc \ + Modules/MContraction/A2ALoop.cc \ + Modules/MContraction/WeakNonEye3pt.cc \ Modules/MContraction/A2AAslashField.cc \ - Modules/MContraction/WardIdentity.cc \ Modules/MContraction/A2AMesonField.cc \ Modules/MContraction/DiscLoop.cc \ Modules/MContraction/Gamma3pt.cc \ Modules/MFermion/FreeProp.cc \ Modules/MFermion/GaugeProp.cc \ + Modules/MFermion/EMLepton.cc \ Modules/MSource/Momentum.cc \ Modules/MSource/Point.cc \ Modules/MSource/Wall.cc \ Modules/MSource/SeqConserved.cc \ Modules/MSource/SeqGamma.cc \ + Modules/MSource/SeqAslash.cc \ Modules/MSource/Z2.cc \ Modules/MSink/Point.cc \ Modules/MSink/Smear.cc \ @@ -26,23 +28,18 @@ modules_cc =\ Modules/MSolver/LocalCoherenceLanczos.cc \ Modules/MGauge/StoutSmearing.cc \ Modules/MGauge/Unit.cc \ - Modules/MGauge/Electrify.cc \ Modules/MGauge/UnitEm.cc \ Modules/MGauge/StochEm.cc \ Modules/MGauge/Random.cc \ + Modules/MGauge/Electrify.cc \ Modules/MGauge/FundtoHirep.cc \ Modules/MGauge/GaugeFix.cc \ - Modules/MNoise/TimeDilutedSpinColorDiagonal.cc \ Modules/MNoise/FullVolumeSpinColorDiagonal.cc \ + Modules/MNoise/TimeDilutedSpinColorDiagonal.cc \ Modules/MUtilities/RandomVectors.cc \ - Modules/MUtilities/TestSeqGamma.cc \ Modules/MUtilities/PrecisionCast.cc \ - Modules/MUtilities/TestSeqConserved.cc \ - Modules/MLoop/NoiseLoop.cc \ Modules/MScalar/FreeProp.cc \ - Modules/MScalar/VPCounterTerms.cc \ Modules/MScalar/ChargedProp.cc \ - Modules/MScalar/ScalarVP.cc \ Modules/MNPR/Amputate.cc \ Modules/MNPR/Bilinear.cc \ Modules/MNPR/FourQuark.cc \ @@ -57,7 +54,6 @@ modules_cc =\ Modules/MScalarSUN/TrMag.cc \ Modules/MScalarSUN/TrKinetic.cc \ Modules/MScalarSUN/EMT.cc \ - Modules/MScalarSUN/ShiftProbe.cc \ Modules/MScalarSUN/TransProj.cc \ Modules/MScalarSUN/StochFreeField.cc \ Modules/MScalarSUN/TwoPoint.cc \ @@ -71,20 +67,21 @@ modules_cc =\ Modules/MIO/LoadA2AVectors.cc modules_hpp =\ + Modules/MContraction/WeakEye3pt.hpp \ Modules/MContraction/Baryon.hpp \ Modules/MContraction/A2AAslashField.hpp \ + Modules/MContraction/A2ALoop.hpp \ Modules/MContraction/A2AMesonField.hpp \ Modules/MContraction/Meson.hpp \ - Modules/MContraction/WeakHamiltonian.hpp \ - Modules/MContraction/WeakHamiltonianNonEye.hpp \ Modules/MContraction/DiscLoop.hpp \ - Modules/MContraction/WeakNeutral4ptDisc.hpp \ Modules/MContraction/Gamma3pt.hpp \ - Modules/MContraction/WardIdentity.hpp \ - Modules/MContraction/WeakHamiltonianEye.hpp \ + Modules/MContraction/WeakMesonDecayKl2.hpp \ + Modules/MContraction/WeakNonEye3pt.hpp \ Modules/MFermion/FreeProp.hpp \ Modules/MFermion/GaugeProp.hpp \ + Modules/MFermion/EMLepton.hpp \ Modules/MSource/SeqGamma.hpp \ + Modules/MSource/SeqAslash.hpp \ Modules/MSource/Point.hpp \ Modules/MSource/Wall.hpp \ Modules/MSource/Z2.hpp \ @@ -94,28 +91,23 @@ modules_hpp =\ Modules/MSink/Point.hpp \ Modules/MSolver/MixedPrecisionRBPrecCG.hpp \ Modules/MSolver/LocalCoherenceLanczos.hpp \ + Modules/MSolver/A2AAslashVectors.hpp \ Modules/MSolver/Guesser.hpp \ Modules/MSolver/RBPrecCG.hpp \ Modules/MSolver/A2AVectors.hpp \ - Modules/MSolver/A2AAslashVectors.hpp \ Modules/MGauge/UnitEm.hpp \ Modules/MGauge/StoutSmearing.hpp \ Modules/MGauge/Unit.hpp \ - Modules/MGauge/Electrify.hpp \ Modules/MGauge/Random.hpp \ Modules/MGauge/GaugeFix.hpp \ Modules/MGauge/FundtoHirep.hpp \ Modules/MGauge/StochEm.hpp \ + Modules/MGauge/Electrify.hpp \ Modules/MNoise/TimeDilutedSpinColorDiagonal.hpp \ Modules/MNoise/FullVolumeSpinColorDiagonal.hpp \ Modules/MUtilities/PrecisionCast.hpp \ Modules/MUtilities/RandomVectors.hpp \ - Modules/MUtilities/TestSeqGamma.hpp \ - Modules/MUtilities/TestSeqConserved.hpp \ - Modules/MLoop/NoiseLoop.hpp \ Modules/MScalar/FreeProp.hpp \ - Modules/MScalar/VPCounterTerms.hpp \ - Modules/MScalar/ScalarVP.hpp \ Modules/MScalar/Scalar.hpp \ Modules/MScalar/ChargedProp.hpp \ Modules/MNPR/Bilinear.hpp \ @@ -129,7 +121,6 @@ modules_hpp =\ Modules/MAction/ScaledDWF.hpp \ Modules/MScalarSUN/StochFreeField.hpp \ Modules/MScalarSUN/TwoPointNPR.hpp \ - Modules/MScalarSUN/ShiftProbe.hpp \ Modules/MScalarSUN/Div.hpp \ Modules/MScalarSUN/TrMag.hpp \ Modules/MScalarSUN/EMT.hpp \ diff --git a/Makefile.am b/Makefile.am index d905b8e8..710514bc 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1,5 +1,5 @@ # additional include paths necessary to compile the C++ library -SUBDIRS = Grid Hadrons benchmarks tests +SUBDIRS = Grid HMC Hadrons benchmarks tests include $(top_srcdir)/doxygen.inc diff --git a/VERSION b/VERSION deleted file mode 100644 index a0211af1..00000000 --- a/VERSION +++ /dev/null @@ -1,5 +0,0 @@ -Version : 0.8.0 - -- Clang 3.5 and above, ICPC v16 and above, GCC 6.3 and above recommended -- MPI and MPI3 comms optimisations for KNL and OPA finished -- Half precision comms diff --git a/bootstrap.sh b/bootstrap.sh index 421b002f..8ebd35ea 100755 --- a/bootstrap.sh +++ b/bootstrap.sh @@ -5,7 +5,10 @@ EIGEN_URL='http://bitbucket.org/eigen/eigen/get/3.3.7.tar.bz2' echo "-- deploying Eigen source..." ARC=`basename ${EIGEN_URL}` wget ${EIGEN_URL} --no-check-certificate && ./scripts/update_eigen.sh ${ARC} && rm ${ARC} -patch Grid/Eigen/unsupported/CXX11/Tensor scripts/eigen-3.3.5.Tensor.patch +# patch for non-portable includes in Eigen 3.3.5 +# apparently already fixed in Eigen HEAD so it should not be +# a problem in the future (A.P.) +patch Eigen/unsupported/Eigen/CXX11/Tensor scripts/eigen-3.3.5.Tensor.patch echo '-- generating Make.inc files...' ./scripts/filelist diff --git a/configure.ac b/configure.ac index 5038065b..f3925c8b 100644 --- a/configure.ac +++ b/configure.ac @@ -617,6 +617,7 @@ AC_SUBST([GRID_SUMMARY]) AC_CONFIG_FILES([grid-config], [chmod +x grid-config]) AC_CONFIG_FILES(Makefile) AC_CONFIG_FILES(Grid/Makefile) +AC_CONFIG_FILES(HMC/Makefile) AC_CONFIG_FILES(tests/Makefile) AC_CONFIG_FILES(tests/IO/Makefile) AC_CONFIG_FILES(tests/core/Makefile) diff --git a/documentation/GridXcode/GridXcFig1.png b/documentation/GridXcode/GridXcFig1.png new file mode 100644 index 00000000..73fd0625 Binary files /dev/null and b/documentation/GridXcode/GridXcFig1.png differ diff --git a/documentation/GridXcode/GridXcFig2.png b/documentation/GridXcode/GridXcFig2.png new file mode 100644 index 00000000..9b169491 Binary files /dev/null and b/documentation/GridXcode/GridXcFig2.png differ diff --git a/documentation/GridXcode/GridXcFig3.png b/documentation/GridXcode/GridXcFig3.png new file mode 100644 index 00000000..02595468 Binary files /dev/null and b/documentation/GridXcode/GridXcFig3.png differ diff --git a/documentation/GridXcode/GridXcFig4.png b/documentation/GridXcode/GridXcFig4.png new file mode 100644 index 00000000..5abd150b Binary files /dev/null and b/documentation/GridXcode/GridXcFig4.png differ diff --git a/documentation/GridXcode/readme.md b/documentation/GridXcode/readme.md new file mode 100644 index 00000000..031ec72a --- /dev/null +++ b/documentation/GridXcode/readme.md @@ -0,0 +1,438 @@ +# Using Xcode for Grid on Mac OS + +This guide explains how to use Xcode as an IDE for Grid on Mac OS. + +*NB: this guide, and the screenshots, were generated using Xcode 10.1.* + +# Initial setup + +For first time setup of the Xcode and Grid build environment on Mac OS, you will need to do the following, in this order: + +1. Install Xcode and the Xcode command-line utilities +2. Set Grid environment variables +3. Install and build Open MPI ***optional*** +4. Install and build Grid pre-requisites +5. Install, Configure and Build Grid + +Apple's [Xcode website][Xcode] is the go-to reference for 1, and the definitive reference for 4 and 5 is the [Grid Documentation][GridDoc]. + +[Xcode]: https://developer.apple.com/xcode/ +[GridDoc]: https://github.com/paboyle/Grid/blob/develop/documentation/Grid.pdf + +The following sections explain these steps in more detail + +## 1. Install Xcode and the Xcode command-line utilities + +See Apple's [Xcode website][Xcode] for instructions on installing Xcode. + +Once Xcode is installed, install the Xcode command-line utilities using: + + xcode-select --install + +## 2. Set Grid environment variables + +To make sure we can share Xcode projects via git and have them work without requiring modification, we will define Grid environment variables. To make sure these environment variables will be available to the Xcode build system, issue the following shell command: + + defaults write com.apple.dt.Xcode UseSanitizedBuildSystemEnvironment -bool NO + +These are the environment variables we will define for Grid: + +Variable | Typical Value | Use +--- | --- | --- +`Grid` | `/Users/user_id/src/Grid` | Path to grid source +`GridPre` | `/Users/user_id/bin` | Path to install directory containing grid pre-requisites built from source +`GridPkg` | **MacPorts**=`/opt/local`, **Homebrew**=`/usr/local` | Path to package manager install directory + +Choose either of the following ways to do this, and when you're done, log out and in again. To check these have been set: + + printenv|grep -i grid + +### Method 1 -- Apple Script + +* Start *Script Editor* (cmd-space, *script editor*) +* Click on *New Document*. Paste the following into the new script, editing the paths appropriately (just replace `user_id` with your *user_id* if you are unsure): + +```apple script +do shell script "launchctl setenv Grid $HOME/src/Grid +launchctl setenv GridPre $HOME/bin +launchctl setenv GridPkg /opt/local" +``` + +* Save the script inside `~/Applications` and give it the name `GridEnv.app`. +* Open `System Preferences`, `Users & Groups` +* Click on `Login Items` +* Click the plus sign to add a new login item +* Select the `~/Applications` folder and select `GridEnv.app` + +Log out and in again. + +### Method 2 -- `environment.plist` + +Make the file `environment.plist` in `~/Library/LaunchAgents` with the following contents, editing the paths appropriately (just replace `user_id` with your *user_id* if you are unsure): + +```html + + + + +Label +Grid.startup +ProgramArguments + +sh +-c +launchctl setenv Grid $HOME/src/Grid +launchctl setenv GridPre $HOME/bin +launchctl setenv GridPkg /opt/local + + +RunAtLoad + + + +``` + +## 3. Install and build Open MPI -- ***optional*** + +Download the latest version of [Open MPI][OMPI] version 3.1 (I used 3.1.3). + +NB: Grid does not have any dependencies on fortran, however many standard scientific packages do, so you may as well download GNU fortran (e.g. MacPorts ``gfortran`` package) and build Open MPI like so: + +[OMPI]: https://www.open-mpi.org/software/ompi/v3.1/ + + ../configure CC=clang CXX=clang++ F77=gfortran FC=gfortran CXXFLAGS=-g --prefix=$GridPre/openmpi + make -j 4 all install + +(If you don't want to bother with fortran bindings, just don't include the F77 and FC flags) + +## 4. Install and build Grid pre-requisites + +To simplify the installation of **Grid pre-requisites**, you can use your favourite package manager, e.g.: + +### 1. [MacPorts][MacPorts] + +[MacPorts]: https://www.macports.org "MacPorts package manager" + +Install [MacPorts][MacPorts] if you haven't done so already, and then install packages with: + + sudo port install + +These are the `portname`s for mandatory Grid libraries: + +* git +* gmp +* mpfr + +and these are the `portname`s for optional Grid libraries: + +* fftw-3 +* hdf5 +* lapack +* doxygen +* OpenBLAS + +***Please update this list with any packages I've missed! ... and double-check whether OpenBLAS is really for Grid*** + +### 2. [Homebrew][Homebrew] + +[Homebrew]: https://brew.sh "Homebrew package manager" + +Install [Homebrew][Homebrew] if you haven't done so already, and then install packages with: + + sudo brew install + +The same packages are available as from MacPorts. + +### Install LIME ***optional*** + +There isn't currently a port for [C-LIME][C-LIME], so download the source and then build it: + +[C-LIME]: https://usqcd-software.github.io/c-lime/ "C-language API for Lattice QCD Interchange Message Encapsulation / Large Internet Message Encapsulation" + + ../configure --prefix=$GridPre/lime CC=clang + make -j 4 all install + +## 5. Install, Configure and Build Grid + +### 5.1 Install Grid + +[Grid]: https://github.com/paboyle/Grid + +Start by cloning [Grid (from GitHub)][Grid] ***into the directory you specified in*** `$Grid`. Bear in mind that git will create the `Grid` subdirectory to place Grid in, so for example if `$Grid` is set to `~/src/Grid` then install Grid with: + + cd ~/src + +followed by either: + + git clone git@github.com:paboyle/Grid.git + +or + + git clone https://github.com/paboyle/Grid.git + +depending on how many times you like to enter your password. + +### 5.2 Configure Grid + +The Xcode build system supports multiple configurations for each project, by default: `Debug` and `Release`, but more configurations can be defined. We will create separate Grid build directories for each configuration, using the Grid **Autoconf** build system to make each configuration. NB: it is **not** necessary to run `make install` on them once they are built (IDE features such as *jump to definition* will work better of you don't). + +Below are shown the `configure` script invocations for three recommended configurations. You are free to define more, fewer or different configurations, but as a minimum, be sure to build a `Debug` configuration. + +#### 1. `Debug` + +This is the build for every day developing and debugging with Xcode. It uses the Xcode clang c++ compiler, without MPI, and defaults to double-precision. Xcode builds the `Debug` configuration with debug symbols for full debugging: + + ../configure --with-hdf5=$GridPkg --with-gmp=$GridPkg --with-mpfr=$GridPkg --with-fftw=$GridPkg --with-lime=$GridPre/lime --enable-simd=GEN --enable-precision=double CXX=clang++ --prefix=$GridPre/GridDebug --enable-comms=none --enable-doxygen-doc + +#### 2. `Release` + +Since Grid itself doesn't really have debug configurations, the release build is recommended to be the same as `Debug`, except using single-precision (handy for validation): + + ../configure --with-hdf5=$GridPkg --with-gmp=$GridPkg --with-mpfr=$GridPkg --with-fftw=$GridPkg --with-lime=$GridPre/lime --enable-simd=GEN --enable-precision=single CXX=clang++ --prefix=$GridPre/GridRelease --enable-comms=none --enable-doxygen-doc + +#### 3. `MPIDebug` + +Debug configuration with MPI: + + ../configure --with-hdf5=$GridPkg --with-gmp=$GridPkg --with-mpfr=$GridPkg --with-fftw=$GridPkg --with-lime=$GridPre/lime --enable-simd=GEN --enable-precision=double CXX=clang++ --prefix=$GridPre/GridMPIDebug --enable-comms=mpi-auto MPICXX=$GridPre/openmpi/bin/mpicxx --enable-doxygen-doc + +### 5.3 Build Grid + +Each configuration must be built before they can be used. You can either: + +1. Use automake and the Grid Makefile with `make -j 4` (NB: you **do not** need to run `make install` for these to work with Xcode) +2. Build `Grid` and `Hadrons` under Xcode (see below) + +# Make a new application which links to Grid / Hadrons + +Making an Xcode project which links to Grid / Hadrons is straightforward: + +* Make a new application (in the usual way) +* Configure your application to use Grid (via three project settings:) + 1. `HEADER_SEARCH_PATHS` + 2. `LIBRARY_SEARCH_PATHS` + 3. `OTHER_LDFLAGS` +* Make additional configurations, e.g. `MPIDebug` (NB Xcode will make `Debug` and `Release` by default) + +Detailed instructions follow, but instead of following the instructions in this section, you can clone `HelloGrid` from the [University of Edinburgh GitLab site][HelloGrid]. + +[HelloGrid]: https://git.ecdf.ed.ac.uk/s1786208/HelloGrid + +## Make a new application + +To make a hello world application for Grid: + +* Start Xcode +* Click 'Create a new project' +* Click ‘macOS’, then in the ‘Application’ section choose ‘Command Line Tool’, then click ‘Next’ +* Choose options for your new project: + * Product Name: HelloGrid + * Team: None + * Organisation Name: sopa + * Organisation Identifier: uk.ac.ed.ph + * Language: C++ + * ... then click ‘Next’ +* Choose a location for your project, e.g. `$HOME/src`. NB: The project and all it’s files will be created inside `$HOME/src/HelloGrid`. If you are using Git, you can put the new project under Git source control immediately, if you like. Now click ‘Create’. + +## Configure your new application to use Grid + +Click the project name (`HelloGrid`) in the project navigator pane on the left (command-1 if it's not visible), then click the project name (`HelloGrid`) under `PROJECT` in the second pane. Click the `Build Settings` tab on the right, then under that click `All` and `Combined`. You should see: + +![Project settings](GridXcFig1.png) + +We now need to make changes to two sections (these are listed in alphabetical order), bearing in mind that if you are not using MPI (or you gave your build directories different names) replace `build_mpidebug` and `build_mpirelease` with the directory names you used. + +### 1. Search Paths + +#### HEADER_SEARCH_PATHS + +Obtain a list of header locations required by Grid by running the following from your Grid build directory (choose an MPI configuration if you built one, e.g. `MPIDebug`): + + ./grid-config --cxxflags + +Output should look similar to: + + -I$GridPre/openmpi/include -I$GridPkg/include -I$GridPre/lime/include -I$GridPkg/include -I$GridPkg/include -I$GridPkg/include -O3 -g -std=c++11 + +The header locations follow the `-I` switches. You can ignore the other switches, and you can ignore duplicate entries, which just mean that your package manager has installed multiple packages in the same location. + +*Note: `grid-config` will output absolute paths. Make sure to replace absolute paths with environment variables (such as `$GridPre`) in your settings, so that the project will work unmodified for other collaborators downloading the same project from git.* + +Set HEADER_SEARCH_PATHS to: + + $Grid/build$(CONFIGURATION)/Grid + $Grid + $Grid/Grid + +followed by (***the order is important***) the locations reported by `grid-config --cxxflags`, ignoring duplicates, e.g.: + + $GridPre/openmpi/include + $GridPkg/include + $GridPre/lime/include + +**Note: the easiest way to set this value is to put it all on one line, space separated, and edit the text to the right of `HEADER_SEARCH_PATHS`**, i.e.: + + $Grid/build$(CONFIGURATION)/Grid $Grid $Grid/Grid $GridPre/openmpi/include $GridPkg/include $GridPre/lime/include + +#### LIBRARY_SEARCH_PATHS + +Obtain a list of library locations required by Grid by running the following from your Grid build directory (again, choose an MPI configuration if you built one, e.g. `MPIDebug`): + + ./grid-config --ldflags + +Output should look similar to: + + -L$GridPre/openmpi/lib -L$GridPkg/lib -L$GridPre/lime/lib -L$GridPkg/lib -L$GridPkg/lib -L$GridPkg/lib + +Paste the output ***with `$Grid/build$(CONFIGURATION)/Grid $Grid/build$(CONFIGURATION)/Hadrons ` prepended*** into `LIBRARY_SEARCH_PATHS`: + + $Grid/build$(CONFIGURATION)/Grid $Grid/build$(CONFIGURATION)/Hadrons $GridPre/openmpi/lib $GridPkg/lib $GridPre/lime/lib + +### 2. Linking + +#### OTHER_LDFLAGS + +The easiest way to link to all required libraries is to obtain a list of all libraries required by Grid by running the following from your Grid build directory: + + ./grid-config --libs + +and pasting the output ***with `-lGrid -lHadrons ` prepended*** (including the `-l` switches) directly into `OTHER_LDFLAGS`, e.g.: + + -lGrid -lHadrons -lmpi -lhdf5_cpp -lz -lcrypto -llime -lfftw3f -lfftw3 -lmpfr -lgmp -lstdc++ -lm -lz -lhdf5 + +## Make additional configurations + +On the project settings, `Info` tab, click the plus sign underneath configurations: + +![Add configurations](GridXcFig4.png) + +Choose `Duplicate "Debug" Configuration` (you can choose `Release` if you prefer) and give the new configuration a name, e.g. `MPIDebug`. + +## Edit your source code + +A hello world for grid is: + +```c++ +#include +using namespace Grid; + +int main(int argc, char * argv[]) { + Grid_init(&argc,&argv); + std::cout << GridLogMessage << "Hello Grid" << std::endl; + Grid_finalize(); + return 0; +} +``` + +## Create a `.gitignore` file for Xcode + +You can create an up-to-date .gitignore file to ignore all the Xcode temporary build files using [gitignore.io][GIO]. + +[GIO]: https://www.gitignore.io/api/xcode + +NB: If you let Xcode add your project to git when you created it, you probably want to remove your personal scheme selection from git: + + git rm --cached HelloGrid.xcodeproj/xcuserdata/$USER.xcuserdatad/xcschemes/xcschememanagement.plist + +## Run your program under the Xcode debugger + +First, specify command-line arguments. From the menu, select `Product`, then `Scheme`, then `Edit Scheme`. Select `Run` on the left, then select the `Arguments` tab on the right. Add the following to `Arguments passed on Launch`: + + --grid 4.4.4.8 + +If your program will be manipulating files, it's a good idea to specify the working directory on the `Options` tab under `Use Custom Working Directory` (by default, Xcode launches the program inside the Xcode build folder). + +Then click `Close`. + +Let's set a breakpoint by clicking on: + + Grid_finalize(); + +then from the menu selecting `Debug`, then `Breakpoints`, then `Add Breakpoint at Current Line`. + +Now click on the `Play` button (the right pointing triangle just to the right of the maximise button) to run your program under the debugger. (You may see dialog boxes the first couple of times asking whether to allow MPI to receive network requests - say yes to these.) + +The debug output pane opens at the bottom of Xcode, with output on the right (ending with `Hello Grid`) and local variables on the left i.e.: + +![Running under the debugger](GridXcFig2.png) + +See the Xcode documentation to learn about the debugger. When you're done, press `ctl-cmd-Y` to let the program run to completion. + +# Debugging multiple MPI processes under Xcode + +You could tell Xcode to use mpirun to launch multiple copies of a target executable, however if you do this the debugger will attach to mpirun - not your target process. + +Instead: + +1. Set a breakpoint just inside `main()` (otherwise your programs may complete before you attach to them all) + +2. From the `Debug` menu, select `Attach to Process by PID or Name ...`. In the `PID or Process Name` field, enter the name of your target. Then click `Attach`. + +3. From a terminal session, locate and run your executable using `mpirun` (*the mangled name of the project build products will not be exactly the same as this example*): + + `$GridPre/openmpi-3.1.3/bin/mpirun -np 2 ~/Library/Developer/Xcode/DerivedData/HelloGrid-fiyyuveptaqelbbvllomcgjyvghr/Build/Products/Debug/HelloGrid --grid 4.4.4.8 --mpi 1.1.1.2` + + The Xcode debugger will attach to the first process. + +4. From the `Debug` menu in Xcode, select `Attach to Process`, and other running instances of your application will appear at the top of the list. Attach to as many instances as you wish to debug. + +5. Click on the first process (which should have stopped at the breakpoint) and restart it with ctl-cmd-y + +You are now debugging multiple MPI instances, and the Xcode debugger should look similar to this: + +![Debugging multiple MPI instances under the Xcode debugger](GridXcFig3.png) + +# Build `Grid` and `Hadrons` libraries under Xcode + +If you want to build `Grid` and `Hadrons` libraries using Xcode, you will need to: + +1. Make new library targets for `Grid` and `Hadrons` + +2. Add Grid source folders to your project: + + a. Right click project then `Add files to "project" ...` + b. Choose `$Grid/Grid` folder + c. Select `Create groups` (`folder references` doesn't work) + d. Make sure none of the targets are selected + e. Click `Add` + f. Add each source file (not header) in `Grid` and its subdirectories to the `Grid` target (option-command-1, then tick source files) + +3. Add Hadrons source folders to your project + + a. As per `Grid`, but add each source file in `Hadrons` (except those in `Archive` and `Utilities`) to the `Hadrons` target + +4. Set the following values *for the entire project* in `Build Settings` + + Group | Variable | Value + --- | --- | --- + `Deployment` | `DSTROOT` | `$Grid/build$(CONFIGURATION)` *(do this for the entire project)* + `Search Paths` | `LIBRARY_SEARCH_PATHS` | remove `$Grid/build$(CONFIGURATION)/Grid $Grid/build$(CONFIGURATION)/Hadrons` from the start of the path + + This sets the deployment location to the makefile build folders (but by default, targets will have `SKIP_INSTALL` set to `Yes`). The change to the paths is to make sure any executable targets link to the versions of the `Grid` and `Hadrons` libraries just built. + +5. Set the following values for each of the `Grid` and `Hadrons` targets in `Build Settings` + + Group | Variable | Value + --- | --- | --- + `Deployment` | `DEPLOYMENT_LOCATION` | `Yes` + `Deployment` | `INSTALL_PATH` | `$(PRODUCT_NAME)/` + `Deployment` | `SKIP_INSTALL` | `No` + `Linking` | `OTHER_LDFLAGS` | remove `-lGrid -lHadrons` from the list + + This ensures that the libraries are copied back into the build folders when they are made (removing the need to run `make -j 4`) + +6. For `Grid`, in `Build Settings` in the `Build Options` group, set: + + Variable | Configuration | Value + --- | --- | --- + `EXCLUDED_SOURCE_FILE_NAMES` | Non-MPI configurations (`Debug` and `Release`) | `$(Grid)/Grid/communicator/Communicator_mpi3.cc $(Grid)/Grid/communicator/SharedMemoryMPI.cc` + `EXCLUDED_SOURCE_FILE_NAMES` | MPI configurations (`MPIDebug`) | `$(Grid)/Grid/communicator/Communicator_none.cc $(Grid)/Grid/communicator/SharedMemoryNone.cc` + +7. Make a new scheme called `Libraries` containing both `Grid` and `Hadrons` targets + + a. Edit the new scheme + b. On the Build tab, add both `Grid` and `Hadrons` targets + +You should now be able to build and debug any configuration. + +Note that with this setup, the Xcode build system is not aware of dependencies of your targets on the grid libraries. So you can modify Grid and/or Hadrons headers if you need to, and build your target without rebuilding the entire Grid and Hadrons Libraries (you can manually force the Libraries to rebuild by making the `Libraries` scheme). You can instead configure target dependencies to `Grid` and `Hadrons` libraries in the Xcode build system, just remember to also remove `-lGrid -lHadrons` from the list under `OTHER_LDFLAGS` for the entire project. diff --git a/scripts/copyright b/scripts/copyright index 2401f4aa..30187653 100755 --- a/scripts/copyright +++ b/scripts/copyright @@ -11,7 +11,7 @@ Grid physics library, www.github.com/paboyle/Grid Source file: $1 -Copyright (C) 2015-2018 +Copyright (C) 2015-2019 EOF diff --git a/scripts/filelist b/scripts/filelist index 9d5f92c2..78747315 100755 --- a/scripts/filelist +++ b/scripts/filelist @@ -52,5 +52,20 @@ for f in $TESTS; do echo ${BNAME}_LDADD=-lGrid>> Make.inc echo >> Make.inc done - +cd .. + + +# HMC Make.inc +cd $home/HMC +echo> Make.inc +TESTS=`ls *.cc` +TESTLIST=`echo ${TESTS} | sed s/.cc//g ` +echo bin_PROGRAMS = ${TESTLIST} > Make.inc +echo >> Make.inc +for f in $TESTS; do + BNAME=`basename $f .cc` + echo ${BNAME}_SOURCES=$f >> Make.inc + echo ${BNAME}_LDADD=-lGrid>> Make.inc + echo >> Make.inc +done cd .. diff --git a/tests/IO/Test_ildg_io.cc b/tests/IO/Test_ildg_io.cc index 94821234..369acfd1 100644 --- a/tests/IO/Test_ildg_io.cc +++ b/tests/IO/Test_ildg_io.cc @@ -53,7 +53,6 @@ int main (int argc, char ** argv) GridCartesian Fine(latt_size,simd_layout,mpi_layout); GridCartesian Coarse(clatt_size,simd_layout,mpi_layout); - GridParallelRNG pRNGa(&Fine); GridParallelRNG pRNGb(&Fine); GridSerialRNG sRNGa; @@ -94,6 +93,27 @@ int main (int argc, char ** argv) _IldgReader.close(); Umu_diff = Umu - Umu_saved; + std::cout < " << filename << " ..."; // writer needs to be destroyed so that writing physically happens { W writer(filename); - - write(writer, "testobject", object); + if( Precision ) + writer.setPrecision(Precision); + write(writer, tag , object); } + std::cout << " done. reading ..."; R reader(filename); - O buf; - bool good; + std::unique_ptr buf( new O ); // In case object too big for stack - read(reader, "testobject", buf); - good = (object == buf); - std::cout << name << " IO test: " << (good ? "success" : "failure"); - std::cout << std::endl; - if (!good) exit(EXIT_FAILURE); + read(reader, tag, *buf); + bool good = Serializable::CompareMember(object, *buf); + if (!good) { + std::cout << " failure!" << std::endl; + exit(EXIT_FAILURE); + } + std::cout << " done." << std::endl; } +// The only way I could get these iterators to work is to put the begin() and end() functions in the Eigen namespace +// So if Eigen ever defines these, we'll have a conflict and have to change this +namespace Eigen { + template + inline typename std::enable_if::value, typename EigenIO::Traits::scalar_type *>::type + begin( ET & et ) { return reinterpret_cast::scalar_type *>(et.data()); } + template + inline typename std::enable_if::value, typename EigenIO::Traits::scalar_type *>::type + end( ET & et ) { return begin(et) + et.size() * EigenIO::Traits::count; } +} + +// Perform I/O tests on a range of tensor types +// Test coverage: scalars, complex and GridVectors in single, double and default precision +class TensorIO : public Serializable { + using TestScalar = ComplexD; + using SR3 = Eigen::Sizes<9,4,2>; + using SR5 = Eigen::Sizes<5,4,3,2,1>; + using ESO = Eigen::StorageOptions; + using TensorRank3 = Eigen::Tensor; + using TensorR5 = Eigen::TensorFixedSize; + using TensorR5Alt = Eigen::TensorFixedSize; + using Tensor942 = Eigen::TensorFixedSize; + using aTensor942 = std::vector; + using Perambulator = Eigen::Tensor; + using LSCTensor = Eigen::TensorFixedSize>; + + static const Real FlagR; + static const Complex Flag; + static const ComplexF FlagF; + static const TestScalar FlagTS; + static const char * const pszFilePrefix; + + void Init(unsigned short Precision) + { + for( auto &s : Perambulator1 ) s = Flag; + for( auto &s : Perambulator2 ) s = Flag; + for( auto &s : tensorR5 ) s = FlagR; + for( auto &s : tensorRank3 ) s = FlagF; + for( auto &s : tensor_9_4_2 ) s = FlagTS; + for( auto &t : atensor_9_4_2 ) + for( auto &s : t ) s = FlagTS; + for( auto &s : MyLSCTensor ) s = Flag; + } + + // Perform an I/O test for a single Eigen tensor (of any type) + template + static void TestOne(const char * MyTypeName, unsigned short Precision, std::string &filename, + const char * pszExtension, unsigned int &TestNum, + typename EigenIO::Traits::scalar_type Flag, IndexTypes... otherDims) + { + using Traits = EigenIO::Traits; + using scalar_type = typename Traits::scalar_type; + std::unique_ptr pTensor{new T(otherDims...)}; + for( auto &s : * pTensor ) s = Flag; + filename = pszFilePrefix + std::to_string(++TestNum) + "_" + MyTypeName + pszExtension; + ioTest(filename, * pTensor, MyTypeName, MyTypeName); + } + +public: + GRID_SERIALIZABLE_CLASS_MEMBERS(TensorIO + , SpinColourVector, spinColourVector + , SpinColourMatrix, spinColourMatrix + , std::vector, DistilParameterNames + , std::vector, DistilParameterValues + , Perambulator, Perambulator1 + , Perambulator, Perambulator2 + , TensorR5, tensorR5 + , TensorRank3, tensorRank3 + , Tensor942, tensor_9_4_2 + , aTensor942, atensor_9_4_2 + , LSCTensor, MyLSCTensor + ); + TensorIO() + : DistilParameterNames {"do", "androids", "dream", "of", "electric", "sheep?"} + , DistilParameterValues{2,3,1,4,5,1} + , Perambulator1(2,3,1,4,5,1) + , Perambulator2(7,1,6,1,5,1) + , tensorRank3(7,3,2) + , atensor_9_4_2(3) {} + +#define TEST_PARAMS( T ) #T, Precision, filename, pszExtension, TestNum + + // Perform a series of I/O tests for Eigen tensors, including a serialisable object + template + static void Test(const char * pszExtension, unsigned short Precision = 0) + { + // Perform a series of tests on progressively more complex tensors + unsigned int TestNum = 0; + std::string filename; + // Rank 1 tensor containing a single integer + using TensorSingle = Eigen::TensorFixedSize>; + TestOne( TEST_PARAMS( TensorSingle ), 7 ); // lucky! + // Rather convoluted way of defining four complex numbers + using TensorSimple = Eigen::Tensor, 6>; + using I = typename TensorSimple::Index; // NB: Never specified, so same for all my test tensors + // Try progressively more complicated tensors + TestOne( TEST_PARAMS( TensorSimple ), FlagTS, 1,1,1,1,1,1 ); + TestOne( TEST_PARAMS( TensorRank3 ), FlagF, 6, 3, 2 ); + TestOne(TEST_PARAMS( Tensor942 ), FlagTS); + TestOne(TEST_PARAMS( LSCTensor ), Flag ); + TestOne(TEST_PARAMS( TensorR5 ), FlagR); + // Now test a serialisable object containing a number of tensors + { + static const char MyTypeName[] = "TensorIO"; + filename = pszFilePrefix + std::to_string(++TestNum) + "_" + MyTypeName + pszExtension; + std::unique_ptr pObj{new TensorIO()}; + pObj->Init(Precision); + ioTest(filename, * pObj, MyTypeName, MyTypeName, Precision); + } + // Stress test. Too large for the XML or text readers and writers! +#ifdef STRESS_TEST + const std::type_info &tw = typeid( WTR_ ); + if( tw == typeid( Hdf5Writer ) || tw == typeid( BinaryWriter ) ) { + using LCMTensor=Eigen::TensorFixedSize,2>,7>,3>, + Eigen::Sizes<2,4,11,10,9>, Eigen::StorageOptions::RowMajor>; + std::cout << "sizeof( LCMTensor ) = " << sizeof( LCMTensor ) / 1024 / 1024 << " MB" << std::endl; + TestOne(TEST_PARAMS( LCMTensor ), Flag); + } +#endif + } +}; + +const Real TensorIO::FlagR {1}; +const Complex TensorIO::Flag {1,-1}; +const ComplexF TensorIO::FlagF {1,-1}; +const TensorIO::TestScalar TensorIO::FlagTS{1,-1}; +const char * const TensorIO::pszFilePrefix = "tensor_"; + template void tensorConvTestFn(GridSerialRNG &rng, const std::string label) { @@ -121,12 +256,12 @@ void tensorConvTestFn(GridSerialRNG &rng, const std::string label) int main(int argc,char **argv) { Grid_init(&argc,&argv); - + std::cout << std::boolalpha << "==== basic IO" << std::endl; // display true / false for boolean + GridSerialRNG rng; rng.SeedFixedIntegers(std::vector({42,10,81,9})); - - std::cout << "==== basic IO" << std::endl; + XmlWriter WR("bother.xml"); // test basic type writing @@ -146,7 +281,6 @@ int main(int argc,char **argv) // test serializable class writing myclass obj(1234); // non-trivial constructor std::vector vec; - std::pair pair; std::cout << "-- serialisable class writing to 'bother.xml'..." << std::endl; write(WR,"obj",obj); @@ -154,15 +288,15 @@ int main(int argc,char **argv) vec.push_back(obj); vec.push_back(myclass(5678)); vec.push_back(myclass(3838)); - pair = std::make_pair(myenum::red, myenum::blue); write(WR, "objvec", vec); std::cout << "-- serialisable class writing to std::cout:" << std::endl; std::cout << obj << std::endl; std::cout << "-- serialisable class comparison:" << std::endl; - std::cout << "vec[0] == obj: " << ((vec[0] == obj) ? "true" : "false") << std::endl; - std::cout << "vec[1] == obj: " << ((vec[1] == obj) ? "true" : "false") << std::endl; + std::cout << "vec[0] == obj: " << (vec[0] == obj) << std::endl; + std::cout << "vec[1] == obj: " << (vec[1] == obj) << std::endl; std::cout << "-- pair writing to std::cout:" << std::endl; + std::pair pair = std::make_pair(myenum::red, myenum::blue); std::cout << pair << std::endl; // read tests @@ -184,7 +318,15 @@ int main(int argc,char **argv) #ifdef HAVE_HDF5 ioTest("iotest.h5", obj, "HDF5 (object) "); ioTest("iotest.h5", vec, "HDF5 (vector of objects)"); + std::cout << "\n==== detailed Hdf5 tensor tests (Grid::EigenIO)" << std::endl; + TensorIO::Test(".h5"); #endif + std::cout << "\n==== detailed binary tensor tests (Grid::EigenIO)" << std::endl; + TensorIO::Test(".bin"); + std::cout << "\n==== detailed xml tensor tests (Grid::EigenIO)" << std::endl; + TensorIO::Test(".xml", 6); + std::cout << "\n==== detailed text tensor tests (Grid::EigenIO)" << std::endl; + TensorIO::Test(".dat", 5); std::cout << "\n==== vector flattening/reconstruction" << std::endl; typedef std::vector>> vec3d; @@ -227,4 +369,19 @@ int main(int argc,char **argv) tensorConvTest(rng, ColourVector); tensorConvTest(rng, SpinMatrix); tensorConvTest(rng, SpinVector); + + { + HMCparameters HMCparams; + HMCparams.StartingType =std::string("CheckpointStart"); + HMCparams.StartTrajectory =7; + HMCparams.Trajectories =1000; + HMCparams.NoMetropolisUntil=0; + HMCparams.MD.name =std::string("Force Gradient"); + HMCparams.MD.MDsteps = 10; + HMCparams.MD.trajL = 1.0; + + XmlWriter HMCwr("HMCparameters.xml"); + write(HMCwr,"HMCparameters",HMCparams); + } + Grid_finalize(); } diff --git a/tests/core/Test_fft_gfix.cc b/tests/core/Test_fft_gfix.cc index 83127c8f..228770a8 100644 --- a/tests/core/Test_fft_gfix.cc +++ b/tests/core/Test_fft_gfix.cc @@ -60,11 +60,18 @@ int main (int argc, char ** argv) std::cout<< "* Testing we can gauge fix steep descent a RGT of Unit gauge *" <::SteepestDescentGaugeFix(Umu,alpha,10000,1.0e-12, 1.0e-12,false); + FourierAcceleratedGaugeFixer::SteepestDescentGaugeFix(Umu,xform1,alpha,10000,1.0e-12, 1.0e-12,false); + + // Check the gauge xform matrices + Utmp=Urnd; + SU::GaugeTransform(Utmp,xform1); + Utmp = Utmp - Umu; + std::cout << " Norm Difference of xformed gauge "<< norm2(Utmp) << std::endl; + plaq=WilsonLoops::avgPlaquette(Umu); std::cout << " Final plaquette "<::SteepestDescentGaugeFix(Umu,alpha,10000,1.0e-12, 1.0e-12,true); + FourierAcceleratedGaugeFixer::SteepestDescentGaugeFix(Umu,xform2,alpha,10000,1.0e-12, 1.0e-12,true); + + Utmp=Urnd; + SU::GaugeTransform(Utmp,xform2); + Utmp = Utmp - Umu; + std::cout << " Norm Difference of xformed gauge "<< norm2(Utmp) << std::endl; + plaq=WilsonLoops::avgPlaquette(Umu); std::cout << " Final plaquette "<::avgPlaquette(Umu); std::cout << " Final plaquette "<::avgPlaquette(Umu); + std::cout << " Initial plaquette "<::SteepestDescentGaugeFix(Umu,xform3,alpha,10000,1.0e-12, 1.0e-12,true,coulomb_dir); + + std::cout << Umu<::avgPlaquette(Umu); + std::cout << " Final plaquette "< - -This program is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License along -with this program; if not, write to the Free Software Foundation, Inc., -51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - -See the full license in the file "LICENSE" in the top level distribution directory -*************************************************************************************/ -/* END LEGAL */ - -#include -#include - -using namespace Grid; -using namespace Hadrons; - -/******************************************************************************* - * Macros to reduce code duplication. - ******************************************************************************/ -// Common initialisation -#define HADRONS_DEFAULT_INIT \ - Grid_init(&argc, &argv); \ - HadronsLogError.Active(GridLogError.isActive()); \ - HadronsLogWarning.Active(GridLogWarning.isActive()); \ - HadronsLogMessage.Active(GridLogMessage.isActive()); \ - HadronsLogIterative.Active(GridLogIterative.isActive()); \ - HadronsLogDebug.Active(GridLogDebug.isActive()); \ - LOG(Message) << "Grid initialized" << std::endl; - -#define HADRONS_DEFAULT_GLOBALS(application) \ -{ \ - Application::GlobalPar globalPar; \ - globalPar.trajCounter.start = 1500; \ - globalPar.trajCounter.end = 1520; \ - globalPar.trajCounter.step = 20; \ - globalPar.runId = "test"; \ - globalPar.genetic.maxGen = 1000; \ - globalPar.genetic.maxCstGen = 200; \ - globalPar.genetic.popSize = 20; \ - globalPar.genetic.mutationRate = .1; \ - application.setPar(globalPar); \ -} - -// Useful definitions -#define ZERO_MOM "0. 0. 0. 0." -#define INIT_INDEX(s, n) (std::string(s) + "_" + std::to_string(n)) -#define ADD_INDEX(s, n) (s + "_" + std::to_string(n)) -#define LABEL_3PT(s, t1, t2) ADD_INDEX(INIT_INDEX(s, t1), t2) -#define LABEL_4PT(s, t1, t2, t3) ADD_INDEX(ADD_INDEX(INIT_INDEX(s, t1), t2), t3) -#define LABEL_4PT_NOISE(s, t1, t2, t3, nn) ADD_INDEX(ADD_INDEX(ADD_INDEX(INIT_INDEX(s, t1), t2), t3), nn) -#define LABEL_5D(s) s + "_5d"; - -// Wall source/sink macros -#define NAME_3MOM_WALL_SOURCE(t, mom) ("wall_" + std::to_string(t) + "_" + mom) -#define NAME_WALL_SOURCE(t) NAME_3MOM_WALL_SOURCE(t, ZERO_MOM) -#define NAME_POINT_SOURCE(pos) ("point_" + pos) - -// Meson module "gammas" special values -#define ALL_GAMMAS "all" - -#define MAKE_3MOM_WALL_PROP(tW, mom, propName, solver)\ -{\ - std::string srcName = NAME_3MOM_WALL_SOURCE(tW, mom);\ - makeWallSource(application, srcName, tW, mom);\ - makePropagator(application, propName, srcName, solver);\ -} - -#define MAKE_WALL_PROP(tW, propName, solver)\ - MAKE_3MOM_WALL_PROP(tW, ZERO_MOM, propName, solver) - -// Sequential source macros -#define MAKE_SEQUENTIAL_PROP(tS, qSrc, mom, seqPropName, solver, gamma)\ -{\ - std::string srcName = seqPropName + "_src";\ - makeSequentialSource(application, srcName, qSrc, tS, gamma, mom);\ - makePropagator(application, seqPropName, srcName, solver);\ -} - -// Point source macros -#define MAKE_POINT_PROP(pos, propName, solver)\ -{\ - std::string srcName = NAME_POINT_SOURCE(pos);\ - makePointSource(application, srcName, pos);\ - makePropagator(application, propName, srcName, solver);\ -} - -/******************************************************************************* - * Action setups. - ******************************************************************************/ - -/******************************************************************************* - * Name: makeWilsonAction - * Parameters: application - main application that stores modules. - * actionName - name of action module to create. - * gaugeField - gauge field module. - * mass - quark mass. - * boundary - fermion boundary conditions (default to periodic - * space, antiperiodic time). - * Returns: None. - ******************************************************************************/ -inline void makeWilsonAction(Application &application, std::string actionName, - std::string &gaugeField, double mass, - std::string boundary = "1 1 1 -1") -{ - if (!(VirtualMachine::getInstance().hasModule(actionName))) - { - MAction::Wilson::Par actionPar; - actionPar.gauge = gaugeField; - actionPar.mass = mass; - actionPar.boundary = boundary; - actionPar.twist = "0. 0. 0. 0."; - application.createModule(actionName, actionPar); - } -} - -/******************************************************************************* - * Name: makeDWFAction - * Parameters: application - main application that stores modules. - * actionName - name of action module to create. - * gaugeField - gauge field module. - * mass - quark mass. - * M5 - domain wall height. - * Ls - fifth dimension extent. - * boundary - fermion boundary conditions (default to periodic - * space, antiperiodic time). - * Returns: None. - ******************************************************************************/ -inline void makeDWFAction(Application &application, std::string actionName, - std::string &gaugeField, double mass, double M5, - unsigned int Ls, std::string boundary = "1 1 1 -1") -{ - if (!(VirtualMachine::getInstance().hasModule(actionName))) - { - MAction::DWF::Par actionPar; - actionPar.gauge = gaugeField; - actionPar.Ls = Ls; - actionPar.M5 = M5; - actionPar.mass = mass; - actionPar.boundary = boundary; - actionPar.twist = "0. 0. 0. 0."; - application.createModule(actionName, actionPar); - } -} - -/******************************************************************************* - * Functions for propagator construction. - ******************************************************************************/ - -/******************************************************************************* - * Name: makeRBPrecCGSolver - * Purpose: Make RBPrecCG solver module for specified action. - * Parameters: application - main application that stores modules. - * solverName - name of solver module to create. - * actionName - action module corresponding to propagators to be - * computed. - * residual - CG target residual. - * Returns: None. - ******************************************************************************/ -inline void makeRBPrecCGSolver(Application &application, std::string &solverName, - std::string &actionName, double residual = 1e-8) -{ - if (!(VirtualMachine::getInstance().hasModule(solverName))) - { - MSolver::RBPrecCG::Par solverPar; - solverPar.action = actionName; - solverPar.residual = residual; - solverPar.maxIteration = 10000; - application.createModule(solverName, - solverPar); - } -} - -/******************************************************************************* - * Name: makePointSource - * Purpose: Construct point source and add to application module. - * Parameters: application - main application that stores modules. - * srcName - name of source module to create. - * pos - Position of point source. - * Returns: None. - ******************************************************************************/ -inline void makePointSource(Application &application, std::string srcName, - std::string pos) -{ - // If the source already exists, don't make the module again. - if (!(VirtualMachine::getInstance().hasModule(srcName))) - { - MSource::Point::Par pointPar; - pointPar.position = pos; - application.createModule(srcName, pointPar); - } -} - -/******************************************************************************* - * Name: makeSequentialSource - * Purpose: Construct sequential source and add to application module. - * Parameters: application - main application that stores modules. - * srcName - name of source module to create. - * qSrc - Input quark for sequential inversion. - * tS - sequential source timeslice. - * mom - momentum insertion (default is zero). - * Returns: None. - ******************************************************************************/ -inline void makeSequentialSource(Application &application, std::string srcName, - std::string qSrc, unsigned int tS, - Gamma::Algebra gamma = Gamma::Algebra::GammaT, - std::string mom = ZERO_MOM) -{ - // If the source already exists, don't make the module again. - if (!(VirtualMachine::getInstance().hasModule(srcName))) - { - MSource::SeqGamma::Par seqPar; - seqPar.q = qSrc; - seqPar.tA = tS; - seqPar.tB = tS; - seqPar.mom = mom; - seqPar.gamma = gamma; - application.createModule(srcName, seqPar); - } -} - -/******************************************************************************* - * Name: makeConservedSequentialSource - * Purpose: Construct sequential source with conserved current insertion and - * add to application module. - * Parameters: application - main application that stores modules. - * srcName - name of source module to create. - * qSrc - Input quark for sequential inversion. - * actionName - action corresponding to quark. - * tS - sequential source timeslice. - * curr - conserved current type to insert. - * mu - Lorentz index of current to insert. - * mom - momentum insertion (default is zero). - * Returns: None. - ******************************************************************************/ -inline void makeConservedSequentialSource(Application &application, - std::string &srcName, - std::string &qSrc, - std::string &actionName, - unsigned int tS, - Current curr, - unsigned int mu, - std::string mom = ZERO_MOM) -{ - // If the source already exists, don't make the module again. - if (!(VirtualMachine::getInstance().hasModule(srcName))) - { - MSource::SeqConserved::Par seqPar; - seqPar.q = qSrc; - seqPar.action = actionName; - seqPar.tA = tS; - seqPar.tB = tS; - seqPar.curr_type = curr; - seqPar.mu_min = mu; - seqPar.mu_min = mu; - seqPar.mom = mom; - application.createModule(srcName, seqPar); - } -} - -/******************************************************************************* - * Name: makeNoiseSource - * Parameters: application - main application that stores modules. - * srcName - name of source module to create. - * tA - lower source timeslice limit. - * tB - upper source timeslice limit. - * Returns: None. - ******************************************************************************/ -inline void makeNoiseSource(Application &application, std::string &srcName, - unsigned int tA, unsigned int tB) -{ - if (!(VirtualMachine::getInstance().hasModule(srcName))) - { - MSource::Z2::Par noisePar; - noisePar.tA = tA; - noisePar.tB = tB; - application.createModule(srcName, noisePar); - } - } - -/******************************************************************************* - * Name: makeWallSource - * Purpose: Construct wall source and add to application module. - * Parameters: application - main application that stores modules. - * srcName - name of source module to create. - * tW - wall source timeslice. - * mom - momentum insertion (default is zero). - * Returns: None. - ******************************************************************************/ -inline void makeWallSource(Application &application, std::string &srcName, - unsigned int tW, std::string mom = ZERO_MOM) -{ - // If the source already exists, don't make the module again. - if (!(VirtualMachine::getInstance().hasModule(srcName))) - { - MSource::Wall::Par wallPar; - wallPar.tW = tW; - wallPar.mom = mom; - application.createModule(srcName, wallPar); - } -} - -/******************************************************************************* - * Name: makePointSink - * Purpose: Create function for point sink smearing of a propagator. - * Parameters: application - main application that stores modules. - * propName - name of input propagator. - * sinkFnct - name of output sink smearing module. - * mom - momentum insertion (default is zero). - * Returns: None. - ******************************************************************************/ -inline void makePointSink(Application &application, std::string &sinkFnct, - std::string mom = ZERO_MOM) -{ - // If the sink function already exists, don't make it again. - if (!(VirtualMachine::getInstance().hasModule(sinkFnct))) - { - MSink::Point::Par pointPar; - pointPar.mom = mom; - application.createModule(sinkFnct, pointPar); - } -} - -/******************************************************************************* - * Name: sinkSmear - * Purpose: Perform sink smearing of a propagator. - * Parameters: application - main application that stores modules. - * sinkFnct - sink smearing module. - * propName - propagator to smear. - * smearedProp - name of output smeared propagator. - * Returns: None. - ******************************************************************************/ -inline void sinkSmear(Application &application, std::string &sinkFnct, - std::string &propName, std::string &smearedProp) -{ - // If the propagator has already been smeared, don't smear it again. - if (!(VirtualMachine::getInstance().hasModule(smearedProp))) - { - MSink::Smear::Par smearPar; - smearPar.q = propName; - smearPar.sink = sinkFnct; - application.createModule(smearedProp, smearPar); - } -} - -/******************************************************************************* - * Name: makePropagator - * Purpose: Construct source and propagator then add to application module. - * Parameters: application - main application that stores modules. - * propName - name of propagator module to create. - * srcName - name of source module to use. - * solver - solver to use (default is CG). - * Returns: None. - ******************************************************************************/ -inline void makePropagator(Application &application, std::string &propName, - std::string &srcName, std::string &solver) -{ - // If the propagator already exists, don't make the module again. - if (!(VirtualMachine::getInstance().hasModule(propName))) - { - MFermion::GaugeProp::Par quarkPar; - quarkPar.source = srcName; - quarkPar.solver = solver; - application.createModule(propName, quarkPar); - } -} - -/******************************************************************************* - * Name: makeLoop - * Purpose: Use noise source and inversion result to make loop propagator, then - * add to application module. - * Parameters: application - main application that stores modules. - * propName - name of propagator module to create. - * srcName - name of noise source module to use. - * resName - name of inversion result on given noise source. - * Returns: None. - ******************************************************************************/ -inline void makeLoop(Application &application, std::string &propName, - std::string &srcName, std::string &resName) -{ - // If the loop propagator already exists, don't make the module again. - if (!(VirtualMachine::getInstance().hasModule(propName))) - { - MLoop::NoiseLoop::Par loopPar; - loopPar.q = resName; - loopPar.eta = srcName; - application.createModule(propName, loopPar); - } -} - -/******************************************************************************* - * Contraction module creation. - ******************************************************************************/ - -/******************************************************************************* - * Name: mesonContraction - * Purpose: Create meson contraction module and add to application module. - * Parameters: application - main application that stores modules. - * modName - unique module name. - * output - name of output files. - * q1 - quark propagator 1. - * q2 - quark propagator 2. - * sink - sink smearing module. - * gammas - gamma insertions at source and sink. - * Returns: None. - ******************************************************************************/ -inline void mesonContraction(Application &application, - std::string &modName, std::string &output, - std::string &q1, std::string &q2, - std::string &sink, - std::string gammas = "") -{ - if (!(VirtualMachine::getInstance().hasModule(modName))) - { - MContraction::Meson::Par mesPar; - mesPar.output = output; - mesPar.q1 = q1; - mesPar.q2 = q2; - mesPar.sink = sink; - mesPar.gammas = gammas; - application.createModule(modName, mesPar); - } - } - -/******************************************************************************* - * Name: gamma3ptContraction - * Purpose: Create gamma3pt contraction module and add to application module. - * Parameters: application - main application that stores modules. - * npt - specify n-point correlator (for labelling). - * q1 - quark propagator 1, sink smeared. - * q2 - quark propagator 2. - * q3 - quark propagator 3. - * label - unique label to construct module name. - * tSnk - sink position of sink for q1. - * gamma - gamma insertions between q2 and q3. - * Returns: None. - ******************************************************************************/ -inline void gamma3ptContraction(Application &application, unsigned int npt, - std::string &q1, std::string &q2, - std::string &q3, std::string &label, - unsigned int tSnk = 0, - Gamma::Algebra gamma = Gamma::Algebra::Identity) -{ - std::string modName = std::to_string(npt) + "pt_" + label; - if (!(VirtualMachine::getInstance().hasModule(modName))) - { - MContraction::Gamma3pt::Par gamma3ptPar; - gamma3ptPar.output = std::to_string(npt) + "pt/" + label; - gamma3ptPar.q1 = q1; - gamma3ptPar.q2 = q2; - gamma3ptPar.q3 = q3; - gamma3ptPar.tSnk = tSnk; - gamma3ptPar.gamma = gamma; - application.createModule(modName, gamma3ptPar); - } - } - -/******************************************************************************* - * Name: weakContraction[Eye,NonEye] - * Purpose: Create Weak Hamiltonian contraction module for Eye/NonEye topology - * and add to application module. - * Parameters: application - main application that stores modules. - * npt - specify n-point correlator (for labelling). - * q1 - quark propagator 1. - * q2 - quark propagator 2. - * q3 - quark propagator 3. - * q4 - quark propagator 4. - * label - unique label to construct module name. - * tSnk - time position of sink (for sink smearing). - * Returns: None. - ******************************************************************************/ -#define HW_CONTRACTION(top) \ -inline void weakContraction##top(Application &application, unsigned int npt,\ - std::string &q1, std::string &q2, \ - std::string &q3, std::string &q4, \ - std::string &label, unsigned int tSnk = 0)\ -{\ - std::string modName = std::to_string(npt) + "pt_" + label;\ - if (!(VirtualMachine::getInstance().hasModule(modName)))\ - {\ - MContraction::WeakHamiltonian##top::Par weakPar;\ - weakPar.output = std::to_string(npt) + "pt/" + label;\ - weakPar.q1 = q1;\ - weakPar.q2 = q2;\ - weakPar.q3 = q3;\ - weakPar.q4 = q4;\ - weakPar.tSnk = tSnk;\ - application.createModule(modName, weakPar);\ - }\ -} -HW_CONTRACTION(Eye) // weakContractionEye -HW_CONTRACTION(NonEye) // weakContractionNonEye - -/******************************************************************************* - * Name: disc0Contraction - * Purpose: Create contraction module for 4pt Weak Hamiltonian + current - * disconnected topology for neutral mesons and add to application - * module. - * Parameters: application - main application that stores modules. - * q1 - quark propagator 1. - * q2 - quark propagator 2. - * q3 - quark propagator 3. - * q4 - quark propagator 4. - * label - unique label to construct module name. - * Returns: None. - ******************************************************************************/ -inline void disc0Contraction(Application &application, - std::string &q1, std::string &q2, - std::string &q3, std::string &q4, - std::string &label) -{ - std::string modName = "4pt_" + label; - if (!(VirtualMachine::getInstance().hasModule(modName))) - { - MContraction::WeakNeutral4ptDisc::Par disc0Par; - disc0Par.output = "4pt/" + label; - disc0Par.q1 = q1; - disc0Par.q2 = q2; - disc0Par.q3 = q3; - disc0Par.q4 = q4; - application.createModule(modName, disc0Par); - } - } - -/******************************************************************************* - * Name: discLoopContraction - * Purpose: Create contraction module for disconnected loop and add to - * application module. - * Parameters: application - main application that stores modules. - * q_loop - loop quark propagator. - * modName - unique module name. - * gamma - gamma matrix to use in contraction. - * Returns: None. - ******************************************************************************/ -inline void discLoopContraction(Application &application, - std::string &q_loop, std::string &modName, - Gamma::Algebra gamma = Gamma::Algebra::Identity) -{ - if (!(VirtualMachine::getInstance().hasModule(modName))) - { - MContraction::DiscLoop::Par discPar; - discPar.output = "disc/" + modName; - discPar.q_loop = q_loop; - discPar.gamma = gamma; - application.createModule(modName, discPar); - } -} - -/******************************************************************************* - * Name: makeWITest - * Purpose: Create module to test Ward Identities for conserved current - * contractions and add to application module. - * Parameters: application - main application that stores modules. - * modName - name of module to create. - * propName - 4D quark propagator. - * actionName - action used to compute quark propagator. - * mass - mass of quark. - * Ls - length of 5th dimension (default = 1). - * test_axial - whether or not to check PCAC relation. - * Returns: None. - ******************************************************************************/ -inline void makeWITest(Application &application, std::string &modName, - std::string &propName, std::string &actionName, - double mass, unsigned int Ls = 1, bool test_axial = false) -{ - if (!(VirtualMachine::getInstance().hasModule(modName))) - { - MContraction::WardIdentity::Par wiPar; - if (Ls > 1) - { - wiPar.q = LABEL_5D(propName); - } - else - { - wiPar.q = propName; - } - wiPar.action = actionName; - wiPar.mass = mass; - wiPar.test_axial = test_axial; - application.createModule(modName, wiPar); - } -} - -/******************************************************************************* - * Name: makeSeqCurrComparison - * Purpose: Create module to compare sequential insertion of conserved current - * against sink contraction and add to application module. - * Parameters: application - main application that stores modules. - * modName - name of module to create. - * propName - quark propagator (point source), 5D if available. - * seqName - 4D quark propagator with sequential insertion of - * conserved current. - * actionName - action used to compute quark propagators. - * origin - origin of point source propagator. - * t_J - time at which sequential current is inserted. - * mu - Lorentz index of sequential current. - * curr - type of conserved current inserted. - * Returns: None. - ******************************************************************************/ -inline void makeSeqCurrComparison(Application &application, std::string &modName, - std::string &propName, std::string &seqName, - std::string &actionName, std::string &origin, - unsigned int t_J, unsigned int mu, Current curr) -{ - if (!(VirtualMachine::getInstance().hasModule(modName))) - { - MUtilities::TestSeqConserved::Par seqPar; - seqPar.q = propName; - seqPar.qSeq = seqName; - seqPar.action = actionName; - seqPar.origin = origin; - seqPar.t_J = t_J; - seqPar.mu = mu; - seqPar.curr = curr; - application.createModule(modName, seqPar); - } -} - -/******************************************************************************* - * Name: makeSeqGamComparison - * Purpose: Create module to compare sequential insertion of gamma matrix - * against sink contraction and add to application module. - * Parameters: application - main application that stores modules. - * modName - name of module to create. - * propName - 4D quark propagator. - * seqProp - 4D quark propagator with sequential insertion of - * gamma matrix. - * gamma - Inserted gamma matrix. - * t_g - time at which gamma matrix is inserted - * sequentially. - * Returns: None. - ******************************************************************************/ -inline void makeSeqGamComparison(Application &application, std::string &modName, - std::string &propName, std::string &seqProp, - std::string &origin, Gamma::Algebra gamma, - unsigned int t_g) -{ - if (!(VirtualMachine::getInstance().hasModule(modName))) - { - MUtilities::TestSeqGamma::Par seqPar; - seqPar.q = propName; - seqPar.qSeq = seqProp; - seqPar.origin = origin; - seqPar.t_g = t_g; - seqPar.gamma = gamma; - application.createModule(modName, seqPar); - } -} diff --git a/tests/hadrons/Test_hadrons_3pt_contractions.cc b/tests/hadrons/Test_hadrons_3pt_contractions.cc deleted file mode 100644 index 09c478bb..00000000 --- a/tests/hadrons/Test_hadrons_3pt_contractions.cc +++ /dev/null @@ -1,123 +0,0 @@ -/************************************************************************************* - -Grid physics library, www.github.com/paboyle/Grid - -Source file: Tests/Hadrons/Test_hadrons_3pt_contractions.cc - -Copyright (C) 2015-2018 - - Author: Andrew Lawson - -This program is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License along -with this program; if not, write to the Free Software Foundation, Inc., -51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - -See the full license in the file "LICENSE" in the top level distribution directory -*************************************************************************************/ -/* END LEGAL */ - -#include "Test_hadrons.hpp" - -using namespace Grid; -using namespace Hadrons; - -int main(int argc, char *argv[]) -{ - // initialization ////////////////////////////////////////////////////////// - HADRONS_DEFAULT_INIT; - - // run setup /////////////////////////////////////////////////////////////// - Application application; - double mass = 0.04; - double M5 = 1.8; - unsigned int Ls = 12; - unsigned int nt = GridDefaultLatt()[Tp]; - unsigned int t_i = 0; - unsigned int t_f = nt / 2; - std::string mom = "1. 0. 0. 0."; - - // global parameters - HADRONS_DEFAULT_GLOBALS(application); - - // gauge field - std::string gaugeField = "gauge"; - application.createModule(gaugeField); - - // Action & solver setup. - std::string action = "DWF"; - std::string solver = "CG"; - makeDWFAction(application, action, gaugeField, mass, M5, Ls); - makeRBPrecCGSolver(application, solver, action); - - /*************************************************************************** - * Weak Contraction test: Non-Eye class. - **************************************************************************/ - // Make wall source propagators for each leg of 4-quark vertex. - std::string q_i_0 = "q_i_0"; - std::string q_i_p = "q_i_p"; - std::string q_f_0 = "q_f_0"; - std::string q_f_p = "q_f_p"; - MAKE_WALL_PROP(t_i, q_i_0, solver); - MAKE_WALL_PROP(t_f, q_f_0, solver); - MAKE_3MOM_WALL_PROP(t_i, mom, q_i_p, solver); - MAKE_3MOM_WALL_PROP(t_f, mom, q_f_p, solver); - - // Perform contractions, zero and non-zero momentum. - std::string HW_CW_0 = LABEL_3PT("HW_CW_0", t_i, t_f); - std::string HW_CW_p = LABEL_3PT("HW_CW_p", t_i, t_f); - weakContractionNonEye(application, 3, q_i_0, q_i_0, q_f_0, q_f_0, HW_CW_0); - weakContractionNonEye(application, 3, q_i_0, q_i_p, q_f_p, q_f_0, HW_CW_p); - - /*************************************************************************** - * Weak Contraction test: Eye-class. - **************************************************************************/ - // Create random propagator for loop. - std::string eta = "noise_source"; - makeNoiseSource(application, eta, 0, nt - 1); - std::string loopProp = "loop"; - std::string loopRes = loopProp + "_res"; - makePropagator(application, loopRes, eta, solver); - makeLoop(application, loopProp, eta, loopRes); - - // Wall sink smear the propagator directly connecting the source & sink. - // (i.e. make point sink but smear before the contraction) - std::string wallSink = "wall_sink"; - std::string qWall = "q_wall"; - makePointSink(application, wallSink); - sinkSmear(application, wallSink, q_i_0, qWall); - - // Perform contractions, zero and non-zero momentum. - std::string HW_SE_0 = LABEL_3PT("HW_SE_0", t_i, t_f); - std::string HW_SE_p = LABEL_3PT("HW_SE_p", t_i, t_f); - weakContractionEye(application, 3, qWall, q_i_0, q_f_p, loopProp, HW_SE_0, t_f); - weakContractionEye(application, 3, qWall, q_i_p, q_f_p, loopProp, HW_SE_p, t_f); - - /*************************************************************************** - * Gamma insertion test. - **************************************************************************/ - Gamma::Algebra gamma = Gamma::Algebra::GammaT; - std::string sd_0 = LABEL_3PT("sd_0", t_i, t_f); - std::string sd_p = LABEL_3PT("sd_p", t_i, t_f); - gamma3ptContraction(application, 3, qWall, q_i_0, q_f_0, sd_0, t_f, gamma); - gamma3ptContraction(application, 3, qWall, q_i_p, q_f_p, sd_p, t_f, gamma); - - // execution - application.saveParameterFile("ContractionTest3pt.xml"); - application.run(); - - // epilogue - LOG(Message) << "Grid is finalizing now" << std::endl; - Grid_finalize(); - - return EXIT_SUCCESS; -} diff --git a/tests/hadrons/Test_hadrons_conserved_current.cc b/tests/hadrons/Test_hadrons_conserved_current.cc deleted file mode 100644 index b8345af7..00000000 --- a/tests/hadrons/Test_hadrons_conserved_current.cc +++ /dev/null @@ -1,151 +0,0 @@ -/************************************************************************************* - -Grid physics library, www.github.com/paboyle/Grid - -Source file: Tests/Hadrons/Test_hadrons_conserved_current.cc - -Copyright (C) 2015-2018 - - Author: Andrew Lawson - -This program is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License along -with this program; if not, write to the Free Software Foundation, Inc., -51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - -See the full license in the file "LICENSE" in the top level distribution directory -*************************************************************************************/ -/* END LEGAL */ - -#include "Test_hadrons.hpp" - -using namespace Grid; -using namespace Hadrons; - -inline void setupSeqCurrTests(Application &application, std::string modStem, - std::string &pointProp, std::string &seqStem, - std::string &actionName, std::string &solverName, - std::string &origin, Current curr, - unsigned int t_J, unsigned int mu, - unsigned int Ls = 1) -{ - std::string modName = ADD_INDEX(modStem, mu); - std::string seqProp = ADD_INDEX(seqStem, mu); - std::string seqSrc = seqProp + "_src"; - - // 5D actions require 5D propagator as input for conserved current - // insertions. - std::string propIn; - if (Ls > 1) - { - propIn = LABEL_5D(pointProp); - } - else - { - propIn = pointProp; - } - - makeConservedSequentialSource(application, seqSrc, propIn, - actionName, t_J, curr, mu); - makePropagator(application, seqProp, seqSrc, solverName); - makeSeqCurrComparison(application, modName, propIn, seqProp, - actionName, origin, t_J, mu, curr); -} - -inline void setupWardIdentityTests(Application &application, - std::string &actionName, - double mass, - unsigned int Ls = 1, - bool perform_axial_tests = false) -{ - // solver - std::string solverName = actionName + "_CG"; - makeRBPrecCGSolver(application, solverName, actionName); - - unsigned int nt = GridDefaultLatt()[Tp]; - unsigned int t_J = nt/2; - - /*************************************************************************** - * Conserved current sink contractions: use a single point propagator for - * the Ward Identity test. - **************************************************************************/ - std::string pointProp = actionName + "_q_0"; - std::string origin = "0 0 0 0"; - std::string modName = actionName + " Ward Identity Test"; - MAKE_POINT_PROP(origin, pointProp, solverName); - makeWITest(application, modName, pointProp, actionName, mass, Ls, - perform_axial_tests); - - /*************************************************************************** - * Conserved current tests with sequential insertion of vector/axial - * current. If above Ward Identity passes, sufficient to test sequential - * insertion of conserved current agrees with contracted version. - **************************************************************************/ - // Compare sequential insertion to contraction. Should be enough to perform - // for time and one space component. - std::string seqStem = ADD_INDEX(pointProp + "seq_V", t_J); - std::string modStem = actionName + " Vector Sequential Test mu"; - setupSeqCurrTests(application, modStem, pointProp, seqStem, actionName, - solverName, origin, Current::Vector, t_J, Tp, Ls); - setupSeqCurrTests(application, modStem, pointProp, seqStem, actionName, - solverName, origin, Current::Vector, t_J, Xp, Ls); - - // Perform axial tests only if partially-conserved axial current exists for - // the action. - if (perform_axial_tests) - { - seqStem = ADD_INDEX(pointProp + "seq_A", t_J); - modStem = actionName + " Axial Sequential Test mu"; - setupSeqCurrTests(application, modStem, pointProp, seqStem, actionName, - solverName, origin, Current::Axial, t_J, Tp, Ls); - setupSeqCurrTests(application, modStem, pointProp, seqStem, actionName, - solverName, origin, Current::Axial, t_J, Xp, Ls); - } -} - -int main(int argc, char *argv[]) -{ - // initialization ////////////////////////////////////////////////////////// - HADRONS_DEFAULT_INIT; - - // run setup /////////////////////////////////////////////////////////////// - Application application; - double mass = 0.04; - double M5 = 1.8; - unsigned int Ls = 12; - - // global parameters - HADRONS_DEFAULT_GLOBALS(application); - - // gauge field - std::string gaugeField = "gauge"; - application.createModule(gaugeField); - - // Setup each action and the conserved current tests relevant to it. - std::string actionName = "DWF"; - makeDWFAction(application, actionName, gaugeField, mass, M5, Ls); - setupWardIdentityTests(application, actionName, mass, Ls, true); - - actionName = "Wilson"; - makeWilsonAction(application, actionName, gaugeField, mass); - setupWardIdentityTests(application, actionName, mass); - - // execution - application.saveParameterFile("ConservedCurrentTest.xml"); - application.run(); - - // epilogue - LOG(Message) << "Grid is finalizing now" << std::endl; - Grid_finalize(); - - return EXIT_SUCCESS; -} diff --git a/tests/hadrons/Test_hadrons_meson_conserved_3pt.cc b/tests/hadrons/Test_hadrons_meson_conserved_3pt.cc deleted file mode 100644 index 1246de02..00000000 --- a/tests/hadrons/Test_hadrons_meson_conserved_3pt.cc +++ /dev/null @@ -1,116 +0,0 @@ -/************************************************************************************* - -Grid physics library, www.github.com/paboyle/Grid - -Source file: Tests/Hadrons/Test_hadrons_meson_conserved_3pt.cc - -Copyright (C) 2015-2018 - - Author: Andrew Lawson - -This program is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License along -with this program; if not, write to the Free Software Foundation, Inc., -51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - -See the full license in the file "LICENSE" in the top level distribution directory -*************************************************************************************/ -/* END LEGAL */ - -#include "Test_hadrons.hpp" - -using namespace Grid; -using namespace Hadrons; - -int main(int argc, char *argv[]) -{ - // initialization ////////////////////////////////////////////////////////// - HADRONS_DEFAULT_INIT; - - // run setup /////////////////////////////////////////////////////////////// - Application application; - - // actions parameters - double mass = 0.04; - unsigned int Ls = 16; - double M5 = 1.8; - - // kinematics - unsigned int nt = GridDefaultLatt()[Tp]; - unsigned int tSrc = 0; - unsigned int tJ = nt / 4; - std::string kmom = "0. 0. 0. 0."; - std::string pmom = "1. 0. 0. 0."; - - // Global parameters. - HADRONS_DEFAULT_GLOBALS(application); - - // Unit gauge field. - std::string gaugeField = "Unit gauge"; - application.createModule(gaugeField); - - // DWF action - std::string actionName = "DWF"; - makeDWFAction(application, actionName, gaugeField, mass, M5, Ls); - - // Solver - std::string solver = "CG"; - makeRBPrecCGSolver(application, solver, actionName); - - // main test body ////////////////////////////////////////////////////////// - // Point sink modules. - std::string sink_0 = "sink_0"; - std::string sink_p = "sink_p"; - MSink::Point::Par sinkPar; - sinkPar.mom = kmom; - application.createModule(sink_0, sinkPar); - sinkPar.mom = pmom; - application.createModule(sink_p, sinkPar); - - // 2pt pion contraction, zero momentum. - std::string q_0 = "Q_0"; - MAKE_WALL_PROP(tSrc, q_0, solver); - std::string modName = INIT_INDEX("2pt_pion_WP", tSrc); - std::string output = "2pt/pion_WP_0"; - mesonContraction(application, modName, output, q_0, q_0, sink_0); - - // 2pt pion contraction, with momentum p. - std::string q_p = "Q_p"; - MAKE_3MOM_WALL_PROP(tSrc, pmom, q_p, solver); - modName = INIT_INDEX("2pt_pion_WP_p", tSrc); - output = "2pt/pion_WP_p"; - mesonContraction(application, modName, output, q_0, q_p, sink_p); - - // 3pt pion(0) -> pion(p), with sequentially inserted vector current in - // time direction. - std::string qSeq = q_0 + INIT_INDEX("_seq_Vc3", tJ); - std::string q5d = LABEL_5D(q_0); // Need 5D prop for DWF conserved current. - std::string srcName = qSeq + "_src"; - modName = LABEL_3PT("3pt_pion_Vc3", tSrc, tJ); - output = "3pt/pion_Vc3_p"; - makeConservedSequentialSource(application, srcName, q5d, actionName, - tJ, Current::Vector, Tp, pmom); - makePropagator(application, qSeq, srcName, solver); - mesonContraction(application, modName, output, q_0, qSeq, sink_p); - - std::string par_file_name = "conserved_3pt.xml"; - application.saveParameterFile(par_file_name); - application.run(); - - // epilogue - LOG(Message) << "Grid is finalizing now" << std::endl; - Grid_finalize(); - - return EXIT_SUCCESS; -} - - diff --git a/tests/hadrons/Test_hadrons_seq_gamma.cc b/tests/hadrons/Test_hadrons_seq_gamma.cc deleted file mode 100644 index 5e10b9f5..00000000 --- a/tests/hadrons/Test_hadrons_seq_gamma.cc +++ /dev/null @@ -1,90 +0,0 @@ -/************************************************************************************* - -Grid physics library, www.github.com/paboyle/Grid - -Source file: Tests/Hadrons/Test_hadrons_seq_gamma.cc - -Copyright (C) 2015-2018 - - Author: Andrew Lawson - -This program is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License along -with this program; if not, write to the Free Software Foundation, Inc., -51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - -See the full license in the file "LICENSE" in the top level distribution directory -*************************************************************************************/ -/* END LEGAL */ - -#include "Test_hadrons.hpp" - -using namespace Grid; -using namespace QCD; -using namespace Hadrons; - -/******************************************************************************* - * Consistency test for sequential gamma insertion. - ******************************************************************************/ - -int main(int argc, char *argv[]) -{ - // initialization ////////////////////////////////////////////////////////// - HADRONS_DEFAULT_INIT; - - // run setup /////////////////////////////////////////////////////////////// - Application application; - unsigned int nt = GridDefaultLatt()[Tp]; - unsigned int tS = nt / 2; - unsigned int Ls = 12; - double mass = 0.04; - double M5 = 1.8; - - // global parameters - HADRONS_DEFAULT_GLOBALS(application); - - // gauge field - std::string gaugeField = "gauge"; - application.createModule(gaugeField); - - // action - std::string actionName = "DWF"; - makeDWFAction(application, actionName, gaugeField, mass, M5, Ls); - - // solver - std::string solverName = "CG"; - makeRBPrecCGSolver(application, solverName, actionName); - - // test sequential propagator, with g5 insertion. - Gamma::Algebra g = Gamma::Algebra::Gamma5; - std::string pointProp = "q_0"; - std::string point5d = LABEL_5D(pointProp); - std::string origin = "0 0 0 0"; - MAKE_POINT_PROP(origin, pointProp, solverName); - - std::string seqProp = ADD_INDEX(pointProp + "_seqg5", tS); - std::string seqSrc = seqProp + "_src"; - MAKE_SEQUENTIAL_PROP(tS, pointProp, ZERO_MOM, seqProp, solverName, g); - - std::string modName = "Test g5 sequential insertion"; - makeSeqGamComparison(application, modName, pointProp, seqProp, origin, g, tS); - - // execution - application.saveParameterFile("SeqGamma5Test.xml"); - application.run(); - - // epilogue - LOG(Message) << "Grid is finalizing now" << std::endl; - Grid_finalize(); - - return EXIT_SUCCESS; -} diff --git a/tests/hadrons/Test_hadrons_wilsonFund.cc b/tests/hadrons/Test_hadrons_wilsonFund.cc deleted file mode 100644 index df621812..00000000 --- a/tests/hadrons/Test_hadrons_wilsonFund.cc +++ /dev/null @@ -1,159 +0,0 @@ -/************************************************************************************* - -Grid physics library, www.github.com/paboyle/Grid - -Source file: Tests/Hadrons/Test_hadrons_wilsonFund.cc - -Copyright (C) 2015-2018 - - Author: Antonin Portelli - -This program is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License along -with this program; if not, write to the Free Software Foundation, Inc., -51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - -See the full license in the file "LICENSE" in the top level distribution directory -*************************************************************************************/ -/* END LEGAL */ - -#include -#include - -using namespace Grid; -using namespace Hadrons; - -int main(int argc, char *argv[]) -{ - // initialization ////////////////////////////////////////////////////////// - Grid_init(&argc, &argv); - HadronsLogError.Active(GridLogError.isActive()); - HadronsLogWarning.Active(GridLogWarning.isActive()); - HadronsLogMessage.Active(GridLogMessage.isActive()); - HadronsLogIterative.Active(GridLogIterative.isActive()); - HadronsLogDebug.Active(GridLogDebug.isActive()); - LOG(Message) << "Grid initialized" << std::endl; - - // run setup /////////////////////////////////////////////////////////////// - Application application; - std::vector flavour = {"l"}; - std::vector mass = {-0.1}; - double csw = 0.0; - - // global parameters - Application::GlobalPar globalPar; - - globalPar.trajCounter.start = 309; - globalPar.trajCounter.end = 310; - globalPar.trajCounter.step = 1; - globalPar.runId = "test"; - - application.setPar(globalPar); - // gauge field - application.createModule("gauge"); - - // sources - //MSource::Z2::Par z2Par; - //z2Par.tA = 0; - //z2Par.tB = 0; - //application.createModule("z2", z2Par); - MSource::Point::Par ptPar; - ptPar.position = "0 0 0 0"; - application.createModule("pt", ptPar); - // sink - MSink::Point::Par sinkPar; - sinkPar.mom = "0 0 0"; - application.createModule("sink", sinkPar); - - // set fermion boundary conditions to be periodic space, antiperiodic time. - std::string boundary = "1 1 1 -1"; - - for (unsigned int i = 0; i < flavour.size(); ++i) - { - // actions - MAction::WilsonClover::Par actionPar; - actionPar.gauge = "gauge"; - actionPar.mass = mass[i]; - actionPar.boundary = boundary; - actionPar.csw_r = csw; - actionPar.csw_t = csw; - - // !!!!! Check if Anisotropy works !!!!! - actionPar.clover_anisotropy.isAnisotropic= false; - actionPar.clover_anisotropy.t_direction = 3 ; // Explicit for D=4 - actionPar.clover_anisotropy.xi_0 = 1.0 ; - actionPar.clover_anisotropy.nu = 1.0 ; - - application.createModule("WilsonClover_" + flavour[i], actionPar); - - // solvers - MSolver::RBPrecCG::Par solverPar; - solverPar.action = "WilsonClover_" + flavour[i]; - solverPar.residual = 1.0e-8; - solverPar.maxIteration = 10000; - application.createModule("CG_" + flavour[i], - solverPar); - - // propagators - MFermion::GaugeProp::Par quarkPar; - quarkPar.solver = "CG_" + flavour[i]; - quarkPar.source = "pt"; - application.createModule("Qpt_" + flavour[i], quarkPar); - // quarkPar.source = "z2"; - // application.createModule("QZ2_" + flavour[i], quarkPar); - } - for (unsigned int i = 0; i < flavour.size(); ++i) - for (unsigned int j = i; j < flavour.size(); ++j) - { - MContraction::Meson::Par mesPar; - - mesPar.output = "Fund_mesons/pt_" + flavour[i] + flavour[j]; - mesPar.q1 = "Qpt_" + flavour[i]; - mesPar.q2 = "Qpt_" + flavour[j]; - mesPar.gammas = "all"; - mesPar.sink = "sink"; - application.createModule("meson_pt_" - + flavour[i] + flavour[j], - mesPar); - // mesPar.output = "mesons/Z2_" + flavour[i] + flavour[j]; - // mesPar.q1 = "QZ2_" + flavour[i]; - // mesPar.q2 = "QZ2_" + flavour[j]; - // mesPar.gammas = "all"; - // mesPar.sink = "sink"; - // application.createModule("meson_Z2_" - // + flavour[i] + flavour[j], - // mesPar); - } - for (unsigned int i = 0; i < flavour.size(); ++i) - for (unsigned int j = i; j < flavour.size(); ++j) - for (unsigned int k = j; k < flavour.size(); ++k) - { - MContraction::Baryon::Par barPar; - - barPar.output = "Fund_baryons/pt_" + flavour[i] + flavour[j] + flavour[k]; - barPar.q1 = "Qpt_" + flavour[i]; - barPar.q2 = "Qpt_" + flavour[j]; - barPar.q3 = "Qpt_" + flavour[k]; - application.createModule( - "baryon_pt_" + flavour[i] + flavour[j] + flavour[k], barPar); - } - - // execution - application.saveParameterFile("WilsonClover_spectrum.xml"); - application.run(); - - // epilogue - LOG(Message) << "Grid is finalizing now" << std::endl; - Grid_finalize(); - - return EXIT_SUCCESS; -} diff --git a/tests/hmc/Test_hmc_Mobius2p1f.cc b/tests/hmc/Test_hmc_Mobius2p1f.cc new file mode 100644 index 00000000..253727d2 --- /dev/null +++ b/tests/hmc/Test_hmc_Mobius2p1f.cc @@ -0,0 +1,217 @@ +/************************************************************************************* + +Grid physics library, www.github.com/paboyle/Grid + +Source file: ./tests/Test_hmc_EODWFRatio.cc + +Copyright (C) 2015-2016 + +Author: Peter Boyle +Author: Guido Cossu + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License along +with this program; if not, write to the Free Software Foundation, Inc., +51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +See the full license in the file "LICENSE" in the top level distribution +directory +*************************************************************************************/ +/* END LEGAL */ +#include + +int main(int argc, char **argv) { + using namespace Grid; + using namespace Grid::QCD; + + Grid_init(&argc, &argv); + int threads = GridThread::GetThreads(); + // 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; + + // Typedefs to simplify notation + typedef WilsonImplR FermionImplPolicy; + typedef MobiusFermionR FermionAction; + typedef typename FermionAction::FermionField FermionField; + + typedef Grid::XmlReader Serialiser; + + //:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: + IntegratorParameters MD; + typedef GenericHMCRunner HMCWrapper; + MD.name = std::string("Leap Frog"); + // typedef GenericHMCRunner HMCWrapper; + // MD.name = std::string("Force Gradient"); + //typedef GenericHMCRunner HMCWrapper; + // MD.name = std::string("MinimumNorm2"); + MD.MDsteps = 40; + MD.trajL = 1.0; + + HMCparameters HMCparams; + HMCparams.StartTrajectory = 0; + HMCparams.Trajectories = 1; + HMCparams.NoMetropolisUntil= 20; + // "[HotStart, ColdStart, TepidStart, CheckpointStart]\n"; + HMCparams.StartingType =std::string("ColdStart"); + HMCparams.MD = MD; + HMCWrapper TheHMC(HMCparams); + + // Grid from the command line arguments --grid and --mpi + TheHMC.Resources.AddFourDimGrid("gauge"); // use default simd lanes decomposition + + CheckpointerParameters CPparams; + CPparams.config_prefix = "ckpoint_EODWF_lat"; + CPparams.rng_prefix = "ckpoint_EODWF_rng"; + CPparams.saveInterval = 10; + CPparams.format = "IEEE64BIG"; + TheHMC.Resources.LoadNerscCheckpointer(CPparams); + + RNGModuleParameters RNGpar; + RNGpar.serial_seeds = "1 2 3 4 5"; + RNGpar.parallel_seeds = "6 7 8 9 10"; + TheHMC.Resources.SetRNGSeeds(RNGpar); + + // Construct observables + // here there is too much indirection + typedef PlaquetteMod PlaqObs; + TheHMC.Resources.AddObservable(); + ////////////////////////////////////////////// + + const int Ls = 4; + Real beta = 2.13; + Real light_mass = 0.01; + Real strange_mass = 0.04; + Real pv_mass = 1.0; + RealD M5 = 1.8; + RealD b = 1.5; // Scale factor two + RealD c = 0.5; + + // RHMC + // OneFlavourRationalParams OFRp; + // OFRp.lo = 1.0e-2; + // OFRp.hi = 25; + // OFRp.MaxIter = 10000; + // OFRp.tolerance= 1.0e-7; + // OFRp.degree = 10; + // OFRp.precision= 40; + + // EOFA + OneFlavourRationalParams OFRp; + OFRp.lo = 0.98; + OFRp.hi = 25.0; + OFRp.MaxIter = 10000; + OFRp.tolerance= 1.0e-7; + OFRp.degree = 10; + OFRp.precision= 40; + + std::vector hasenbusch({ 0.1 }); + + auto GridPtr = TheHMC.Resources.GetCartesian(); + auto GridRBPtr = TheHMC.Resources.GetRBCartesian(); + auto FGrid = SpaceTimeGrid::makeFiveDimGrid(Ls,GridPtr); + auto FrbGrid = SpaceTimeGrid::makeFiveDimRedBlackGrid(Ls,GridPtr); + + IwasakiGaugeActionR GaugeAction(beta); + + // temporarily need a gauge field + LatticeGaugeField U(GridPtr); + + // These lines are unecessary if BC are all periodic + std::vector boundary = {1,1,1,-1}; + FermionAction::ImplParams Params(boundary); + + double StoppingCondition = 1e-10; + double MaxCGIterations = 30000; + ConjugateGradient CG(StoppingCondition,MaxCGIterations); + + //////////////////////////////////// + // Collect actions + //////////////////////////////////// + ActionLevel Level1(1); + ActionLevel Level2(4); + + //////////////////////////////////// + // Strange action + //////////////////////////////////// + + // Setup for RHMC + // FermionAction StrangeOp(U,*FGrid,*FrbGrid,*GridPtr,*GridRBPtr,light_mass,M5,b,c, Params); + // OneFlavourRationalPseudoFermionAction StrangePseudoFermion(StrangeOp,OFRp); + // Level1.push_back(&StrangePseudoFermion); + + // DJM: setup for EOFA ratio (Shamir) + // DomainWallEOFAFermionR Strange_Op_L(U, *FGrid, *FrbGrid, *GridPtr, *GridRBPtr, strange_mass, strange_mass, pv_mass, 0.0, -1, M5); + // DomainWallEOFAFermionR Strange_Op_R(U, *FGrid, *FrbGrid, *GridPtr, *GridRBPtr, pv_mass, strange_mass, pv_mass, -1.0, 1, M5); + // ExactOneFlavourRatioPseudoFermionAction EOFA(Strange_Op_L, Strange_Op_R, CG, OFRp, true); + // Level1.push_back(&EOFA); + + // DJM: setup for EOFA ratio (Mobius) + MobiusEOFAFermionR Strange_Op_L(U, *FGrid, *FrbGrid, *GridPtr, *GridRBPtr, strange_mass, strange_mass, pv_mass, 0.0, -1, M5, b, c); + MobiusEOFAFermionR Strange_Op_R(U, *FGrid, *FrbGrid, *GridPtr, *GridRBPtr, pv_mass, strange_mass, pv_mass, -1.0, 1, M5, b, c); + ExactOneFlavourRatioPseudoFermionAction EOFA(Strange_Op_L, Strange_Op_R, CG, OFRp, true); + Level1.push_back(&EOFA); + + // Setup for RHMC ratio + // FermionAction StrangeOp (U,*FGrid,*FrbGrid,*GridPtr,*GridRBPtr,strange_mass,M5,b,c, Params); + // FermionAction StrangePauliVillarsOp(U,*FGrid,*FrbGrid,*GridPtr,*GridRBPtr,pv_mass, M5,b,c, Params); + // OneFlavourEvenOddRatioRationalPseudoFermionAction StrangePseudoFermion(StrangePauliVillarsOp,StrangeOp,OFRp); + // Level1.push_back(&StrangePseudoFermion); + + //////////////////////////////////// + // up down action + //////////////////////////////////// + std::vector light_den; + std::vector light_num; + + int n_hasenbusch = hasenbusch.size(); + light_den.push_back(light_mass); + for(int h=0;h Numerators; + std::vector Denominators; + std::vector *> Quotients; + + for(int h=0;h(*Numerators[h],*Denominators[h],CG,CG)); + } + + for(int h=0;h + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + + See the full license in the file "LICENSE" in the top level distribution directory + *************************************************************************************/ + /* END LEGAL */ +#include + +using namespace std; +using namespace Grid; +using namespace Grid::QCD; + + +int main (int argc, char ** argv) +{ + Grid_init(&argc,&argv); + + + std::vector latt_size = GridDefaultLatt(); + std::vector simd_layout = GridDefaultSimd(Nd,vComplex::Nsimd()); + std::vector mpi_layout = GridDefaultMpi(); + GridCartesian Grid(latt_size,simd_layout,mpi_layout); + + std::vector seeds({1,2,3,4}); + GridParallelRNG pRNG(&Grid); pRNG.SeedFixedIntegers(seeds); + + LatticeFermion src(&Grid); random(pRNG,src); + RealD nrm = norm2(src); + LatticeFermion result(&Grid); result=zero; + LatticeGaugeField Umu(&Grid); + // SU3::HotConfiguration(pRNG,Umu); + SU3::ColdConfiguration(Umu); + std::vector U(4,&Grid); + + for(int mu=0;mu(Umu,mu); + } + + std::vector site({4,4,0,0}); + src=zero; + SpinColourVector scv; + scv=zero; + scv()(0)(0) = 1.0; + pokeSite(scv,src,site); + + CovariantSmearing::GaussianSmear(U, src, 2.0, 50, Tdir); + + std::cout << src < + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + + See the full license in the file "LICENSE" in the top level distribution directory + *************************************************************************************/ +/* */ + + +#include +#include + +using namespace std; +using namespace Grid; +using namespace Grid::QCD; + +int main(int argc, char **argv) { + + + Grid_init(&argc, &argv); + + // clang-format off + GridCartesian *FGrid_d = SpaceTimeGrid::makeFourDimGrid(GridDefaultLatt(), GridDefaultSimd(Nd, vComplexD::Nsimd()), GridDefaultMpi()); + GridCartesian *FGrid_f = SpaceTimeGrid::makeFourDimGrid(GridDefaultLatt(), GridDefaultSimd(Nd, vComplexF::Nsimd()), GridDefaultMpi()); + GridRedBlackCartesian *FrbGrid_d = SpaceTimeGrid::makeFourDimRedBlackGrid(FGrid_d); + GridRedBlackCartesian *FrbGrid_f = SpaceTimeGrid::makeFourDimRedBlackGrid(FGrid_f); + // clang-format on + + std::vector fSeeds({1, 2, 3, 4}); + GridParallelRNG fPRNG(FGrid_d); + fPRNG.SeedFixedIntegers(fSeeds); + + // clang-format off + LatticeFermionD src_d(FGrid_d); gaussian(fPRNG, src_d); + LatticeFermionD resultMGD_d(FGrid_d); resultMGD_d = zero; + LatticeFermionD resultMGF_d(FGrid_d); resultMGF_d = zero; + LatticeGaugeFieldD Umu_d(FGrid_d); + +#if 0 + { + FieldMetaData header; + std::string file("./qcdsf.769.00399.lime"); + std::cout < MdagMOpDwc_d(Dwc_d); + MdagMLinearOperator MdagMOpDwc_f(Dwc_f); + + std::cout << GridLogMessage << "**************************************************" << std::endl; + std::cout << GridLogMessage << "Testing single-precision Multigrid for Wilson Clover" << std::endl; + std::cout << GridLogMessage << "**************************************************" << std::endl; + + auto MGPreconDwc_f = createMGInstance(mgParams, levelInfo_f, Dwc_f, Dwc_f); + + MGPreconDwc_f->setup(); + + if(GridCmdOptionExists(argv, argv + argc, "--runchecks")) { + MGPreconDwc_f->runChecks(1e-6); + } + + MixedPrecisionFlexibleGeneralisedMinimalResidual MPFGMRESPREC( + 1.0e-12, 50000, FGrid_f, *MGPreconDwc_f, 100, false); + + std::cout << std::endl << "Starting with a new solver" << std::endl; + MPFGMRESPREC(MdagMOpDwc_d, src_d, resultMGF_d); + + MGPreconDwc_f->reportTimings(); + + if(GridCmdOptionExists(argv, argv + argc, "--docomparison")) { + + std::cout << GridLogMessage << "**************************************************" << std::endl; + std::cout << GridLogMessage << "Testing double-precision Multigrid for Wilson Clover" << std::endl; + std::cout << GridLogMessage << "**************************************************" << std::endl; + + auto MGPreconDwc_d = createMGInstance(mgParams, levelInfo_d, Dwc_d, Dwc_d); + + MGPreconDwc_d->setup(); + + if(GridCmdOptionExists(argv, argv + argc, "--runchecks")) { + MGPreconDwc_d->runChecks(1e-13); + } + + FlexibleGeneralisedMinimalResidual FGMRESPREC(1.0e-12, 50000, *MGPreconDwc_d, 100, false); + + std::cout << std::endl << "Starting with a new solver" << std::endl; + FGMRESPREC(MdagMOpDwc_d, src_d, resultMGD_d); + + MGPreconDwc_d->reportTimings(); + + std::cout << GridLogMessage << "**************************************************" << std::endl; + std::cout << GridLogMessage << "Comparing single-precision Multigrid with double-precision one for Wilson Clover" << std::endl; + std::cout << GridLogMessage << "**************************************************" << std::endl; + + LatticeFermionD diffFullSolver(FGrid_d); + + RealD deviationFullSolver = axpy_norm(diffFullSolver, -1.0, resultMGF_d, resultMGD_d); + + // clang-format off + LatticeFermionF src_f(FGrid_f); precisionChange(src_f, src_d); + LatticeFermionF resMGF_f(FGrid_f); resMGF_f = zero; + LatticeFermionD resMGD_d(FGrid_d); resMGD_d = zero; + // clang-format on + + (*MGPreconDwc_f)(src_f, resMGF_f); + (*MGPreconDwc_d)(src_d, resMGD_d); + + LatticeFermionD diffOnlyMG(FGrid_d); + LatticeFermionD resMGF_d(FGrid_d); + precisionChange(resMGF_d, resMGF_f); + + RealD deviationOnlyPrec = axpy_norm(diffOnlyMG, -1.0, resMGF_d, resMGD_d); + + // clang-format off + std::cout << GridLogMessage << "Absolute difference between FGMRES preconditioned by double and single precicision MG: " << deviationFullSolver << std::endl; + std::cout << GridLogMessage << "Relative deviation between FGMRES preconditioned by double and single precicision MG: " << deviationFullSolver / norm2(resultMGD_d) << std::endl; + std::cout << GridLogMessage << "Absolute difference between one iteration of MG Prec in double and single precision: " << deviationOnlyPrec << std::endl; + std::cout << GridLogMessage << "Relative deviation between one iteration of MG Prec in double and single precision: " << deviationOnlyPrec / norm2(resMGD_d) << std::endl; + // clang-format on + } + + Grid_finalize(); +}