su2hmc
Loading...
Searching...
No Matches
Molecular dynamics
Collaboration diagram for Molecular dynamics:

Topics

 Clover Force

Functions

int Gauge_Update (const double d, double *pp, Complex *ut[2], Complex_f *ut_f[2])
 Gauge update for the integration step of the HMC.
int Momentum_Update (const double d, const double *dSdpi, double *pp)
 Wrapper for the momentum update during the integration step of the HMC.
int Leapfrog (Complex *ut[2], Complex_f *ut_f[2], Complex *X0, Complex *X1, Complex *Phi, double *dk[2], float *dk_f[2], double *dSdpi, double *pp, 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, const Complex jqq, const float beta, const float akappa, const float c_sw, const int stepl, const float dt, double *ancg, int *itot, const float proby)
 Leapfrog integrator. Each trajectory step takes the form of p->p+dt/2,u->u+dt,p->p+dt/2 In practice this is implemented for the entire trajectory as p->p+dt/2,u->u+dt,p->p+dt,u->u+dt,p->p+dt,...p->p+dt/2,u->u+dt,p->p+dt/2.
int OMF2 (Complex *ut[2], Complex_f *ut_f[2], Complex *X0, Complex *X1, Complex *Phi, double *dk[2], float *dk_f[2], double *dSdpi, double *pp, 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, const Complex jqq, const float beta, const float akappa, const float c_sw, const int stepl, const float dt, double *ancg, int *itot, const float proby)
 OMF second order five step integrator.
int OMF4 (Complex *ut[2], Complex_f *ut_f[2], Complex *X0, Complex *X1, Complex *Phi, double *dk[2], float *dk_f[2], double *dSdpi, double *pp, 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, const Complex jqq, const float beta, const float akappa, const float c_sw, const int stepl, const float dt, double *ancg, int *itot, const float proby)
 OMF fourth order eleven step integrator.
void cuGauge_Update (const double d, double *pp, Complex *ut[2], dim3 dimGrid, dim3 dimBlock)
 CUDA wrapper for the gauge update during the integration step of the HMC.
void Force_s (double *dSdpi, Complex_f *ut[2], Complex_f *X1, Complex_f *X2, Complex_f gamval[20], unsigned int *iu, const unsigned short gamin[16], const float akappa, const unsigned short mu)
 Calculates the force \(\frac{dS}{d\pi}\) at each intermediate time.
void Force_t (double *dSdpi, Complex_f *ut[2], Complex_f *X1, Complex_f *X2, Complex_f gamval[20], float *dk[2], unsigned int *iu, const unsigned short gamin[16], float akappa)
 Calculates the force \(\frac{dS}{d\pi}\) at each intermediate time.
int Force (double *dSdpi, const bool iflag, double res1, Complex *X0, Complex *X1, Complex *Phi, Complex *ut[2], Complex_f *ut_f[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], const Complex_f jqq, const float akappa, const float beta, const float c_sw, double *ancg)
 Calculates the force \(\frac{dS}{d\pi}\) at each intermediate time.
