su2hmc
Loading...
Searching...
No Matches
Observable Quantities
Collaboration diagram for Observable Quantities:

Topics

 Bosonic Observables
 Fermionic Observables

Functions

int Hamilton (double *h, double *s, double res2, double *pp, Complex *X0, Complex *X1, Complex *Phi, Complex *ud[2], Complex_f *ut[2], unsigned int *iu, unsigned int *id, Complex gamval[20], Complex_f gamval_f[20], const unsigned short gamin[16], Complex *sigval, Complex_f *sigval_f, unsigned short *sigin, double *dk[2], float *dk_f[2], Complex_f jqq, float akappa, float beta, float c_sw, double *ancgh, int traj)
 Calculate the Hamiltonian.

Detailed Description

Function Documentation

◆ Hamilton()

int Hamilton ( double * h,
double * s,
double res2,
double * pp,
Complex * X0,
Complex * X1,
Complex * Phi,
Complex * ud[2],
Complex_f * ut[2],
unsigned int * iu,
unsigned int * id,
Complex gamval[20],
Complex_f gamval_f[20],
const unsigned short gamin[16],
Complex * sigval,
Complex_f * sigval_f,
unsigned short * sigin,
double * dk[2],
float * dk_f[2],
Complex_f jqq,
float akappa,
float beta,
float c_sw,
double * ancgh,
int traj )

Calculate the Hamiltonian.

Parameters
[out]hHamiltonian
[out]sAction
[in]res2Limit for conjugate gradient
[in]ppMomentum field
[in]X0Up/down partitioned pseudofermion field
[in]X1Holder for the partitioned fermion field, then the conjugate gradient output
[in]PhiPseudofermion field
[in]ut,udGauge fields (single/double precision)
[in]iu,idLattice indices
[in]gamval,gamval_fGamma matrices rescaled by kappa
[in]gaminGamma indices
[in]sigval,sigval_fCommutators of gamma matrices scaled by \(\frac{c_\text{SW}}{2}\)
[in]siginWhat element of the spinor is multiplied by row idirac each sigma matrix?
[in]dk,dk_f\(\left(1+\gamma_0\right)e^{-\mu}\) and \(\left(1-\gamma_0\right)e^\mu\) float
[in]jqqDiquark source
[in]akappaHopping parameter
[in]betaInverse gauge coupling
[in]c_swClover coefficient. If non-zero calculate the clover contribution
[in]ancghConjugate gradient iterations counter
[in]trajCalling trajectory for error reporting
Returns
Zero on success. Integer Error code otherwise.
Postcondition
h and s overwritten with output

Definition at line 168 of file su2hmc.c.

