mirror of
				https://github.com/paboyle/Grid.git
				synced 2025-10-28 10:39:34 +00:00 
			
		
		
		
	Compare commits
	
		
			26 Commits
		
	
	
		
			debug-crus
			...
			b15d9b294c
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
|  | b15d9b294c | ||
|  | ffd7301649 | ||
|  | d2a8494044 | ||
|  | 0982e0d19b | ||
|  | 3badbfc3c1 | ||
|  | 5465961e30 | ||
|  | 4835fd1a87 | ||
|  | 6533c25814 | ||
|  | 1b2914ec09 | ||
|  | 519f795066 | ||
|  | 4240ad5ca8 | ||
|  | d418347d86 | ||
|  | 29a4bfe5e5 | ||
|  | 9955bf9daf | ||
|  | 876c8f4478 | ||
|  | 9c8750f261 | ||
|  | 91efd08179 | ||
|  | 9953511b65 | ||
|  | 025fa9991a | ||
|  | e8c60c355b | ||
|  | 6c9c7f9d85 | ||
|  | f534523ede | ||
|  | 1b8a834beb | ||
|  | ccd21f96ff | ||
|  | 4b90cb8888 | ||
| 32e6d58356 | 
| @@ -27,7 +27,7 @@ Author: Christoph Lehner <christoph@lhnr.de> | ||||
| *************************************************************************************/ | ||||
| /*  END LEGAL */ | ||||
|  | ||||
| #define header "SharedMemoryMpi: " | ||||
| #define Mheader "SharedMemoryMpi: " | ||||
|  | ||||
| #include <Grid/GridCore.h> | ||||
| #include <pwd.h> | ||||
| @@ -174,8 +174,8 @@ void GlobalSharedMemory::Init(Grid_MPI_Comm comm) | ||||
|   MPI_Comm_size(WorldShmComm     ,&WorldShmSize); | ||||
|  | ||||
|   if ( WorldRank == 0) { | ||||
|     std::cout << header " World communicator of size " <<WorldSize << std::endl;   | ||||
|     std::cout << header " Node  communicator of size " <<WorldShmSize << std::endl; | ||||
|     std::cout << Mheader " World communicator of size " <<WorldSize << std::endl;   | ||||
|     std::cout << Mheader " Node  communicator of size " <<WorldShmSize << std::endl; | ||||
|   } | ||||
|   // WorldShmComm, WorldShmSize, WorldShmRank | ||||
|  | ||||
| @@ -452,7 +452,7 @@ void GlobalSharedMemory::OptimalCommunicatorSharedMemory(const Coordinate &proce | ||||
| #ifdef GRID_MPI3_SHMGET | ||||
| void GlobalSharedMemory::SharedMemoryAllocate(uint64_t bytes, int flags) | ||||
| { | ||||
|   std::cout << header "SharedMemoryAllocate "<< bytes<< " shmget implementation "<<std::endl; | ||||
|   std::cout << Mheader "SharedMemoryAllocate "<< bytes<< " shmget implementation "<<std::endl; | ||||
|   assert(_ShmSetup==1); | ||||
|   assert(_ShmAlloc==0); | ||||
|  | ||||
| @@ -537,7 +537,7 @@ void GlobalSharedMemory::SharedMemoryAllocate(uint64_t bytes, int flags) | ||||
|     exit(EXIT_FAILURE);   | ||||
|   } | ||||
|  | ||||
|   std::cout << WorldRank << header " SharedMemoryMPI.cc acceleratorAllocDevice "<< bytes  | ||||
|   std::cout << WorldRank << Mheader " SharedMemoryMPI.cc acceleratorAllocDevice "<< bytes  | ||||
| 	    << "bytes at "<< std::hex<< ShmCommBuf <<std::dec<<" for comms buffers " <<std::endl; | ||||
|  | ||||
|   SharedMemoryZero(ShmCommBuf,bytes); | ||||
| @@ -580,7 +580,7 @@ void GlobalSharedMemory::SharedMemoryAllocate(uint64_t bytes, int flags) | ||||
|     exit(EXIT_FAILURE);   | ||||
|   } | ||||
|   if ( WorldRank == 0 ){ | ||||
|     std::cout << WorldRank << header " SharedMemoryMPI.cc acceleratorAllocDevice "<< bytes  | ||||
|     std::cout << WorldRank << Mheader " SharedMemoryMPI.cc acceleratorAllocDevice "<< bytes  | ||||
| 	      << "bytes at "<< std::hex<< ShmCommBuf << " - "<<(bytes-1+(uint64_t)ShmCommBuf) <<std::dec<<" for comms buffers " <<std::endl; | ||||
|   } | ||||
|   SharedMemoryZero(ShmCommBuf,bytes); | ||||
| @@ -744,7 +744,7 @@ void GlobalSharedMemory::SharedMemoryAllocate(uint64_t bytes, int flags) | ||||
| #ifdef GRID_MPI3_SHMMMAP | ||||
| void GlobalSharedMemory::SharedMemoryAllocate(uint64_t bytes, int flags) | ||||
| { | ||||
|   std::cout << header "SharedMemoryAllocate "<< bytes<< " MMAP implementation "<< GRID_SHM_PATH <<std::endl; | ||||
|   std::cout << Mheader "SharedMemoryAllocate "<< bytes<< " MMAP implementation "<< GRID_SHM_PATH <<std::endl; | ||||
|   assert(_ShmSetup==1); | ||||
|   assert(_ShmAlloc==0); | ||||
|   ////////////////////////////////////////////////////////////////////////////////////////////////////////// | ||||
| @@ -781,7 +781,7 @@ void GlobalSharedMemory::SharedMemoryAllocate(uint64_t bytes, int flags) | ||||
|     assert(((uint64_t)ptr&0x3F)==0); | ||||
|     close(fd); | ||||
|     WorldShmCommBufs[r] =ptr; | ||||
|     //    std::cout << header "Set WorldShmCommBufs["<<r<<"]="<<ptr<< "("<< bytes<< "bytes)"<<std::endl; | ||||
|     //    std::cout << Mheader "Set WorldShmCommBufs["<<r<<"]="<<ptr<< "("<< bytes<< "bytes)"<<std::endl; | ||||
|   } | ||||
|   _ShmAlloc=1; | ||||
|   _ShmAllocBytes  = bytes; | ||||
| @@ -791,7 +791,7 @@ void GlobalSharedMemory::SharedMemoryAllocate(uint64_t bytes, int flags) | ||||
| #ifdef GRID_MPI3_SHM_NONE | ||||
| void GlobalSharedMemory::SharedMemoryAllocate(uint64_t bytes, int flags) | ||||
| { | ||||
|   std::cout << header "SharedMemoryAllocate "<< bytes<< " MMAP anonymous implementation "<<std::endl; | ||||
|   std::cout << Mheader "SharedMemoryAllocate "<< bytes<< " MMAP anonymous implementation "<<std::endl; | ||||
|   assert(_ShmSetup==1); | ||||
|   assert(_ShmAlloc==0); | ||||
|   ////////////////////////////////////////////////////////////////////////////////////////////////////////// | ||||
| @@ -838,7 +838,7 @@ void GlobalSharedMemory::SharedMemoryAllocate(uint64_t bytes, int flags) | ||||
| //////////////////////////////////////////////////////////////////////////////////////////// | ||||
| void GlobalSharedMemory::SharedMemoryAllocate(uint64_t bytes, int flags) | ||||
| {  | ||||
|   std::cout << header "SharedMemoryAllocate "<< bytes<< " SHMOPEN implementation "<<std::endl; | ||||
|   std::cout << Mheader "SharedMemoryAllocate "<< bytes<< " SHMOPEN implementation "<<std::endl; | ||||
|   assert(_ShmSetup==1); | ||||
|   assert(_ShmAlloc==0);  | ||||
|   MPI_Barrier(WorldShmComm); | ||||
|   | ||||
| @@ -707,9 +707,9 @@ void localCopyRegion(const Lattice<vobj> &From,Lattice<vobj> & To,Coordinate Fro | ||||
|   Coordinate ist = Tg->_istride; | ||||
|   Coordinate ost = Tg->_ostride; | ||||
|  | ||||
|   autoView( t_v , To, AcceleratorWrite); | ||||
|   autoView( f_v , From, AcceleratorRead); | ||||
|   accelerator_for(idx,Fg->lSites(),1,{ | ||||
|   autoView( t_v , To, CpuWrite); | ||||
|   autoView( f_v , From, CpuRead); | ||||
|   thread_for(idx,Fg->lSites(),{ | ||||
|     sobj s; | ||||
|     Coordinate Fcoor(nd); | ||||
|     Coordinate Tcoor(nd); | ||||
| @@ -722,15 +722,20 @@ void localCopyRegion(const Lattice<vobj> &From,Lattice<vobj> & To,Coordinate Fro | ||||
|       Tcoor[d] = ToLowerLeft[d]+ Fcoor[d]-FromLowerLeft[d]; | ||||
|     } | ||||
|     if (in_region) { | ||||
|       Integer idx_f = 0; for(int d=0;d<nd;d++) idx_f+=isf[d]*(Fcoor[d]/rdf[d]); | ||||
|       Integer idx_t = 0; for(int d=0;d<nd;d++) idx_t+=ist[d]*(Tcoor[d]/rdt[d]); | ||||
|       Integer odx_f = 0; for(int d=0;d<nd;d++) odx_f+=osf[d]*(Fcoor[d]%rdf[d]); | ||||
|       Integer odx_t = 0; for(int d=0;d<nd;d++) odx_t+=ost[d]*(Tcoor[d]%rdt[d]); | ||||
|       vector_type * fp = (vector_type *)&f_v[odx_f]; | ||||
|       vector_type * tp = (vector_type *)&t_v[odx_t]; | ||||
| #if 0       | ||||
|       Integer idx_f = 0; for(int d=0;d<nd;d++) idx_f+=isf[d]*(Fcoor[d]/rdf[d]); // inner index from | ||||
|       Integer idx_t = 0; for(int d=0;d<nd;d++) idx_t+=ist[d]*(Tcoor[d]/rdt[d]); // inner index to | ||||
|       Integer odx_f = 0; for(int d=0;d<nd;d++) odx_f+=osf[d]*(Fcoor[d]%rdf[d]); // outer index from | ||||
|       Integer odx_t = 0; for(int d=0;d<nd;d++) odx_t+=ost[d]*(Tcoor[d]%rdt[d]); // outer index to | ||||
|       scalar_type * fp = (scalar_type *)&f_v[odx_f]; | ||||
|       scalar_type * tp = (scalar_type *)&t_v[odx_t]; | ||||
|       for(int w=0;w<words;w++){ | ||||
| 	tp[w].putlane(fp[w].getlane(idx_f),idx_t); | ||||
|       } | ||||
| #else | ||||
|     peekLocalSite(s,f_v,Fcoor); | ||||
|     pokeLocalSite(s,t_v,Tcoor); | ||||
| #endif | ||||
|     } | ||||
|   }); | ||||
| } | ||||
| @@ -841,9 +846,9 @@ void InsertSliceLocal(const Lattice<vobj> &lowDim, Lattice<vobj> & higherDim,int | ||||
|  | ||||
|   for(int d=0;d<nh;d++){ | ||||
|     if ( d!=orthog ) { | ||||
|     assert(lg->_processors[d]  == hg->_processors[d]); | ||||
|     assert(lg->_ldimensions[d] == hg->_ldimensions[d]); | ||||
|   } | ||||
|       assert(lg->_processors[d]  == hg->_processors[d]); | ||||
|       assert(lg->_ldimensions[d] == hg->_ldimensions[d]); | ||||
|     } | ||||
|   } | ||||
|  | ||||
|   // the above should guarantee that the operations are local | ||||
|   | ||||
							
								
								
									
										136
									
								
								Grid/lattice/PaddedCell.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										136
									
								
								Grid/lattice/PaddedCell.h
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,136 @@ | ||||
| /************************************************************************************* | ||||
|     Grid physics library, www.github.com/paboyle/Grid  | ||||
|  | ||||
|     Source file: ./lib/lattice/PaddedCell.h | ||||
|  | ||||
|     Copyright (C) 2019 | ||||
|  | ||||
| Author: Peter Boyle pboyle@bnl.gov | ||||
|  | ||||
|     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 */ | ||||
| #pragma once | ||||
|  | ||||
| NAMESPACE_BEGIN(Grid); | ||||
|  | ||||
| class PaddedCell { | ||||
| public: | ||||
|   GridCartesian * unpadded_grid; | ||||
|   int dims; | ||||
|   int depth; | ||||
|   std::vector<GridCartesian *> grids; | ||||
|   ~PaddedCell() | ||||
|   { | ||||
|     DeleteGrids(); | ||||
|   } | ||||
|   PaddedCell(int _depth,GridCartesian *_grid) | ||||
|   { | ||||
|     unpadded_grid = _grid; | ||||
|     depth=_depth; | ||||
|     dims=_grid->Nd(); | ||||
|     AllocateGrids(); | ||||
|     Coordinate local     =unpadded_grid->LocalDimensions(); | ||||
|     for(int d=0;d<dims;d++){ | ||||
|       assert(local[d]>=depth); | ||||
|     } | ||||
|   } | ||||
|   void DeleteGrids(void) | ||||
|   { | ||||
|     for(int d=0;d<grids.size();d++){ | ||||
|       delete grids[d]; | ||||
|     } | ||||
|     grids.resize(0); | ||||
|   }; | ||||
|   void AllocateGrids(void) | ||||
|   { | ||||
|     Coordinate local     =unpadded_grid->LocalDimensions(); | ||||
|     Coordinate simd      =unpadded_grid->_simd_layout; | ||||
|     Coordinate processors=unpadded_grid->_processors; | ||||
|     Coordinate plocal    =unpadded_grid->LocalDimensions(); | ||||
|     Coordinate global(dims); | ||||
|  | ||||
|     // expand up one dim at a time | ||||
|     for(int d=0;d<dims;d++){ | ||||
|  | ||||
|       plocal[d] += 2*depth;  | ||||
|  | ||||
|       for(int d=0;d<dims;d++){ | ||||
| 	global[d] = plocal[d]*processors[d]; | ||||
|       } | ||||
|  | ||||
|       grids.push_back(new GridCartesian(global,simd,processors)); | ||||
|     } | ||||
|   }; | ||||
|   template<class vobj> | ||||
|   inline Lattice<vobj> Extract(Lattice<vobj> &in) | ||||
|   { | ||||
|     Lattice<vobj> out(unpadded_grid); | ||||
|  | ||||
|     Coordinate local     =unpadded_grid->LocalDimensions(); | ||||
|     Coordinate fll(dims,depth); // depends on the MPI spread | ||||
|     Coordinate tll(dims,0); // depends on the MPI spread | ||||
|     localCopyRegion(in,out,fll,tll,local); | ||||
|     return out; | ||||
|   } | ||||
|   template<class vobj> | ||||
|   inline Lattice<vobj> Exchange(Lattice<vobj> &in) | ||||
|   { | ||||
|     GridBase *old_grid = in.Grid(); | ||||
|     int dims = old_grid->Nd(); | ||||
|     Lattice<vobj> tmp = in; | ||||
|     for(int d=0;d<dims;d++){ | ||||
|       tmp = Expand(d,tmp); // rvalue && assignment | ||||
|     } | ||||
|     return tmp; | ||||
|   } | ||||
|   // expand up one dim at a time | ||||
|   template<class vobj> | ||||
|   inline Lattice<vobj> Expand(int dim,Lattice<vobj> &in) | ||||
|   { | ||||
|     GridBase *old_grid = in.Grid(); | ||||
|     GridCartesian *new_grid = grids[dim];//These are new grids | ||||
|     Lattice<vobj>  padded(new_grid); | ||||
|     Lattice<vobj> shifted(old_grid);     | ||||
|     Coordinate local     =old_grid->LocalDimensions(); | ||||
|     Coordinate plocal    =new_grid->LocalDimensions(); | ||||
|     if(dim==0) conformable(old_grid,unpadded_grid); | ||||
|     else       conformable(old_grid,grids[dim-1]); | ||||
|  | ||||
|     std::cout << " dim "<<dim<<" local "<<local << " padding to "<<plocal<<std::endl; | ||||
|     // Middle bit | ||||
|     for(int x=0;x<local[dim];x++){ | ||||
|       InsertSliceLocal(in,padded,x,depth+x,dim); | ||||
|     } | ||||
|     // High bit | ||||
|     shifted = Cshift(in,dim,depth); | ||||
|     for(int x=0;x<depth;x++){ | ||||
|       InsertSliceLocal(shifted,padded,local[dim]-depth+x,depth+local[dim]+x,dim); | ||||
|     } | ||||
|     // Low bit | ||||
|     shifted = Cshift(in,dim,-depth); | ||||
|     for(int x=0;x<depth;x++){ | ||||
|       InsertSliceLocal(shifted,padded,x,x,dim); | ||||
|     } | ||||
|     return padded; | ||||
|   } | ||||
|  | ||||
| }; | ||||
|   | ||||
|  | ||||
| NAMESPACE_END(Grid); | ||||
|  | ||||
| @@ -104,6 +104,7 @@ template<typename vtype> using iSpinMatrix                = iScalar<iMatrix<iSca | ||||
| template<typename vtype> using iColourMatrix              = iScalar<iScalar<iMatrix<vtype, Nc> > > ; | ||||
| template<typename vtype> using iSpinColourMatrix          = iScalar<iMatrix<iMatrix<vtype, Nc>, Ns> >; | ||||
| template<typename vtype> using iLorentzColourMatrix       = iVector<iScalar<iMatrix<vtype, Nc> >, Nd > ; | ||||
| template<typename vtype> using iLorentzComplex            = iVector<iScalar<iScalar<vtype> >, Nd > ; | ||||
| template<typename vtype> using iDoubleStoredColourMatrix  = iVector<iScalar<iMatrix<vtype, Nc> >, Nds > ; | ||||
| template<typename vtype> using iSpinVector                = iScalar<iVector<iScalar<vtype>, Ns> >; | ||||
| template<typename vtype> using iColourVector              = iScalar<iScalar<iVector<vtype, Nc> > >; | ||||
| @@ -178,6 +179,15 @@ typedef iLorentzColourMatrix<vComplexF>  vLorentzColourMatrixF; | ||||
| typedef iLorentzColourMatrix<vComplexD>  vLorentzColourMatrixD; | ||||
| typedef iLorentzColourMatrix<vComplexD2> vLorentzColourMatrixD2; | ||||
|  | ||||
| // LorentzComplex | ||||
| typedef iLorentzComplex<Complex  > LorentzComplex; | ||||
| typedef iLorentzComplex<ComplexF > LorentzComplexF; | ||||
| typedef iLorentzComplex<ComplexD > LorentzComplexD; | ||||
|  | ||||
| typedef iLorentzComplex<vComplex > vLorentzComplex; | ||||
| typedef iLorentzComplex<vComplexF> vLorentzComplexF; | ||||
| typedef iLorentzComplex<vComplexD> vLorentzComplexD; | ||||
|  | ||||
| // DoubleStored gauge field | ||||
| typedef iDoubleStoredColourMatrix<Complex  > DoubleStoredColourMatrix; | ||||
| typedef iDoubleStoredColourMatrix<ComplexF > DoubleStoredColourMatrixF; | ||||
| @@ -307,6 +317,10 @@ typedef Lattice<vLorentzColourMatrixF>  LatticeLorentzColourMatrixF; | ||||
| typedef Lattice<vLorentzColourMatrixD>  LatticeLorentzColourMatrixD; | ||||
| typedef Lattice<vLorentzColourMatrixD2> LatticeLorentzColourMatrixD2; | ||||
|  | ||||
| typedef Lattice<vLorentzComplex>  LatticeLorentzComplex; | ||||
| typedef Lattice<vLorentzComplexF> LatticeLorentzComplexF; | ||||
| typedef Lattice<vLorentzComplexD> LatticeLorentzComplexD; | ||||
|  | ||||
| // DoubleStored gauge field | ||||
| typedef Lattice<vDoubleStoredColourMatrix>   LatticeDoubleStoredColourMatrix; | ||||
| typedef Lattice<vDoubleStoredColourMatrixF>  LatticeDoubleStoredColourMatrixF; | ||||
|   | ||||
| @@ -34,10 +34,24 @@ directory | ||||
|  | ||||
| NAMESPACE_BEGIN(Grid); | ||||
|  | ||||
| /////////////////////////////////// | ||||
| // Smart configuration base class | ||||
| /////////////////////////////////// | ||||
| template< class Field > | ||||
| class ConfigurationBase | ||||
| { | ||||
| public: | ||||
|   ConfigurationBase() {} | ||||
|   virtual ~ConfigurationBase() {} | ||||
|   virtual void set_Field(Field& U) =0; | ||||
|   virtual void smeared_force(Field&) const = 0; | ||||
|   virtual Field& get_SmearedU() =0; | ||||
|   virtual Field &get_U(bool smeared = false) = 0; | ||||
| }; | ||||
|  | ||||
| template <class GaugeField > | ||||
| class Action  | ||||
| { | ||||
|  | ||||
| public: | ||||
|   bool is_smeared = false; | ||||
|   RealD deriv_norm_sum; | ||||
| @@ -77,11 +91,39 @@ public: | ||||
|   void refresh_timer_stop(void)  { refresh_us+=usecond(); } | ||||
|   void S_timer_start(void)       { S_us-=usecond(); } | ||||
|   void S_timer_stop(void)        { S_us+=usecond(); } | ||||
|   ///////////////////////////// | ||||
|   // Heatbath? | ||||
|   ///////////////////////////// | ||||
|   virtual void refresh(const GaugeField& U, GridSerialRNG &sRNG, GridParallelRNG& pRNG) = 0; // refresh pseudofermions | ||||
|   virtual RealD S(const GaugeField& U) = 0;                             // evaluate the action | ||||
|   virtual RealD Sinitial(const GaugeField& U) { return this->S(U); } ;  // if the refresh computes the action, can cache it. Alternately refreshAndAction() ? | ||||
|   virtual void deriv(const GaugeField& U, GaugeField& dSdU) = 0;        // evaluate the action derivative | ||||
|  | ||||
|   ///////////////////////////////////////////////////////////// | ||||
|   // virtual smeared interface through configuration container | ||||
|   ///////////////////////////////////////////////////////////// | ||||
|   virtual void refresh(ConfigurationBase<GaugeField> & U, GridSerialRNG &sRNG, GridParallelRNG& pRNG) | ||||
|   { | ||||
|     refresh(U.get_U(is_smeared),sRNG,pRNG); | ||||
|   } | ||||
|   virtual RealD S(ConfigurationBase<GaugeField>& U) | ||||
|   { | ||||
|     return S(U.get_U(is_smeared)); | ||||
|   } | ||||
|   virtual RealD Sinitial(ConfigurationBase<GaugeField>& U)  | ||||
|   { | ||||
|     return Sinitial(U.get_U(is_smeared)); | ||||
|   } | ||||
|   virtual void deriv(ConfigurationBase<GaugeField>& U, GaugeField& dSdU) | ||||
|   { | ||||
|     deriv(U.get_U(is_smeared),dSdU);  | ||||
|     if ( is_smeared ) { | ||||
|       U.smeared_force(dSdU); | ||||
|     } | ||||
|   } | ||||
|   /////////////////////////////// | ||||
|   // Logging | ||||
|   /////////////////////////////// | ||||
|   virtual std::string action_name()    = 0;                             // return the action name | ||||
|   virtual std::string LogParameters()  = 0;                             // prints action parameters | ||||
|   virtual ~Action(){} | ||||
|   | ||||
| @@ -30,6 +30,8 @@ directory | ||||
| #ifndef QCD_ACTION_CORE | ||||
| #define QCD_ACTION_CORE | ||||
|  | ||||
| #include <Grid/qcd/action/gauge/GaugeImplementations.h> | ||||
|  | ||||
| #include <Grid/qcd/action/ActionBase.h> | ||||
| NAMESPACE_CHECK(ActionBase); | ||||
| #include <Grid/qcd/action/ActionSet.h> | ||||
|   | ||||
| @@ -196,6 +196,7 @@ void WilsonFermion5D<Impl>::DhopDir(const FermionField &in, FermionField &out,in | ||||
|    | ||||
|   uint64_t Nsite = Umu.Grid()->oSites(); | ||||
|   Kernels::DhopDirKernel(Stencil,Umu,Stencil.CommBuf(),Ls,Nsite,in,out,dirdisp,gamma); | ||||
|  | ||||
| }; | ||||
| template<class Impl> | ||||
| void WilsonFermion5D<Impl>::DhopDirAll(const FermionField &in, std::vector<FermionField> &out) | ||||
| @@ -246,14 +247,10 @@ void WilsonFermion5D<Impl>::DerivInternal(StencilImpl & st, | ||||
|  | ||||
|     Kernels::DhopDirKernel(st, U, st.CommBuf(), Ls, Usites, B, Btilde, mu,gamma); | ||||
|  | ||||
|     std::cout << " InsertForce Btilde "<< norm2(Btilde)<<std::endl; | ||||
|  | ||||
|     //////////////////////////// | ||||
|     // spin trace outer product | ||||
|     //////////////////////////// | ||||
|     Impl::InsertForce5D(mat, Btilde, Atilde, mu); | ||||
|  | ||||
|     std::cout << " InsertForce "<< norm2(mat)<<std::endl; | ||||
|   } | ||||
| } | ||||
|  | ||||
|   | ||||
| @@ -86,8 +86,13 @@ public: | ||||
|     assert(ForceE.Checkerboard()==Even); | ||||
|     assert(ForceO.Checkerboard()==Odd); | ||||
|  | ||||
| #if defined(GRID_CUDA) || defined(GRID_HIP)  || defined(GRID_SYCL) | ||||
|     acceleratorSetCheckerboard(Force,ForceE); | ||||
|     acceleratorSetCheckerboard(Force,ForceO); | ||||
| #else | ||||
|     setCheckerboard(Force,ForceE);  | ||||
|     setCheckerboard(Force,ForceO); | ||||
| #endif | ||||
|     Force=-Force; | ||||
|  | ||||
|     delete forcecb; | ||||
| @@ -119,25 +124,24 @@ public: | ||||
|     //  X^dag Der_oe MeeInv Meo Y | ||||
|     // Use Mooee as nontrivial but gauge field indept | ||||
|     this->_Mat.MeooeDag   (V,tmp1);      // odd->even -- implicit -0.5 factor to be applied | ||||
|     std::cout << " tmp 1" << norm2(tmp1)<<std::endl; | ||||
|     this->_Mat.MooeeInvDag(tmp1,tmp2);   // even->even  | ||||
|     std::cout << " tmp 1" << norm2(tmp2)<<std::endl; | ||||
|     this->_Mat.MoeDeriv(ForceO,U,tmp2,DaggerYes); | ||||
|     std::cout << " ForceO " << norm2(ForceO)<<std::endl; | ||||
|            | ||||
|     //  Accumulate X^dag M_oe MeeInv Der_eo Y | ||||
|     this->_Mat.Meooe   (U,tmp1);    // even->odd -- implicit -0.5 factor to be applied | ||||
|     std::cout << " tmp 1" << norm2(tmp1)<<std::endl; | ||||
|     this->_Mat.MooeeInv(tmp1,tmp2); // even->even  | ||||
|     std::cout << " tmp 2" << norm2(tmp2)<<std::endl; | ||||
|     this->_Mat.MeoDeriv(ForceE,tmp2,V,DaggerYes); | ||||
|     std::cout << " ForceE " << norm2(ForceE)<<std::endl; | ||||
|  | ||||
|     assert(ForceE.Checkerboard()==Even); | ||||
|     assert(ForceO.Checkerboard()==Odd); | ||||
|  | ||||
| #if defined(GRID_CUDA) || defined(GRID_HIP)  || defined(GRID_SYCL) | ||||
|     acceleratorSetCheckerboard(Force,ForceE); | ||||
|     acceleratorSetCheckerboard(Force,ForceO); | ||||
| #else | ||||
|     setCheckerboard(Force,ForceE);  | ||||
|     setCheckerboard(Force,ForceO); | ||||
| #endif | ||||
|     Force=-Force; | ||||
|  | ||||
|     delete forcecb; | ||||
|   | ||||
| @@ -7,26 +7,27 @@ | ||||
|  | ||||
| NAMESPACE_BEGIN(Grid); | ||||
|  | ||||
|  | ||||
| //trivial class for no smearing | ||||
| template< class Impl > | ||||
| class NoSmearing | ||||
| class NoSmearing : public ConfigurationBase<typename Impl::Field> | ||||
| { | ||||
| public: | ||||
|   INHERIT_FIELD_TYPES(Impl); | ||||
|  | ||||
|   Field* ThinField; | ||||
|   Field* ThinLinks; | ||||
|  | ||||
|   NoSmearing(): ThinField(NULL) {} | ||||
|   NoSmearing(): ThinLinks(NULL) {} | ||||
|  | ||||
|   void set_Field(Field& U) { ThinField = &U; } | ||||
|   void set_Field(Field& U) { ThinLinks = &U; } | ||||
|  | ||||
|   void smeared_force(Field&) const {} | ||||
|  | ||||
|   Field& get_SmearedU() { return *ThinField; } | ||||
|   Field& get_SmearedU() { return *ThinLinks; } | ||||
|  | ||||
|   Field &get_U(bool smeared = false) | ||||
|   { | ||||
|     return *ThinField; | ||||
|     return *ThinLinks; | ||||
|   } | ||||
| }; | ||||
|  | ||||
| @@ -42,19 +43,24 @@ public: | ||||
|   It stores a list of smeared configurations. | ||||
| */ | ||||
| template <class Gimpl> | ||||
| class SmearedConfiguration | ||||
| class SmearedConfiguration : public ConfigurationBase<typename Gimpl::Field> | ||||
| { | ||||
| public: | ||||
|   INHERIT_GIMPL_TYPES(Gimpl); | ||||
|  | ||||
| private: | ||||
| protected: | ||||
|   const unsigned int smearingLevels; | ||||
|   Smear_Stout<Gimpl> *StoutSmearing; | ||||
|   std::vector<GaugeField> SmearedSet; | ||||
|  | ||||
| public: | ||||
|   GaugeField*  ThinLinks; /* Pointer to the thin links configuration */ // move to base??? | ||||
| protected: | ||||
|    | ||||
|   // Member functions | ||||
|   //==================================================================== | ||||
|   void fill_smearedSet(GaugeField &U) | ||||
|  | ||||
|   // Overridden in masked version | ||||
|   virtual void fill_smearedSet(GaugeField &U) | ||||
|   { | ||||
|     ThinLinks = &U;  // attach the smearing routine to the field U | ||||
|  | ||||
| @@ -82,9 +88,10 @@ private: | ||||
|       } | ||||
|     } | ||||
|   } | ||||
|   //==================================================================== | ||||
|   GaugeField AnalyticSmearedForce(const GaugeField& SigmaKPrime, | ||||
|                                   const GaugeField& GaugeK) const  | ||||
|  | ||||
|   //overridden in masked verson | ||||
|   virtual GaugeField AnalyticSmearedForce(const GaugeField& SigmaKPrime, | ||||
| 					  const GaugeField& GaugeK) const  | ||||
|   { | ||||
|     GridBase* grid = GaugeK.Grid(); | ||||
|     GaugeField C(grid), SigmaK(grid), iLambda(grid); | ||||
| @@ -213,8 +220,6 @@ private: | ||||
|  | ||||
|   //==================================================================== | ||||
| public: | ||||
|   GaugeField* | ||||
|       ThinLinks; /* Pointer to the thin links configuration */ | ||||
|  | ||||
|   /* Standard constructor */ | ||||
|   SmearedConfiguration(GridCartesian* UGrid, unsigned int Nsmear, | ||||
|   | ||||
							
								
								
									
										776
									
								
								Grid/qcd/smearing/GaugeConfigurationMasked.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										776
									
								
								Grid/qcd/smearing/GaugeConfigurationMasked.h
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,776 @@ | ||||
| /*! | ||||
|   @file GaugeConfiguration.h | ||||
|   @brief Declares the GaugeConfiguration class | ||||
| */ | ||||
| #pragma once | ||||
|  | ||||
| NAMESPACE_BEGIN(Grid); | ||||
|  | ||||
| /*! | ||||
|   @brief Smeared configuration masked container | ||||
|   Modified for a multi-subset smearing (aka Luscher Flowed HMC) | ||||
| */ | ||||
| template <class Gimpl> | ||||
| class SmearedConfigurationMasked : public SmearedConfiguration<Gimpl> | ||||
| { | ||||
| public: | ||||
|   INHERIT_GIMPL_TYPES(Gimpl); | ||||
|  | ||||
| private: | ||||
|   // These live in base class | ||||
|   //  const unsigned int smearingLevels; | ||||
|   //  Smear_Stout<Gimpl> *StoutSmearing; | ||||
|   //  std::vector<GaugeField> SmearedSet; | ||||
|    | ||||
|   std::vector<LatticeLorentzComplex> masks; | ||||
|  | ||||
|   typedef typename SU3Adjoint::AMatrix AdjMatrix; | ||||
|   typedef typename SU3Adjoint::LatticeAdjMatrix  AdjMatrixField; | ||||
|   typedef typename SU3Adjoint::LatticeAdjVector  AdjVectorField; | ||||
|  | ||||
|   // Adjoint vector to GaugeField force | ||||
|   void InsertForce(GaugeField &Fdet,AdjVectorField &Fdet_nu,int nu) | ||||
|   { | ||||
|     Complex ci(0,1); | ||||
|     GaugeLinkField Fdet_pol(Fdet.Grid()); | ||||
|     Fdet_pol=Zero(); | ||||
|     for(int e=0;e<8;e++){ | ||||
|       ColourMatrix te; | ||||
|       SU3::generator(e, te); | ||||
|       auto tmp=peekColour(Fdet_nu,e); | ||||
|       Fdet_pol=Fdet_pol + ci*tmp*te; // but norm of te is different.. why? | ||||
|     } | ||||
|     pokeLorentz(Fdet, Fdet_pol, nu); | ||||
|   } | ||||
|   void Compute_MpInvJx_dNxxdSy(const GaugeLinkField &PlaqL,const GaugeLinkField &PlaqR, AdjMatrixField MpInvJx,AdjVectorField &Fdet2 ) | ||||
|   { | ||||
|     GaugeLinkField UtaU(PlaqL.Grid()); | ||||
|     GaugeLinkField D(PlaqL.Grid()); | ||||
|     AdjMatrixField Dbc(PlaqL.Grid()); | ||||
|     LatticeComplex tmp(PlaqL.Grid()); | ||||
|     const int Ngen = SU3Adjoint::Dimension; | ||||
|     Complex ci(0,1); | ||||
|     ColourMatrix   ta,tb,tc; | ||||
|      | ||||
|     for(int a=0;a<Ngen;a++) { | ||||
|       SU3::generator(a, ta); | ||||
|       // Qlat Tb = 2i Tb^Grid | ||||
|       UtaU= 2.0*ci*adj(PlaqL)*ta*PlaqR; | ||||
|       for(int c=0;c<Ngen;c++) { | ||||
| 	SU3::generator(c, tc); | ||||
| 	D = Ta( (2.0)*ci*tc *UtaU); | ||||
| 	for(int b=0;b<Ngen;b++){ | ||||
| 	  SU3::generator(b, tb); | ||||
| 	  tmp =-trace(ci*tb*D);  | ||||
| 	  PokeIndex<ColourIndex>(Dbc,tmp,b,c);  // Adjoint rep | ||||
| 	} | ||||
|       } | ||||
|       tmp = trace(MpInvJx * Dbc); | ||||
|       PokeIndex<ColourIndex>(Fdet2,tmp,a); | ||||
|     } | ||||
|   } | ||||
|    | ||||
|   void ComputeNxy(const GaugeLinkField &PlaqL,const GaugeLinkField &PlaqR,AdjMatrixField &NxAd) | ||||
|   { | ||||
|     GaugeLinkField Nx(PlaqL.Grid()); | ||||
|     const int Ngen = SU3Adjoint::Dimension; | ||||
|     Complex ci(0,1); | ||||
|     ColourMatrix   tb; | ||||
|     ColourMatrix   tc; | ||||
|     for(int b=0;b<Ngen;b++) { | ||||
|       SU3::generator(b, tb); | ||||
|       Nx = (2.0)*Ta( adj(PlaqL)*ci*tb * PlaqR ); | ||||
|       for(int c=0;c<Ngen;c++) { | ||||
| 	SU3::generator(c, tc); | ||||
| 	auto tmp =closure( -trace(ci*tc*Nx));  | ||||
| 	PokeIndex<ColourIndex>(NxAd,tmp,c,b);  | ||||
|       } | ||||
|     } | ||||
|   } | ||||
|   void ApplyMask(GaugeField &U,int smr) | ||||
|   { | ||||
|     LatticeComplex tmp(U.Grid()); | ||||
|     GaugeLinkField Umu(U.Grid()); | ||||
|     for(int mu=0;mu<Nd;mu++){ | ||||
|       Umu=PeekIndex<LorentzIndex>(U,mu); | ||||
|       tmp=PeekIndex<LorentzIndex>(masks[smr],mu); | ||||
|       Umu=Umu*tmp; | ||||
|       PokeIndex<LorentzIndex>(U, Umu, mu); | ||||
|     } | ||||
|   } | ||||
| public: | ||||
|  | ||||
|   void logDetJacobianForceLevel(const GaugeField &U, GaugeField &force ,int smr) | ||||
|   { | ||||
|     GridBase* grid = U.Grid(); | ||||
|     ColourMatrix   tb; | ||||
|     ColourMatrix   tc; | ||||
|     ColourMatrix   ta; | ||||
|     GaugeField C(grid); | ||||
|     GaugeField Umsk(grid); | ||||
|     std::vector<GaugeLinkField> Umu(Nd,grid); | ||||
|     GaugeLinkField Cmu(grid); // U and staple; C contains factor of epsilon | ||||
|     GaugeLinkField Zx(grid);  // U times Staple, contains factor of epsilon | ||||
|     GaugeLinkField Nxx(grid);  // Nxx fundamental space | ||||
|     GaugeLinkField Utmp(grid); | ||||
|     GaugeLinkField PlaqL(grid); | ||||
|     GaugeLinkField PlaqR(grid); | ||||
|     const int Ngen = SU3Adjoint::Dimension; | ||||
|     AdjMatrix TRb; | ||||
|     ColourMatrix Ident; | ||||
|     LatticeComplex  cplx(grid); | ||||
|      | ||||
|     AdjVectorField  dJdXe_nMpInv(grid);  | ||||
|     AdjVectorField  dJdXe_nMpInv_y(grid);  | ||||
|     AdjMatrixField  MpAd(grid);    // Mprime luchang's notes | ||||
|     AdjMatrixField  MpAdInv(grid); // Mprime inverse | ||||
|     AdjMatrixField  NxxAd(grid);    // Nxx in adjoint space | ||||
|     AdjMatrixField  JxAd(grid);      | ||||
|     AdjMatrixField  ZxAd(grid); | ||||
|     AdjMatrixField  mZxAd(grid); | ||||
|     AdjMatrixField  X(grid); | ||||
|     Complex ci(0,1); | ||||
|  | ||||
|     Ident = ComplexD(1.0); | ||||
|     for(int d=0;d<Nd;d++){ | ||||
|       Umu[d] = peekLorentz(U, d); | ||||
|     } | ||||
|     int mu= (smr/2) %Nd; | ||||
|  | ||||
|     //////////////////////////////////////////////////////////////////////////////// | ||||
|     // Mask the gauge field | ||||
|     //////////////////////////////////////////////////////////////////////////////// | ||||
|     auto mask=PeekIndex<LorentzIndex>(masks[smr],mu); // the cb mask | ||||
|  | ||||
|     Umsk = U; | ||||
|     ApplyMask(Umsk,smr); | ||||
|     Utmp = peekLorentz(Umsk,mu); | ||||
|  | ||||
|     //////////////////////////////////////////////////////////////////////////////// | ||||
|     // Retrieve the eps/rho parameter(s) -- could allow all different but not so far | ||||
|     //////////////////////////////////////////////////////////////////////////////// | ||||
|     double rho=this->StoutSmearing->SmearRho[1]; | ||||
|     int idx=0; | ||||
|     for(int mu=0;mu<4;mu++){ | ||||
|     for(int nu=0;nu<4;nu++){ | ||||
|       if ( mu!=nu) assert(this->StoutSmearing->SmearRho[idx]==rho); | ||||
|       else         assert(this->StoutSmearing->SmearRho[idx]==0.0); | ||||
|       idx++; | ||||
|     }} | ||||
|     ////////////////////////////////////////////////////////////////// | ||||
|     // Assemble the N matrix | ||||
|     ////////////////////////////////////////////////////////////////// | ||||
|     // Computes ALL the staples -- could compute one only and do it here | ||||
|     this->StoutSmearing->BaseSmear(C, U); | ||||
|     Cmu = peekLorentz(C, mu); | ||||
|  | ||||
|     ////////////////////////////////////////////////////////////////// | ||||
|     // Assemble Luscher exp diff map J matrix  | ||||
|     ////////////////////////////////////////////////////////////////// | ||||
|     // Ta so Z lives in Lie algabra | ||||
|     Zx  = Ta(Cmu * adj(Umu[mu])); | ||||
|  | ||||
|     // Move Z to the Adjoint Rep == make_adjoint_representation | ||||
|     ZxAd = Zero(); | ||||
|     for(int b=0;b<8;b++) { | ||||
|       // Adj group sets traceless antihermitian T's -- Guido, really???? | ||||
|       SU3::generator(b, tb);         // Fund group sets traceless hermitian T's | ||||
|       SU3Adjoint::generator(b,TRb); | ||||
|       TRb=-TRb; | ||||
|       cplx = 2.0*trace(ci*tb*Zx); // my convention 1/2 delta ba | ||||
|       ZxAd = ZxAd + cplx * TRb; // is this right? YES - Guido used Anti herm Ta's and with bloody wrong sign. | ||||
|     } | ||||
|  | ||||
|     ////////////////////////////////////// | ||||
|     // J(x) = 1 + Sum_k=1..N (-Zac)^k/(k+1)! | ||||
|     ////////////////////////////////////// | ||||
|     X=1.0;  | ||||
|     JxAd = X; | ||||
|     mZxAd = (-1.0)*ZxAd;  | ||||
|     RealD kpfac = 1; | ||||
|     for(int k=1;k<12;k++){ | ||||
|       X=X*mZxAd; | ||||
|       kpfac = kpfac /(k+1); | ||||
|       JxAd = JxAd + X * kpfac; | ||||
|     } | ||||
|  | ||||
|     ////////////////////////////////////// | ||||
|     // dJ(x)/dxe | ||||
|     ////////////////////////////////////// | ||||
|     std::vector<AdjMatrixField>  dJdX;    dJdX.resize(8,grid); | ||||
|     AdjMatrixField tbXn(grid); | ||||
|     AdjMatrixField sumXtbX(grid); | ||||
|     AdjMatrixField t2(grid); | ||||
|     AdjMatrixField dt2(grid); | ||||
|     AdjMatrixField t3(grid); | ||||
|     AdjMatrixField dt3(grid); | ||||
|     AdjMatrixField aunit(grid); | ||||
|     for(int b=0;b<8;b++){ | ||||
|       aunit = ComplexD(1.0); | ||||
|       SU3Adjoint::generator(b, TRb); //dt2 | ||||
|  | ||||
|       X  = (-1.0)*ZxAd;  | ||||
|       t2 = X; | ||||
|       dt2 = TRb; | ||||
|       for (int j = 20; j > 1; --j) { | ||||
| 	t3 = t2*(1.0 / (j + 1))  + aunit; | ||||
| 	dt3 = dt2*(1.0 / (j + 1)); | ||||
| 	t2 = X * t3; | ||||
| 	dt2 = TRb * t3 + X * dt3; | ||||
|       } | ||||
|       dJdX[b] = -dt2;  | ||||
|     } | ||||
|     ///////////////////////////////////////////////////////////////// | ||||
|     // Mask Umu for this link | ||||
|     ///////////////////////////////////////////////////////////////// | ||||
|     PlaqL = Ident; | ||||
|     PlaqR = Utmp*adj(Cmu); | ||||
|     ComputeNxy(PlaqL,PlaqR,NxxAd); | ||||
|      | ||||
|     //////////////////////////// | ||||
|     // Mab | ||||
|     //////////////////////////// | ||||
|     MpAd = Complex(1.0,0.0); | ||||
|     MpAd = MpAd - JxAd * NxxAd; | ||||
|  | ||||
|     ///////////////////////// | ||||
|     // invert the 8x8 | ||||
|     ///////////////////////// | ||||
|     MpAdInv = Inverse(MpAd); | ||||
|      | ||||
|     ///////////////////////////////////////////////////////////////// | ||||
|     // Nxx Mp^-1 | ||||
|     ///////////////////////////////////////////////////////////////// | ||||
|     AdjVectorField  FdetV(grid); | ||||
|     AdjVectorField  Fdet1_nu(grid); | ||||
|     AdjVectorField  Fdet2_nu(grid); | ||||
|     AdjVectorField  Fdet2_mu(grid); | ||||
|     AdjVectorField  Fdet1_mu(grid); | ||||
|  | ||||
|     AdjMatrixField nMpInv(grid); | ||||
|     nMpInv= NxxAd *MpAdInv; | ||||
|  | ||||
|     AdjMatrixField MpInvJx(grid); | ||||
|     AdjMatrixField MpInvJx_nu(grid); | ||||
|     MpInvJx = (-1.0)*MpAdInv * JxAd;// rho is on the plaq factor | ||||
|  | ||||
|     Compute_MpInvJx_dNxxdSy(PlaqL,PlaqR,MpInvJx,FdetV); | ||||
|     Fdet2_mu=FdetV; | ||||
|     Fdet1_mu=Zero(); | ||||
|      | ||||
|     for(int e =0 ; e<8 ; e++){ | ||||
|       LatticeComplexD tr(grid); | ||||
|       ColourMatrix te; | ||||
|       SU3::generator(e, te); | ||||
|       tr = trace(dJdX[e] * nMpInv); | ||||
|       pokeColour(dJdXe_nMpInv,tr,e); | ||||
|     } | ||||
|     /////////////////////////////// | ||||
|     // Mask it off | ||||
|     /////////////////////////////// | ||||
|     auto tmp=PeekIndex<LorentzIndex>(masks[smr],mu); | ||||
|     dJdXe_nMpInv = dJdXe_nMpInv*tmp; | ||||
|      | ||||
|     //    dJdXe_nMpInv needs to multiply: | ||||
|     //       Nxx_mu (site local)                           (1) | ||||
|     //       Nxy_mu one site forward  in each nu direction (3) | ||||
|     //       Nxy_mu one site backward in each nu direction (3) | ||||
|     //       Nxy_nu 0,0  ; +mu,0; 0,-nu; +mu-nu   [ 3x4 = 12] | ||||
|     // 19 terms. | ||||
|     AdjMatrixField Nxy(grid); | ||||
|  | ||||
|     GaugeField Fdet1(grid); | ||||
|     GaugeField Fdet2(grid); | ||||
|     GaugeLinkField Fdet_pol(grid); // one polarisation | ||||
|  | ||||
|     for(int nu=0;nu<Nd;nu++){ | ||||
|  | ||||
|       if (nu!=mu) { | ||||
| 	///////////////// +ve nu ///////////////// | ||||
| 	//     __ | ||||
| 	//    |  | | ||||
| 	//    x==    // nu polarisation -- clockwise | ||||
|  | ||||
| 	PlaqL=Ident; | ||||
|  | ||||
| 	PlaqR=(-rho)*Gimpl::CovShiftForward(Umu[nu], nu, | ||||
|  	       Gimpl::CovShiftForward(Umu[mu], mu, | ||||
| 	         Gimpl::CovShiftBackward(Umu[nu], nu, | ||||
| 		   Gimpl::CovShiftIdentityBackward(Utmp, mu)))); | ||||
|  | ||||
| 	dJdXe_nMpInv_y =   dJdXe_nMpInv; | ||||
| 	ComputeNxy(PlaqL,PlaqR,Nxy); | ||||
| 	Fdet1_nu = transpose(Nxy)*dJdXe_nMpInv_y; | ||||
|  | ||||
| 	PlaqR=(-1.0)*PlaqR; | ||||
| 	Compute_MpInvJx_dNxxdSy(PlaqL,PlaqR,MpInvJx,FdetV); | ||||
| 	Fdet2_nu = FdetV; | ||||
| 	 | ||||
| 	//    x== | ||||
| 	//    |  | | ||||
| 	//    .__|    // nu polarisation -- anticlockwise | ||||
|  | ||||
| 	PlaqR=(rho)*Gimpl::CovShiftForward(Umu[nu], nu, | ||||
| 		      Gimpl::CovShiftBackward(Umu[mu], mu, | ||||
|     	 	        Gimpl::CovShiftIdentityBackward(Umu[nu], nu))); | ||||
|  | ||||
| 	PlaqL=Gimpl::CovShiftIdentityBackward(Utmp, mu); | ||||
|  | ||||
| 	dJdXe_nMpInv_y = Cshift(dJdXe_nMpInv,mu,-1); | ||||
| 	ComputeNxy(PlaqL, PlaqR,Nxy); | ||||
| 	Fdet1_nu = Fdet1_nu+transpose(Nxy)*dJdXe_nMpInv_y; | ||||
| 	 | ||||
|  | ||||
| 	MpInvJx_nu = Cshift(MpInvJx,mu,-1); | ||||
| 	Compute_MpInvJx_dNxxdSy(PlaqL,PlaqR,MpInvJx_nu,FdetV); | ||||
| 	Fdet2_nu = Fdet2_nu+FdetV; | ||||
| 	 | ||||
| 	///////////////// -ve nu ///////////////// | ||||
| 	//  __ | ||||
| 	// |  | | ||||
| 	// x==          // nu polarisation -- clockwise | ||||
|  | ||||
| 	PlaqL=(rho)* Gimpl::CovShiftForward(Umu[mu], mu, | ||||
| 		       Gimpl::CovShiftForward(Umu[nu], nu, | ||||
| 			 Gimpl::CovShiftIdentityBackward(Utmp, mu))); | ||||
|  | ||||
|         PlaqR = Gimpl::CovShiftIdentityForward(Umu[nu], nu); | ||||
|  | ||||
| 	dJdXe_nMpInv_y = Cshift(dJdXe_nMpInv,nu,1); | ||||
| 	ComputeNxy(PlaqL,PlaqR,Nxy); | ||||
| 	Fdet1_nu = Fdet1_nu + transpose(Nxy)*dJdXe_nMpInv_y; | ||||
|  | ||||
| 	MpInvJx_nu = Cshift(MpInvJx,nu,1); | ||||
| 	Compute_MpInvJx_dNxxdSy(PlaqL,PlaqR,MpInvJx_nu,FdetV); | ||||
| 	Fdet2_nu = Fdet2_nu+FdetV; | ||||
| 	 | ||||
| 	// x== | ||||
| 	// |  | | ||||
| 	// |__|         // nu polarisation | ||||
|  | ||||
| 	PlaqL=(-rho)*Gimpl::CovShiftForward(Umu[nu], nu, | ||||
|  	        Gimpl::CovShiftIdentityBackward(Utmp, mu)); | ||||
|  | ||||
| 	PlaqR=Gimpl::CovShiftBackward(Umu[mu], mu, | ||||
| 	        Gimpl::CovShiftIdentityForward(Umu[nu], nu)); | ||||
|  | ||||
| 	dJdXe_nMpInv_y = Cshift(dJdXe_nMpInv,mu,-1); | ||||
| 	dJdXe_nMpInv_y = Cshift(dJdXe_nMpInv_y,nu,1); | ||||
|  | ||||
| 	ComputeNxy(PlaqL,PlaqR,Nxy); | ||||
| 	Fdet1_nu = Fdet1_nu + transpose(Nxy)*dJdXe_nMpInv_y; | ||||
|  | ||||
| 	MpInvJx_nu = Cshift(MpInvJx,mu,-1); | ||||
| 	MpInvJx_nu = Cshift(MpInvJx_nu,nu,1); | ||||
| 	Compute_MpInvJx_dNxxdSy(PlaqL,PlaqR,MpInvJx_nu,FdetV); | ||||
| 	Fdet2_nu = Fdet2_nu+FdetV; | ||||
|  | ||||
| 	///////////////////////////////////////////////////////////////////// | ||||
| 	// Set up the determinant force contribution in 3x3 algebra basis | ||||
| 	///////////////////////////////////////////////////////////////////// | ||||
| 	InsertForce(Fdet1,Fdet1_nu,nu); | ||||
| 	InsertForce(Fdet2,Fdet2_nu,nu); | ||||
| 	 | ||||
| 	////////////////////////////////////////////////// | ||||
| 	// Parallel direction terms | ||||
| 	////////////////////////////////////////////////// | ||||
|  | ||||
|         //     __ | ||||
| 	//    |  " | ||||
| 	//    |__"x    // mu polarisation | ||||
| 	PlaqL=(-rho)*Gimpl::CovShiftForward(Umu[mu], mu, | ||||
| 		      Gimpl::CovShiftBackward(Umu[nu], nu, | ||||
|    		        Gimpl::CovShiftIdentityBackward(Utmp, mu))); | ||||
|  | ||||
| 	PlaqR=Gimpl::CovShiftIdentityBackward(Umu[nu], nu); | ||||
| 	 | ||||
| 	dJdXe_nMpInv_y = Cshift(dJdXe_nMpInv,nu,-1); | ||||
|  | ||||
| 	ComputeNxy(PlaqL,PlaqR,Nxy); | ||||
| 	Fdet1_mu = Fdet1_mu + transpose(Nxy)*dJdXe_nMpInv_y; | ||||
|  | ||||
| 	MpInvJx_nu = Cshift(MpInvJx,nu,-1); | ||||
|  | ||||
| 	Compute_MpInvJx_dNxxdSy(PlaqL,PlaqR,MpInvJx_nu,FdetV); | ||||
| 	Fdet2_mu = Fdet2_mu+FdetV; | ||||
|  | ||||
| 	//  __ | ||||
| 	// "  | | ||||
| 	// x__|          // mu polarisation | ||||
|  | ||||
| 	PlaqL=(-rho)*Gimpl::CovShiftForward(Umu[mu], mu, | ||||
| 		       Gimpl::CovShiftForward(Umu[nu], nu, | ||||
| 		 	 Gimpl::CovShiftIdentityBackward(Utmp, mu))); | ||||
|  | ||||
|         PlaqR=Gimpl::CovShiftIdentityForward(Umu[nu], nu); | ||||
|  | ||||
| 	dJdXe_nMpInv_y = Cshift(dJdXe_nMpInv,nu,1); | ||||
|  | ||||
| 	ComputeNxy(PlaqL,PlaqR,Nxy); | ||||
| 	Fdet1_mu = Fdet1_mu + transpose(Nxy)*dJdXe_nMpInv_y; | ||||
|  | ||||
| 	MpInvJx_nu = Cshift(MpInvJx,nu,1); | ||||
|  | ||||
| 	Compute_MpInvJx_dNxxdSy(PlaqL,PlaqR,MpInvJx_nu,FdetV); | ||||
| 	Fdet2_mu = Fdet2_mu+FdetV; | ||||
| 	 | ||||
|       } | ||||
|     } | ||||
|  | ||||
|     Fdet1_mu = Fdet1_mu + transpose(NxxAd)*dJdXe_nMpInv; | ||||
|  | ||||
|     InsertForce(Fdet1,Fdet1_mu,mu); | ||||
|     InsertForce(Fdet2,Fdet2_mu,mu); | ||||
|  | ||||
|     force= (-0.5)*( Fdet1 + Fdet2); | ||||
|   } | ||||
|   RealD logDetJacobianLevel(const GaugeField &U,int smr) | ||||
|   { | ||||
|     GridBase* grid = U.Grid(); | ||||
|     GaugeField C(grid); | ||||
|     GaugeLinkField Nb(grid); | ||||
|     GaugeLinkField Z(grid); | ||||
|     GaugeLinkField Umu(grid), Cmu(grid); | ||||
|     ColourMatrix   Tb; | ||||
|     ColourMatrix   Tc; | ||||
|     typedef typename SU3Adjoint::AMatrix AdjMatrix; | ||||
|     typedef typename SU3Adjoint::LatticeAdjMatrix  AdjMatrixField; | ||||
|     typedef typename SU3Adjoint::LatticeAdjVector  AdjVectorField; | ||||
|     const int Ngen = SU3Adjoint::Dimension; | ||||
|     AdjMatrix TRb; | ||||
|     LatticeComplex       cplx(grid);  | ||||
|     AdjVectorField  AlgV(grid);  | ||||
|     AdjMatrixField  Mab(grid); | ||||
|     AdjMatrixField  Ncb(grid); | ||||
|     AdjMatrixField  Jac(grid); | ||||
|     AdjMatrixField  Zac(grid); | ||||
|     AdjMatrixField  mZac(grid); | ||||
|     AdjMatrixField  X(grid); | ||||
|  | ||||
|     int mu= (smr/2) %Nd; | ||||
|  | ||||
|     auto mask=PeekIndex<LorentzIndex>(masks[smr],mu); // the cb mask | ||||
|  | ||||
|     ////////////////////////////////////////////////////////////////// | ||||
|     // Assemble the N matrix | ||||
|     ////////////////////////////////////////////////////////////////// | ||||
|     // Computes ALL the staples -- could compute one only here | ||||
|     this->StoutSmearing->BaseSmear(C, U); | ||||
|     Cmu = peekLorentz(C, mu); | ||||
|     Umu = peekLorentz(U, mu); | ||||
|     Complex ci(0,1); | ||||
|     for(int b=0;b<Ngen;b++) { | ||||
|       SU3::generator(b, Tb); | ||||
|       // Qlat Tb = 2i Tb^Grid | ||||
|       Nb = (2.0)*Ta( ci*Tb * Umu * adj(Cmu)); | ||||
|       for(int c=0;c<Ngen;c++) { | ||||
| 	SU3::generator(c, Tc); | ||||
| 	auto tmp = -trace(ci*Tc*Nb); // Luchang's norm: (2Tc) (2Td) N^db = -2 delta cd N^db // - was important | ||||
| 	PokeIndex<ColourIndex>(Ncb,tmp,c,b);  | ||||
|       } | ||||
|     }       | ||||
|  | ||||
|     ////////////////////////////////////////////////////////////////// | ||||
|     // Assemble Luscher exp diff map J matrix  | ||||
|     ////////////////////////////////////////////////////////////////// | ||||
|     // Ta so Z lives in Lie algabra | ||||
|     Z  = Ta(Cmu * adj(Umu)); | ||||
|  | ||||
|     // Move Z to the Adjoint Rep == make_adjoint_representation | ||||
|     Zac = Zero(); | ||||
|     for(int b=0;b<8;b++) { | ||||
|       // Adj group sets traceless antihermitian T's -- Guido, really???? | ||||
|       // Is the mapping of these the same? Same structure constants | ||||
|       // Might never have been checked. | ||||
|       SU3::generator(b, Tb);         // Fund group sets traceless hermitian T's | ||||
|       SU3Adjoint::generator(b,TRb); | ||||
|       TRb=-TRb; | ||||
|       cplx = 2.0*trace(ci*Tb*Z); // my convention 1/2 delta ba | ||||
|       Zac = Zac + cplx * TRb; // is this right? YES - Guido used Anti herm Ta's and with bloody wrong sign. | ||||
|     } | ||||
|  | ||||
|     ////////////////////////////////////// | ||||
|     // J(x) = 1 + Sum_k=1..N (-Zac)^k/(k+1)! | ||||
|     ////////////////////////////////////// | ||||
|     X=1.0;  | ||||
|     Jac = X; | ||||
|     mZac = (-1.0)*Zac;  | ||||
|     RealD kpfac = 1; | ||||
|     for(int k=1;k<12;k++){ | ||||
|       X=X*mZac; | ||||
|       kpfac = kpfac /(k+1); | ||||
|       Jac = Jac + X * kpfac; | ||||
|     } | ||||
|  | ||||
|     //////////////////////////// | ||||
|     // Mab | ||||
|     //////////////////////////// | ||||
|     Mab = Complex(1.0,0.0); | ||||
|     Mab = Mab - Jac * Ncb; | ||||
|  | ||||
|     //////////////////////////// | ||||
|     // det | ||||
|     //////////////////////////// | ||||
|     LatticeComplex       det(grid);  | ||||
|     det = Determinant(Mab); | ||||
|  | ||||
|     //////////////////////////// | ||||
|     // ln det | ||||
|     //////////////////////////// | ||||
|     LatticeComplex       ln_det(grid);  | ||||
|     ln_det = log(det); | ||||
|  | ||||
|     //////////////////////////// | ||||
|     // Masked sum | ||||
|     //////////////////////////// | ||||
|     ln_det = ln_det * mask; | ||||
|     Complex result = sum(ln_det); | ||||
|     return result.real(); | ||||
|   } | ||||
| public: | ||||
|   RealD logDetJacobian(void) | ||||
|   { | ||||
|     RealD ln_det = 0; | ||||
|     if (this->smearingLevels > 0) | ||||
|     { | ||||
|       double start = usecond(); | ||||
|       for (int ismr = this->smearingLevels - 1; ismr > 0; --ismr) { | ||||
| 	ln_det+= logDetJacobianLevel(this->get_smeared_conf(ismr-1),ismr); | ||||
|       } | ||||
|       ln_det +=logDetJacobianLevel(*(this->ThinLinks),0); | ||||
|  | ||||
|       double end = usecond(); | ||||
|       double time = (end - start)/ 1e3; | ||||
|       std::cout << GridLogMessage << "GaugeConfigurationMasked: logDetJacobian took " << time << " ms" << std::endl;   | ||||
|     } | ||||
|     return ln_det; | ||||
|   } | ||||
|   void logDetJacobianForce(GaugeField &force) | ||||
|   { | ||||
|     force =Zero(); | ||||
|     GaugeField force_det(force.Grid()); | ||||
|  | ||||
|     if (this->smearingLevels > 0) | ||||
|     { | ||||
|       double start = usecond(); | ||||
|  | ||||
|       GaugeLinkField tmp_mu(force.Grid()); | ||||
|  | ||||
|       for (int ismr = this->smearingLevels - 1; ismr > 0; --ismr) { | ||||
|  | ||||
| 	// remove U in UdSdU... | ||||
| 	for (int mu = 0; mu < Nd; mu++) { | ||||
| 	  tmp_mu = adj(peekLorentz(this->get_smeared_conf(ismr), mu)) * peekLorentz(force, mu); | ||||
| 	  pokeLorentz(force, tmp_mu, mu); | ||||
| 	} | ||||
| 	 | ||||
|       	// Propagate existing force | ||||
|         force = this->AnalyticSmearedForce(force, this->get_smeared_conf(ismr - 1), ismr); | ||||
|  | ||||
| 	// Add back U in UdSdU... | ||||
| 	for (int mu = 0; mu < Nd; mu++) { | ||||
| 	  tmp_mu = peekLorentz(this->get_smeared_conf(ismr - 1), mu) * peekLorentz(force, mu); | ||||
| 	  pokeLorentz(force, tmp_mu, mu); | ||||
| 	} | ||||
|     	 | ||||
| 	// Get this levels determinant force | ||||
| 	force_det = Zero(); | ||||
| 	logDetJacobianForceLevel(this->get_smeared_conf(ismr-1),force_det,ismr); | ||||
|  | ||||
| 	// Sum the contributions | ||||
| 	force = force + force_det; | ||||
|       } | ||||
|      | ||||
|       // remove U in UdSdU... | ||||
|       for (int mu = 0; mu < Nd; mu++) { | ||||
| 	tmp_mu = adj(peekLorentz(this->get_smeared_conf(0), mu)) * peekLorentz(force, mu); | ||||
| 	pokeLorentz(force, tmp_mu, mu); | ||||
|       } | ||||
|  | ||||
|       force = this->AnalyticSmearedForce(force, *this->ThinLinks,0); | ||||
|  | ||||
|       for (int mu = 0; mu < Nd; mu++) { | ||||
| 	tmp_mu = peekLorentz(*this->ThinLinks, mu) * peekLorentz(force, mu); | ||||
| 	pokeLorentz(force, tmp_mu, mu); | ||||
|       } | ||||
|  | ||||
|       force_det = Zero(); | ||||
|  | ||||
|       logDetJacobianForceLevel(*this->ThinLinks,force_det,0); | ||||
|  | ||||
|       force = force + force_det; | ||||
|  | ||||
|       force=Ta(force); // Ta | ||||
|        | ||||
|       double end = usecond(); | ||||
|       double time = (end - start)/ 1e3; | ||||
|       std::cout << GridLogMessage << "GaugeConfigurationMasked: lnDetJacobianForce took " << time << " ms" << std::endl;   | ||||
|     }  // if smearingLevels = 0 do nothing | ||||
|   } | ||||
|  | ||||
| private: | ||||
|   //==================================================================== | ||||
|   // Override base clas here to mask it | ||||
|   virtual void fill_smearedSet(GaugeField &U) | ||||
|   { | ||||
|     this->ThinLinks = &U;  // attach the smearing routine to the field U | ||||
|  | ||||
|     // check the pointer is not null | ||||
|     if (this->ThinLinks == NULL) | ||||
|       std::cout << GridLogError << "[SmearedConfigurationMasked] Error in ThinLinks pointer\n"; | ||||
|  | ||||
|     if (this->smearingLevels > 0) | ||||
|     { | ||||
|       std::cout << GridLogMessage << "[SmearedConfigurationMasked] Filling SmearedSet\n"; | ||||
|       GaugeField previous_u(this->ThinLinks->Grid()); | ||||
|  | ||||
|       GaugeField smeared_A(this->ThinLinks->Grid()); | ||||
|       GaugeField smeared_B(this->ThinLinks->Grid()); | ||||
|  | ||||
|       previous_u = *this->ThinLinks; | ||||
|       double start = usecond(); | ||||
|       for (int smearLvl = 0; smearLvl < this->smearingLevels; ++smearLvl) | ||||
|       { | ||||
|         this->StoutSmearing->smear(smeared_A, previous_u); | ||||
| 	ApplyMask(smeared_A,smearLvl); | ||||
| 	smeared_B = previous_u; | ||||
| 	ApplyMask(smeared_B,smearLvl); | ||||
| 	// Replace only the masked portion | ||||
| 	this->SmearedSet[smearLvl] = previous_u-smeared_B + smeared_A; | ||||
|         previous_u = this->SmearedSet[smearLvl]; | ||||
|  | ||||
|         // For debug purposes | ||||
|         RealD impl_plaq = WilsonLoops<Gimpl>::avgPlaquette(previous_u); | ||||
|         std::cout << GridLogMessage << "[SmearedConfigurationMasked] smeared Plaq: " << impl_plaq << std::endl; | ||||
|       } | ||||
|       double end = usecond(); | ||||
|       double time = (end - start)/ 1e3; | ||||
|       std::cout << GridLogMessage << "GaugeConfigurationMasked: Link smearing took " << time << " ms" << std::endl;   | ||||
|     } | ||||
|   } | ||||
|   //==================================================================== | ||||
|   // Override base to add masking | ||||
|   virtual GaugeField AnalyticSmearedForce(const GaugeField& SigmaKPrime, | ||||
| 					  const GaugeField& GaugeK,int level)  | ||||
|   { | ||||
|     GridBase* grid = GaugeK.Grid(); | ||||
|     GaugeField C(grid), SigmaK(grid), iLambda(grid); | ||||
|     GaugeField SigmaKPrimeA(grid); | ||||
|     GaugeField SigmaKPrimeB(grid); | ||||
|     GaugeLinkField iLambda_mu(grid); | ||||
|     GaugeLinkField iQ(grid), e_iQ(grid); | ||||
|     GaugeLinkField SigmaKPrime_mu(grid); | ||||
|     GaugeLinkField GaugeKmu(grid), Cmu(grid); | ||||
|      | ||||
|     this->StoutSmearing->BaseSmear(C, GaugeK); | ||||
|     SigmaK = Zero(); | ||||
|     iLambda = Zero(); | ||||
|  | ||||
|     SigmaKPrimeA = SigmaKPrime; | ||||
|     ApplyMask(SigmaKPrimeA,level); | ||||
|     SigmaKPrimeB = SigmaKPrime - SigmaKPrimeA; | ||||
|      | ||||
|     // Could get away with computing only one polarisation here | ||||
|     // int mu= (smr/2) %Nd; | ||||
|     // SigmaKprime_A has only one component | ||||
|     for (int mu = 0; mu < Nd; mu++) | ||||
|     { | ||||
|       Cmu = peekLorentz(C, mu); | ||||
|       GaugeKmu = peekLorentz(GaugeK, mu); | ||||
|       SigmaKPrime_mu = peekLorentz(SigmaKPrimeA, mu); | ||||
|       iQ = Ta(Cmu * adj(GaugeKmu)); | ||||
|       this->set_iLambda(iLambda_mu, e_iQ, iQ, SigmaKPrime_mu, GaugeKmu); | ||||
|       pokeLorentz(SigmaK, SigmaKPrime_mu * e_iQ + adj(Cmu) * iLambda_mu, mu); | ||||
|       pokeLorentz(iLambda, iLambda_mu, mu); | ||||
|     } | ||||
|     this->StoutSmearing->derivative(SigmaK, iLambda,GaugeK);  // derivative of SmearBase | ||||
|  | ||||
|     //////////////////////////////////////////////////////////////////////////////////// | ||||
|     // propagate the rest of the force as identity map, just add back | ||||
|     //////////////////////////////////////////////////////////////////////////////////// | ||||
|     SigmaK = SigmaK+SigmaKPrimeB; | ||||
|  | ||||
|     return SigmaK; | ||||
|   } | ||||
|  | ||||
| public: | ||||
|  | ||||
|   /* Standard constructor */ | ||||
|   SmearedConfigurationMasked(GridCartesian* _UGrid, unsigned int Nsmear, Smear_Stout<Gimpl>& Stout,bool domask=false) | ||||
|     : SmearedConfiguration<Gimpl>(_UGrid, Nsmear,Stout) | ||||
|   { | ||||
|     if(domask) assert(Nsmear%(2*Nd)==0); // Or multiply by 8?? | ||||
|  | ||||
|     // was resized in base class | ||||
|     assert(this->SmearedSet.size()==Nsmear); | ||||
|      | ||||
|     GridRedBlackCartesian * UrbGrid; | ||||
|     UrbGrid = SpaceTimeGrid::makeFourDimRedBlackGrid(_UGrid); | ||||
|     LatticeComplex one(_UGrid); one = ComplexD(1.0,0.0); | ||||
|     LatticeComplex tmp(_UGrid); | ||||
|  | ||||
|     for (unsigned int i = 0; i < this->smearingLevels; ++i) { | ||||
|  | ||||
|       masks.push_back(*(new LatticeLorentzComplex(_UGrid))); | ||||
|       if (domask) { | ||||
|  | ||||
| 	int mu= (i/2) %Nd; | ||||
| 	int cb= (i%2); | ||||
| 	LatticeComplex tmpcb(UrbGrid); | ||||
| 	 | ||||
| 	masks[i]=Zero(); | ||||
| 	//////////////////// | ||||
| 	// Setup the mask | ||||
| 	//////////////////// | ||||
| 	tmp = Zero(); | ||||
| 	pickCheckerboard(cb,tmpcb,one); | ||||
| 	setCheckerboard(tmp,tmpcb); | ||||
| 	PokeIndex<LorentzIndex>(masks[i],tmp, mu); | ||||
| 	 | ||||
|       } else { | ||||
| 	for(int mu=0;mu<Nd;mu++){ | ||||
| 	  PokeIndex<LorentzIndex>(masks[i],one, mu); | ||||
| 	} | ||||
|       } | ||||
|     } | ||||
|     delete UrbGrid; | ||||
|   } | ||||
|    | ||||
|   virtual void smeared_force(GaugeField &SigmaTilde)  | ||||
|   { | ||||
|     if (this->smearingLevels > 0) | ||||
|     { | ||||
|       double start = usecond(); | ||||
|       GaugeField force = SigmaTilde; // actually = U*SigmaTilde | ||||
|       GaugeLinkField tmp_mu(SigmaTilde.Grid()); | ||||
|  | ||||
|       // Remove U from UdSdU | ||||
|       for (int mu = 0; mu < Nd; mu++) | ||||
|       { | ||||
|         // to get just SigmaTilde | ||||
|         tmp_mu = adj(peekLorentz(this->SmearedSet[this->smearingLevels - 1], mu)) * peekLorentz(force, mu); | ||||
|         pokeLorentz(force, tmp_mu, mu); | ||||
|       } | ||||
|  | ||||
|       for (int ismr = this->smearingLevels - 1; ismr > 0; --ismr) { | ||||
|         force = this->AnalyticSmearedForce(force, this->get_smeared_conf(ismr - 1),ismr); | ||||
|       } | ||||
|        | ||||
|       force = this->AnalyticSmearedForce(force, *this->ThinLinks,0); | ||||
|  | ||||
|       // Add U to UdSdU | ||||
|       for (int mu = 0; mu < Nd; mu++) | ||||
|       { | ||||
|         tmp_mu = peekLorentz(*this->ThinLinks, mu) * peekLorentz(force, mu); | ||||
|         pokeLorentz(SigmaTilde, tmp_mu, mu); | ||||
|       } | ||||
|       double end = usecond(); | ||||
|       double time = (end - start)/ 1e3; | ||||
|       std::cout << GridLogMessage << " GaugeConfigurationMasked: Smeared Force chain rule took " << time << " ms" << std::endl;   | ||||
|     }  // if smearingLevels = 0 do nothing | ||||
|   } | ||||
|  | ||||
| }; | ||||
|  | ||||
| NAMESPACE_END(Grid); | ||||
|  | ||||
							
								
								
									
										91
									
								
								Grid/qcd/smearing/JacobianAction.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										91
									
								
								Grid/qcd/smearing/JacobianAction.h
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,91 @@ | ||||
| /************************************************************************************* | ||||
|  | ||||
| Grid physics library, www.github.com/paboyle/Grid | ||||
|  | ||||
| Source file: ./lib/qcd/action/gauge/WilsonGaugeAction.h | ||||
|  | ||||
| Copyright (C) 2015 | ||||
|  | ||||
| Author: Azusa Yamaguchi <ayamaguc@staffmail.ed.ac.uk> | ||||
| Author: Peter Boyle <paboyle@ph.ed.ac.uk> | ||||
| Author: neo <cossu@post.kek.jp> | ||||
| Author: paboyle <paboyle@ph.ed.ac.uk> | ||||
| Author: Guido Cossu <guido.cossu@ed.ac.uk> | ||||
|  | ||||
| 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 */ | ||||
| #pragma once | ||||
|  | ||||
| NAMESPACE_BEGIN(Grid); | ||||
|  | ||||
| //////////////////////////////////////////////////////////////////////// | ||||
| // Jacobian Action ..  | ||||
| //////////////////////////////////////////////////////////////////////// | ||||
| template <class Gimpl> | ||||
| class JacobianAction : public Action<typename Gimpl::GaugeField> { | ||||
| public:   | ||||
|   INHERIT_GIMPL_TYPES(Gimpl); | ||||
|  | ||||
|   SmearedConfigurationMasked<Gimpl> * smearer; | ||||
|   /////////////////////////// constructors | ||||
|   explicit JacobianAction(SmearedConfigurationMasked<Gimpl> * _smearer ) { smearer=_smearer;}; | ||||
|  | ||||
|   virtual std::string action_name() {return "JacobianAction";} | ||||
|  | ||||
|   virtual std::string LogParameters(){ | ||||
|     std::stringstream sstream; | ||||
|     sstream << GridLogMessage << "[JacobianAction] " << std::endl; | ||||
|     return sstream.str(); | ||||
|   } | ||||
|  | ||||
|   ////////////////////////////////// | ||||
|   // Usual cases are not used | ||||
|   ////////////////////////////////// | ||||
|   virtual void refresh(const GaugeField &U, GridSerialRNG &sRNG, GridParallelRNG &pRNG){ assert(0);}; | ||||
|   virtual RealD S(const GaugeField &U) { assert(0); } | ||||
|   virtual void deriv(const GaugeField &U, GaugeField &dSdU) { assert(0);  } | ||||
|  | ||||
|   ////////////////////////////////// | ||||
|   // Functions of smart configs only | ||||
|   ////////////////////////////////// | ||||
|   virtual void refresh(ConfigurationBase<GaugeField> & U, GridSerialRNG &sRNG, GridParallelRNG& pRNG) | ||||
|   { | ||||
|     return; | ||||
|   } | ||||
|   virtual RealD S(ConfigurationBase<GaugeField>& U) | ||||
|   { | ||||
|     // det M = e^{ - ( - logDetM) } | ||||
|     assert( &U == smearer ); | ||||
|     return -smearer->logDetJacobian(); | ||||
|   } | ||||
|   virtual RealD Sinitial(ConfigurationBase<GaugeField>& U)  | ||||
|   { | ||||
|     return S(U); | ||||
|   } | ||||
|   virtual void deriv(ConfigurationBase<GaugeField>& U, GaugeField& dSdU) | ||||
|   { | ||||
|     assert( &U == smearer ); | ||||
|     smearer->logDetJacobianForce(dSdU); | ||||
|   } | ||||
|  | ||||
| private: | ||||
|  }; | ||||
|  | ||||
| NAMESPACE_END(Grid); | ||||
|  | ||||
| @@ -40,7 +40,9 @@ template <class Gimpl> | ||||
| class Smear_Stout : public Smear<Gimpl> { | ||||
|  private: | ||||
|   int OrthogDim = -1; | ||||
| public: | ||||
|   const std::vector<double> SmearRho; | ||||
| private: | ||||
|   // Smear<Gimpl>* ownership semantics: | ||||
|   //    Smear<Gimpl>* passed in to constructor are owned by caller, so we don't delete them here | ||||
|   //    Smear<Gimpl>* created within constructor need to be deleted as part of the destructor | ||||
|   | ||||
| @@ -823,6 +823,35 @@ LatticeComplexD Determinant(const Lattice<iScalar<iScalar<iMatrix<vComplexD, N> | ||||
|   return ret; | ||||
| } | ||||
| template<int N> | ||||
| Lattice<iScalar<iScalar<iMatrix<vComplexD, N> > > > Inverse(const Lattice<iScalar<iScalar<iMatrix<vComplexD, N> > > > &Umu) | ||||
| { | ||||
|   GridBase *grid=Umu.Grid(); | ||||
|   auto lvol = grid->lSites(); | ||||
|   Lattice<iScalar<iScalar<iMatrix<vComplexD, N> > > > ret(grid); | ||||
|    | ||||
|   autoView(Umu_v,Umu,CpuRead); | ||||
|   autoView(ret_v,ret,CpuWrite); | ||||
|   thread_for(site,lvol,{ | ||||
|     Eigen::MatrixXcd EigenU = Eigen::MatrixXcd::Zero(N,N); | ||||
|     Coordinate lcoor; | ||||
|     grid->LocalIndexToLocalCoor(site, lcoor); | ||||
|     iScalar<iScalar<iMatrix<ComplexD, N> > > Us; | ||||
|     iScalar<iScalar<iMatrix<ComplexD, N> > > Ui; | ||||
|     peekLocalSite(Us, Umu_v, lcoor); | ||||
|     for(int i=0;i<N;i++){ | ||||
|       for(int j=0;j<N;j++){ | ||||
| 	EigenU(i,j) = Us()()(i,j); | ||||
|       }} | ||||
|     Eigen::MatrixXcd EigenUinv = EigenU.inverse(); | ||||
|     for(int i=0;i<N;i++){ | ||||
|       for(int j=0;j<N;j++){ | ||||
| 	Ui()()(i,j) = EigenUinv(i,j); | ||||
|       }} | ||||
|     pokeLocalSite(Ui,ret_v,lcoor); | ||||
|   }); | ||||
|   return ret; | ||||
| } | ||||
| template<int N> | ||||
| static void ProjectSUn(Lattice<iScalar<iScalar<iMatrix<vComplexD, N> > > > &Umu) | ||||
| { | ||||
|   Umu      = ProjectOnGroup(Umu); | ||||
|   | ||||
| @@ -51,6 +51,7 @@ public: | ||||
|   typedef Lattice<iVector<iScalar<iMatrix<vComplexF, Dimension> >, Nd> > LatticeAdjFieldF; | ||||
|   typedef Lattice<iVector<iScalar<iMatrix<vComplexD, Dimension> >, Nd> > LatticeAdjFieldD; | ||||
|  | ||||
|   typedef Lattice<iScalar<iScalar<iVector<vComplex, Dimension> > > >  LatticeAdjVector; | ||||
|  | ||||
|   template <class cplx> | ||||
|   static void generator(int Index, iSUnAdjointMatrix<cplx> &iAdjTa) { | ||||
|   | ||||
| @@ -123,7 +123,7 @@ public: | ||||
| 	  } | ||||
| 	  if ( permute_slice ) { | ||||
| 	    int ptype       =grid->PermuteType(d); | ||||
| 	    uint8_t mask    =grid->Nsimd() >> (ptype + 1);		 | ||||
| 	    uint8_t mask    =0x1<<ptype; | ||||
| 	    SE._permute    |= mask; | ||||
| 	  } | ||||
| 	}	 | ||||
|   | ||||
| @@ -451,7 +451,6 @@ public: | ||||
|     else if ( this->fullDirichlet ) DslashLogDirichlet(); | ||||
|     else DslashLogFull(); | ||||
|     acceleratorCopySynchronise(); | ||||
|     // Everyone agrees we are all done | ||||
|     _grid->StencilBarrier();  | ||||
|   } | ||||
|   //////////////////////////////////////////////////////////////////////// | ||||
| @@ -540,6 +539,7 @@ public: | ||||
|       compress.Point(point); | ||||
|       HaloGatherDir(source,compress,point,face_idx); | ||||
|     } | ||||
|     accelerator_barrier(); | ||||
|     face_table_computed=1; | ||||
|     assert(u_comm_offset==_unified_buffer_size); | ||||
|  | ||||
|   | ||||
							
								
								
									
										90
									
								
								documentation/David_notes.txt
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										90
									
								
								documentation/David_notes.txt
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,90 @@ | ||||
| Branch: develop | ||||
|  | ||||
| Files: | ||||
|  | ||||
| Grid/lattice/PaddedCell.h -- Halo exchange | ||||
| tests/Test_general_stencil.cc -- test local off axis stencil addressing | ||||
| tests/debug/Test_padded_cell.cc -- test PaddedCell halo exchange and the General local stencil  by computing ALL plaquettes on lattice | ||||
|  | ||||
| Functionality: | ||||
|  | ||||
| -- extend a lattice field: | ||||
| Grid/lattice/PaddedCell.h | ||||
|  | ||||
| // Constructor | ||||
|   PaddedCell(int _depth,GridCartesian *_grid) | ||||
|  | ||||
| // Expand a field "in" to depth "d" | ||||
|   template<class vobj> | ||||
|   inline Lattice<vobj> Exchange(Lattice<vobj> &in) | ||||
|    | ||||
| // Take the "apple core" of in to a smaller local volume | ||||
|   template<class vobj> | ||||
|   inline Lattice<vobj> Extract(Lattice<vobj> &in) | ||||
|  | ||||
| -- Plaquette test: | ||||
| tests/debug/Test_padded_cell.cc | ||||
|   ///////////////////////////////////////////////// | ||||
|   // Create a padded cell of extra padding depth=1 | ||||
|   ///////////////////////////////////////////////// | ||||
|   int depth = 1; | ||||
|   PaddedCell Ghost(depth,&GRID); | ||||
|   LatticeGaugeField Ughost = Ghost.Exchange(Umu); | ||||
|  | ||||
| ///// Array for the site plaquette | ||||
|   GridBase *GhostGrid = Ughost.Grid(); | ||||
|   LatticeComplex gplaq(GhostGrid);  | ||||
|  | ||||
|   std::vector<Coordinate> shifts; | ||||
|   for(int mu=0;mu<Nd;mu++){ | ||||
|     for(int nu=mu+1;nu<Nd;nu++){ | ||||
|    | ||||
|       //    Umu(x) Unu(x+mu) Umu^dag(x+nu) Unu^dag(x) | ||||
|       Coordinate shift_0(Nd,0); | ||||
|       Coordinate shift_mu(Nd,0); shift_mu[mu]=1; | ||||
|       Coordinate shift_nu(Nd,0); shift_nu[nu]=1; | ||||
|       shifts.push_back(shift_0); | ||||
|       shifts.push_back(shift_mu); | ||||
|       shifts.push_back(shift_nu); | ||||
|       shifts.push_back(shift_0); | ||||
|     } | ||||
|   } | ||||
|   GeneralLocalStencil gStencil(GhostGrid,shifts); | ||||
|  | ||||
|   gplaq=Zero(); | ||||
|   { | ||||
|     autoView( gp_v , gplaq, CpuWrite); | ||||
|     autoView( t_v , trplaq, CpuRead); | ||||
|     autoView( U_v , Ughost, CpuRead); | ||||
|     for(int ss=0;ss<gp_v.size();ss++){ | ||||
|       int s=0; | ||||
|       for(int mu=0;mu<Nd;mu++){ | ||||
| 	for(int nu=mu+1;nu<Nd;nu++){ | ||||
|  | ||||
| 	  auto SE0 = gStencil.GetEntry(s+0,ss); | ||||
| 	  auto SE1 = gStencil.GetEntry(s+1,ss); | ||||
| 	  auto SE2 = gStencil.GetEntry(s+2,ss); | ||||
| 	  auto SE3 = gStencil.GetEntry(s+3,ss); | ||||
| 	 | ||||
| 	  int o0 = SE0->_offset; | ||||
| 	  int o1 = SE1->_offset; | ||||
| 	  int o2 = SE2->_offset; | ||||
| 	  int o3 = SE3->_offset; | ||||
| 	   | ||||
| 	  auto U0 = U_v[o0](mu); | ||||
| 	  auto U1 = U_v[o1](nu); | ||||
| 	  auto U2 = adj(U_v[o2](mu)); | ||||
| 	  auto U3 = adj(U_v[o3](nu)); | ||||
|  | ||||
| 	  gpermute(U0,SE0->_permute); | ||||
| 	  gpermute(U1,SE1->_permute); | ||||
| 	  gpermute(U2,SE2->_permute); | ||||
| 	  gpermute(U3,SE3->_permute); | ||||
| 	   | ||||
| 	  gp_v[ss]() =gp_v[ss]() + trace( U0*U1*U2*U3 ); | ||||
| 	  s=s+4; | ||||
| 	} | ||||
|       } | ||||
|     } | ||||
|   } | ||||
|   cplaq = Ghost.Extract(gplaq); | ||||
| @@ -60,7 +60,7 @@ while test $# -gt 0; do | ||||
|     ;; | ||||
|      | ||||
|     --cxxflags) | ||||
|       echo @GRID_CXXFLAGS@ | ||||
|       echo @GRID_CXXFLAGS@ -I@prefix@/include | ||||
|     ;; | ||||
|      | ||||
|     --cxx) | ||||
| @@ -72,11 +72,11 @@ while test $# -gt 0; do | ||||
|     ;; | ||||
|      | ||||
|     --ldflags) | ||||
|       echo @GRID_LDFLAGS@ | ||||
|       echo @GRID_LDFLAGS@ -L@prefix@/lib | ||||
|     ;; | ||||
|      | ||||
|     --libs) | ||||
|       echo @GRID_LIBS@ | ||||
|       echo @GRID_LIBS@ -lGrid | ||||
|     ;; | ||||
|      | ||||
|     --summary) | ||||
|   | ||||
							
								
								
									
										32
									
								
								systems/Lumi/config-command
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										32
									
								
								systems/Lumi/config-command
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,32 @@ | ||||
| spack load c-lime | ||||
| spack load gmp | ||||
| spack load mpfr | ||||
| CLIME=`spack find --paths c-lime | grep c-lime| cut -c 15-` | ||||
| GMP=`spack find --paths gmp | grep gmp | cut -c 12-` | ||||
| MPFR=`spack find --paths mpfr | grep mpfr | cut -c 12-` | ||||
| echo clime $CLIME | ||||
| echo gmp $GMP | ||||
| echo mpfr $MPFR | ||||
|  | ||||
| ../../configure --enable-comms=mpi-auto \ | ||||
| --with-lime=$CLIME \ | ||||
| --enable-unified=no \ | ||||
| --enable-shm=nvlink \ | ||||
| --enable-tracing=timer \ | ||||
| --enable-accelerator=hip \ | ||||
| --enable-gen-simd-width=64 \ | ||||
| --enable-simd=GPU \ | ||||
| --disable-accelerator-cshift \ | ||||
| --with-gmp=$OLCF_GMP_ROOT \ | ||||
| --with-fftw=$FFTW_DIR/.. \ | ||||
| --with-mpfr=/opt/cray/pe/gcc/mpfr/3.1.4/ \ | ||||
| --disable-fermion-reps \ | ||||
| --disable-gparity \ | ||||
| CXX=hipcc MPICXX=mpicxx \ | ||||
| CXXFLAGS="-fPIC -I{$ROCM_PATH}/include/ -std=c++14 -I${MPICH_DIR}/include -L/lib64 --amdgpu-target=gfx90a" \ | ||||
|  LDFLAGS="-L/lib64 -L/opt/rocm-5.2.0/lib/ -L${MPICH_DIR}/lib -lmpi -L${CRAY_MPICH_ROOTDIR}/gtl/lib -lmpi_gtl_hsa -lamdhip64 --amdgpu-target=gfx90a " | ||||
|  | ||||
|  | ||||
| #--enable-simd=GPU-RRII \ | ||||
|  | ||||
|  | ||||
							
								
								
									
										1
									
								
								systems/Lumi/sourceme.sh
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										1
									
								
								systems/Lumi/sourceme.sh
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1 @@ | ||||
| module load CrayEnv LUMI/22.12 partition/G  cray-fftw/3.3.10.1 | ||||
| @@ -1,2 +1,4 @@ | ||||
| CXX=mpicxx-openmpi-mp CXXFLAGS=-I/opt/local/include/ LDFLAGS=-L/opt/local/lib/ ../../configure --enable-simd=GEN --enable-debug --enable-comms=mpi --enable-unified=yes | ||||
| BREW=/opt/local/ | ||||
| MPICXX=mpicxx CXX=c++-12 ../../configure --enable-simd=GEN --enable-comms=mpi-auto --enable-unified=yes --prefix $HOME/QCD/GridInstall --with-lime=/Users/peterboyle/QCD/SciDAC/install/ --with-openssl=$BREW --disable-fermion-reps --disable-gparity  | ||||
|  | ||||
|  | ||||
|   | ||||
| @@ -115,6 +115,7 @@ int main(int argc, char ** argv) | ||||
| 	  if (SE->_permute & 0x2 ) { permute(check[i],tmp,1); tmp=check[i];} | ||||
| 	  if (SE->_permute & 0x4 ) { permute(check[i],tmp,2); tmp=check[i];} | ||||
| 	  if (SE->_permute & 0x8 ) { permute(check[i],tmp,3); tmp=check[i];} | ||||
| 	  //	  std::cout<<GridLogMessage<<"stencil["<<i<<"] "<< check[i]<< " perm "<<(uint32_t)SE->_permute <<std::endl; | ||||
| 	} | ||||
|  | ||||
| 	Real nrmC = norm2(Check); | ||||
| @@ -138,18 +139,17 @@ int main(int argc, char ** argv) | ||||
| 	  ddiff = check -bar; | ||||
| 	  diff =norm2(ddiff); | ||||
| 	  if ( diff > 0){ | ||||
| 	    std::cout <<"Coor (" << coor[0]<<","<<coor[1]<<","<<coor[2]<<","<<coor[3] | ||||
| 		      <<") " <<check<<" vs "<<bar<<std::endl; | ||||
| 	    std::cout <<"Diff at Coor (" << coor[0]<<","<<coor[1]<<","<<coor[2]<<","<<coor[3] | ||||
| 		      <<") stencil " <<check<<" vs cshift "<<bar<<std::endl; | ||||
| 	  } | ||||
|  | ||||
|  | ||||
| 	}}}} | ||||
|  | ||||
| 	if (nrm > 1.0e-4) { | ||||
| 	  autoView( check , Check, CpuRead); | ||||
| 	  autoView(   bar ,   Bar, CpuRead); | ||||
| 	  for(int i=0;i<check.size();i++){ | ||||
| 	    std::cout << i<<" Check "<<check[i]<< "\n"<<i<<" Bar "<<bar[i]<<std::endl; | ||||
| 	    std::cout << i<<" ERROR Check \n"<<check[i]<< "\n"<<i<<" Bar \n"<<bar[i]<<std::endl; | ||||
| 	  } | ||||
| 	} | ||||
| 	if (nrm > 1.0e-4) exit(-1); | ||||
|   | ||||
| @@ -63,7 +63,9 @@ int main(int argc, char** argv) { | ||||
|   std::cout << "Dimension of adjoint representation: "<< SU2Adjoint::Dimension << std::endl; | ||||
|  | ||||
|   // guard as this code fails to compile for Nc != 3 | ||||
| #if (Nc == 3) | ||||
| #if 1 | ||||
|  | ||||
|   std::cout << " Printing  Adjoint Generators"<< std::endl; | ||||
|      | ||||
|   SU2Adjoint::printGenerators(); | ||||
|   SU2::testGenerators(); | ||||
| @@ -148,10 +150,33 @@ int main(int argc, char** argv) { | ||||
|     typename AdjointRep<Nc>::LatticeMatrix Vrmu = peekLorentz(Vr,mu); | ||||
|     pokeLorentz(UrVr,Urmu*Vrmu, mu); | ||||
|   } | ||||
|      | ||||
|  | ||||
|   typedef typename SU_Adjoint<Nc>::AMatrix AdjointMatrix; | ||||
|   typename AdjointRep<Nc>::LatticeField Diff_check = UVr - UrVr; | ||||
|   std::cout << GridLogMessage << "Group structure SU("<<Nc<<") check difference (Adjoint representation) : " << norm2(Diff_check) << std::endl; | ||||
|      | ||||
|  | ||||
|   std::cout << GridLogMessage << "****************************************** " << std::endl; | ||||
|   std::cout << GridLogMessage << " MAP BETWEEN FUNDAMENTAL AND ADJOINT CHECK " << std::endl; | ||||
|   std::cout << GridLogMessage << "****************************************** " << std::endl; | ||||
|   for(int a=0;a<Nc*Nc-1;a++){ | ||||
|   for(int b=0;b<Nc*Nc-1;b++){ | ||||
|   for(int c=0;c<Nc*Nc-1;c++){ | ||||
|     ColourMatrix Ta; | ||||
|     ColourMatrix Tb; | ||||
|     ColourMatrix Tc; | ||||
|     SU3::generator(a, Ta); | ||||
|     SU3::generator(b, Tb); | ||||
|     SU3::generator(c, Tc); | ||||
|     AdjointMatrix TRa; | ||||
|     SU3Adjoint::generator(a,TRa); | ||||
|     Complex tr1 = trace ( Tc * ( Ta*Tb-Tb*Ta)); // i/2 fabc | ||||
|     Complex tr2 = TRa()()(b,c) * Complex(0,1); | ||||
|     std::cout << " 2 Tr( Tc[Ta,Tb]) " << 2.0*tr1<<std::endl; | ||||
|     std::cout << " - TRa_bc " << tr2<<std::endl; | ||||
|     assert(abs( (2.0*tr1-tr2) ) < 1.0e-7); | ||||
|     std::cout << "------------------"<<std::endl; | ||||
|   }}} | ||||
|    | ||||
|   // Check correspondence of algebra and group transformations | ||||
|   // Create a random vector | ||||
|   SU3::LatticeAlgebraVector h_adj(grid); | ||||
|   | ||||
							
								
								
									
										184
									
								
								tests/debug/Test_padded_cell.cc
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										184
									
								
								tests/debug/Test_padded_cell.cc
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,184 @@ | ||||
|     /************************************************************************************* | ||||
|  | ||||
|     Grid physics library, www.github.com/paboyle/Grid  | ||||
|  | ||||
|     Source file: ./tests/Test_padded_cell.cc | ||||
|  | ||||
|     Copyright (C) 2015 | ||||
|  | ||||
| Author: Peter Boyle <paboyle@ph.ed.ac.uk> | ||||
|  | ||||
|     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 <Grid/Grid.h> | ||||
| #include <Grid/lattice/PaddedCell.h> | ||||
| #include <Grid/stencil/GeneralLocalStencil.h> | ||||
|  | ||||
| using namespace std; | ||||
| using namespace Grid; | ||||
|  | ||||
| template<class vobj> void gpermute(vobj & inout,int perm){ | ||||
|   vobj tmp=inout; | ||||
|   if (perm & 0x1 ) { permute(inout,tmp,0); tmp=inout;} | ||||
|   if (perm & 0x2 ) { permute(inout,tmp,1); tmp=inout;} | ||||
|   if (perm & 0x4 ) { permute(inout,tmp,2); tmp=inout;} | ||||
|   if (perm & 0x8 ) { permute(inout,tmp,3); tmp=inout;} | ||||
| } | ||||
|    | ||||
| int main (int argc, char ** argv) | ||||
| { | ||||
|   Grid_init(&argc,&argv); | ||||
|  | ||||
|   Coordinate latt_size  = GridDefaultLatt(); | ||||
|   Coordinate simd_layout= GridDefaultSimd(Nd,vComplexD::Nsimd()); | ||||
|   Coordinate mpi_layout = GridDefaultMpi(); | ||||
|   std::cout << " mpi "<<mpi_layout<<std::endl; | ||||
|   std::cout << " simd "<<simd_layout<<std::endl; | ||||
|   std::cout << " latt "<<latt_size<<std::endl; | ||||
|   GridCartesian GRID(latt_size,simd_layout,mpi_layout); | ||||
|  | ||||
|   GridParallelRNG   pRNG(&GRID); | ||||
|   pRNG.SeedFixedIntegers(std::vector<int>({45,12,81,9})); | ||||
|   LatticeGaugeField Umu(&GRID); | ||||
|  | ||||
|   SU<Nc>::HotConfiguration(pRNG,Umu); | ||||
|  | ||||
|   Real plaq=WilsonLoops<PeriodicGimplR>::avgPlaquette(Umu); | ||||
|   LatticeComplex trplaq(&GRID); | ||||
|  | ||||
|   std::vector<LatticeColourMatrix> U(Nd, Umu.Grid()); | ||||
|   for (int mu = 0; mu < Nd; mu++) { | ||||
|     U[mu] = PeekIndex<LorentzIndex>(Umu, mu); | ||||
|   } | ||||
|  | ||||
|   std::cout << GridLogMessage << " Average plaquette "<<plaq<<std::endl; | ||||
|  | ||||
|   LatticeComplex cplaq(&GRID); cplaq=Zero(); | ||||
|  | ||||
|   ///////////////////////////////////////////////// | ||||
|   // Create a padded cell of extra padding depth=1 | ||||
|   ///////////////////////////////////////////////// | ||||
|   int depth = 1; | ||||
|   PaddedCell Ghost(depth,&GRID); | ||||
|   LatticeGaugeField Ughost = Ghost.Exchange(Umu); | ||||
|  | ||||
|   /////////////////////////////////////////////////////////////////// | ||||
|   // Temporary debug Hack for single rank sim: | ||||
|   // Check the contents of the cell are periodcally replicated | ||||
|   // In future ONLY pad those dimensions that are not local to node | ||||
|   /////////////////////////////////////////////////////////////////// | ||||
| #if 0 | ||||
|   { | ||||
|     double diff=0; | ||||
|     double n=0; | ||||
|   { | ||||
|     autoView( Ug_v , Ughost, CpuRead); | ||||
|     autoView( Ul_v , Umu   , CpuRead); | ||||
|   for(int x=0;x<latt_size[0]+2;x++){ | ||||
|   for(int y=0;y<latt_size[1]+2;y++){ | ||||
|   for(int z=0;z<latt_size[2]+2;z++){ | ||||
|   for(int t=0;t<latt_size[3]+2;t++){ | ||||
|     int lx=(x-1+latt_size[0])%latt_size[0]; | ||||
|     int ly=(y-1+latt_size[1])%latt_size[1]; | ||||
|     int lz=(z-1+latt_size[2])%latt_size[2]; | ||||
|     int lt=(t-1+latt_size[3])%latt_size[3]; | ||||
|     Coordinate gcoor({x,y,z,t}); | ||||
|     Coordinate lcoor({lx,ly,lz,lt}); | ||||
|     LorentzColourMatrix g; | ||||
|     LorentzColourMatrix l; | ||||
|     peekLocalSite(g,Ug_v,gcoor); | ||||
|     peekLocalSite(l,Ul_v,lcoor); | ||||
|     g=g-l; | ||||
|     assert(norm2(g)==0); | ||||
|     diff = diff + norm2(g); | ||||
|     n = n + norm2(l); | ||||
|   }}}} | ||||
|   } | ||||
|   std::cout << "padded field check diff "<< diff <<" / "<< n<<std::endl; | ||||
|   std::cout << norm2(Ughost)<< " " << norm2(Umu)<<std::endl; | ||||
|   } | ||||
| #endif | ||||
|  | ||||
|   ///// Array for the site plaquette | ||||
|   GridBase *GhostGrid = Ughost.Grid(); | ||||
|   LatticeComplex gplaq(GhostGrid);  | ||||
|    | ||||
|   std::vector<Coordinate> shifts; | ||||
|   for(int mu=0;mu<Nd;mu++){ | ||||
|     for(int nu=mu+1;nu<Nd;nu++){ | ||||
|    | ||||
|       //    Umu(x) Unu(x+mu) Umu^dag(x+nu) Unu^dag(x) | ||||
|       Coordinate shift_0(Nd,0); | ||||
|       Coordinate shift_mu(Nd,0); shift_mu[mu]=1; | ||||
|       Coordinate shift_nu(Nd,0); shift_nu[nu]=1; | ||||
|       shifts.push_back(shift_0); | ||||
|       shifts.push_back(shift_mu); | ||||
|       shifts.push_back(shift_nu); | ||||
|       shifts.push_back(shift_0); | ||||
|     } | ||||
|   } | ||||
|   GeneralLocalStencil gStencil(GhostGrid,shifts); | ||||
|  | ||||
|   gplaq=Zero(); | ||||
|   { | ||||
|     autoView( gp_v , gplaq, CpuWrite); | ||||
|     autoView( t_v , trplaq, CpuRead); | ||||
|     autoView( U_v , Ughost, CpuRead); | ||||
|     for(int ss=0;ss<gp_v.size();ss++){ | ||||
|       int s=0; | ||||
|       for(int mu=0;mu<Nd;mu++){ | ||||
| 	for(int nu=mu+1;nu<Nd;nu++){ | ||||
|  | ||||
| 	  auto SE0 = gStencil.GetEntry(s+0,ss); | ||||
| 	  auto SE1 = gStencil.GetEntry(s+1,ss); | ||||
| 	  auto SE2 = gStencil.GetEntry(s+2,ss); | ||||
| 	  auto SE3 = gStencil.GetEntry(s+3,ss); | ||||
| 	 | ||||
| 	  int o0 = SE0->_offset; | ||||
| 	  int o1 = SE1->_offset; | ||||
| 	  int o2 = SE2->_offset; | ||||
| 	  int o3 = SE3->_offset; | ||||
| 	   | ||||
| 	  auto U0 = U_v[o0](mu); | ||||
| 	  auto U1 = U_v[o1](nu); | ||||
| 	  auto U2 = adj(U_v[o2](mu)); | ||||
| 	  auto U3 = adj(U_v[o3](nu)); | ||||
|  | ||||
| 	  gpermute(U0,SE0->_permute); | ||||
| 	  gpermute(U1,SE1->_permute); | ||||
| 	  gpermute(U2,SE2->_permute); | ||||
| 	  gpermute(U3,SE3->_permute); | ||||
| 	   | ||||
| 	  gp_v[ss]() =gp_v[ss]() + trace( U0*U1*U2*U3 ); | ||||
| 	  s=s+4; | ||||
| 	} | ||||
|       } | ||||
|     } | ||||
|   } | ||||
|   cplaq = Ghost.Extract(gplaq); | ||||
|   RealD vol = cplaq.Grid()->gSites(); | ||||
|   RealD faces = (Nd * (Nd-1))/2; | ||||
|   auto p = TensorRemove(sum(cplaq)); | ||||
|   auto result = p.real()/vol/faces/Nc; | ||||
|  | ||||
|   std::cout << GridLogMessage << " Average plaquette via padded cell "<<result<<std::endl; | ||||
|   std::cout << GridLogMessage << " Diff "<<result-plaq<<std::endl; | ||||
|    | ||||
|   assert(fabs(result-plaq)<1.0e-8); | ||||
|   Grid_finalize(); | ||||
| } | ||||
							
								
								
									
										170
									
								
								tests/forces/Test_fthmc.cc
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										170
									
								
								tests/forces/Test_fthmc.cc
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,170 @@ | ||||
| /************************************************************************************* | ||||
|  | ||||
|     Grid physics library, www.github.com/paboyle/Grid  | ||||
|  | ||||
|     Source file: ./tests/Test_fthmc.cc | ||||
|  | ||||
|     Copyright (C) 2022 | ||||
|  | ||||
| Author: Peter Boyle <pboyle@bnl.gov> | ||||
|  | ||||
|     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 <Grid/Grid.h> | ||||
| #include <Grid/qcd/smearing/GaugeConfigurationMasked.h> | ||||
| #include <Grid/qcd/smearing/JacobianAction.h> | ||||
|  | ||||
| using namespace std; | ||||
| using namespace Grid; | ||||
|  | ||||
|  | ||||
| template<class Gimpl> | ||||
| void ForceTest(Action<LatticeGaugeField> &action,SmearedConfigurationMasked<PeriodicGimplR> & smU,MomentumFilterBase<LatticeGaugeField> &Filter) | ||||
| { | ||||
|   LatticeGaugeField U = smU.get_U(false); // unsmeared config | ||||
|   GridBase *UGrid = U.Grid(); | ||||
|  | ||||
|   std::vector<int> seeds({1,2,3,5}); | ||||
|   GridSerialRNG            sRNG;         sRNG.SeedFixedIntegers(seeds); | ||||
|   GridParallelRNG          RNG4(UGrid);  RNG4.SeedFixedIntegers(seeds); | ||||
|  | ||||
|   LatticeColourMatrix Pmu(UGrid);  | ||||
|   LatticeGaugeField P(UGrid);  | ||||
|   LatticeGaugeField UdSdU(UGrid);  | ||||
|  | ||||
|   std::cout << GridLogMessage << "*********************************************************"<<std::endl; | ||||
|   std::cout << GridLogMessage << " Force test for "<<action.action_name()<<std::endl; | ||||
|   std::cout << GridLogMessage << "*********************************************************"<<std::endl; | ||||
|    | ||||
|   RealD eps=0.005; | ||||
|  | ||||
|   std::cout << GridLogMessage << "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++"<<std::endl; | ||||
|   std::cout << GridLogMessage << " Refresh "<<action.action_name()<<std::endl; | ||||
|   std::cout << GridLogMessage << "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++"<<std::endl; | ||||
|    | ||||
|   Gimpl::generate_momenta(P,sRNG,RNG4); | ||||
|   Filter.applyFilter(P); | ||||
|  | ||||
|   action.refresh(smU,sRNG,RNG4); | ||||
|  | ||||
|   std::cout << GridLogMessage << "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++"<<std::endl; | ||||
|   std::cout << GridLogMessage << " Action "<<action.action_name()<<std::endl; | ||||
|   std::cout << GridLogMessage << "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++"<<std::endl; | ||||
|  | ||||
|   RealD S1 = action.S(smU); | ||||
|  | ||||
|   Gimpl::update_field(P,U,eps); | ||||
|   smU.set_Field(U); | ||||
|  | ||||
|   std::cout << GridLogMessage << "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++"<<std::endl; | ||||
|   std::cout << GridLogMessage << " Derivative "<<action.action_name()<<std::endl; | ||||
|   std::cout << GridLogMessage << "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++"<<std::endl; | ||||
|   action.deriv(smU,UdSdU); | ||||
|   UdSdU = Ta(UdSdU); | ||||
|   Filter.applyFilter(UdSdU); | ||||
|  | ||||
|   DumpSliceNorm("Force",UdSdU,Nd-1); | ||||
|    | ||||
|   Gimpl::update_field(P,U,eps); | ||||
|   smU.set_Field(U); | ||||
|  | ||||
|   std::cout << GridLogMessage << "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++"<<std::endl; | ||||
|   std::cout << GridLogMessage << " Action "<<action.action_name()<<std::endl; | ||||
|   std::cout << GridLogMessage << "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++"<<std::endl; | ||||
|    | ||||
|   RealD S2 = action.S(smU); | ||||
|  | ||||
|   // Use the derivative | ||||
|   LatticeComplex dS(UGrid); dS = Zero(); | ||||
|   for(int mu=0;mu<Nd;mu++){ | ||||
|     auto UdSdUmu = PeekIndex<LorentzIndex>(UdSdU,mu); | ||||
|     Pmu= PeekIndex<LorentzIndex>(P,mu); | ||||
|     dS = dS - trace(Pmu*UdSdUmu)*eps*2.0*2.0; | ||||
|   } | ||||
|   ComplexD dSpred    = sum(dS); | ||||
|   RealD diff =  S2-S1-dSpred.real(); | ||||
|  | ||||
|   std::cout<< GridLogMessage << "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++"<<std::endl; | ||||
|   std::cout<< GridLogMessage << "S1 : "<< S1    <<std::endl; | ||||
|   std::cout<< GridLogMessage << "S2 : "<< S2    <<std::endl; | ||||
|   std::cout<< GridLogMessage << "dS : "<< S2-S1 <<std::endl; | ||||
|   std::cout<< GridLogMessage << "dSpred : "<< dSpred.real() <<std::endl; | ||||
|   std::cout<< GridLogMessage << "diff : "<< diff<<std::endl; | ||||
|   std::cout<< GridLogMessage << "*********************************************************"<<std::endl; | ||||
|   //  assert(diff<1.0); | ||||
|   std::cout<< GridLogMessage << "Done" <<std::endl; | ||||
|   std::cout << GridLogMessage << "*********************************************************"<<std::endl; | ||||
| } | ||||
|  | ||||
| int main (int argc, char ** argv) | ||||
| { | ||||
|   Grid_init(&argc,&argv); | ||||
|  | ||||
|   std::cout << std::setprecision(14); | ||||
|   Coordinate latt_size   = GridDefaultLatt(); | ||||
|   Coordinate mpi_layout  = GridDefaultMpi(); | ||||
|   Coordinate simd_layout = GridDefaultSimd(Nd,vComplex::Nsimd()); | ||||
|   Coordinate shm; | ||||
|   GlobalSharedMemory::GetShmDims(mpi_layout,shm); | ||||
|  | ||||
|   const int Ls=12; | ||||
|   const int Nt = latt_size[3]; | ||||
|   GridCartesian         * UGrid   = SpaceTimeGrid::makeFourDimGrid(GridDefaultLatt(), GridDefaultSimd(Nd,vComplex::Nsimd()),GridDefaultMpi()); | ||||
|   GridCartesian         * FGrid   = SpaceTimeGrid::makeFiveDimGrid(Ls,UGrid); | ||||
|  | ||||
|   ///////////////////// Gauge Field and Gauge Forces //////////////////////////// | ||||
|   LatticeGaugeField U(UGrid); | ||||
|  | ||||
| #if  0 | ||||
|   FieldMetaData header; | ||||
|   std::string file("./ckpoint_lat.2000"); | ||||
|   NerscIO::readConfiguration(U,header,file); | ||||
| #else | ||||
|   std::vector<int> seeds({1,2,3,4,5,6,7,8}); | ||||
|   GridParallelRNG          RNG4(UGrid);  RNG4.SeedFixedIntegers(seeds); | ||||
|   SU<Nc>::HotConfiguration(RNG4,U); | ||||
| #endif | ||||
|  | ||||
|    | ||||
|   RealD beta=6.0; | ||||
|   WilsonGaugeActionR  PlaqAction(beta); | ||||
|   IwasakiGaugeActionR RectAction(beta); | ||||
|  | ||||
|  | ||||
|   //////////////////////////////////////////////// | ||||
|   // Plaquette only FTHMC smearer | ||||
|   //////////////////////////////////////////////// | ||||
|   double rho = 0.1; | ||||
|   Smear_Stout<PeriodicGimplR> Smearer(rho); | ||||
|   SmearedConfigurationMasked<PeriodicGimplR> SmartConfig(UGrid,2*Nd,Smearer,true); | ||||
|  | ||||
|   JacobianAction<PeriodicGimplR> Jacobian(&SmartConfig); | ||||
|    | ||||
|   //////////////////////////////////////////////// | ||||
|   // Run some tests | ||||
|   //////////////////////////////////////////////// | ||||
|   MomentumFilterNone<LatticeGaugeField> FilterNone; | ||||
|   SmartConfig.set_Field(U); | ||||
|   ForceTest<GimplTypesR>(PlaqAction,SmartConfig,FilterNone); | ||||
|   SmartConfig.set_Field(U); | ||||
|   ForceTest<GimplTypesR>(RectAction,SmartConfig,FilterNone); | ||||
|   SmartConfig.set_Field(U); | ||||
|   ForceTest<GimplTypesR>(Jacobian,SmartConfig,FilterNone); | ||||
|  | ||||
|   Grid_finalize(); | ||||
| } | ||||
| @@ -85,7 +85,7 @@ int main(int argc, char **argv) { | ||||
|   TheHMC.Resources.AddObservable<PlaqObs>(); | ||||
|   ////////////////////////////////////////////// | ||||
|  | ||||
|   const int Ls      = 8; | ||||
|   const int Ls      = 4; | ||||
|   Real beta         = 2.13; | ||||
|   Real light_mass   = 0.01; | ||||
|   Real strange_mass = 0.04; | ||||
|   | ||||
		Reference in New Issue
	
	Block a user