int Gauge_force (double *dSdpi, Complex_f *ut[2], unsigned int *iu, unsigned int *id, float beta)
 Calculates the gauge force due to the Wilson Action at each intermediate time.
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 \((M^\dagger)Mx=\Phi\) Implements up/down partitioning The matrix multiplication step is done at mixed precision, while the update is done at double.
int Congradp (int na, double res, Complex *Phi, Complex *xi, 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 (no up/down flavour partitioning). Solves \((M^\dagger)Mx=\Phi\) The matrix multiplication step is done at single precision, while the update is done at double.
void cuGauge_force (Complex_f *ut[2], double *dSdpi, float beta, unsigned int *iu, unsigned int *id, dim3 dimGrid, dim3 dimBlock)
 Calculate the gauge contribution to the force.
void cuForce (double *dSdpi, Complex_f *ut[2], Complex_f *X1, Complex_f *X2, Complex_f gamval[20], float *dk[2], unsigned int *iu, const unsigned short gamin[16], float akappa, dim3 dimGrid, dim3 dimBlock)
 Calculates the force \(\frac{dS}{d\pi}\) at each intermediate time.
__global__ void Kernels::Plus_staple (const __grid_constant__ unsigned short mu, const __grid_constant__ unsigned short nu, const unsigned int *iu, Complex_f *Sigma11, Complex_f *Sigma12, const Complex_f *u11t, const Complex_f *u12t)
 Calculates the staple in the positive \(\mu\) direction.
__global__ void Kernels::Minus_staple (const __grid_constant__ unsigned short mu, const __grid_constant__ unsigned short nu, const unsigned int *iu, const unsigned int *id, Complex_f *Sigma11, Complex_f *Sigma12, const Complex_f *u11sh, const Complex_f *u12sh, const Complex_f *u11t, const Complex_f *u12t)
 Calculates the staple in the negative \(\mu\) direction.
__global__ void Kernels::cuGaugeForce (const __grid_constant__ int mu, const Complex_f *Sigma11, const Complex_f *Sigma12, double *dSdpi, const Complex_f *u11t, const Complex_f *u12t, const __grid_constant__ float beta)
 Calculates the gauge force due to the Wilson Action at each intermediate time.
__global__ void Kernels::cuForce_s (double *dSdpi, const Complex_f *u11t, const Complex_f *u12t, const Complex_f *X1, const Complex_f *X2, const __grid_constant__ Complex_f gamval[20], const unsigned int *iu, const __grid_constant__ unsigned short gamin[16], const __grid_constant__ float akappa, const __grid_constant__ unsigned short mu)
 Calculates the force \(\frac{dS}{d\pi}\) at each intermediate time.
__global__ void Kernels::cuForce_t (double *dSdpi, const Complex_f *u11t, const Complex_f *u12t, const Complex_f *X1, const Complex_f *X2, const __grid_constant__ Complex_f gamval[20], const float *dk4m, const float *dk4p, const unsigned int *iu, const __grid_constant__ unsigned short gamin[16])
 Calculates the force \(\frac{dS}{d\pi}\) at each intermediate time.
__global__ void Kernels::cuGauge_Update (const double d, const double *pp, Complex *u11t, Complex *u12t, const int mu)
 Gauge update for the integration step of the HMC.

Detailed Description

Function Documentation

◆ Congradp()

int Congradp ( int na,
double res,
Complex * Phi,
Complex * xi,
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 (no up/down flavour partitioning). Solves \((M^\dagger)Mx=\Phi\) The matrix multiplication step is done at single precision, while the update is done at double.

Parameters
[in]naFlavour index
[in]resLimit for conjugate gradient
[in]PhiPseudofermion field.
[in,out]xiReturned as \((M^\dagger M)^{-1} \Phi\)
[in]ut,udDouble/float Gauge fields
[in]iu,idUpper/Lower halo indices
[in]gamval,gamval_fdouble float Gamma matrices rescaled by kappa
[in]gaminDirac indices
[in]clover_fArray of clover fields
[in]sigval,sigval_fDouble/float Commutators 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_fDouble/float \(\left(1+\gamma_0\right)e^{-\mu}\) and \(\left(1-\gamma_0\right)e^\mu\)
[in]jqqDiquark source
[in]akappaHopping Parameter
[in]c_swClover coefficient.
[in]itercgCounts the iterations of the conjugate gradient
Returns
0 on success, integer error code otherwise
Postcondition
Contents of Phi overwritten

TODO: Set this as an argument How much does the residue have to shrink by before we do a double precision update

\(x2 = (M^\dagger M)p \)

\(\alpha_d= p* (M^\dagger M)p\)

\(alpha=\frac{\alpha_n} {\alpha_d}=\frac{r\cdot r}{p(M^\dagger M)p}\)

\(x+\alpha p\)

Definition at line 780 of file congrad.c.

783 {
784 const char funcname[] = "Congradp";
785 //Return value
786 int ret_val=0;
787 const double resid = res*res;
788#ifdef _DEBUGCG
789#warning "CG Debugging"
790 char *endline = "\n";
791#else
792 char *endline = "\r";
793#endif
794
797 const float d_prec=1.0f/256.0f;
798
799 //These were evaluated only in the first loop of niterx so we'll just do it outside of the loop.
800 alignas(8) double alphan=1.0;
801 //These alpha and beta terms should be double, but that causes issues with BLAS. Instead we declare
802 //them Complex and work with the real part (especially for \alpha_d)
803 //Give initial values Will be overwritten if niterx>0
804 alignas(8) double betad = 1.0; alignas(8) Complex_f alphad=0; alignas(16)Complex alpha = 1; //Alignment needed for cuBLAS
805
806 Complex_f *p_f, *r_f, *x1_f, *x2_f, *xi_f;
807 Complex *p, *r, *x1, *x2, *clover[nc];
808 P_allocate_f(&p_f,&r_f,&x1_f,&x2_f,&xi_f);
809 P_allocate(&p, &r, &x1, &x2,clover);
810
811 ComplexConvert(r_f,Phi+na*kferm,kferm,true,1);
812 ComplexConvert(xi_f,xi,kferm,true,1);
813 if(c_sw){
814 ComplexConvert(clover_f[0],clover[0],6*kvol,false,1);
815 ComplexConvert(clover_f[1],clover[1],6*kvol,false,1);
816 }
817 //Instead of copying element-wise in a loop, use memcpy.
818#ifdef USE_GPU
819 //Get r in single precision
820 //Get xi in single precision
821 cudaMemcpy(r,Phi+na*kferm,kferm*sizeof(Complex),cudaMemcpyDefault);
822#if (nproc>1)//strided memcpy
823 for(unsigned short j=0;j<nc*ngorkov;j++){
824 cudaMemcpyAsync(p+j*kvolHalo,xi+j*kvol,kvol*sizeof(Complex),cudaMemcpyDefault,streams[j]);
825 cudaMemcpyAsync(p_f+j*kvolHalo,xi_f+j*kvol,kvol*sizeof(Complex_f),cudaMemcpyDefault,streams[j]);
826 }
827#else
828 cudaMemcpyAsync(p,xi,kferm*sizeof(Complex),cudaMemcpyDefault,streams[0]);
829 cudaMemcpyAsync(p_f,xi_f,kferm*sizeof(Complex_f),cudaMemcpyDefault,streams[1]);
830#endif
832#else
833 memcpy(r,Phi+na*kferm,kferm*sizeof(Complex));
834 //These strided loops for MPI halos are a total pain in the arse...
835 for(unsigned short j=0;j<nc*ngorkov;j++){
836 memcpy(p+j*kvolHalo,xi+j*kvol,kvol*sizeof(Complex));
837 memcpy(p_f+j*kvolHalo,xi_f+j*kvol,kvol*sizeof(Complex_f));
838 }
839#endif
840
841 double betan=1;double beta_max=FLT_MAX; bool do_dp=true;
842 for((*itercg)=0; (*itercg)<niterc; (*itercg)++){
843 //Don't overwrite on first run.
844 if(do_dp){
845#ifdef _DEBUGCG
846 if(!rank)
847 printf("Going to double precision on iteration %d. %sbetan %e\talpha %e. %s",
848 *itercg,endline,betan,creal(alpha),endline);
849#elifdef _DEBUG
850 if(!rank)
851 printf("\nGoing to double precision on iteration %d. %sbetan %e\talpha %e.\n",
852 *itercg,endline,betan,creal(alpha));
853#endif
854 ComplexConvert(r_f,r,kferm,false,1);
855 //TODO: Banking on converting the halo too being faster than multiple launches
856 ComplexConvert(p_f,p,kvol,false,nc*ngorkov);
857 //Update the residue vector, but not on the first call.
858 if(*itercg){
859#ifdef USE_GPU
860 cuMixed_Sumto((double *)xi,(float *)xi_f,2*kferm,dimGrid,dimBlock);
861 //Bring everything into double precision
862 //Reset xi_f to zero.
864#else
865#pragma omp parallel for simd aligned(xi,xi_f:AVX)
866 for(unsigned int i=0;i<kferm;i++)
867 xi[i]+=(Complex)xi_f[i];
868#endif
869#if(nproc>1)
870 //Dslash needs its input laid out with halos, xi has none
871 Complex *xh;
872#ifdef USE_GPU
873 cudaMallocAsync((void **)&xh,kfermHalo*sizeof(Complex),streams[0]);
874 for(unsigned short j=0;j<nc*ngorkov;j++)
875 cudaMemcpyAsync(xh+j*kvolHalo,xi+j*kvol,kvol*sizeof(Complex),cudaMemcpyDefault,streams[0]);
877#else
878 xh=(Complex *)aligned_alloc(AVX,kfermHalo*sizeof(Complex));
879 for(unsigned short j=0;j<nc*ngorkov;j++)
880 memcpy(xh+j*kvolHalo,xi+j*kvol,kvol*sizeof(Complex));
881#endif
882#else
883 Complex *xh=xi;
884#endif
885 Dslash(x1,xh,ud,iu,id,gamval,gamin,dk,jqq,akappa);
886 if(c_sw)
887 ByClover(x1,xh,clover,sigval,akappa,sigin,false);
888 Dslashd(x2,x1,ud,iu,id,gamval,gamin,dk,jqq,akappa);
889 if(c_sw)
890 ByClover(x2,x1,clover,sigval,akappa,sigin,true);
891#ifdef USE_GPU
893#if(nproc>1)
894 cudaFreeAsync(xh,streams[0]);
895#endif
896 cudaMemcpy(r,Phi+na*kferm,kferm*sizeof(Complex),cudaMemcpyDefault);
897 alignas(16) Complex m_one=-1.0;
898 cublasZaxpy(cublas_handle,kferm,(cuDoubleComplex *)&m_one,(cuDoubleComplex *)x2,1,(cuDoubleComplex *)r,1);
899#else
900#if(nproc>1)
901 free(xh);
902#endif
903#pragma omp parallel for simd
904 for(unsigned int i=0;i<kferm;i++)
905 r[i]=Phi[i+na*kferm]-x2[i];
906#endif
907 }
909 //No need to synchronise here. The memcpy in Dslash is blocking
910 Dslash(x1,p,ud,iu,id,gamval,gamin,dk,jqq,akappa);
911 if(c_sw)
912 ByClover(x1,p,clover,sigval,akappa,sigin,false);
913 Dslashd(x2,x1,ud,iu,id,gamval,gamin,dk,jqq,akappa);
914 if(c_sw)
915 ByClover(x2,x1,clover,sigval,akappa,sigin,true);
916#ifdef USE_GPU
918#endif
919
921 if(*itercg){
922 alpha=0;
923#ifdef USE_GPU
924#if (nproc>1)//Strided
925 for(unsigned short j=0;j<nc*ngorkov;j++){
926 alignas(16) Complex alpha_t=0;
927 cublasZdotc(cublas_handle,kvol,(cuDoubleComplex *)p+j*kvolHalo,1,(cuDoubleComplex *)x2+j*kvol,1,(cuDoubleComplex *)&alpha_t);
928 alpha+=alpha_t
929 }
930#else
931 cublasZdotc(cublas_handle,kferm,(cuDoubleComplex *)p,1,(cuDoubleComplex *)x2,1,(cuDoubleComplex *)&alpha);
932#endif
933#elif defined USE_BLAS
934 for(unsigned short j=0;j<nc*ngorkov;j++){
935 Complex alpha_t=0;
936 cblas_zdotc_sub(kvol, p+j*kvolHalo, 1, x2+j*kvol, 1, &alpha_t);
937 alpha+=alpha_t;
938 }
939#else
940#pragma omp parallel for simd collapse(2) aligned(p,x2:AVX) reduction(+:alpha)
941 for(unsigned short j=0;j<nc*ngorkov;j++)
942 for(unsigned int i=0; i<kvol; i++)
943 alpha+=conj(p[i+j*kvolHalo])*x2[i+j*kvol];
944#endif
945 //For now I'll cast it into a float for the reduction. Each rank only sends and writes
946 //to the real part so this is fine
947#if (nproc>1)
948 Par_dsum((double *)&alpha);
949#endif
951 alpha=alphan/creal(alpha);
953#ifdef USE_GPU
954#if (nproc>1)
955 for(unsigned short j=0;j<nc*ngorkov;j++)
956 cublasZaxpy(cublas_handle,kvol,(cuDoubleComplex *)&alpha,(cuDoubleComplex *)p+j*kvolHalo,1,(cuDoubleComplex *)xi+j*kvol,1);
957#else
958 cublasZaxpy(cublas_handle,kferm,(cuDoubleComplex *)&alpha,(cuDoubleComplex *)p,1,(cuDoubleComplex *)xi,1);
959#endif
960#elif defined USE_BLAS
961 for(unsigned short j=0;j<nc*ngorkov;j++)
962 cblas_zaxpy(kvol, &alpha, p+j*kvolHalo, 1, xi+j*kvol, 1);
963#else
964#pragma omp parallel for simd collapse(2) aligned(p,xi:AVX)
965 for(unsigned short j=0;j<nc*ngorkov;j++)
966 for(unsigned int i=0; i<kvol; i++)
967 xi[i+j*kvol]+=alpha*p[i+j*kvolHalo];
968#endif
969 }
970
971#ifdef USE_GPU
972 Complex alpha_m=(Complex)(-alpha);
973 cublasZaxpy(cublas_handle, kferm,(cuDoubleComplex *)&alpha_m,(cuDoubleComplex *)x2,1,(cuDoubleComplex *)r,1);
974 double betan_d;
975 cublasDznrm2(cublas_handle,kferm,(cuDoubleComplex *)r,1,&betan_d);
976 betan=betan_d*betan_d;
977#elif defined USE_BLAS
978 const Complex alpha_m = (Complex)(-alpha);
979 cblas_zaxpy(kferm, &alpha_m, x2, 1, r, 1);
980 //Undo the negation for the BLAS routine
981 double betan_d = cblas_dznrm2(kferm, r,1);
982 //Gotta square it to "undo" the norm
983 betan = betan_d*betan_d;
984#else
985 betan=0;
986#pragma omp parallel for simd aligned(r,x2:AVX) reduction(+:betan)
987 for(unsigned int i=0; i<kferm; i++){
988 r[i]-=alpha*x2[i];
989 betan += conj(r[i])*r[i];
990 }
991 double betan_d=sqrt(betan);
992#endif
993 //And... reduce.
994#if (nproc>1)
995 Par_dsum(&betan);
996#endif
997 betan_d=sqrt(betan);
998 //Update beta_max. Mandatory for double precision.
999 beta_max=betan_d;
1000#ifdef _DEBUG
1001 if(! rank) printf("DP Iter(CG)=%i\tbeta_n=%e\talpha=%e\n", *itercg, betan, creal(alpha));
1002 fflush(stdout);
1003#endif
1004 alignas(16) const Complex beta = (*itercg) ? betan/betad : 0;
1005 betad=betan; alphan=betan;
1006#ifdef USE_GPU
1007 cudaMemsetAsync(xi_f,0,kferm*sizeof(Complex_f),streams[0]);
1008 alpha_m=1;
1009#if (nproc>1)
1010 for(unsigned short j=0;j<nc*ngorkov;j++){
1011 cublasZdscal(cublas_handle,kvol,(double *)&beta,(cuDoubleComplex *)p+j*kvolHalo,1);
1012 cublasZaxpy(cublas_handle,kvol,(cuDoubleComplex *)&alpha_m,(cuDoubleComplex *)r+j*kvol,1,(cuDoubleComplex *)p+j*kvolHalo,1);
1013 }
1014#else
1015 cublasZdscal(cublas_handle,kferm,(double *)&beta,(cuDoubleComplex *)p,1);
1016 cublasZaxpy(cublas_handle,kferm,(cuDoubleComplex *)&alpha_m,(cuDoubleComplex *)r,1,(cuDoubleComplex *)p,1);
1017#endif
1019#elif (defined __USE_MKL__||defined OPENBLAS||defined AMD_BLAS)
1020 memset(xi_f,0,kferm*sizeof(Complex_f));
1021 const Complex a = 1.0;
1022 //There is cblas_? axpby in the MKL and AMD though, set a = 1 and b = \beta.
1023 //If we get a small enough \beta_n before hitting the iteration cap we break
1024 for(unsigned short j=0;j<nc*ngorkov;j++)
1025 cblas_zaxpby(kvol, &a, r+j*kvol, 1, &beta, p+j*kvolHalo, 1);
1026#elif defined USE_BLAS
1027 memset(xi_f,0,kferm*sizeof(Complex_f));
1028 const Complex a = 1.0;
1029 for(unsigned short j=0;j<nc*ngorkov;j++){
1030 cblas_zscal(kvol,&beta,p+j*kvolHalo,1);
1031 cblas_zaxpy(kvol,&a,r+j*kvol,1,p+j*kvolHalo,1);
1032 }
1033#else
1034 memset(xi_f,0,kferm*sizeof(Complex_f));
1035#pragma omp parallel for simd collapse(2) aligned(r,p:AVX)
1036 for(unsigned short j=0;j<nc*ngorkov;j++)
1037 for(unsigned int i=0; i<kvol; i++)
1038 p[i+j*kvolHalo]=r[i+j*kvol]+beta*p[i+j*kvolHalo];
1039#endif
1040 ComplexConvert(p_f,p,kvol,true,nc*ngorkov);
1041 ComplexConvert(r_f,r,kferm,true,1);
1042#ifdef _DEBUGCG
1043 if(! rank) printf("Double precision. Iter(CG)=%i\tbeta_n=%e\talpha=%e\n", *itercg, betan, creal(alpha));
1044 fflush(stdout);
1045#endif
1046 if(betan<resid){
1047 (*itercg)++;
1048#ifdef _DEBUG
1049 if(!rank) printf("\nIter(CG)=%i\tResidue: %e\tTolerance: %e\n", *itercg, betan, resid);
1050#endif
1051 ret_val=0; break;
1052 }
1053 else
1054 do_dp=false;
1055 }
1056 else{
1057 //x2=(M^\dagger)x1=(M^\dagger)Mp
1058 Dslash_f(x1_f,p_f,ut,iu,id,gamval_f,gamin,dk_f,jqq,akappa);
1059 if(c_sw)
1060 ByClover_f(x1_f,p_f,clover_f,sigval_f,akappa,sigin,false);
1061 Dslashd_f(x2_f,x1_f,ut,iu,id,gamval_f,gamin,dk_f,jqq,akappa);
1062 if(c_sw)
1063 ByClover_f(x2_f,x1_f,clover_f,sigval_f,akappa,sigin,true);
1064#ifdef USE_GPU
1066#endif
1067 //We can't evaluate \alpha on the first niterx because we need to get \beta_n.
1068 if(*itercg){
1069 //x*.x
1070 alphad=0;
1071#ifdef USE_GPU
1072#if(nproc>1)//strided
1073 for(unsigned short j=0;j<nc*ngorkov;j++){
1074 alignas(8) Complex_f alpha_t=0;
1075 cublasCdotc(cublas_handle,kvol,(cuComplex *)p_f+j*kvolHalo,1,(cuComplex *)x2_f+j*kvol,1,(cuComplex *)&alpha_t);
1076 alphad+=alpha_t;
1077 }
1078#else
1079 cublasCdotc(cublas_handle,kferm,(cuComplex *)p_f,1,(cuComplex *)x2_f,1,(cuComplex *)&alphad);
1080#endif
1081#elifdef USE_BLAS
1082 for(unsigned short j=0;j<nc*ngorkov;j++){
1083 alignas(8) Complex_f alpha_t=0;
1084 cblas_cdotc_sub(kvol,p_f+j*kvolHalo,1,x2_f+j*kvol,1,&alpha_t);
1085 alphad+=alpha_t;
1086 }
1087#else
1088#pragma omp parallel for simd collapse(2) aligned(p_f,x2_f:AVX) reduction(+:alphad)
1089 for(unsigned short j=0;j<nc*ngorkov;j++)
1090 for(unsigned int i = 0; i<kvol; i++)
1091 alphad+=conj(p_f[i+j*kvolHalo])*x2_f[i+j*kvol];
1092#endif
1093#if (nproc>1)
1094 Par_fsum((float *)&alphad);
1095#endif
1096 //alpha=(r.r)/p(M^\dagger)Mp
1097 alpha=alphan/creal(alphad);
1098 // Complex_f alpha_f = (Complex_f)alpha;
1099 //x+\alpha p
1100#ifdef USE_BLAS
1101 alignas(8) Complex_f alpha_f=(float)alpha;
1102#ifdef USE_GPU
1103#if (nproc>1) //strided
1104 for(unsigned short j=0;j<nc*ngorkov;j++)
1105 cublasCaxpy(cublas_handle,kvol,(cuComplex*) &alpha_f,(cuComplex*) p_f+j*kvolHalo,1,(cuComplex*) xi_f+j*kvol,1);
1106#else
1107 cublasCaxpy(cublas_handle,kferm,(cuComplex*) &alpha_f,(cuComplex*) p_f,1,(cuComplex*) xi_f,1);
1108#endif
1109#else
1110 for(unsigned short j=0;j<nc*ngorkov;j++)
1111 cblas_caxpy(kvol, (Complex_f*)&alpha_f,(Complex_f*)p_f+j*kvolHalo, 1, (Complex_f*)xi_f+j*kvol, 1);
1112#endif
1113#else
1114#pragma omp parallel for simd collapse(2) aligned(xi_f,p_f:AVX)
1115 for(unsigned short j=0;j<nc*ngorkov;j++)
1116 for(unsigned int i = 0; i<kvol; i++)
1117 xi_f[i+j*kvol]+=alpha*p_f[i+j*kvolHalo];
1118#endif
1119 }
1120
1121 //r=\alpha(M^\dagger)Mp and \beta_n=r*.r
1122 alignas(8) float betan_f=0;
1123#if defined USE_BLAS
1124 alignas(16) Complex_f alpha_m=(Complex_f)(-alpha);
1125#ifdef USE_GPU
1126 cublasCaxpy(cublas_handle,kferm, (cuComplex *)&alpha_m,(cuComplex *) x2_f, 1,(cuComplex *) r_f, 1);
1127 //cudaDeviceSynchronise();
1128 //r*.r
1129 cublasScnrm2(cublas_handle,kferm,(cuComplex *) r_f,1,(float *)&betan_f);
1130#else
1131 cblas_caxpy(kferm,(Complex_f*) &alpha_m,(Complex_f*) x2_f, 1,(Complex_f*) r_f, 1);
1132 //r*.r
1133 betan_f = cblas_scnrm2(kferm, (Complex_f*)r_f,1);
1134#endif
1135 //Gotta square it to "undo" the norm
1136 betan=betan_f*betan_f;
1137#else
1138 //Just like Congradq, this loop could be unrolled but will need a reduction to deal with the betan
1139 //addition.
1140 betan = 0;
1141 //If we get a small enough \beta_n before hitting the iteration cap we break
1142#pragma omp parallel for simd aligned(x2_f,r_f:AVX) reduction(+:betan)
1143 for(unsigned int i = 0; i<kferm;i++){
1144 r_f[i]-=alpha*x2_f[i];
1145 betan+=conj(r_f[i])*r_f[i];
1146 }
1147 betan_f=sqrt(betan);
1148#endif
1149 //This is basically just congradq at the end. Check there for comments
1150#if (nproc>1)
1151 Par_dsum(&betan);
1152#endif
1153 //Update beta_max if needed. On paper congrad is monotonically decreasing
1154 betan_f=sqrt(betan);
1155 beta_max = (betan_f>beta_max) ?betan_f : beta_max;
1156#ifdef _DEBUG
1157 if(!rank) printf("Iter (CG) = %i beta_n= %e alpha= %e%s", *itercg, betan, creal(alpha),endline);
1158#endif
1159 if(betan_f<beta_max*d_prec){
1160#ifdef _DEBUG
1161 if(!rank)
1162 printf("Residue %e is less than %e times %e. %s",betan_f,d_prec,beta_max,endline);
1163#endif
1164 do_dp=true;
1165 }
1166 else if(betan<resid){
1167 //Started counting from zero so add one to make it accurate
1168 (*itercg)++;
1169#ifdef _DEBUG
1170 if(!rank) printf("\nIter (CG) = %i resid = %e toler = %e\n", *itercg, betan, resid);
1171#endif
1172 //Final iteration should be in double precision.
1173 do_dp=true;
1174 }
1175 else if(*itercg==niterc-1){
1176 if(!rank) fprintf(stderr, "Warning %i in %s: Exceeded iteration limit %i beta_n=%e\n",
1177 ITERLIM, funcname, niterc, betan);
1178 ret_val=ITERLIM; break;
1179 }
1180 //Note that beta below is not the global beta and scoping is used to avoid conflict between them
1181 alignas(8) Complex beta = (*itercg) ? betan/betad : 0;
1182 betad=betan; alphan=betan;
1183 //BLAS for p=r+\betap doesn't exist in standard BLAS. This is NOT an axpy case as we're multiplying y by
1184 //\beta instead of x.
1185 //There is cblas_zaxpby in the MKL though, set a = 1 and b = \beta.
1186#ifdef USE_BLAS
1187 alignas(8) Complex_f beta_f = (Complex_f)beta;
1188 alignas(8) Complex_f a = 1.0;
1189#ifdef USE_GPU
1190#if (nproc>1) //strided
1191 for(unsigned short j=0;j<nc*ngorkov;j++){
1192 cublasCscal(cublas_handle,kvol,(cuComplex *)&beta_f,(cuComplex *)p_f+j*kvolHalo,1);
1193 cublasCaxpy(cublas_handle,kvol,(cuComplex *)&a,(cuComplex *)r_f+j*kvol,1,(cuComplex *)p_f+j*kvolHalo,1);
1194 }
1195#else
1196 cublasCscal(cublas_handle,kferm,(cuComplex *)&beta_f,(cuComplex *)p_f,1);
1197 cublasCaxpy(cublas_handle,kferm,(cuComplex *)&a,(cuComplex *)r_f,1,(cuComplex *)p_f,1);
1198#endif
1200#elif (defined __USE_MKL__||defined OPENBLAS||defined AMD_BLAS)
1201 for(unsigned short j=0;j<nc*ngorkov;j++)
1202 cblas_caxpby(kvol, &a, r_f+j*kvol, 1, &beta_f, p_f+j*kvolHalo, 1);
1203#else
1204 for(unsigned short j=0;j<nc*ngorkov;j++){
1205 cblas_cscal(kvol,&beta_f,p_f+j*kvolHalo,1);
1206 cblas_caxpy(kvol,&a,r_f+j*kvol,1,p_f+j*kvolHalo,1);
1207 }
1208#endif
1209#else
1210#pragma omp parallel for simd aligned(r_f,p_f:AVX)
1211 for(unsigned short j=0;j<nc*ngorkov;j++)
1212 for(unsigned int i=0; i<kvol; i++)
1213 p_f[i+j*kvolHalo]=r_f[i+j*kvol]+beta*p_f[i+j*kvolHalo];
1214#endif
1215 }
1216 }
1217#ifdef USE_GPU
1219#endif
1220 P_free_f(&p_f,&r_f,&x1_f,&x2_f,&xi_f);
1221 P_free(&p,&r,&x1,&x2,clover);
1222 return ret_val;
1223}
#define ITERLIM
Exceeded max number of iterations.
Definition errorcodes.h:137
void ByClover(Complex *phi, Complex *r, Complex *clover[2], Complex *sigval, const float akappa, unsigned short *sigin, bool dag)
Clover analogue of the Dslash operation. This version acts on all flavours similar to Dslash and Dsla...
Definition clover.c:243
void ByClover_f(Complex_f *phi, Complex_f *r, Complex_f *clover[2], Complex_f *sigval, const float akappa, unsigned short *sigin, bool dag)
Clover analogue of the Dslash operation. This version acts on all flavours similar to Dslash and Dsla...
Definition clover.c:329
int Dslash_f(Complex_f *phi, Complex_f *r, Complex_f *ut[nc], unsigned int *iu, unsigned int *id, Complex_f gamval[20], const unsigned short gamin[16], float *dk[nc], Complex_f jqq, float akappa)
Evaluates in single precision.
Definition matrices.c:448
int Dslashd_f(Complex_f *phi, Complex_f *r, Complex_f *ut[nc], unsigned int *iu, unsigned int *id, Complex_f gamval[20], const unsigned short gamin[16], float *dk[nc], Complex_f jqq, float akappa)
Evaluates in single precision.
Definition matrices.c:567
int Dslashd(Complex *phi, Complex *r, Complex *ut[nc], unsigned int *iu, unsigned int *id, Complex gamval[20], const unsigned short gamin[16], double *dk[nc], Complex_f jqq, float akappa)
Evaluates in double precision.
Definition matrices.c:133
int Dslash(Complex *phi, Complex *r, Complex *ut[nc], unsigned int *iu, unsigned int *id, Complex gamval[20], const unsigned short gamin[16], double *dk[nc], Complex_f jqq, float akappa)
Evaluates in double precision.
Definition matrices.c:16
void P_allocate(Complex **p, Complex **r, Complex **x1, Complex **x2, Complex *clover[2])
Allocates double precision memory needed for Congradp. Just to improve readability Note that since C ...
Definition congrad.c:140
void P_free(Complex **p, Complex **r, Complex **x1, Complex **x2, Complex *clover[2])
Frees memory needed for Congradp. Just to improve readability Note that since C does not modify it's ...
Definition congrad.c:263
void P_allocate_f(Complex_f **p_f, Complex_f **r_f, Complex_f **x1_f, Complex_f **x2_f, Complex_f **xi_f)
Allocates memory needed for Congradp. Just to improve readability Note that since C does not modify i...
Definition congrad.c:103
int ComplexConvert(Complex_f *a, Complex *b, const unsigned int len, const bool dtof, const unsigned short stride)
takes an array of complex float and double precision numbers and converts the precision
Definition coord.c:420
__device__ __forceinline__ T conj(const T &z)
Complex Conjugation.
Definition cusu2hmc.cu:33
void cuMixed_Sumto(double *d, float *f, const unsigned int n, const dim3 dimGrid, const dim3 dimBlock)
Add a single to a double value, and save the output in the double array For complex valued arrays,...
void P_free_f(Complex_f **p_f, Complex_f **r_f, Complex_f **x1_f, Complex_f **x2_f, Complex_f **xi_f)
Frees memory needed for Congradp. Just to improve readability Note that since C does not modify it's ...
Definition congrad.c:243
int Par_fsum(float *dval)
Performs a reduction on a float dval to get a sum which is then distributed to all ranks.
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:283
#define nc
Colours.
Definition sizes.h:186
#define ngorkov
Gor'kov indices.
Definition sizes.h:194
#define niterc
Hard limit for runaway trajectories in Conjugate gradient.
Definition sizes.h:176
#define kvol
Sublattice volume.
Definition sizes.h:167
#define Complex
Double precision complex number.
Definition sizes.h:68
#define kferm
sublattice size including Gor'kov indices
Definition sizes.h:199
#define cudaDeviceSynchronise()
Get rid of that bastardised yankee English.
Definition sizes.h:57
#define Complex_f
Single precision complex number.
Definition sizes.h:66
dim3 dimGrid
Default grid size. First component is normally nt. Second and third depend whatever is needed to get ...
Definition cusu2hmc.cu:27
#define kvolHalo
Subvolume + halo size.
Definition sizes.h:238
#define kfermHalo
Gor'kov lattice and halo.
Definition sizes.h:240
dim3 dimBlock
Default block size. Usually 128.
Definition cusu2hmc.cu:25
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 AVX, ByClover(), ByClover_f(), Complex, Complex_f, ComplexConvert(), Congradp(), conj(), creal, cudaDeviceSynchronise, cuMixed_Sumto(), dimBlock, dimGrid, Dslash(), Dslash_f(), Dslashd(), Dslashd_f(), ITERLIM, kferm, kfermHalo, kvol, kvolHalo, nc, ngorkov, niterc, P_allocate(), P_allocate_f(), P_free(), P_free_f(), Par_dsum(), Par_fsum(), rank, and streams.

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

◆ Congradq()

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 \((M^\dagger)Mx=\Phi\) Implements up/down partitioning The matrix multiplication step is done at mixed precision, while the update is done at double.

Parameters
[in]naFlavour index
[in]resLimit for conjugate gradient
[in,out]X1Pseudofermion field \(\Phi\) initially, returned as \((M^\dagger M)^{-1} \Phi\)
[in]rPartition of \(\Phi\) being used. Gets recycled as the residual vector
[in]ud,utDouble/float Trial colour fields
[in]iu,idUpper/lower halo indices
[in]gamval,gamval_fDouble/float gamma matrices rescaled by kappa
[in]gaminWhat element of the spinor is multiplied by row idirac each gamma matrix?
[in]clover_fArray of clover fields
[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\)
[in]jqqDiquark source
[in]akappaHopping Parameter
[in]c_swClover coefficient. If non-zero calculate the clover contribution
[in]itercgCounts the iterations of the conjugate gradient
Returns
0 on success, integer error code otherwise
Postcondition
Contents of X1 and r overwritten

TODO: Set this as an argument How much does the residue have to shrink by before we do a double precision update

The \(\kappa^2\) factor is needed to normalise the fields correctly \(j_{qq}\) is the diquark condensate and is global scope.

The alpha and beta terms should be double, but that causes issues with BLAS pointers. Instead we declare them complex and work with the real part (especially for \(\alpha_d\)) Give initial values Will be overwritten if niterx>0

\(x2 = (M^\dagger M)p \)

\(\alpha_d= p* (M^\dagger M+c_\text{SW} \sum\limits_{\mu\ne\nu}\frac{1}{2}\sigma_{\mu\nu}F_{\mu\nu}+J^2)p\)

\(\alpha=\frac{\alpha_n}{\alpha_d}=\frac{r\cdot r}{p(M^\dagger M+c_\text{SW} \sum\limits_{\mu\ne\nu}\frac{1}{2}\sigma_{\mu\nu}F_{\mu\nu}+J^2)p}\)

\(x+\alpha p\)

\(x2 = (M^\dagger M)p \)

\(x2 = (M^\dagger M+J^2)p\)

First iteration \( \vec{r}_0=\vec{p}_0\)
\(\alpha_d= p* (M^\dagger M+c_\text{SW} \sum\limits_{\mu\ne\nu}\frac{1}{2}\sigma_{\mu\nu}F_{\mu\nu}+J^2)p\)

\(\alpha=\frac{\alpha_n}{\alpha_d}=\frac{r\cdot r}{p(M^\dagger M+c_\text{SW} \sum\limits_{\mu\ne\nu}\frac{1}{2}\sigma_{\mu\nu}F_{\mu\nu}+J^2)p}\)

\(x+\alpha p\)

\(r_{n+1} = r_n-\alpha(M^\dagger M)p_n\) and \(\beta_n=r^\dagger r\)

Definition at line 278 of file congrad.c.

281 {
282 const char funcname[] = "Congradq";
283 int ret_val=0;
284 const double resid = res*res;
285#ifdef _DEBUGCG
286#warning "CG Debugging"
287 char *endline = "\n";
288#else
289 char *endline = "\r";
290#endif
291
294 const float d_prec=1.0f/256.0f;
297 alignas(16) const Complex_f fac_f = conj(jqq)*jqq*akappa*akappa;
298 //These were evaluated only in the first loop of niterx so we'll just do it outside of the loop.
299 //n suffix is numerator, d is denominator
300 alignas(16) double alphan=1;
304 //Alignment needed for cuBLAS
305 alignas(16) double betad = 1.0; alignas(8) Complex_f alphad=0; alignas(16) Complex alpha = 1;
306 //Because we're dealing with flattened arrays here we can call cblas safely without the halo
307
308 Complex_f *p_f, *x1_f, *x2_f, *r_f, *X1_f;
309 Complex *p, *x1, *x2, *clover[2];
310 Q_allocate_f(&p_f,&x1_f,&x2_f,&r_f,&X1_f);
311 Q_allocate(&p,&x1,&x2,clover);
312
313 //Copy of the source, so the true residual can be recomputed in double precision (reliable updates)
314 Complex *b0;
315#ifdef USE_GPU
316 cudaMallocAsync((void **)&b0,kferm2*sizeof(Complex),streams[5]);
317#else
318 b0=(Complex *)aligned_alloc(AVX,kferm2*sizeof(Complex));
319#endif
320
321 //Instead of copying element-wise in a loop, use memcpy.
322 //Get X1 in single precision
323 //Since X1 has a halo and X1_f does not we have to do this manually
324#if (nproc>1)
325 for(unsigned short j=0;j<nc*ndirac;j++)
326 ComplexConvert(X1_f+j*kvol,X1+j*kvolHalo,kvol,true,1);
327#else
328 ComplexConvert(X1_f,X1,kferm2,true,1);
329#endif
330 ComplexConvert(r_f,r,kferm2,true,1);
331 //And clover in double
332 if(c_sw){
333 ComplexConvert(clover_f[0],clover[0],6*kvol,false,1);
334 ComplexConvert(clover_f[1],clover[1],6*kvol,false,1);
335 }
336#ifdef USE_GPU
337 //Ensure conversion is done
339 //Needs to be strided
340#if (nproc>1)
341 for(unsigned int j=0;j<nc*ndirac;j++)
342 cudaMemcpyAsync(p_f+j*kvolHalo, X1_f+j*kvol, kvol*sizeof(Complex_f),cudaMemcpyDefault,streams[j]);
343#else
344 cudaMemcpyAsync(p_f, X1_f, kferm2*sizeof(Complex_f),cudaMemcpyDefault,streams[0]);
345#endif
346 cudaMemcpyAsync(b0,r,kferm2*sizeof(Complex),cudaMemcpyDefault,streams[1]);
348#else
349#pragma omp parallel for simd aligned(X1_f,r_f,X1,r:AVX)
350 for(unsigned int j=0;j<nc*ndirac;j++)
351 memcpy(p_f+j*kvolHalo, X1_f+j*kvol, kvol*sizeof(Complex_f));
352 memcpy(b0,r,kferm2*sizeof(Complex));
353#endif
354
355 alignas(16) double betan=1;double beta_max=FLT_MAX; bool do_dp=true;
356 for(*itercg=0; *itercg<niterc; (*itercg)++){
357 if(do_dp){
358#ifdef _DEBUGCG
359 if(!rank)
360 printf("Going to double precision on iteration %d. betan %e\talpha %e.\n",
361 *itercg,betan,creal(alpha));
362#elifdef _DEBUG
363 if(!rank)
364 printf("\nGoing to double precision on iteration %d. betan %e\talpha %e.\n",
365 *itercg,betan,creal(alpha));
366#endif
367 ComplexConvert(r_f,r,kferm2,false,1);
368 ComplexConvert(p_f,p,kvol,false,nc*ndirac);
369 //Update the residue vector, but not on the first call.
370 if(*itercg){
371#ifdef USE_GPU
372 //TODO: Check for multi-gpu. I fear this will get messy
373 cuMixed_Sumto((double *)X1,(float *)X1_f,2*kferm2,dimGrid,dimBlock);
374 //Bring everything into double precision
375 //Reset X1_f to zero.
376#else
377 //Update the residue vector, but not on the first call.
378#pragma omp parallel for simd collapse(2) aligned(X1,X1_f:AVX)
379 for(unsigned short j=0;j<nc*ndirac;j++)
380 for(unsigned int i=0;i<kvol;i++){
381 X1[i+j*kvolHalo]+=(Complex)X1_f[i+j*kvol];
382 }
383#endif
384 //Recompute residue for double precision update instead of promoting erronous single precision
385 Hdslash(x1,X1,ud,iu,id,gamval,gamin,dk,akappa);
386 if(c_sw)
387 HbyClover(x1,X1,clover,sigval,akappa,sigin,false);
388 Hdslashd(x2,x1,ud,iu,id,gamval,gamin,dk,akappa);
389 if(c_sw)
390 HbyClover(x2,x1,clover,sigval,akappa,sigin,true);
391#ifdef USE_GPU
393 cudaMemcpy(r,b0,kferm2*sizeof(Complex),cudaMemcpyDefault);
394 alignas(16) Complex m_one=-1.0;
395 cublasZaxpy(cublas_handle,kferm2,(cuDoubleComplex *)&m_one,(cuDoubleComplex *)x2,1,(cuDoubleComplex *)r,1);
396 if(fac_f!=0){
397 alignas(16) Complex m_fac=-(Complex)fac_f;
398#if(nproc>1)
399 for(unsigned short j=0;j<nc*ndirac;j++)
400 cublasZaxpy(cublas_handle,kvol,(cuDoubleComplex *)&m_fac,(cuDoubleComplex *)X1+j*kvolHalo,1,(cuDoubleComplex *)r+j*kvol,1);
401#else
402 cublasZaxpy(cublas_handle,kferm2,(cuDoubleComplex *)&m_fac,(cuDoubleComplex *)X1,1,(cuDoubleComplex *)r,1);
403#endif
404 }
405#else
406 const double fac_d=crealf(fac_f);
407#pragma omp parallel for simd collapse(2)
408 for(unsigned short j=0;j<nc*ndirac;j++)
409 for(unsigned int i=0;i<kvol;i++)
410 r[i+j*kvol]=b0[i+j*kvol]-x2[i+j*kvol]-fac_d*X1[i+j*kvolHalo];
411#endif
412 }
414 //No need to synchronise here. The memcpy in Hdslash is blocking
415 Hdslash(x1,p,ud,iu,id,gamval,gamin,dk,akappa);
416 //Clover contribution
417 if(c_sw)
418 HbyClover(x1,p,clover,sigval,akappa,sigin,false);
419 Hdslashd(x2,x1,ud,iu,id,gamval,gamin,dk,akappa);
420 //Clover contribution
421 if(c_sw)
422 HbyClover(x2,x1,clover,sigval,akappa,sigin,true);
423#ifdef USE_GPU
425#endif
426 if(fac_f!=0){
427 alignas(16) const Complex fac=(Complex)fac_f;
428#ifdef USE_GPU
429 //Multiple ranks means we need striding
430#if (nproc>1)
431 for(unsigned short j=0;j<nc*ndirac;j++)
432 cublasZaxpy(cublas_handle,kvol,(cuDoubleComplex *)&fac,(cuDoubleComplex *)p+j*kvolHalo,1,(cuDoubleComplex *)x2+j*kvol,1);
433#else
434 //Single GPU, no halos, so make it one call to speed things up
435 cublasZaxpy(cublas_handle,kferm2,(cuDoubleComplex *)&fac,(cuDoubleComplex *)p,1,(cuDoubleComplex *)x2,1);
436#endif
437#elif defined USE_BLAS
438 for(unsigned short j=0;j<nc*ndirac;j++)
439 cblas_zaxpy(kvol, &fac, p+j*kvolHalo, 1, x2+j*kvol, 1);
440#else
441#pragma omp parallel for simd collapse(2) aligned(p,x2:AVX)
442 for(unsigned short j=0;j<nc*ndirac;j++)
443 for(unsigned int i=0; i<kvol; i++)
444 x2[i+j*kvol]+=fac*p[i+j*kvolHalo];
445#endif
446 }
447
449 if(*itercg){
450 alpha=0;
451#ifdef USE_GPU
452#if (nproc>1)
453 for(unsigned short j=0;j<nc*ndirac;j++){
454 Complex alpha_t=0;
455 cublasZdotc(cublas_handle,kvol,(cuDoubleComplex *)p+j*kvolHalo,1,(cuDoubleComplex *)x2+j*kvol,1,(cuDoubleComplex *)&alpha_t);
456 alpha+=alpha_t;
457 }
458#else
459 cublasZdotc(cublas_handle,kferm2,(cuDoubleComplex *)p,1,(cuDoubleComplex *)x2,1,(cuDoubleComplex *)&alpha);
460#endif
461#elif defined USE_BLAS
462 for(unsigned short j=0;j<nc*ndirac;j++){
463 Complex alpha_t=0;
464 cblas_zdotc_sub(kvol, p+j*kvolHalo, 1, x2+j*kvol, 1, &alpha_t);
465 alpha+=creal(alpha_t);
466 }
467#else
468#pragma omp parallel for simd collapse(2) aligned(p,x2:AVX) reduction(+:alpha)
469 for(unsigned short j=0;j<nc*ndirac;j++)
470 for(unsigned int i=0; i<kvol; i++)
471 alpha+=conj(p[i+j*kvolHalo])*x2[i+j*kvol];
472#endif
473 //For now I'll cast it into a float for the reduction. Each rank only sends and writes
474 //to the real part so this is fine
475#if (nproc>1)
476 Par_dsum((double *)&alpha);
477#endif
479 alpha=alphan/creal(alpha);
481#ifdef USE_GPU
482#if (nproc>1)
483 for(unsigned short j=0;j<nc*ndirac;j++)
484 cublasZaxpy(cublas_handle,kvol,(cuDoubleComplex *)&alpha,(cuDoubleComplex *)p+j*kvolHalo,1,(cuDoubleComplex *)X1+j*kvolHalo,1);
485#else
486 cublasZaxpy(cublas_handle,kferm2,(cuDoubleComplex *)&alpha,(cuDoubleComplex *)p,1,(cuDoubleComplex *)X1,1);
487#endif
488#elif defined USE_BLAS
489 for(unsigned short j=0;j<nc*ndirac;j++)
490 cblas_zaxpy(kvol, &alpha, p+j*kvolHalo, 1, X1+j*kvolHalo, 1);
491#else
492#pragma omp parallel for simd collapse(2) aligned(p,X1:AVX)
493 for(unsigned short j=0;j<nc*ndirac;j++)
494 for(unsigned int i=0; i<kvol; i++)
495 X1[i+j*kvolHalo]+=alpha*p[i+j*kvolHalo];
496#endif
497 }
498
499#ifdef USE_GPU
500 alignas(16) Complex alpha_m=(Complex)(-alpha);
501 cublasZaxpy(cublas_handle, kferm2,(cuDoubleComplex *)&alpha_m,(cuDoubleComplex *)x2,1,(cuDoubleComplex *)r,1);
502 alignas(16) double betan_d;
503 cublasDznrm2(cublas_handle,kferm2,(cuDoubleComplex *)r,1,&betan_d);
504 betan=betan_d*betan_d;
505#elif defined USE_BLAS
506 const Complex alpha_m = (Complex)(-alpha);
507 cblas_zaxpy(kferm2, &alpha_m, x2, 1, r, 1);
508 //Undo the negation for the BLAS routine
509 double betan_d = cblas_dznrm2(kferm2, r,1);
510 //Gotta square it to "undo" the norm
511 betan = betan_d*betan_d;
512#else
513 betan=0;
514#pragma omp parallel for simd aligned(r_f,x2_f:AVX) reduction(+:betan)
515 for(unsigned int i=0; i<kferm2; i++){
516 r[i]-=alpha*x2[i];
517 betan += conj(r[i])*r[i];
518 }
519 alignas(16) double betan_d=sqrt(betan);
520#endif
521 //And... reduce.
522#if (nproc>1)
523 Par_dsum(&betan);
524#endif
525 betan_d=sqrt(betan);
526 //Update beta_max. Mandatory for double precision.
527 beta_max=betan_d;
528#ifdef _DEBUG
529 if(!rank) printf("DP Iter(CG)=%i\tbeta_n=%e\talpha=%e\n", *itercg, betan, creal(alpha));
530 fflush(stdout);
531#endif
532 alignas(16) const Complex beta = (*itercg) ? betan/betad : 0;
533 betad=betan; alphan=betan;
534#ifdef USE_GPU
535 cudaMemsetAsync(X1_f,0,kferm2*sizeof(Complex_f),streams[0]);
536 alpha_m=1;
537 //Strided multi-gpu
538#if (nproc>1)
539 for(unsigned short j=0;j<nc*ndirac;j++){
540 cublasZdscal(cublas_handle,kvol,(double *)&beta,(cuDoubleComplex *)p+j*kvolHalo,1);
541 cublasZaxpy(cublas_handle,kvol,(cuDoubleComplex *)&alpha_m,(cuDoubleComplex *)r+j*kvol,1,(cuDoubleComplex *)p+j*kvolHalo,1);
542 }
543 //And single GPU
544#else
545 cublasZdscal(cublas_handle,kferm2,(double *)&beta,(cuDoubleComplex *)p,1);
546 cublasZaxpy(cublas_handle,kferm2,(cuDoubleComplex *)&alpha_m,(cuDoubleComplex *)r,1,(cuDoubleComplex *)p,1);
547#endif
548#elif (defined __USE_MKL__||defined OPENBLAS||defined AMD_BLAS)
549 memset(X1_f,0,kferm2*sizeof(Complex_f));
550 const Complex a = 1.0;
551 //There is cblas_?axpby in the MKL and AMD though, set a = 1 and b = \beta.
552 //If we get a small enough \beta_n before hitting the iteration cap we break
553 for(unsigned short j=0;j<nc*ndirac;j++)
554 cblas_zaxpby(kvol, &a, r+j*kvol, 1, &beta, p+j*kvolHalo, 1);
555#elifdef USE_BLAS
556 memset(X1_f,0,kferm2*sizeof(Complex_f));
557 const Complex a = 1.0;
558 for(unsigned short j=0;j<nc*ndirac;j++){
559 cblas_zscal(kvol,&beta,p+j*kvolHalo,1);
560 cblas_zaxpy(kvol,&a,r+j*kvol,1,p+j*kvolHalo,1);
561 }
562#else
563 memset(X1_f,0,kferm2*sizeof(Complex_f));
564#pragma omp parallel for simd collapse(2) aligned(r,p:AVX)
565 for(unsigned short j=0;j<nc*ndirac;j++)
566 for(unsigned int i=0; i<kvol; i++)
567 p[i+j*kvolHalo]=r[i+j*kvol]+beta*p[i+j*kvolHalo];
568#endif
569 ComplexConvert(p_f,p,kvol,true,nc*ndirac);
570 ComplexConvert(r_f,r,kferm2,true,1);
571#ifdef _DEBUGCG
572 if(!rank) printf("Double precision. Iter(CG)=%i\tbeta_n=%e\talpha=%e\n", *itercg, betan, creal(alpha));
573 fflush(stdout);
574#endif
575 if(betan<resid){
576 (*itercg)++;
577#ifdef _DEBUG
578 if(!rank) printf("\nIter(CG)=%i\tResidue: %e\tTolerance: %e\n", *itercg, betan, resid);
579#endif
580 ret_val=0; break;
581 }
582 else
583 do_dp=false;
584 }
585 else{
587 //No need to synchronise here. The memcpy in Hdslash is blocking
588 Hdslash_f(x1_f,p_f,ut,iu,id,gamval_f,gamin,dk_f,akappa);
589 //Clover contribution
590 if(c_sw)
591 HbyClover_f(x1_f,p_f,clover_f,sigval_f,akappa,sigin,false);
592 Hdslashd_f(x2_f,x1_f,ut,iu,id,gamval_f,gamin,dk_f,akappa);
593 //Clover contribution
594 if(c_sw)
595 HbyClover_f(x2_f,x1_f,clover_f,sigval_f,akappa,sigin,true);
596#ifdef USE_GPU
598#endif
600 //No point adding zero a couple of hundred times if the diquark source is zero
601 if(fac_f!=0){
602#ifdef USE_GPU
603 //Strided multi-gpu
604#if (nproc>1)
605 for(unsigned short j=0;j<nc*ndirac;j++)
606 cublasCaxpy(cublas_handle,kvol,(cuComplex *)&fac_f,(cuComplex *)p_f+j*kvolHalo,1,(cuComplex *)x2_f+j*kvol,1);
607 //Single GPU
608#else
609 cublasCaxpy(cublas_handle,kferm2,(cuComplex *)&fac_f,(cuComplex *)p_f,1,(cuComplex *)x2_f,1);
610#endif
611#elif defined USE_BLAS
612 for(unsigned short j=0;j<nc*ndirac;j++)
613 cblas_caxpy(kvol, &fac_f, p_f+j*kvolHalo, 1, x2_f+j*kvol, 1);
614#else
615#pragma omp parallel for simd collapse(2) aligned(p_f,x2_f:AVX)
616 for(unsigned short j=0;j<nc*ndirac;j++)
617 for(unsigned int i=0; i<kvol; i++)
618 x2_f[i+j*kvol]+=fac_f*p_f[i+j*kvolHalo];
619#endif
620 }
623 if(*itercg){
624 alphad=0;
625#ifdef USE_GPU
626#if (nproc>1)
627 for(unsigned short j=0;j<nc*ndirac;j++){
628 Complex alpha_t=0;
629 cublasCdotc(cublas_handle,kvol,(cuComplex *)p_f+j*kvolHalo,1,(cuComplex *)x2_f+j*kvol,1,(cuComplex *)&alpha_t);
630 alphad+=alpha_t;
631 }
632#else
633 cublasCdotc(cublas_handle,kferm2,(cuComplex *)p_f,1,(cuComplex *)x2_f,1,(cuComplex *)&alphad);
634#endif
635#elif defined USE_BLAS
636 for(unsigned short j=0;j<nc*ndirac;j++){
637 Complex_f alpha_t=0;
638 cblas_cdotc_sub(kvol, p_f+j*kvolHalo, 1, x2_f+j*kvol, 1, &alpha_t);
639 alphad+=creal(alpha_t);
640 }
641#else
642#pragma omp parallel for simd aligned(p_f,x2_f:AVX) reduction(alphad:+)
643 for(unsigned short j=0;j<nc*ndirac;j++)
644 for(unsigned int i=0; i<kvol; i++)
645 alphad+=conj(p_f[i+j*kvolHalo])*x2_f[i+j*kvol];
646#endif
647 //For now I'll cast it into a float for the reduction. Each rank only sends and writes
648 //to the real part so this is fine
649#if (nproc>1)
650 Par_fsum((float *)&alphad);
651#endif
653 alpha=alphan/creal(alphad);
655#ifdef USE_GPU
656 alignas(8) Complex_f alpha_f = (Complex_f)alpha;
657#if (nproc>1)
658 for(unsigned short j=0;j<nc*ndirac;j++)
659 cublasCaxpy(cublas_handle,kvol,(cuComplex *)&alpha_f,(cuComplex *)p_f+j*kvolHalo,1,(cuComplex *)X1_f+j*kvol,1);
660#else
661 cublasCaxpy(cublas_handle,kferm2,(cuComplex *)&alpha_f,(cuComplex *)p_f,1,(cuComplex *)X1_f,1);
662#endif
663#elif defined USE_BLAS
664 Complex_f alpha_f = (Complex_f)alpha;
665 for(unsigned short j=0;j<nc*ndirac;j++)
666 cblas_caxpy(kvol, &alpha_f, p_f+j*kvolHalo, 1, X1_f+j*kvol, 1);
667#else
668#pragma omp parallel for simd collapse(2) aligned(X1_f,p_f:AVX)
669 for(unsigned short j=0;j<nc*ndirac;j++)
670 for(unsigned int i=0; i<kvol; i++)
671 X1_f[i+j*kvol]+=alpha*p_f[i+j*kvolHalo];
672#endif
673 }
675 // And no Halos here so nice and easy
676#ifdef USE_GPU
677 alignas(8) __managed__ Complex_f alpha_m=(Complex_f)(-alpha);
678 cublasCaxpy(cublas_handle, kferm2,(cuComplex *)&alpha_m,(cuComplex *)x2_f,1,(cuComplex *)r_f,1);
679 alignas(8) float betan_f;
680 cublasScnrm2(cublas_handle,kferm2,(cuComplex *)r_f,1,&betan_f);
681 betan = betan_f*betan_f;
682#elif defined USE_BLAS
683 const Complex_f alpha_m = (Complex_f)(-alpha);
684 cblas_caxpy(kferm2, &alpha_m, x2_f, 1, r_f, 1);
685 //Undo the negation for the BLAS routine
686 float betan_f = cblas_scnrm2(kferm2, r_f,1);
687 //Gotta square it to "undo" the norm
688 betan = betan_f*betan_f;
689#else
690 betan=0;
691#pragma omp parallel for simd aligned(r_f,x2_f:AVX) reduction(+:betan)
692 for(unsigned int i=0; i<kferm2; i++){
693 r_f[i]-=alpha*x2_f[i];
694 betan += conj(r_f[i])*r_f[i];
695 }
696 alignas(8) float betan_f=sqrt(betan);
697#endif
698 //And... reduce.
699#if (nproc>1)
700 Par_dsum(&betan);
701#endif
702 betan_f=sqrt(betan);
703 //Update beta_max if needed. On paper congrad is monotonically decreasing
704 beta_max = (betan_f>beta_max) ?betan_f : beta_max;
705
706#ifdef _DEBUG
707 if(!rank) printf("Iter(CG)=%i\tbeta_n=%e\talpha=%e%s", *itercg, betan, creal(alpha),endline);
708 fflush(stdout);
709#endif
710 if(betan_f<beta_max*d_prec){
711#ifdef _DEBUG
712 if(!rank)
713 printf("\nResidue %e is less than %e times %e.%s",betan_f,d_prec,beta_max,endline);
714#endif
715 do_dp=true;
716 }
717 else if(betan<resid){
718#ifdef _DEBUG
719 if(!rank)
720 printf("\nBetan %e is less than target residue %e.\n",betan,resid);
721#endif
722 do_dp=true;
723 //break;
724 }
725 else if(*itercg==niterc-1){
726 if(!rank) fprintf(stderr, "\nWarning %i in %s: Exceeded iteration limit %i beta_n=%e\n",\
727 ITERLIM, funcname, *itercg, betan);
728 ret_val=ITERLIM; break;
729 }
730 //Here we evaluate beta=(r_{k+1}.r_{k+1})/(r_k.r_k) and then shuffle our indices down the line.
731 //On the first iteration we define beta to be zero.
732 //Note that beta below is not the global beta and scoping is used to avoid conflict between them
733 Complex beta = (*itercg) ? betan/betad : 0;
734 betad=betan; alphan=betan;
735 //BLAS for p=r+\betap doesn't exist in standard BLAS. This is NOT an axpy case as we're multiplying y by
736 //\beta instead of x.
737#ifdef USE_GPU
738 alignas(8) Complex_f beta_f=(Complex_f)beta;
739 alpha_m = 1.0;
740#if (nproc>1)
741 for(unsigned short j=0;j<nc*ndirac;j++){
742 cublasCscal(cublas_handle,kvol,(cuComplex *)&beta_f,(cuComplex *)p_f+j*kvolHalo,1);
743 cublasCaxpy(cublas_handle,kvol,(cuComplex *)&alpha_m,(cuComplex *)r_f+j*kvolHalo,1,(cuComplex *)p_f+j*kvolHalo,1);
744 }
745#else
746 cublasCscal(cublas_handle,kferm2,(cuComplex *)&beta_f,(cuComplex *)p_f,1);
747 cublasCaxpy(cublas_handle,kferm2,(cuComplex *)&alpha_m,(cuComplex *)r_f,1,(cuComplex *)p_f,1);
748#endif
749#elif (defined __USE_MKL__||defined OPENBLAS||defined AMD_BLAS)
750 Complex_f a = 1.0;
751 Complex_f beta_f=(Complex_f)beta;
752 //There is cblas_?axpby in the MKL and AMD though, set a = 1 and b = \beta.
753 //If we get a small enough \beta_n before hitting the iteration cap we break
754 for(unsigned short j=0;j<nc*ndirac;j++)
755 cblas_caxpby(kvol, &a, r_f+j*kvol, 1, &beta_f, p_f+j*kvolHalo, 1);
756#elif defined USE_BLAS
757 Complex_f beta_f=(Complex_f)beta;
758 Complex_f a = 1.0;
759 for(unsigned short j=0;j<nc*ndirac;j++){
760 cblas_cscal(kvol,&beta_f,p_f+j*kvolHalo,1);
761 cblas_caxpy(kvol,&a,r_f+j*kvol,1,p_f+j*kvolHalo,1);
762 }
763#else
764#pragma omp parallel for simd collapse(2) aligned(p_f,r_f:AVX)
765 for(unsigned short j=0;j<nc*ndirac;j++)
766 for(unsigned int i=0; i<kvol; i++)
767 p_f[i+j*kvolHalo]=r_f[i+j*kvol]+beta*p_f[i+j*kvolHalo];
768#endif
769 }
770 }
771 Q_free_f(&p_f,&x1_f,&x2_f,&r_f,&X1_f);
772 Q_free(&p,&x1,&x2,clover);
773#ifdef USE_GPU
774 cudaFreeAsync(b0,streams[1]);
775#else
776 free(b0);
777#endif
778 return ret_val;
779}
void HbyClover(Complex *phi, Complex *r, Complex *clover[2], Complex *sigval, const float akappa, unsigned short *sigin, bool dag)
Clover analogue of the Dslash operation. This version acts on all flavours similar to Dslash and Dsla...
Definition clover.c:287
void HbyClover_f(Complex_f *phi, Complex_f *r, Complex_f *clover[2], Complex_f *sigval, const float akappa, unsigned short *sigin, bool dag)
Clover analogue of the Dslash operation. This version acts on all flavours similar to Dslash and Dsla...
Definition clover.c:373
int Hdslashd_f(Complex_f *phi, Complex_f *r, Complex_f *ut[nc], unsigned int *iu, unsigned int *id, Complex_f gamval[20], const unsigned short gamin[16], float *dk[nc], float akappa)
Evaluates in single precision.
Definition matrices.c:784
int Hdslashd(Complex *phi, Complex *r, Complex *ut[nc], unsigned int *iu, unsigned int *id, Complex gamval[20], const unsigned short gamin[16], double *dk[nc], float akappa)
Evaluates in double precision.
Definition matrices.c:346
int Hdslash(Complex *phi, Complex *r, Complex *ut[nc], unsigned int *iu, unsigned int *id, Complex gamval[20], const unsigned short gamin[16], double *dk[nc], float akappa)
Evaluates in double precision.
Definition matrices.c:250
int Hdslash_f(Complex_f *phi, Complex_f *r, Complex_f *ut[nc], unsigned int *iu, unsigned int *id, Complex_f gamval[20], const unsigned short gamin[16], float *dk[nc], float akappa)
Evaluates in single precision.
Definition matrices.c:686
void Q_allocate_f(Complex_f **p_f, Complex_f **x1_f, Complex_f **x2_f, Complex_f **r_f, Complex_f **X1_f)
Allocates memory needed for Congradq. Just to improve readability Note that since C does not modify i...
Definition congrad.c:23
void Q_allocate(Complex **p, Complex **x1, Complex **x2, Complex *clover[2])
Allocates double precision memory needed for Congradq. Just to improve readability Note that since C ...
Definition congrad.c:64
void Q_free(Complex **p, Complex **x1, Complex **x2, Complex *clover[2])
Frees double precision memory needed for Congradq. Just to improve readability Note that since C does...
Definition congrad.c:211
void Q_free_f(Complex_f **p_f, Complex_f **x1_f, Complex_f **x2_f, Complex_f **r_f, Complex_f **X1_f)
Frees memory needed for Congradq. Just to improve readability Note that since C does not modify it's ...
Definition congrad.c:181
#define ndirac
Dirac indices.
Definition sizes.h:190
#define kferm2
sublattice size including Dirac indices
Definition sizes.h:201

References AVX, Complex, Complex_f, ComplexConvert(), Congradq(), conj(), creal, cudaDeviceSynchronise, cuMixed_Sumto(), dimBlock, dimGrid, HbyClover(), HbyClover_f(), Hdslash(), Hdslash_f(), Hdslashd(), Hdslashd_f(), ITERLIM, kferm2, kvol, kvolHalo, nc, ndirac, niterc, Par_dsum(), Par_fsum(), Q_allocate(), Q_allocate_f(), Q_free(), Q_free_f(), rank, and streams.

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

◆ cuForce()

void cuForce ( double * dSdpi,
Complex_f * ut[2],
Complex_f * X1,
Complex_f * X2,
Complex_f gamval[20],
float * dk[2],
unsigned int * iu,
const unsigned short gamin[16],
float akappa,
dim3 dimGrid,
dim3 dimBlock )

Calculates the force \(\frac{dS}{d\pi}\) at each intermediate time.

Parameters
[in,out]dSdpiThe force
[in]utGauge fields
[in]X1Inverted field
[in]X2\(MX_1\)
[in]gamvalDouble/float precision gamma matrices rescaled by \(\kappa\)
[in]gaminGamma indices
[in]iuLattice indices
[in]dk\(e^{-\mu}\) and \(e^\mu\)
[in]akappaHopping parameter
[in]dimGrid,dimBlockCUDA grid/block size
Postcondition
Fermion force added onto dSdpi

Definition at line 392 of file cuforce.cu.

394 {
395 const char *funcname = "Force";
396 //X1=(M†M)^{1} Phi
397 // Transpose_z(X1,ndirac*nc,kvol); Transpose_z(X2,ndirac*nc,kvol);
399#pragma unroll
400 for(unsigned short mu=0;mu<3;mu++){
401 Kernels::cuForce_s<<<dimGrid,dimBlock,0,streams[mu]>>>(dSdpi,ut[0],ut[1],X1,X2,gamval,iu,gamin,akappa,mu);
402 }
403 //Set stream for time direction
404 unsigned short mu=3;
405 Kernels::cuForce_t<<<dimGrid,dimBlock,0,streams[mu]>>>(dSdpi,ut[0],ut[1],X1,X2,gamval,dk[0],dk[1],iu,gamin);
407}
__global__ void cuForce_t(double *dSdpi, const Complex_f *u11t, const Complex_f *u12t, const Complex_f *X1, const Complex_f *X2, const __grid_constant__ Complex_f gamval[20], const float *dk4m, const float *dk4p, const unsigned int *iu, const __grid_constant__ unsigned short gamin[16])
Calculates the force at each intermediate time.
Definition cuforce.cu:255
__global__ void cuForce_s(double *dSdpi, const Complex_f *u11t, const Complex_f *u12t, const Complex_f *X1, const Complex_f *X2, const __grid_constant__ Complex_f gamval[20], const unsigned int *iu, const __grid_constant__ unsigned short gamin[16], const __grid_constant__ float akappa, const __grid_constant__ unsigned short mu)
Calculates the force at each intermediate time.
Definition cuforce.cu:152

References Complex_f, cudaDeviceSynchronise, cuForce(), Kernels::cuForce_s(), Kernels::cuForce_t(), dimBlock, and dimGrid.

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

◆ cuForce_s()

__global__ void Kernels::cuForce_s ( double * dSdpi,
const Complex_f * u11t,
const Complex_f * u12t,
const Complex_f * X1,
const Complex_f * X2,
const __grid_constant__ Complex_f gamval[20],
const unsigned int * iu,
const __grid_constant__ unsigned short gamin[16],
const __grid_constant__ float akappa,
const __grid_constant__ unsigned short mu )

Calculates the force \(\frac{dS}{d\pi}\) at each intermediate time.

Parameters
[in,out]dSdpiThe force
[in]u11t,u12tFloat precision colour fields
[in]X1Inverted field
[in]X2\(MX_1\)
[in]gamvalGamma matrices rescaled by \(\kappa\)
[in]iuLattice indices
[in]gaminGamma indices
[in]akappaHopping parameter
[in]muForce direction
Postcondition
Force added to dSdpi

Definition at line 152 of file cuforce.cu.

156 {
157 const unsigned int gsize = gridDim.x*gridDim.y*gridDim.z;
158 const unsigned int bsize = blockDim.x*blockDim.y*blockDim.z;
159 volatile const unsigned int blockId = blockIdx.x+ blockIdx.y * gridDim.x+ gridDim.x * gridDim.y * blockIdx.z;
160 volatile const unsigned int bthreadId= (threadIdx.z * blockDim.y+ threadIdx.y)* blockDim.x+ threadIdx.x;
161 const unsigned int gthreadId= blockId * bsize+bthreadId;
162
163 for(unsigned int i=gthreadId;i<kvol;i+=gsize*bsize){
164 unsigned int ind=i+kvolHalo*mu;
165 const Complex_f u11s=u11t[ind]; const Complex_f u12s=u12t[ind];
166 const unsigned int uid = iu[i+kvol*mu];
167 //Similarly to Hdslash we always see idirac*nc so we do that here too.
168 float dSdpis[3]={0,0,0};
169 for(unsigned short idirac=0;idirac<nc*ndirac;idirac+=nc){
170 Complex_f X1s[nc]; Complex_f X1su[nc];
171 Complex_f X2s[nc]; Complex_f X2su[nc];
172
173 ind=kvolHalo*idirac;
174 X1s[0]=X1[i+ind]; X1su[0]=X1[uid+ind];
175 X2s[0]=2*X2[i+ind]; X2su[0]=2*X2[uid+ind];
176 ind=kvolHalo*(idirac+1);
177 X1s[1]=X1[i+ind];X1su[1]=X1[uid+ind];
178 X2s[1]=2*X2[i+ind]; X2su[1]=2*X2[uid+ind];
179 // Need to be double to avoid accumulation errors
180 //Careful!! cant use ind here as dSdpi has no halo!
181 // dSdpis[0]=dSdpi[i+kvol*mu];
182 //Multiplying by i and taking the real component is the same as taking the negative imaginary component
183 //The positions of u11 and u12 might look a bit funky here. That's just because we've multiplied by the
184 //generators by hand
185 dSdpis[0]+=-akappa*(
186 conj(X1s[0])*(-conj(u12s)*X2su[0]+conj(u11s)*X2su[1])
187 +conj(X1s[1])*(u11s*X2su[0]+u12s*X2su[1])
188 +conj(X1su[0])*(u12s*X2s[0]-conj(u11s)*X2s[1])
189 +conj(X1su[1])*(-u11s*X2s[0]-conj(u12s)*X2s[1])).imag();
190
191 // dSdpis[1]=dSdpi[i+kvol*(ndim+mu)];
192 dSdpis[1]+=akappa*(
193 (conj(X1s[0])*(-conj(u12s)*X2su[0]+conj(u11s)*X2su[1])
194 +conj(X1s[1])*(-u11s*X2su[0]-u12s*X2su[1])
195 +conj(X1su[0])*(-u12s*X2s[0]-conj(u11s)*X2s[1])
196 +conj(X1su[1])*(u11s*X2s[0]-conj(u12s)*X2s[1]))).real();
197
198 // dSdpis[2]=dSdpi[i+kvol*(2*ndim+mu)];
199 dSdpis[2]+=-akappa*(
200 conj(X1s[0])*(u11s *X2su[0]+u12s *X2su[1])
201 +conj(X1s[1])*(conj(u12s)*X2su[0]-conj(u11s)*X2su[1])
202 +conj(X1su[0])*(-conj(u11s)*X2s[0]-u12s *X2s[1])
203 +conj(X1su[1])*(-conj(u12s)*X2s[0]+u11s *X2s[1])).imag();
204
205 const unsigned short gindex=mu*ndirac+(idirac>>1);
206 const Complex_f gamval_c=gamval[gindex];
207 //Rescaling gind by nc
208 const unsigned short gind = gamin[gindex]<<1;
209 ind=kvolHalo*gind;
210 X2s[0]=2*X2[i+ind]; X2su[0]=2*X2[uid+ind];
211 ind=kvolHalo*(gind+1);
212 X2s[1]=2*X2[i+ind]; X2su[1]=2*X2[uid+ind];
213 //If you are asked to rederive the force from Montvay and Munster you'll notice that it should be kappa*gamma
214 //but below is only gamma. We rescaled gamma by kappa already when we defined it so that's where it has gone
215 dSdpis[0]+=-(gamval_c*
216 (conj(X1s[0])* (-conj(u12s)*X2su[0]+conj(u11s)*X2su[1])
217 +conj(X1s[1])* (u11s *X2su[0]+u12s *X2su[1])
218 +conj(X1su[0])* (-u12s *X2s[0] +conj(u11s)*X2s[1])
219 +conj(X1su[1])*(u11s *X2s[0] +conj(u12s)*X2s[1]))).imag();
220
221 dSdpis[1]+=(gamval_c*
222 (conj(X1s[0])* (-conj(u12s)*X2su[0] +conj(u11s)*X2su[1])
223 +conj(X1s[1])*(-u11s *X2su[0]-u12s *X2su[1])
224 +conj(X1su[0])* (u12s *X2s[0]+conj(u11s)*X2s[1])
225 +conj(X1su[1])* (-u11s *X2s[0]+conj(u12s)*X2s[1]))).real();
226
227 dSdpis[2]+=-(gamval_c*
228 (conj(X1s[0])*(u11s *X2su[0]+u12s *X2su[1])
229 +conj(X1s[1])*(conj(u12s)*X2su[0]-conj(u11s)*X2su[1])
230 +conj(X1su[0])*(conj(u11s)*X2s[0]+u12s *X2s[1])
231 +conj(X1su[1])*(conj(u12s)*X2s[0]-u11s *X2s[1]))).imag();
232 }
233 dSdpi[i+kvol*mu]+=dSdpis[0];
234 dSdpi[i+kvol*(ndim+mu)]+=dSdpis[1];
235 dSdpi[i+kvol*(2*ndim+mu)]+=dSdpis[2];
236 }
237 }
#define ndim
Dimensions.
Definition sizes.h:192

References __BSIZE__, Complex_f, conj(), cuForce_s(), kvol, kvolHalo, nc, ndim, and ndirac.

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

◆ cuForce_t()

__global__ void Kernels::cuForce_t ( double * dSdpi,
const Complex_f * u11t,
const Complex_f * u12t,
const Complex_f * X1,
const Complex_f * X2,
const __grid_constant__ Complex_f gamval[20],
const float * dk4m,
const float * dk4p,
const unsigned int * iu,
const __grid_constant__ unsigned short gamin[16] )

Calculates the force \(\frac{dS}{d\pi}\) at each intermediate time.

Parameters
[in,out]dSdpiThe force
[in]u11t,u12tFloat precision colour fields
[in]X1Inverted field
[in]X2\(MX_1\)
[in]gamvalGamma matrices rescaled by \(\kappa\)
[in]dk4m,dk4p\(e^{-\mu}\) and \(e^\mu\)
[in]iuLattice indices
[in]gaminGamma indices
Postcondition
Force added to dSdpi
Note
cuForce_s uses akappa everywhere. With the boundary conditions and chemical potential in the time direction cuForce_t needs to access those values from memory, reducing performance

Definition at line 255 of file cuforce.cu.

259 {
260 const unsigned int gsize = gridDim.x*gridDim.y*gridDim.z;
261 const unsigned int bsize = blockDim.x*blockDim.y*blockDim.z;
262 volatile const unsigned int blockId = blockIdx.x+ blockIdx.y * gridDim.x+ gridDim.x * gridDim.y * blockIdx.z;
263 volatile const unsigned int bthreadId= (threadIdx.z * blockDim.y+ threadIdx.y)* blockDim.x+ threadIdx.x;
264 const unsigned int gthreadId= blockId * bsize+bthreadId;
265
266 const unsigned short mu=3;
267 for(unsigned int i=gthreadId;i<kvol;i+=gsize*bsize){
268 unsigned int ind=i+kvolHalo*mu;
269 const Complex_f u11s=u11t[ind]; const Complex_f u12s=u12t[ind];
270 const float dk4ms=dk4m[i]; const float dk4ps=dk4p[i];
271 //Up indices
272 const unsigned int uid = iu[i+kvol*mu];
273 //Similarly to Hdslash we always see idirac*nc so we do that here too.
274 float dSdpis[3]={0,0,0};
275 for(unsigned short idirac=0;idirac<ndirac*nc;idirac+=nc){
276 Complex_f X1s[nc]; Complex_f X1su[nc];
277 Complex_f X2s[nc]; Complex_f X2su[nc];
278
279 ind=kvolHalo*idirac;
280 X1s[0]=X1[i+ind]; X1su[0]=X1[uid+ind];
281 X2s[0]=2*X2[i+ind]; X2su[0]=2*X2[uid+ind];
282 ind=kvolHalo*(idirac+1);
283 X1s[1]=X1[i+ind];X1su[1]=X1[uid+ind];
284 X2s[1]=2*X2[i+ind];X2su[1]=2*X2[uid+ind];
285 // Need to be double to avoid accumulation errors
286 // dSdpis[0]=dSdpi[i+kvol*mu];
287 //Multiplying by i and taking the real component is the same as taking the negative imaginary component
288 //The positions of u11 and u12 might look a bit funky here. That's just because we've multiplied by the
289 //generators by hand
290 dSdpis[0]+=-dk4ms*(conj(X1s[0])*(-conj(u12s)*X2su[0]+conj(u11s)*X2su[1])
291 +conj(X1s[1])*(u11s *X2su[0]+u12s *X2su[1])).imag()
292 -dk4ps*(conj(X1su[0])*(+u12s*X2s[0]-conj(u11s)*X2s[1])
293 +conj(X1su[1])*(-u11s*X2s[0]-conj(u12s)*X2s[1])).imag();
294
295 // dSdpis[1]=dSdpi[i+kvol*(ndim+mu)];
296 dSdpis[1]+=dk4ms*(conj(X1s[0])*(-conj(u12s)*X2su[0]+conj(u11s)*X2su[1])
297 +conj(X1s[1])*(-u11s *X2su[0]-u12s *X2su[1])).real()
298 +dk4ps*(conj(X1su[0])*(-u12s *X2s[0]-conj(u11s)*X2s[1])
299 +conj(X1su[1])*( u11s *X2s[0]-conj(u12s)*X2s[1])).real();
300
301 // dSdpis[2]=dSdpi[i+kvol*(2*ndim+mu)];
302 dSdpis[2]+=-dk4ms* (conj(X1s[0])* (u11s *X2su[0]+u12s *X2su[1])
303 +conj(X1s[1])* (conj(u12s)*X2su[0]-conj(u11s)*X2su[1])).imag()
304 -dk4ps*(conj(X1su[0])*(-conj(u11s)*X2s[0]-u12s *X2s[1])
305 +conj(X1su[1])* (-conj(u12s)*X2s[0]+u11s *X2s[1])).imag();
306
307 const unsigned short gindex=mu*ndirac+(idirac>>1);
308 //Rescaling gind by nc
309 const unsigned short gind = gamin[gindex]<<1;
310 ind=kvolHalo*gind;
311 X2s[0]=2*X2[i+ind]; X2su[0]=2*X2[uid+ind];
312 ind=kvolHalo*(1+gind);
313 X2s[1]=2*X2[i+ind]; X2su[1]=2*X2[uid+ind];
314
315 dSdpis[0]+=-dk4ms*(conj(X1s[0])*(-conj(u12s)*X2su[0]+conj(u11s)*X2su[1])
316 +conj(X1s[1])*(u11s *X2su[0]+u12s *X2su[1])).imag()
317 +dk4ps*((conj(X1su[0])* (u12s *X2s[0]-conj(u11s)*X2s[1])
318 +conj(X1su[1])*(-u11s *X2s[0]-conj(u12s)*X2s[1]))).imag();
319
320 dSdpis[1]+=dk4ms*(conj(X1s[0])*(-conj(u12s)*X2su[0]+conj(u11s)*X2su[1])
321 +conj(X1s[1])*(-u11s*X2su[0]-u12s *X2su[1])).real()
322 -dk4ps*(conj(X1su[0])*(-u12s *X2s[0]-conj(u11s)*X2s[1])
323 +conj(X1su[1])*(u11s*X2s[0]-conj(u12s)*X2s[1])).real();
324
325 dSdpis[2]+=-dk4ms*(conj(X1s[0])*(u11s*X2su[0] +u12s *X2su[1])
326 +conj(X1s[1])* (conj(u12s)*X2su[0]-conj(u11s)*X2su[1])).imag()
327 +dk4ps*(conj(X1su[0])*(-conj(u11s)*X2s[0]-u12s *X2s[1])
328 +conj(X1su[1])*(-conj(u12s)*X2s[0]+u11s *X2s[1])).imag();
329 }
330 dSdpi[i+kvol*mu]+=dSdpis[0];
331 dSdpi[i+kvol*(ndim+mu)]+=dSdpis[1];
332 dSdpi[i+kvol*(2*ndim+mu)]+=dSdpis[2];
333 }
334 }

References __BSIZE__, Complex_f, conj(), cuForce_t(), kvol, kvolHalo, nc, ndim, and ndirac.

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

◆ cuGauge_force()

void cuGauge_force ( Complex_f * ut[2],
double * dSdpi,
float beta,
unsigned int * iu,
unsigned int * id,
dim3 dimGrid,
dim3 dimBlock )

Calculate the gauge contribution to the force.

Parameters
[in]utGauge fields
[out]dSdpiForce
[in]betaInverse gauge coupling
[in]iu,idUpper/lower indices
[in]dimGrid,dimBlockCUDA grid/block size
Postcondition
Contents of dSdpi overwritten

Definition at line 337 of file cuforce.cu.

337 {
338 const char funcname[] = "Gauge_force";
339 int device=-1;
340 cudaGetDevice(&device);
341 Complex_f *Sigma[ndim][2], *ush[ndim][2];
342 for(unsigned short i=0;i<ndim;i++){
343#ifdef _DEBUG
344 cudaMallocManaged((void **)&Sigma[i][0],kvol*sizeof(Complex_f),cudaMemAttachGlobal);
345 cudaMallocManaged((void **)&Sigma[i][1],kvol*sizeof(Complex_f),cudaMemAttachGlobal);
346 cudaMallocManaged((void **)&ush[i][0],kvolHalo*sizeof(Complex_f),cudaMemAttachGlobal);
347 cudaMallocManaged((void **)&ush[i][1],kvolHalo*sizeof(Complex_f),cudaMemAttachGlobal);
348#else
349 cudaMallocAsync((void **)&Sigma[i][0],kvol*sizeof(Complex_f),streams[i]);
350 cudaMallocAsync((void **)&Sigma[i][1],kvol*sizeof(Complex_f),streams[i]);
351 cudaMallocAsync((void **)&ush[i][0],kvolHalo*sizeof(Complex_f),streams[i]);
352 cudaMallocAsync((void **)&ush[i][1],kvolHalo*sizeof(Complex_f),streams[i]);
353#endif
354 }
355 for(unsigned short mu=0; mu<ndim; mu++){
356 //TODO: This is needed. Setting to zero inside plus staple fails for some reason
357 cudaMemsetAsync(Sigma[mu][0],0, kvol*sizeof(Complex_f),streams[mu]);
358 cudaMemsetAsync(Sigma[mu][1],0, kvol*sizeof(Complex_f),streams[mu]);
359 for(unsigned short nu=0; nu<ndim; nu++)
360 if(nu!=mu){
361 //The @f$-\nu@f$ Staple
362 Kernels::Plus_staple<<<dimGrid,dimBlock,0,streams[mu]>>>(mu, nu, iu, Sigma[mu][0], Sigma[mu][1],ut[0],ut[1]);
363 Kernels::Gather<<<dimGrid,dimBlock,0,streams[mu]>>>(ush[mu][0], ut[0], kvol, id, nu);
364 Kernels::Gather<<<dimGrid,dimBlock,0,streams[mu]>>>(ush[mu][1], ut[1], kvol, id, nu);
365
366#if(nproc>1)
367 //Prefetch to the CPU for until we get NCCL working
368 //cudaMemPrefetchAsync(ush[0], kvolHalo*sizeof(Complex_f),cudaCpuDeviceId,streams[0]);
369 //cudaMemPrefetchAsync(ush[1], kvolHalo*sizeof(Complex_f),cudaCpuDeviceId,streams[1]);
370 CHalo_swap_dir(ush[mu][0], 1, mu, DOWN); CHalo_swap_dir(ush[mu][1], 1, mu, DOWN);
371 //cudaMemPrefetchAsync(ush[0]+kvol, halo*sizeof(Complex_f),device,streams[0]);
372 //cudaMemPrefetchAsync(ush[1]+kvol, halo*sizeof(Complex_f),device,streams[1]);
373#endif
374 //Next up, the @f$-\nu@f$ staple
375 Kernels::Minus_staple<<<dimGrid,dimBlock,0,streams[mu]>>>(mu, nu, iu, id,Sigma[mu][0],Sigma[mu][1],\
376 ush[mu][0],ush[mu][1],ut[0],ut[1]);
377 }
378 //Now get the gauge force acting in the @f$\mu@f$ direction
379 Kernels::cuGaugeForce<<<dimGrid,dimBlock,0,streams[mu]>>>(mu,Sigma[mu][0],Sigma[mu][1],dSdpi,ut[0],ut[1],beta);
380 }
381 for(unsigned short i=0;i<ndim;i++){
382#ifdef _DEBUG
383 cudaFree(Sigma[i][0]); cudaFree(Sigma[i][1]);
384 cudaFree(ush[i][0]); cudaFree(ush[i][1]);
385#else
386 cudaFreeAsync(Sigma[i][0],streams[i]); cudaFreeAsync(Sigma[i][1],streams[i]);
387 cudaFreeAsync(ush[i][0],streams[i]); cudaFreeAsync(ush[i][1],streams[i]);
388#endif
389 }
391}
__global__ void Gather(T *x, const T *y, const __grid_constant__ unsigned int n, const unsigned int *table, const __grid_constant__ unsigned short mu)
Extracts all the single precision gauge links in the direction only.
Definition cuforce.cu:121
__global__ void Minus_staple(const __grid_constant__ unsigned short mu, const __grid_constant__ unsigned short nu, const unsigned int *iu, const unsigned int *id, Complex_f *Sigma11, Complex_f *Sigma12, const Complex_f *u11sh, const Complex_f *u12sh, const Complex_f *u11t, const Complex_f *u12t)
Calculates the staple in the negative direction.
Definition cuforce.cu:57
__global__ void Plus_staple(const __grid_constant__ unsigned short mu, const __grid_constant__ unsigned short nu, const unsigned int *iu, Complex_f *Sigma11, Complex_f *Sigma12, const Complex_f *u11t, const Complex_f *u12t)
Calculates the staple in the positive direction.
Definition cuforce.cu:23
__global__ void cuGaugeForce(const __grid_constant__ int mu, const Complex_f *Sigma11, const Complex_f *Sigma12, double *dSdpi, const Complex_f *u11t, const Complex_f *u12t, const __grid_constant__ float beta)
Calculates the gauge force due to the Wilson Action at each intermediate time.
Definition cuforce.cu:92
int CHalo_swap_dir(Complex_f *c, int ncpt, int idir, int layer)
Swaps the halos along the axis given by idir in the direction given by layer.
#define DOWN
Flag for send down.
Definition par_mpi.h:37

References CHalo_swap_dir(), Complex_f, cudaDeviceSynchronise, cuGauge_force(), Kernels::cuGaugeForce(), dimBlock, dimGrid, DOWN, Kernels::Gather(), kvol, kvolHalo, Kernels::Minus_staple(), ndim, Kernels::Plus_staple(), and streams.

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

◆ cuGauge_Update() [1/2]

void cuGauge_Update ( const double d,
double * pp,
Complex * ut[2],
dim3 dimGrid,
dim3 dimBlock )

CUDA wrapper for the gauge update during the integration step of the HMC.

Parameters
[in]dGauge step size
[in]ppMomentum field
[in,out]ut: Double precision gauge fields
[in]dimGrid,dimBlockCUDA Grid/Block dimensions
Postcondition
ut updated in place

Definition at line 304 of file cusu2hmc.cu.

304 {
305 for(int mu=0;mu<ndim;mu++)
306 Kernels::cuGauge_Update<<<dimGrid,dimBlock,0,streams[mu]>>>(d,pp,ut[0],ut[1],mu);
308}
__global__ void cuGauge_Update(const double d, const double *pp, Complex *u11t, Complex *u12t, const int mu)
Gauge update for the integration step of the HMC.
Definition cusu2hmc.cu:177

References Complex, cudaDeviceSynchronise, cuGauge_Update(), Kernels::cuGauge_Update(), dimBlock, dimGrid, ndim, and streams.

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

◆ cuGauge_Update() [2/2]

__global__ void Kernels::cuGauge_Update ( const double d,
const double * pp,
Complex * u11t,
Complex * u12t,
const int mu )

Gauge update for the integration step of the HMC.

Parameters
[in]dGauge step size
[in]ppMomentum field
[in,out]u11t,u12tDouble precision gauge fields
[in]muLattice direction being updated
Postcondition
ut and ut_f updated in place

Definition at line 177 of file cusu2hmc.cu.

178 {
179 const unsigned int gsize = gridDim.x*gridDim.y*gridDim.z;
180 const unsigned int bsize = blockDim.x*blockDim.y*blockDim.z;
181 const unsigned int blockId = blockIdx.x+ blockIdx.y * gridDim.x+ gridDim.x * gridDim.y * blockIdx.z;
182 const unsigned int bthreadId= (threadIdx.z * blockDim.y+ threadIdx.y)* blockDim.x+ threadIdx.x;
183 const unsigned int gthreadId= blockId * bsize+bthreadId;
184 for(unsigned int i=gthreadId;i<kvol;i+=gsize*bsize){
185 //Sticking to what was in the FORTRAN for variable names.
186 //CCC for cosine SSS for sine AAA for...
187 //Re-exponentiating the force field. Can be done analytically in SU(2)
188 //using sine and cosine which is nice
189 unsigned int ind = i+kvol*mu;
190 double AAA = d*sqrt(pp[ind]*pp[ind]\
191 +pp[i+kvol*(1*ndim+mu)]*pp[i+kvol*(1*ndim+mu)]\
192 +pp[i+kvol*(2*ndim+mu)]*pp[i+kvol*(2*ndim+mu)]);
193 double CCC = cos(AAA);
194 double SSS = d*sin(AAA)/AAA;
195 Complex a11 = CCC+I*SSS*pp[i+kvol*(2*ndim+mu)];
196 Complex a12 = pp[i+kvol*(1*ndim+mu)]*SSS + I*SSS*pp[ind];
197 //b11 and b12 are u11t and u12t terms, so we'll use u12t directly
198 //but use b11 for u11t to prevent RAW dependency
199 ind = i+kvolHalo*mu;
200 Complex b11 = u11t[ind];
201 u11t[ind] = a11*b11-a12*conj(u12t[ind]);
202 u12t[ind] = a11*u12t[ind]+a12*conj(b11);
203 }
204 }
#define I
Define I in double precision using C standard notation.

References Complex, conj(), cuGauge_Update(), I, kvol, kvolHalo, and ndim.

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

◆ cuGaugeForce()

__global__ void Kernels::cuGaugeForce ( const __grid_constant__ int mu,
const Complex_f * Sigma11,
const Complex_f * Sigma12,
double * dSdpi,
const Complex_f * u11t,
const Complex_f * u12t,
const __grid_constant__ float beta )

Calculates the gauge force due to the Wilson Action at each intermediate time.

Parameters
[out]dSdpiThe force
[in]u11t,u12tGauge fields
[in]Sigma11,Sigma12Staples
[in]muGenerator index
[in]betaInverse gauge coupling
Postcondition
Gauge force written to dSdpi.

Definition at line 92 of file cuforce.cu.

94 {
95 const unsigned int gsize = gridDim.x*gridDim.y*gridDim.z;
96 const unsigned int bsize = blockDim.x*blockDim.y*blockDim.z;
97 const unsigned int blockId = blockIdx.x+ blockIdx.y * gridDim.x+ gridDim.x * gridDim.y * blockIdx.z;
98 const unsigned int threadId= blockId * bsize+(threadIdx.z * blockDim.y+ threadIdx.y)* blockDim.x+ threadIdx.x;
99 for(unsigned int i=threadId;i<kvol;i+=gsize*bsize){
100 const unsigned int ind = i+kvolHalo*mu;
101 const Complex_f a11 = u11t[ind]*Sigma12[i]+u12t[ind]*conj(Sigma11[i]);
102 const Complex_f a12 = u11t[ind]*Sigma11[i]+conj(u12t[ind])*Sigma12[i];
103 //Not worth splitting into different streams, before we get ideas...
104 dSdpi[i+kvol*mu]=beta*a11.imag();
105 dSdpi[i+kvol*(1*ndim+mu)]=beta*a11.real();
106 dSdpi[i+kvol*(2*ndim+mu)]=beta*a12.imag();
107 }
108 }

References __BSIZE__, Complex_f, conj(), cuGaugeForce(), kvol, kvolHalo, and ndim.

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

◆ Force()

int Force ( double * dSdpi,
const bool iflag,
double res1,
Complex * X0,
Complex * X1,
Complex * Phi,
Complex * ut[2],
Complex_f * ut_f[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],
const Complex_f jqq,
const float akappa,
const float beta,
const float c_sw,
double * ancg )

Calculates the force \(\frac{dS}{d\pi}\) at each intermediate time.

Parameters
[in,out]dSdpiThe force
[in]iflagInvert before evaluating the force. 0 to invert, one not to. Blame FORTRAN...
[in]res1Conjugate gradient residue
[in]X0Up/down partitioned pseudofermion field
[in]X1Holder for the partitioned fermion field, then the inverted dield
[in]PhiPseudofermion field
[in]ut,ut_fDouble/float precision colour fields
[in]iu,idLattice indices
[in]gamval,gamval_fDouble/float precision gamma matrices rescaled by \(\kappa\)
[in]gaminGamma indices
[in]sigval,sigval_fDouble/float Commutators 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_fDouble/float \(e^{-\mu}\) and \(e^\mu\)
[in]jqqDiquark source
[in]akappaHopping parameter
[in]betaInverse gauge coupling
[in]c_swClover coefficient. If non-zero calculate the clover contribution
[in]ancgCounter for conjugate gradient iterations
Returns
Zero on success, integer error code otherwise
Postcondition
Force added to dSdpi
Todo
If Gauge_force has not been called then set dSdpi to zero. The rest of the force uses += and as a result will add onto the previous answer instead of giving just the fermion force at this step

\((X1=(M\dagger M)^{-1} \Phi\)

Definition at line 228 of file force.c.

231 {
232 const char funcname[] = "Force";
233#ifdef USE_GPU
234 int device=-1;
235 cudaGetDevice(&device);
236#endif
237#ifndef NO_GAUGE
238 Gauge_force(dSdpi,ut_f,iu,id,beta);
239#else
240#endif
243 if(!akappa)
244 return 0;
245 //X1=(M†M)^{1} Phi
246 int itercg=1;
247 Complex_f *clover[2];
248#ifdef USE_GPU
249 Complex_f *X1_f, *X2_f;
250 cudaMallocAsync((void **)&X1_f,kferm2Halo*sizeof(Complex_f),streams[1]);
251 cudaMallocAsync((void **)&X2_f,kferm2Halo*sizeof(Complex_f),streams[0]);
252#else
253 Complex_f *X1_f= (Complex_f *)aligned_alloc(AVX,kferm2Halo*sizeof(Complex_f));
254 Complex_f *X2_f= (Complex_f *)aligned_alloc(AVX,kferm2Halo*sizeof(Complex_f));
255#endif
256 if(c_sw)
257 Clover(clover,ut_f,iu,id);
258
259 for(int na = 0; na<nf; na++){
260#ifdef USE_GPU
261#if(nproc>1) //Strided
262 for(unsigned short j=0;j<nc*idirac;j++)
263 cudaMemcpyAsync(X1+j*kvolHalo,X0+na*kferm2+j*kvol,kvol*sizeof(Complex),cudaMemcpyDeviceToDevice,streams[j]);
264#else
265 cudaMemcpyAsync(X1,X0+na*kferm2,kferm2*sizeof(Complex),cudaMemcpyDeviceToDevice,NULL);
266#endif
267#else
268 for(unsigned short j=0;j<nc*ndirac;j++)
269 memcpy(X1+j*kvolHalo,X0+na*kferm2+j*kvol,kvol*sizeof(Complex));
270#endif
271 if(!iflag){
272 int itercg=1;
273#ifdef USE_GPU
274 Complex *smallPhi;
275 cudaMallocAsync((void **)&smallPhi,kferm2*sizeof(Complex),streams[0]);
276#else
277 Complex *smallPhi = (Complex *)aligned_alloc(AVX,kferm2*sizeof(Complex));
278#endif
279 Fill_Small_Phi(na, smallPhi, Phi);
281 Congradq(na,res1,X1,smallPhi,ut,ut_f,clover,iu,id,gamval,gamval_f,gamin,sigval,sigval_f,sigin,dk,dk_f,\
282 jqq,akappa,c_sw,&itercg);
283#ifdef USE_GPU
284 cudaFreeAsync(smallPhi,streams[0]);
285#else
286 free(smallPhi);
287#endif
288 *ancg+=itercg;
289#ifdef USE_GPU
290 alignas(16) const Complex blasa=2.0; alignas(16) const double blasb=-1.0;
291 cublasZdscal(cublas_handle,kferm2,&blasb,(cuDoubleComplex *)(X0+na*kferm2),1);
292#if(nproc>1) //strided
293 for(unsigned short j=0;j<nc*ndirac;j++)
294 cublasZaxpy(cublas_handle,kvol,(cuDoubleComplex *)&blasa,(cuDoubleComplex *)X1+j*kvolHalo,1,(cuDoubleComplex *)X0+na*kferm2+j*kvol,1);
295#else
296 cublasZaxpy(cublas_handle,kferm2,(cuDoubleComplex *)&blasa,(cuDoubleComplex *)X1,1,(cuDoubleComplex *)(X0+na*kferm2),1);
297#endif
298#elif (defined __USE_MKL__||defined OPENBLAS||defined AMD_BLAS)
299 const Complex blasa=2.0; const Complex blasb=-1.0;
300 //This is not a general BLAS Routine. BLIS and MKl support it
301 //CUDA and GSL does not support it
302 cblas_zaxpby(kferm2, &blasa, X1, 1, &blasb, X0+na*kferm2, 1);
303#elifdef USE_BLAS
304 const Complex blasa=2.0; const double blasb=-1.0;
305 cblas_zdscal(kferm2,blasb,X0+na*kferm2,1);
306 for(unsigned short j=0;j<nc*ndirac;j++)
307 cblas_zaxpy(kvol,&blasa,X1+j*kvolHalo,1,X0+na*kferm2+j*kvol,1);
308#else
309#pragma omp parallel for simd collapse(2) aligned(X0,X1:AVX)
310 for(int idirac=0;idirac<ndirac;idirac++){
311 for(int i=0;i<kvol;i++)
312 X0[i+kvol*(0+nc*(idirac+ndirac*na))]=
313 2*X1[i+kvolHalo*(0+idirac*nc)]-X0[i+kvol*(0+nc*(idirac+ndirac*na))];
314 X0[i+kvol*(1+nc*(idirac+ndirac*na))]=
315 2*X1[i+kvolHalo*(1+idirac*nc)]-X0[i+kvol*(1+nc*(idirac+ndirac*na))];
316 }
317#endif
318 }
319#ifdef USE_GPU
321#endif
322 //Since it has to be stridded in MPI, we have to pass kvol and nc*ndirac instead of kferm2
323 ComplexConvert(X1_f,X1,kvol,true,nc*ndirac);
324 Hdslash_f(X2_f,X1_f,ut_f,iu,id,gamval_f,gamin,dk_f,akappa);
325 if(c_sw)
326 HbyClover_f(X2_f,X1_f,clover,sigval_f,akappa,sigin,false);
327 //NOTE: This was orginally two. But was changed as a test for Claude so the two appears inside Force_s and Force_t
328 //It may need to be reverted back later
329 alignas(8) const float blasd=1.0;
330#ifdef USE_GPU
332#if(nproc>1)
333 for(unsigned short j=0;j<nc*ndirac;j++)
334 cublasCsscal(cublas_handle,kvol, &blasd, (cuComplex *)X2_f+j*kvolHalo, 1);
335#else
336 cublasCsscal(cublas_handle,kferm2, &blasd, (cuComplex *)X2_f, 1);
337#endif
338#elif defined USE_BLAS
339 for(unsigned short j=0;j<nc*ndirac;j++)
340 cblas_csscal(kvol, blasd, X2_f+j*kvolHalo, 1);
341#else
342#pragma unroll
343#pragma omp parallel for simd collapse(2) aligned(X2_f:AVX)
344 for(unsigned short j=0;j<nc*ndirac;j++)
345 for(unsigned int i=0;i<kvol;i++)
346 X2_f[i+j*kvolHalo]*=1;
347#endif
348#if(npx>1)
351#endif
352#if(npy>1)
355#endif
356#if(npz>1)
359#endif
360#if(npt>1)
363#endif
364
365 // The original FORTRAN Comment:
366 // dSdpi=dSdpi-Re(X1*(d(Mdagger)dp)*X2) -- Yikes!
367 // we're gonna need drugs for this one......
368 //
369 // Makes references to X1(.,.,iu(i,mu)) AND X2(.,.,iu(i,mu))
370 // as a result, need to swap the DOWN halos in all dirs for
371 // both these arrays, each of which has 8 cpts
372 //
373#ifdef USE_GPU
374 cuForce(dSdpi,ut_f,X1_f,X2_f,gamval_f,dk_f,iu,gamin,akappa,dimGrid,dimBlock);
376#else
377 //Thankfully the CUDA version is much neater so we're using that style going forwards
378 for(unsigned short mu=0;mu<ndim-1;mu++)
379 Force_s(dSdpi,ut_f,X1_f,X2_f,gamval_f,iu,gamin,akappa,mu);
380 Force_t(dSdpi,ut_f,X1_f,X2_f,gamval_f,dk_f,iu,gamin,akappa);
381#endif
382 if(c_sw){
383 Clov_Force(dSdpi,ut_f,X1_f,X2_f,sigval_f,sigin,iu,id,akappa);
384 Clover_free(clover);
385 }
386 }
387#ifdef USE_GPU
388 cudaFreeAsync(X1_f,streams[0]); cudaFreeAsync(X2_f,streams[1]);
389#else
390 free(X1_f); free(X2_f);
391#endif
392 return 0;
393}
void Clov_Force(double *dSdpi, Complex_f *ut[2], Complex_f *X1, Complex_f *X2, const Complex_f *sigval, const unsigned short *sigin, unsigned int *iu, unsigned int *id, const float akappa)
Gets the clover contribution to the force.
Definition clover.c:533
void Clover_free(Complex_f *clover[nc])
Free's memory used for clover terms and leaves.
Definition clover.c:741
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
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
void Force_t(double *dSdpi, Complex_f *ut[2], Complex_f *X1, Complex_f *X2, Complex_f gamval[20], float *dk[2], unsigned int *iu, const unsigned short gamin[16], float akappa)
Calculates the force at each intermediate time.
Definition force.c:156
void cuForce(double *dSdpi, Complex_f *ut[2], Complex_f *X1, Complex_f *X2, Complex_f gamval[20], float *dk[2], unsigned int *iu, const unsigned short gamin[16], float akappa, dim3 dimGrid, dim3 dimBlock)
Calculates the force at each intermediate time.
Definition cuforce.cu:392
void Force_s(double *dSdpi, Complex_f *ut[2], Complex_f *X1, Complex_f *X2, Complex_f gamval[20], unsigned int *iu, const unsigned short gamin[16], const float akappa, const unsigned short mu)
Calculates the force at each intermediate time.
Definition force.c:81
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 Gauge_force(double *dSdpi, Complex_f *ut[2], unsigned int *iu, unsigned int *id, float beta)
Calculates the gauge force due to the Wilson Action at each intermediate time.
Definition force.c:11
#define kferm2Halo
Dirac lattice and halo.
Definition sizes.h:242
#define nf
Fermion flavours (double it).
Definition sizes.h:164

References AVX, CHalo_swap_dir(), Clov_Force(), Clover(), Clover_free(), Complex, Complex_f, ComplexConvert(), Congradq(), cudaDeviceSynchronise, cuForce(), dimBlock, dimGrid, DOWN, Fill_Small_Phi(), Force(), Force_s(), Force_t(), Gauge_force(), HbyClover_f(), Hdslash_f(), kferm2, kferm2Halo, kvol, kvolHalo, nc, ndim, ndirac, nf, and streams.

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

◆ Force_s()

void Force_s ( double * dSdpi,
Complex_f * ut[2],
Complex_f * X1,
Complex_f * X2,
Complex_f gamval[20],
unsigned int * iu,
const unsigned short gamin[16],
const float akappa,
const unsigned short mu )

Calculates the force \(\frac{dS}{d\pi}\) at each intermediate time.

Parameters
[in,out]dSdpiThe force
[in]utFloat precision colour fields
[in]X1Inverted field
[in]X2\(MX_1\)
[in]gamvalGamma matrices rescaled by \(\kappa\)
[in]iuLattice indices
[in]gaminGamma indices
[in]akappaHopping parameter
[in]muForce direction
Postcondition
Force added to dSdpi

Definition at line 81 of file force.c.

82 {
83#pragma omp parallel for simd
84 for(unsigned int i=0;i<kvol;i++){
85 const unsigned int ind=i+kvolHalo*mu;
86 const Complex_f u11s=ut[0][ind]; const Complex_f u12s=ut[1][ind];
87 const unsigned int uid = iu[i+kvol*mu];
88 //Similarly to Hdslash we always see idirac*nc so we do that here too.
89 for(unsigned short idirac=0;idirac<nc*ndirac;idirac+=nc){
90 Complex_f X1s[nc]; Complex_f X1su[nc];
91 Complex_f X2s[nc]; Complex_f X2su[nc];
92
93 X1s[0]=X1[i+kvolHalo*(idirac)]; X1s[1]=X1[i+kvolHalo*(1+idirac)];
94 X1su[0]=X1[uid+kvolHalo*(idirac)]; X1su[1]=X1[uid+kvolHalo*(1+idirac)];
95 X2s[0]=2*X2[i+kvolHalo*(idirac)]; X2s[1]=2*X2[i+kvolHalo*(1+idirac)];
96 X2su[0]=2*X2[uid+kvolHalo*(idirac)]; X2su[1]=2*X2[uid+kvolHalo*(1+idirac)];
97
98 float dSdpis[3];
99 dSdpis[0]=dSdpi[i+kvol*mu];
100 //Multiplying by i and taking the real component is the same as taking the negative imaginary component
101 //The positions of u11 and u12 might look a bit funky here. That's just because we've multiplied by the
102 //generators by hand
103 dSdpis[0]+=-akappa*cimag(
104 conj(X1s[0])*(-conj(u12s)*X2su[0]+conj(u11s)*X2su[1])
105 +conj(X1s[1])*(u11s*X2su[0]+u12s*X2su[1])
106 +conj(X1su[0])*(u12s*X2s[0]-conj(u11s)*X2s[1])
107 +conj(X1su[1])*(-u11s*X2s[0]-conj(u12s)*X2s[1]));
108
109 dSdpis[1]=dSdpi[i+kvol*(ndim+mu)];
110 dSdpis[1]+=akappa*creal(
111 (conj(X1s[0])*(-conj(u12s)*X2su[0]+conj(u11s)*X2su[1])
112 +conj(X1s[1])*(-u11s*X2su[0]-u12s*X2su[1])
113 +conj(X1su[0])*(-u12s*X2s[0]-conj(u11s)*X2s[1])
114 +conj(X1su[1])*(u11s*X2s[0]-conj(u12s)*X2s[1])));
115
116 dSdpis[2]=dSdpi[i+kvol*(2*ndim+mu)];
117 dSdpis[2]+=-akappa*cimag(
118 conj(X1s[0])*(u11s *X2su[0]+u12s *X2su[1])
119 +conj(X1s[1])*(conj(u12s)*X2su[0]-conj(u11s)*X2su[1])
120 +conj(X1su[0])*(-conj(u11s)*X2s[0]-u12s *X2s[1])
121 +conj(X1su[1])*(-conj(u12s)*X2s[0]+u11s *X2s[1]));
122
123 const unsigned short gindex=mu*ndirac+(idirac>>1);
124 const Complex_f gamval_c=gamval[gindex];
125 //Rescaling gind by nc
126 const unsigned short gind = gamin[gindex]<<1;
127 X2s[0]=2*X2[i+kvolHalo*(gind)]; X2s[1]=2*X2[i+kvolHalo*(1+gind)];
128 X2su[0]=2*X2[uid+kvolHalo*(gind)]; X2su[1]=2*X2[uid+kvolHalo*(1+gind)];
129
130 //If you are asked to rederive the force from Montvay and Munster you'll notice that it should be kappa*gamma
131 //but below is only gamma. We rescaled gamma by kappa already when we defined it so that's where it has gone
132 dSdpis[0]+=-cimag(gamval_c*
133 (conj(X1s[0])* (-conj(u12s)*X2su[0]+conj(u11s)*X2su[1])
134 +conj(X1s[1])* (u11s *X2su[0]+u12s *X2su[1])
135 +conj(X1su[0])* (-u12s *X2s[0] +conj(u11s)*X2s[1])
136 +conj(X1su[1])*(u11s *X2s[0] +conj(u12s)*X2s[1])));
137 dSdpi[i+kvol*mu]=dSdpis[0];
138
139 dSdpis[1]+=creal(gamval_c*
140 (conj(X1s[0])* (-conj(u12s)*X2su[0] +conj(u11s)*X2su[1])
141 +conj(X1s[1])*(-u11s *X2su[0]-u12s *X2su[1])
142 +conj(X1su[0])* (u12s *X2s[0]+conj(u11s)*X2s[1])
143 +conj(X1su[1])* (-u11s *X2s[0]+conj(u12s)*X2s[1])));
144 dSdpi[i+kvol*(ndim+mu)]=dSdpis[1];
145
146 dSdpis[2]+=-cimag(gamval_c*
147 (conj(X1s[0])*(u11s *X2su[0]+u12s *X2su[1])
148 +conj(X1s[1])*(conj(u12s)*X2su[0]-conj(u11s)*X2su[1])
149 +conj(X1su[0])*(conj(u11s)*X2s[0]+u12s *X2s[1])
150 +conj(X1su[1])*(conj(u12s)*X2s[0]-u11s *X2s[1])));
151 dSdpi[i+kvol*(2*ndim+mu)]=dSdpis[2];
152 }
153 }
154 return;
155}
#define cimag(z)
Extract Imaginary Component using C standard notation.

References cimag, Complex_f, conj(), creal, Force_s(), kvol, kvolHalo, nc, ndim, and ndirac.

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

◆ Force_t()

void Force_t ( double * dSdpi,
Complex_f * ut[2],
Complex_f * X1,
Complex_f * X2,
Complex_f gamval[20],
float * dk[2],
unsigned int * iu,
const unsigned short gamin[16],
float akappa )

Calculates the force \(\frac{dS}{d\pi}\) at each intermediate time.

Parameters
[in,out]dSdpiThe force
[in]utFloat precision colour fields
[in]X1Inverted field
[in]X2\(MX_1\)
[in]gamvalGamma matrices rescaled by \(\kappa\)
[in]dk\(e^{-\mu}\) and \(e^\mu\)
[in]iuLattice indices
[in]gaminGamma indices
[in]akappaHopping parameter
Postcondition
Force added to dSdpi

Definition at line 156 of file force.c.

157 {
158
159 const unsigned short mu=3;
160#pragma omp parallel for simd
161 for(unsigned int i=0;i<kvol;i++){
162 const unsigned int ind=i+kvolHalo*mu;
163 const Complex_f u11s=ut[0][ind]; const Complex_f u12s=ut[1][ind];
164 //TODO: The only diffrence with these is that the sign flips for the temporal components
165 // Can we figure out a way of doing this without having to read in a large array.
166 // Will result in a conditional inside a CUDA loop. If i>kvol3
167 const float dks[2] = {dk[0][i],dk[1][i]};
168 //Up indices
169 const unsigned int uid = iu[i+kvol*mu];
170 //Similarly to Hdslash we always see idirac*nc so we do that here too.
171 for(unsigned short idirac=0;idirac<ndirac*nc;idirac+=nc){
172 Complex_f X1s[nc]; Complex_f X1su[nc];
173 Complex_f X2s[nc]; Complex_f X2su[nc];
174
175 X1s[0]=X1[i+kvolHalo*(idirac)]; X1s[1]=X1[i+kvolHalo*(1+idirac)];
176 X1su[0]=X1[uid+kvolHalo*(idirac)]; X1su[1]=X1[uid+kvolHalo*(1+idirac)];
177 X2s[0]=2*X2[i+kvolHalo*(idirac)]; X2s[1]=2*X2[i+kvolHalo*(1+idirac)];
178 X2su[0]=2*X2[uid+kvolHalo*(idirac)]; X2su[1]=2*X2[uid+kvolHalo*(1+idirac)];
179
180 float dSdpis[3];
181 dSdpis[0]=dSdpi[i+kvol*mu];
182 //Multiplying by i and taking the real component is the same as taking the negative imaginary component
183 //The positions of u11 and u12 might look a bit funky here. That's just because we've multiplied by the
184 //generators by hand
185 dSdpis[0]+=-cimag(dks[0]*(conj(X1s[0])*(-conj(u12s)*X2su[0]+conj(u11s)*X2su[1])
186 +conj(X1s[1])*(u11s *X2su[0]+u12s *X2su[1]))
187 +dks[1]*(conj(X1su[0])*(+u12s*X2s[0]-conj(u11s)*X2s[1])
188 +conj(X1su[1])*(-u11s*X2s[0]-conj(u12s)*X2s[1])));
189
190 dSdpis[1]=dSdpi[i+kvol*(ndim+mu)];
191 dSdpis[1]+=creal(dks[0]*(conj(X1s[0])*(-conj(u12s)*X2su[0]+conj(u11s)*X2su[1])
192 +conj(X1s[1])*(-u11s *X2su[0]-u12s *X2su[1]))
193 +dks[1]*(conj(X1su[0])*(-u12s *X2s[0]-conj(u11s)*X2s[1])
194 +conj(X1su[1])*( u11s *X2s[0]-conj(u12s)*X2s[1])));
195
196 dSdpis[2]=dSdpi[i+kvol*(2*ndim+mu)];
197 dSdpis[2]+=-cimag(dks[0]* (conj(X1s[0])* (u11s *X2su[0]+u12s *X2su[1])
198 +conj(X1s[1])* (conj(u12s)*X2su[0]-conj(u11s)*X2su[1]))
199 +dks[1]*(conj(X1su[0])*(-conj(u11s)*X2s[0]-u12s *X2s[1])
200 +conj(X1su[1])* (-conj(u12s)*X2s[0]+u11s *X2s[1])));
201
202 const unsigned short gindex=mu*ndirac+(idirac>>1);
203 //Rescaling gind by nc
204 const unsigned short gind = gamin[gindex]<<1;
205 X2s[0]=2*X2[i+kvolHalo*(gind)]; X2s[1]=2*X2[i+kvolHalo*(1+gind)];
206 X2su[0]=2*X2[uid+kvolHalo*(gind)]; X2su[1]=2*X2[uid+kvolHalo*(1+gind)];
207
208 dSdpis[0]+=-cimag(dks[0]*(conj(X1s[0])*(-conj(u12s)*X2su[0]+conj(u11s)*X2su[1])
209 +conj(X1s[1])*(u11s *X2su[0]+u12s *X2su[1]))
210 -dks[1]*(conj(X1su[0])* (u12s *X2s[0]-conj(u11s)*X2s[1])
211 +conj(X1su[1])*(-u11s *X2s[0]-conj(u12s)*X2s[1])));
212 dSdpi[i+kvol*mu]=dSdpis[0];
213
214 dSdpis[1]+=creal(dks[0]*(conj(X1s[0])*(-conj(u12s)*X2su[0]+conj(u11s)*X2su[1])
215 +conj(X1s[1])*(-u11s*X2su[0]-u12s *X2su[1]))
216 -dks[1]*(conj(X1su[0])*(-u12s *X2s[0]-conj(u11s)*X2s[1])
217 +conj(X1su[1])*(u11s*X2s[0]-conj(u12s)*X2s[1])));
218 dSdpi[i+kvol*(ndim+mu)]=dSdpis[1];
219
220 dSdpis[2]+=-cimag(dks[0]*(conj(X1s[0])*(u11s*X2su[0] +u12s *X2su[1])
221 +conj(X1s[1])* (conj(u12s)*X2su[0]-conj(u11s)*X2su[1]))
222 -dks[1]*(conj(X1su[0])*(-conj(u11s)*X2s[0]-u12s *X2s[1])
223 +conj(X1su[1])*(-conj(u12s)*X2s[0]+u11s *X2s[1])));
224 dSdpi[i+kvol*(2*ndim+mu)]=dSdpis[2];
225 }
226 }
227}

References cimag, Complex_f, conj(), creal, Force_t(), kvol, kvolHalo, nc, ndim, and ndirac.

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

◆ Gauge_force()

int Gauge_force ( double * dSdpi,
Complex_f * ut[2],
unsigned int * iu,
unsigned int * id,
float beta )

Calculates the gauge force due to the Wilson Action at each intermediate time.

Parameters
[out]dSdpiThe force
[in]utGauge fields
[in]iu,idLattice indices
[in]betaInverse gauge coupling
Returns
Zero on success, integer error code otherwise
Postcondition
Contents of dSdpi replaced by gauge force

Definition at line 11 of file force.c.

11 {
12 const char funcname[] = "Gauge_force";
13
14 //We define zero halos for debugging
15 // #ifdef _DEBUG
16 // memset(ut[0][kvol], 0, ndim*halo*sizeof(Complex_f));
17 // memset(ut[1][kvol], 0, ndim*halo*sizeof(Complex_f));
18 // #endif
19 //Was a trial field halo exchange here at one point.
20#ifdef USE_GPU
21 cuGauge_force(ut,dSdpi,beta,iu,id,dimGrid,dimBlock);
23#else
24 Complex_f *Sigma[2], *ush[2];
25 Sigma[0] = (Complex_f *)aligned_alloc(AVX,kvol*sizeof(Complex_f));
26 Sigma[1]= (Complex_f *)aligned_alloc(AVX,kvol*sizeof(Complex_f));
27 ush[0] = (Complex_f *)aligned_alloc(AVX,kvolHalo*sizeof(Complex_f));
28 ush[1] = (Complex_f *)aligned_alloc(AVX,kvolHalo*sizeof(Complex_f));
29 //Holders for directions
30 for(int mu=0; mu<ndim; mu++){
31 memset(Sigma[0],0, kvol*sizeof(Complex_f));
32 memset(Sigma[1],0, kvol*sizeof(Complex_f));
33 for(int nu=0; nu<ndim; nu++)
34 if(nu!=mu){
35 //The +@f$\nu@f$ Staple
36#pragma omp parallel for simd //aligned(ut[0],ut[1],Sigma[0],Sigma[1],iu:AVX)
37 for(int i=0;i<kvol;i++){
38 int uidm = iu[mu*kvol+i];
39 int uidn = iu[nu*kvol+i];
40 Complex_f a11=ut[0][uidm+kvolHalo*nu]*conj(ut[0][uidn+kvolHalo*mu])+\
41 ut[1][uidm+kvolHalo*nu]*conj(ut[1][uidn+kvolHalo*mu]);
42 Complex_f a12=-ut[0][uidm+kvolHalo*nu]*ut[1][uidn+kvolHalo*mu]+\
43 ut[1][uidm+kvolHalo*nu]*ut[0][uidn+kvolHalo*mu];
44 Sigma[0][i]+=a11*conj(ut[0][i+kvolHalo*nu])+a12*conj(ut[1][i+kvolHalo*nu]);
45 Sigma[1][i]+=-a11*ut[1][i+kvolHalo*nu]+a12*ut[0][i+kvolHalo*nu];
46 }
47 C_gather(ush[0], ut[0], kvol, id, nu);
48 C_gather(ush[1], ut[1], kvol, id, nu);
49#if(nproc>1)
50 CHalo_swap_dir(ush[0], 1, mu, DOWN); CHalo_swap_dir(ush[1], 1, mu, DOWN);
51#endif
52 //Next up, the -@f$\nu@f$ staple
53#pragma omp parallel for simd //aligned(ut[0],ut[1],ush[0],ush[1],Sigma[0],Sigma[1],iu,id:AVX)
54 for(int i=0;i<kvol;i++){
55 int uidm = iu[mu*kvol+i];
56 int didn = id[nu*kvol+i];
57 //uidm is correct here
58 Complex_f a11=conj(ush[0][uidm])*conj(ut[0][didn+kvolHalo*mu])-\
59 ush[1][uidm]*conj(ut[1][didn+kvolHalo*mu]);
60 Complex_f a12=-conj(ush[0][uidm])*ut[1][didn+kvolHalo*mu]-\
61 ush[1][uidm]*ut[0][didn+kvolHalo*mu];
62 Sigma[0][i]+=a11*ut[0][didn+kvolHalo*nu]-a12*conj(ut[1][didn+kvolHalo*nu]);
63 Sigma[1][i]+=a11*ut[1][didn+kvolHalo*nu]+a12*conj(ut[0][didn+kvolHalo*nu]);
64 }
65 }
66#pragma omp parallel for simd //aligned(ut[0],ut[1],Sigma[0],Sigma[1],dSdpi:AVX)
67 for(int i=0;i<kvol;i++){
68 const unsigned int ind = i+kvolHalo*mu;
69 Complex_f a11 = ut[0][ind]*Sigma[1][i]+ut[1][ind]*conj(Sigma[0][i]);
70 Complex_f a12 = ut[0][ind]*Sigma[0][i]+conj(ut[1][ind])*Sigma[1][i];
71
72 dSdpi[i+kvol*mu]=(double)(beta*cimag(a11));
73 dSdpi[i+kvol*(1*ndim+mu)]=(double)(beta*creal(a11));
74 dSdpi[i+kvol*(2*ndim+mu)]=(double)(beta*cimag(a12));
75 }
76 }
77 free(ush[0]); free(ush[1]); free(Sigma[0]); free(Sigma[1]);
78#endif
79 return 0;
80}
int C_gather(Complex_f *x, Complex_f *y, int n, unsigned int *table, unsigned int mu)
Extracts all the single precision gauge links in the direction only.
Definition su2hmc.c:291
void cuGauge_force(Complex_f *ut[2], double *dSdpi, float beta, unsigned int *iu, unsigned int *id, dim3 dimGrid, dim3 dimBlock)
Calculate the gauge contribution to the force.
Definition cuforce.cu:337

References AVX, C_gather(), CHalo_swap_dir(), cimag, Complex_f, conj(), creal, cudaDeviceSynchronise, cuGauge_force(), dimBlock, dimGrid, DOWN, Gauge_force(), kvol, kvolHalo, and ndim.

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

◆ Gauge_Update()

int Gauge_Update ( const double d,
double * pp,
Complex * ut[2],
Complex_f * ut_f[2] )

Gauge update for the integration step of the HMC.

Parameters
[in]dGauge step size
[in]ppMomentum field
[in,out]utDouble precision gauge fields
[in,out]ut_fSingle precision gauge fields
Returns
Zero on success, integer error code otherwise.
Postcondition
ut and ut_f updated in place

Definition at line 37 of file integrate.c.

37 {
38 char funcname[] = "Gauge_Update";
39#ifdef USE_GPU
41#else
42#pragma omp parallel for simd collapse(2) aligned(pp:AVX)
43 for(unsigned int i=0;i<kvol;i++)
44 for(unsigned short mu = 0; mu<ndim; mu++){
45 /*
46 * Sticking to what was in the FORTRAN for variable names.
47 * CCC for cosine SSS for sine AAA for...
48 * Re-exponentiating the force field. Can be done analytically in SU(2)
49 * using sine and cosine which is nice
50 */
51 const unsigned int ind = i+kvol*mu;
52 double AAA = d*sqrt(pp[ind]*pp[ind]\
53 +pp[i+kvol*(1*ndim+mu)]*pp[i+kvol*(1*ndim+mu)]\
54 +pp[i+kvol*(2*ndim+mu)]*pp[i+kvol*(2*ndim+mu)]);
55 double CCC = cos(AAA);
56 double SSS = d*sin(AAA)/AAA;
57 Complex a11 = CCC+I*SSS*pp[i+kvol*(2*ndim+mu)];
58 Complex a12 = pp[i+kvol*(1*ndim+mu)]*SSS + I*SSS*pp[ind];
59 //b11 and b12 are ut[0] and ut[1] terms, so we'll use ut[1] directly
60 //but use b11 for ut[0] to prevent RAW dependency
61 Complex b11 = ut[0][i+kvolHalo*mu];
62 ut[0][i+kvolHalo*mu] = a11*b11-a12*conj(ut[1][i+kvolHalo*mu]);
63 ut[1][i+kvolHalo*mu] = a11*ut[1][i+kvolHalo*mu]+a12*conj(b11);
64 }
65#endif
66 Reunitarise(ut);
67 //Get trial fields from accelerator for halo exchange
68 Trial_Exchange(ut,ut_f);
69 return 0;
70}
int Reunitarise(Complex *ut[2])
Reunitarises u11t and u12t as in conj(u11t[i])*u11t[i]+conj(u12t[i])*u12t[i]=1.
Definition su2hmc.c:342
void cuGauge_Update(const double d, double *pp, Complex *ut[2], dim3 dimGrid, dim3 dimBlock)
CUDA wrapper for the gauge update during the integration step of the HMC.
Definition cusu2hmc.cu:304
int Trial_Exchange(Complex *ut[2], Complex_f *ut_f[2])
Exchanges the trial fields.
Definition par_mpi.c:1043

References Complex, Complex_f, conj(), cuGauge_Update(), dimBlock, dimGrid, Gauge_Update(), I, kvol, kvolHalo, ndim, Reunitarise(), and Trial_Exchange().

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

◆ Leapfrog()

int Leapfrog ( Complex * ut[2],
Complex_f * ut_f[2],
Complex * X0,
Complex * X1,
Complex * Phi,
double * dk[2],
float * dk_f[2],
double * dSdpi,
double * pp,
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,
const Complex jqq,
const float beta,
const float akappa,
const float c_sw,
const int stepl,
const float dt,
double * ancg,
int * itot,
const float proby )

Leapfrog integrator. Each trajectory step takes the form of p->p+dt/2,u->u+dt,p->p+dt/2 In practice this is implemented for the entire trajectory as p->p+dt/2,u->u+dt,p->p+dt,u->u+dt,p->p+dt,...p->p+dt/2,u->u+dt,p->p+dt/2.

Parameters
[in,out]utDouble precision colour fields
[in,out]ut_fSingle precision colour fields
[in]X0Up/down partitioned pseudofermion field
[in]X1Holder for the partitioned fermion field, then the conjugate gradient output
[in]PhiPseudofermion field
[in]dk\(\left(1+\gamma_0\right)e^{-\mu}\) and \(\left(1-\gamma_0\right)e^\mu\)
[in]dk_f\(\left(1+\gamma_0\right)e^{-\mu}\) and \(\left(1-\gamma_0\right)e^\mu\) float
[in,out]dSdpiThe force
[in,out]ppMomentum field
[in]iu,idLattice indices
[in]gaminGamma indices
[in]gamvalDouble precision gamma matrices rescaled by kappa
[in]gamval_fSingle precision gamma matrices rescaled by kappa
[in]sigval,sigval_fDouble/float Commutators 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]c_swClover coefficient
[in]jqqDiquark source
[in]akappaHopping parameter
[in]betaInverse gauge coupling
[in]steplSteps per trajectory
[in]dtStep size
[in]ancgCounter for average conjugate gradient iterations
[in]itotTotal average conjugate gradient iterations
[in]probyTermination probability for random trajectory length
Returns
Zero on success, integer error code otherwise
Postcondition
ut, ut_f, pp and dSdpi updated in place throughout the integration

References Complex, Complex_f, Leapfrog(), and OMF2().

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

◆ Minus_staple()

__global__ void Kernels::Minus_staple ( const __grid_constant__ unsigned short mu,
const __grid_constant__ unsigned short nu,
const unsigned int * iu,
const unsigned int * id,
Complex_f * Sigma11,
Complex_f * Sigma12,
const Complex_f * u11sh,
const Complex_f * u12sh,
const Complex_f * u11t,
const Complex_f * u12t )

Calculates the staple in the negative \(\mu\) direction.

Parameters
[in]mu\(\mu\) direction
[in]nu\(\nu\) direction
[in]iu,idUpper/lower indices
[in,out]Sigma11,Sigma12Staple output
[in]u11sh,u12shGauge fields in \(\mu\) direction only
[in]u11t,u12tGauge fields
Postcondition
Staples added to Sigma11 and Sigma12

Definition at line 57 of file cuforce.cu.

61 {
62 const unsigned int gsize = gridDim.x*gridDim.y*gridDim.z;
63 const unsigned int bsize = blockDim.x*blockDim.y*blockDim.z;
64 const unsigned int blockId = blockIdx.x+ blockIdx.y * gridDim.x+ gridDim.x * gridDim.y * blockIdx.z;
65 const unsigned int threadId= blockId * bsize+(threadIdx.z * blockDim.y+ threadIdx.y)* blockDim.x+ threadIdx.x;
66 for(unsigned int i=threadId;i<kvol;i+=gsize*bsize){
67 const unsigned int uidm = iu[mu*kvol+i];
68 const unsigned int didn = id[nu*kvol+i];
69 //uidm is correct here
70 unsigned int ind=didn+kvolHalo*mu;
71 Complex_f u11s=u11t[ind]; Complex_f u12s=u12t[ind];
72 const Complex_f a11=conj(u11sh[uidm])*conj(u11s)- u12sh[uidm]*conj(u12s);
73 const Complex_f a12=-conj(u11sh[uidm])*u12s- u12sh[uidm]*u11s;
74 ind=didn+kvolHalo*nu;
75 u11s=u11t[ind]; u12s=u12t[ind];
76 Sigma11[i]+=a11*u11s-a12*conj(u12s);
77 Sigma12[i]+=a11*u12s+a12*conj(u11s);
78 }
79 }

References __BSIZE__, Complex_f, conj(), kvol, kvolHalo, and Minus_staple().

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

◆ Momentum_Update()

int Momentum_Update ( const double d,
const double * dSdpi,
double * pp )
inline

Wrapper for the momentum update during the integration step of the HMC.

Parameters
[in]dStep size
[in,out]ppMomentum field
[in]dSdpiForce field
Returns
Zero on success, integer error code otherwise.
Postcondition
pp update in place

Definition at line 71 of file integrate.c.

72{
73 const char funcname[] = "Momentum_Update";
74#ifdef USE_GPU
75 cublasDaxpy(cublas_handle,kmom, &d, dSdpi, 1, pp, 1);
77#elif defined USE_BLAS
78 cblas_daxpy(kmom, d, dSdpi, 1, pp, 1);
79#else
80#pragma omp parallel for simd
81 for(int i=0;i<kmom;i++)
82 pp[i]+=d*dSdpi[i];
83#endif
84 return 0;
85}
#define kmom
sublattice momentum sites
Definition sizes.h:197

References cudaDeviceSynchronise, kmom, and Momentum_Update().

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

◆ OMF2()

int OMF2 ( Complex * ut[2],
Complex_f * ut_f[2],
Complex * X0,
Complex * X1,
Complex * Phi,
double * dk[2],
float * dk_f[2],
double * dSdpi,
double * pp,
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,
const Complex jqq,
const float beta,
const float akappa,
const float c_sw,
const int stepl,
const float dt,
double * ancg,
int * itot,
const float proby )

OMF second order five step integrator.

Parameters
[in,out]utDouble precision colour fields
[in,out]ut_fSingle precision colour fields
[in]X0Up/down partitioned pseudofermion field
[in]X1Holder for the partitioned fermion field, then the conjugate gradient output
[in]PhiPseudofermion field
[in]dk\(\left(1+\gamma_0\right)e^{-\mu}\) and \(\left(1-\gamma_0\right)e^\mu\)
[in]dk_f\(\left(1+\gamma_0\right)e^{-\mu}\) and \(\left(1-\gamma_0\right)e^\mu\) float
[in,out]dSdpiThe force
[in,out]ppMomentum field
[in]iu,idLattice indices
[in]gaminGamma indices
[in]gamvalDouble precision gamma matrices rescaled by kappa
[in]gamval_fSingle precision gamma matrices rescaled by kappa
[in]sigval,sigval_fDouble/float Commutators 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]c_swClover coefficient
[in]jqqDiquark source
[in]akappaHopping parameter
[in]betaInverse gauge coupling
[in]steplSteps per trajectory
[in]dtStep size
[in]ancgCounter for average conjugate gradient iterations
[in]itotTotal average conjugate gradient iterations
[in]probyTermination probability for random trajectory length
Returns
Zero on success, integer error code otherwise
Postcondition
ut, ut_f, pp and dSdpi updated in place throughout the integration

Definition at line 141 of file integrate.c.

145 {
146 const char funcname[] = "OMF2";
147 const double lambda=0.5-(pow(2.0*sqrt(326.0)+36.0,1.0/3.0)/12.0)+1.0/(6*pow(2.0*sqrt(326.0) + 36.0,1.0/3.0));
148 //const double lambda=1.0/6.0;
149 // const double lambda=0.5;
150
151 //Gauge update by half dt
152 const double dU = dt*0.5;
153
154 //Momentum updates by lambda, 2lambda and (1-2lambda) in the middle
155 const double dp= -lambda*dt;
156 const double dp2= 2.0*dp;
157 const double dpm= -(1.0-2.0*lambda)*dt;
158 //Initial step forward for p
159 //=======================
160#ifdef _DEBUG
161 if(!rank){
162 double ave_dSdpi[3];
163 Force_debug(ave_dSdpi,dSdpi);
164 printf("Before evaluating force on rank %i, dSdpi[0] %e dSdpi[1] %e dSdpi[2] %e\n", rank,ave_dSdpi[0],ave_dSdpi[1],ave_dSdpi[2]);
165 double ave_pp[3];
166 Force_debug(ave_pp,pp);
167 printf("Average momentum pp[0] %e pp[1] %e pp[2] %e\n", ave_pp[0],ave_pp[1],ave_pp[2]);
168 }
169#endif
170 Force(dSdpi, 1, rescgg,X0,X1,Phi,ut,ut_f,iu,id,gamval,gamval_f,gamin,sigval,sigval_f,sigin,dk,dk_f,jqq,akappa,beta,c_sw,ancg);
171#ifdef _DEBUG
172 if(!rank){
173 double ave_dSdpi[3];
174 Force_debug(ave_dSdpi,dSdpi);
175 printf("Average force on rank %i, dSdpi[0] %e dSdpi[1] %e dSdpi[2] %e\n", rank,ave_dSdpi[0],ave_dSdpi[1],ave_dSdpi[2]);
176 }
177#endif
178 //Initial momentum update
179 Momentum_Update(dp,dSdpi,pp);
180#ifdef _DEBUG
181 if(!rank){
182 double ave_pp[3];
183 Force_debug(ave_pp,pp);
184 printf("Average initial momentum on rank %i, pp[0] %e pp[1] %e pp[2] %e\n", rank,ave_pp[0],ave_pp[1],ave_pp[2]);
185 }
186#endif
187
188 //Main loop for classical time evolution
189 //======================================
190 bool end_traj=false; int step =1;
191 // for(int step = 1; step<=stepmax; step++){
192 do{
193#ifdef _DEBUG
194 if(!rank)
195 printf("Step: %d\n", step);
196#endif
197 //First gauge update
198 Gauge_Update(dU,pp,ut,ut_f);
199
200 //Calculate force for middle momentum update
201 Force(dSdpi, 0, rescgg,X0,X1,Phi,ut,ut_f,iu,id,gamval,gamval_f,gamin,sigval,sigval_f,sigin,dk,dk_f,jqq,akappa,beta,c_sw,ancg);
202#ifdef _DEBUG
203 if(!rank){
204 double ave_dSdpi[3];
205 Force_debug(ave_dSdpi,dSdpi);
206 printf("First force update on rank %i, dSdpi[0] %e dSdpi[1] %e dSdpi[2] %e\n", rank,ave_dSdpi[0],ave_dSdpi[1],ave_dSdpi[2]);
207 }
208#endif
209 //Now do the middle momentum update
210 Momentum_Update(dpm,dSdpi,pp);
211#ifdef _DEBUG
212 if(!rank){
213 double ave_pp[3];
214 Force_debug(ave_pp,pp);
215 printf("Average middle momentum on rank %i, pp[0] %e pp[1] %e pp[2] %e\n", rank,ave_pp[0],ave_pp[1],ave_pp[2]);
216 }
217#endif
218
219 //Second gauge update
220 Gauge_Update(dU,pp,ut,ut_f);
221
222 //Calculate force for second momentum update
223 Force(dSdpi, 0, rescgg,X0,X1,Phi,ut,ut_f,iu,id,gamval,gamval_f,gamin,sigval,sigval_f,sigin,dk,dk_f,jqq,akappa,beta,c_sw,ancg);
224#ifdef _DEBUG
225 if(!rank){
226 double ave_dSdpi[3];
227 Force_debug(ave_dSdpi,dSdpi);
228 printf("Second force update on rank %i, dSdpi[0] %e dSdpi[1] %e dSdpi[2] %e\n", rank,ave_dSdpi[0],ave_dSdpi[1],ave_dSdpi[2]);
229 }
230#endif
231
232 //if(step>=stepl*4.0/5.0 && (step>=stepl*(6.0/5.0) || Par_granf()<proby)){
233 if(step==stepl){
234 //Final momentum step
235 Momentum_Update(dp,dSdpi,pp);
236#ifdef _DEBUG
237 if(!rank){
238 double ave_pp[3];
239 Force_debug(ave_pp,pp);
240 printf("Average final momentum on rank %i, pp[0] %e pp[1] %e pp[2] %e\n", rank,ave_pp[0],ave_pp[1],ave_pp[2]);
241 }
242#endif
243 *itot+=step;
244 //Two force terms, so an extra factor of two in the average?
245 //Or leave it as it was, to get the average CG iterations per trajectory rather than force
246 *ancg/=step;
247 end_traj=true;
248 break;
249 }
250 else{
251 //Since we apply the momentum at the start and end of a step we instead apply a double step here
252 Momentum_Update(dp2,dSdpi,pp);
253#ifdef _DEBUG
254 if(!rank){
255 double ave_pp[3];
256 Force_debug(ave_pp,pp);
257 printf("Average intermediate momentum on rank %i, pp[0] %e pp[1] %e pp[2] %e\n", rank,ave_pp[0],ave_pp[1],ave_pp[2]);
258 }
259#endif
260 step++;
261 }
262 }while(!end_traj);
263 return 0;
264 }
void Force_debug(double ave_dSdpi[3], double *dSdpi)
Gets average for each generator of the Lie algebra.
Definition integrate.c:19
int Gauge_Update(const double d, double *pp, Complex *ut[2], Complex_f *ut_f[2])
Gauge update for the integration step of the HMC.
Definition integrate.c:37
int Momentum_Update(const double d, const double *dSdpi, double *pp)
Wrapper for the momentum update during the integration step of the HMC.
Definition integrate.c:71
int Force(double *dSdpi, const bool iflag, double res1, Complex *X0, Complex *X1, Complex *Phi, Complex *ut[2], Complex_f *ut_f[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], const Complex_f jqq, const float akappa, const float beta, const float c_sw, double *ancg)
Calculates the force at each intermediate time.
Definition force.c:228
#define rescgg
Conjugate gradient residue for update.
Definition sizes.h:255

References Complex, Complex_f, Force(), Force_debug(), Gauge_Update(), Momentum_Update(), OMF2(), rank, and rescgg.

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

◆ OMF4()

int OMF4 ( Complex * ut[2],
Complex_f * ut_f[2],
Complex * X0,
Complex * X1,
Complex * Phi,
double * dk[2],
float * dk_f[2],
double * dSdpi,
double * pp,
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,
const Complex jqq,
const float beta,
const float akappa,
const float c_sw,
const int stepl,
const float dt,
double * ancg,
int * itot,
const float proby )

OMF fourth order eleven step integrator.

Parameters
[in,out]utDouble precision colour fields
[in,out]ut_fSingle precision colour fields
[in]X0Up/down partitioned pseudofermion field
[in]X1Holder for the partitioned fermion field, then the conjugate gradient output
[in]PhiPseudofermion field
[in]dk\(\left(1+\gamma_0\right)e^{-\mu}\) and \(\left(1-\gamma_0\right)e^\mu\)
[in]dk_f\(\left(1+\gamma_0\right)e^{-\mu}\) and \(\left(1-\gamma_0\right)e^\mu\) float
[in,out]dSdpiThe force
[in,out]ppMomentum field
[in]iu,idLattice indices
[in]gaminGamma indices
[in]gamvalDouble precision gamma matrices rescaled by kappa
[in]gamval_fSingle precision gamma matrices rescaled by kappa
[in]sigval,sigval_fDouble/float Commutators 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]c_swClover coefficient
[in]jqqDiquark source
[in]akappaHopping parameter
[in]betaInverse gauge coupling
[in]steplSteps per trajectory
[in]dtStep size
[in]ancgCounter for average conjugate gradient iterations
[in,out]itotTotal average conjugate gradient iterations
[in]probyTermination probability for random trajectory length
Returns
Zero on success, integer error code otherwise
Postcondition
ut, ut_f, pp and dSdpi updated in place throughout the integration

References Complex, Complex_f, cuGauge_Update(), dimBlock, dimGrid, and OMF4().

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

◆ Plus_staple()

__global__ void Kernels::Plus_staple ( const __grid_constant__ unsigned short mu,
const __grid_constant__ unsigned short nu,
const unsigned int * iu,
Complex_f * Sigma11,
Complex_f * Sigma12,
const Complex_f * u11t,
const Complex_f * u12t )

Calculates the staple in the positive \(\mu\) direction.

Parameters
[in]mu\(\mu\) direction
[in]nu\(\nu\) direction
[in]iuUpper indices
[in,out]Sigma11,Sigma12Staple output
[in]u11t,u12tGauge fields
Postcondition
Staples added to Sigma11 and Sigma12

Definition at line 23 of file cuforce.cu.

25 {
26 const unsigned int gsize = gridDim.x*gridDim.y*gridDim.z;
27 const unsigned int bsize = blockDim.x*blockDim.y*blockDim.z;
28 const unsigned int blockId = blockIdx.x+ blockIdx.y * gridDim.x+ gridDim.x * gridDim.y * blockIdx.z;
29 const unsigned int threadId= blockId * bsize+(threadIdx.z * blockDim.y+ threadIdx.y)* blockDim.x+ threadIdx.x;
30 for(unsigned int i=threadId;i<kvol;i+=gsize*bsize){
31 const unsigned int uidm = iu[mu*kvol+i];
32 unsigned int indn=uidm+kvolHalo*nu;
33 const unsigned int uidn = iu[nu*kvol+i];
34 unsigned int indm=uidn+kvolHalo*mu;
35 Complex_f a11=u11t[indn]*conj(u11t[indm])+\
36 u12t[indn]*conj(u12t[indm]);
37 Complex_f a12=-u11t[indn]*u12t[indm]+\
38 u12t[indn]*u11t[indm];
39 indn=i+kvolHalo*nu;
40 Sigma11[i]+=a11*conj(u11t[indn])+a12*conj(u12t[indn]);
41 Sigma12[i]+=-a11*u12t[indn]+a12*u11t[indn];
42 }
43 }

References __BSIZE__, Complex_f, conj(), kvol, kvolHalo, and Plus_staple().

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