171 {
172 const char funcname[] = "Hamilton";
173 //Iterate over momentum terms.
174#ifdef USE_GPU
175 double hp;
176 int device=-1;
177 cudaGetDevice(&device);
178 //cudaMemPrefetchAsync(pp,kmom*sizeof(double),device,NULL);
179 cublasDnrm2(cublas_handle, kmom, pp, 1,&hp);
180 hp*=hp;
181#elif defined USE_BLAS
182 double hp = cblas_dnrm2(kmom, pp, 1);
183 hp*=hp;
184#else
185 double hp=0;
186 for(unsigned int i = 0; i<kmom; i++)
187 hp+=pp[i]*pp[i];
188#endif
189 hp*=0.5;
190 double avplaqs, avplaqt;
191 double hg = 0;
192 //avplaq? isn't seen again here.
193 Average_Plaquette(&hg,&avplaqs,&avplaqt,ut,iu,beta);
194
195 alignas(8) double hf = 0; int itercg = 0;
196#ifdef USE_GPU
197 Complex *smallPhi;
198#ifdef _DEBUG
199 cudaMallocManaged((void **)&smallPhi,kferm2*sizeof(Complex),cudaMemAttachGlobal);
200#else
201 cudaMallocAsync((void **)&smallPhi,kferm2*sizeof(Complex),NULL);
202#endif
203#else
204 Complex *smallPhi = aligned_alloc(AVX,kferm2*sizeof(Complex));
205#endif
206 Complex_f *clover[nc];
207 if(c_sw)
208 Clover(clover,ut,iu,id);
209 //Iterating over flavours
210 for(unsigned short na=0;na<nf;na++){
211#ifdef USE_GPU
212#if (nproc>1) //strided for multi-GPU
213 for(unsigned short j=0;j<nc*ndirac;j++)
214 cudaMemcpyAsync(X1+j*kvolHalo,X0+na*kferm2+j*kvol,kvol*sizeof(Complex),cudaMemcpyDeviceToDevice,streams[j]);
215#else
216 cudaMemcpyAsync(X1,X0+na*kferm2,kferm2*sizeof(Complex),cudaMemcpyDeviceToDevice,streams[0]);
217#endif
218#else
219 for(unsigned short j=0;j<nc*ndirac;j++)
220 memcpy(X1+j*kvolHalo,X0+na*kferm2+j*kvol,kvol*sizeof(Complex));
221#endif
222 Fill_Small_Phi(na, smallPhi, Phi);
223 if(Congradq(na,res2,X1,smallPhi,ud,ut,clover,iu,id,gamval,gamval_f,gamin,sigval,sigval_f,sigin,dk,dk_f,\
224 jqq,akappa,c_sw,&itercg))
225 fprintf(stderr,"Trajectory %d\n", traj);
226
227 *ancgh+=itercg;
228#ifdef USE_GPU
229#if (nproc>1) //strided for multi-GPU
230 for(unsigned short j=0;j<nc*ndirac;j++)
231 cudaMemcpyAsync(X0+na*kferm2+j*kvol,X1+j*kvolHalo,kvol*sizeof(Complex),cudaMemcpyDeviceToDevice,streams[j]);
232#else
233 cudaMemcpyAsync(X0+na*kferm2,X1,kferm2*sizeof(Complex),cudaMemcpyDeviceToDevice,streams[0]);
234#endif
235#else
236 for(unsigned short j=0;j<nc*ndirac;j++)
237 memcpy(X0+na*kferm2+j*kvol,X1+j*kvolHalo,kvol*sizeof(Complex));
238#endif
239 Fill_Small_Phi(na, smallPhi,Phi);
240#ifdef USE_GPU
241 alignas(16) Complex dot=0;
242#if (nproc>1)
243 for(unsigned short j=0;j<nc*ndirac;j++){
244 alignas(16) Complex buff;
245 cublasZdotc(cublas_handle,kvol,(cuDoubleComplex *)smallPhi+j*kvol,1,(cuDoubleComplex *) X1+j*kvolHalo,1,(cuDoubleComplex *) &buff);
246 dot+=buff;
247 }
248#else
249 cublasZdotc(cublas_handle,kferm2,(cuDoubleComplex *)smallPhi,1,(cuDoubleComplex *) X1,1,(cuDoubleComplex *) &dot);
250#endif
251 hf+=creal(dot);
252#elif defined USE_BLAS
253 Complex dot=0;
254 for(unsigned short j=0;j<nc*ndirac;j++){
255 alignas(16) Complex buff=0;
256 cblas_zdotc_sub(kvol, smallPhi+j*kvol, 1, X1+j*kvolHalo, 1, &buff);
257 dot+=buff;
258 }
259 hf+=creal(dot);
260#else
261 //It is a dot product of the flattened arrays, could use
262 //a module to convert index to coordinate array...
263#pragma omp parallel for simd collapse(2) aligned(smallPhi,X1:AVX)
264 for(unsigned short j=0;j<nc*ndirac;j++)
265 for(unsigned int i=0;i<kvol;i++)
266 hf+=creal(conj(smallPhi[i+j*kvol])*X1[i+j*kvolHalo]);
267#endif
268 }
269 if(c_sw)
270 Clover_free(clover);
271#ifdef USE_GPU
272#ifdef _DEBUG
273 cudaFree(smallPhi);
274#else
275 cudaFreeAsync(smallPhi,NULL);
276#endif
277#else
278 free(smallPhi);
279#endif
280 //hg was summed over inside of Average_Plaquette.
281#if(nproc>1)
282 Par_dsum(&hp); Par_dsum(&hf);
283#endif
284 *s=hg+hf; *h=(*s)+hp;
285#ifdef _DEBUG
286 if(!rank)
287 printf("hg=%.5e; hf=%.5e; hp=%.5e; h=%.5e\n", hg, hf, hp, *h);
288#endif
289 return 0;
290}
int Average_Plaquette(double *hg, double *avplaqs, double *avplaqt, Complex_f *ut[2], unsigned int *iu, float beta)
Calculates the gauge action using new (how new?) lookup table Follows a routine called qedplaq in som...
Definition bosonic.c:14
void Clover_free(Complex_f *clover[nc])
Free's memory used for clover terms and leaves.
Definition clover.c:750
void Clover(Complex_f *clover[2], Complex_f *ut[2], unsigned int *iu, unsigned int *id)
Calculates the clovers in all directions at all sites.
Definition clover.c:203
__device__ __forceinline__ T conj(const T &z)
Complex Conjugation.
Definition cusu2hmc.cu:33
int Fill_Small_Phi(int na, Complex *smallPhi, Complex *Phi)
Copies necessary (2*4*kvol) elements of Phi into a vector variable.
Definition su2hmc.c:311
int Congradq(int na, double res, Complex *X1, Complex *r, Complex *ud[2], Complex_f *ut[2], Complex_f *clover_f[nc], unsigned int *iu, unsigned int *id, Complex gamval[20], Complex_f gamval_f[20], const unsigned short gamin[16], Complex *sigval, Complex_f *sigval_f, unsigned short *sigin, double *dk[2], float *dk_f[2], Complex_f jqq, float akappa, float c_sw, int *itercg)
Matrix Inversion via Conjugate Gradient (up/down flavour partitioning). Solves Implements up/down pa...
Definition congrad.c:278
int Par_dsum(double *dval)
Performs a reduction on a double dval to get a sum which is then distributed to all ranks.
int rank
The MPI rank.
Definition par_mpi.c:20
#define AVX
Alignment of arrays. 64 for AVX-512, 32 for AVX/AVX2. 16 for SSE. Since AVX is standard on modern x86...
Definition sizes.h:279
#define nc
Colours.
Definition sizes.h:182
#define kmom
sublattice momentum sites
Definition sizes.h:193
#define kvol
Sublattice volume.
Definition sizes.h:163
#define Complex
Double precision complex number.
Definition sizes.h:64
#define nf
Fermion flavours (double it).
Definition sizes.h:160
#define ndirac
Dirac indices.
Definition sizes.h:186
cublasHandle_t cublas_handle
Handle for cuBLAS.
Definition main.c:47
#define Complex_f
Single precision complex number.
Definition sizes.h:62
#define kferm2
sublattice size including Dirac indices
Definition sizes.h:197
#define kvolHalo
Subvolume + halo size.
Definition sizes.h:234
cudaStream_t streams[ndirac *ndim *nadj]
An array of concurrent GPU streams to keep it busy.
Definition cusu2hmc.cu:29
#define creal(z)
Extract Real Component using C standard notation.

References Average_Plaquette(), AVX, Clover(), Clover_free(), Complex, Complex_f, Congradq(), conj(), creal, cublas_handle, Fill_Small_Phi(), kferm2, kmom, kvol, kvolHalo, nc, ndirac, nf, Par_dsum(), rank, and streams.

Here is the call graph for this function:
Here is the caller graph for this function: