19#include <cuda_runtime.h>
20cublasHandle_t cublas_handle;
21cublasStatus_t cublas_status;
26int main(
int argc,
char *argv[]){
27 const char funcname[] =
"main";
30#error nproc>1 in sizes.h. Ensure npx=npy=npt=npt=1, and then compile.
36 cublasCreate(&cublas_handle);
41 cudaGetDevice(&device);
47 cudaDeviceGetDefaultMemPool(&mempool, device);
49 cudaMemPoolSetAttribute(mempool, cudaMemPoolAttrReleaseThreshold, &threshold);
52 const char *filename = (argc!=2) ?
"midout":argv[1];
54 if( !(midout = fopen(filename, fileop) ) ){
55 fprintf(stderr,
"Error %i in %s: Failed to open file %s for %s.\nExiting\n\n",\
62 float kappa = 0.1780f;
72 fscanf(midout,
"%f %f %f %f %f %f %f %d %d %d %d %d", &dt, &beta, &kappa,\
73 &jqq, &c_sw, &mu, &delb, &stepl, &ntraj, &istart, &icheck, &iread);
75 assert(stepl>0); assert(ntraj>0); assert(istart>=0); assert(icheck>0); assert(iread>=0);
77 const int ibound = -1;
80 printf(
"Reading %d configs\n",ntraj);
100 unsigned int *iu, *id;
105 cudaMallocManaged((
void**)&iu,
ndim*
kvol*
sizeof(
int),cudaMemAttachGlobal);
106 cudaMallocManaged((
void**)&
id,
ndim*
kvol*
sizeof(
int),cudaMemAttachGlobal);
108 cudaMallocManaged((
void **)&dk[0],(
kvolHalo)*
sizeof(
double),cudaMemAttachGlobal);
109 cudaMallocManaged((
void **)&dk[1],(
kvolHalo)*
sizeof(
double),cudaMemAttachGlobal);
111 cudaMallocManaged((
void **)&dk_f[0],(
kvolHalo)*
sizeof(
float),cudaMemAttachGlobal);
112 cudaMallocManaged((
void **)&dk_f[1],(
kvolHalo)*
sizeof(
float),cudaMemAttachGlobal);
114 cudaMalloc((
void **)&dk_f[0],(
kvolHalo)*
sizeof(
float));
115 cudaMalloc((
void **)&dk_f[1],(
kvolHalo)*
sizeof(
float));
119 cudaMallocManaged((
void **)&gamin,4*4*
sizeof(
short),cudaMemAttachGlobal);
120 cudaMallocManaged((
void **)&gamval,5*4*
sizeof(
Complex),cudaMemAttachGlobal);
121 cudaMallocManaged((
void **)&gamval_f,5*4*
sizeof(
Complex_f),cudaMemAttachGlobal);
123 cudaMallocManaged((
void **)&u[0],
ndim*
kvol*
sizeof(
Complex),cudaMemAttachGlobal);
124 cudaMallocManaged((
void **)&u[1],
ndim*
kvol*
sizeof(
Complex),cudaMemAttachGlobal);
131 cudaMallocManaged((
void **)&Phi,
nf*
kferm*
sizeof(
Complex),cudaMemAttachGlobal);
138 id = (
unsigned int*)aligned_alloc(
AVX,
ndim*
kvol*
sizeof(
int));
139 iu = (
unsigned int*)aligned_alloc(
AVX,
ndim*
kvol*
sizeof(
int));
143 dk[0] = (
double *)aligned_alloc(
AVX,(
kvolHalo)*
sizeof(
double));
144 dk[1] = (
double *)aligned_alloc(
AVX,(
kvolHalo)*
sizeof(
double));
145 dk_f[0] = (
float *)aligned_alloc(
AVX,(
kvolHalo)*
sizeof(
float));
146 dk_f[1] = (
float *)aligned_alloc(
AVX,(
kvolHalo)*
sizeof(
float));
176 Init(istart,ibound,iread,beta,mu,kappa,jqq,c_sw,u,ut,ut_f,gamval,gamval_f,gamin,dk,dk_f,iu,
id);
183 Init_CUDA(ut[0],ut[1],gamval,gamval_f,gamin,dk[0],dk[1],iu,
id);
190 for(
unsigned short mu=0;mu<
ndim;mu++){
199 for(
unsigned short mu=0;mu<
ndim;mu++){
209 int buffer;
char buff2[7];
211 buffer = (int)round(100*beta);
212 sprintf(buff2,
"b%03d",buffer);
213 strcat(suffix,buff2);
215 buffer = (int)round(10000*kappa);
216 sprintf(buff2,
"k%04d",buffer);
217 strcat(suffix,buff2);
219 buffer = (int)round(1000*mu);
220 sprintf(buff2,
"mu%04d",buffer);
221 strcat(suffix,buff2);
223 buffer = (int)round(1000*jqq);
224 sprintf(buff2,
"j%03d",buffer);
225 strcat(suffix,buff2);
228 buffer = (int)round(100*c_sw);
229 sprintf(buff2,
"c%03d",buffer);
230 strcat(suffix,buff2);
233 sprintf(buff2,
"s%02d",
nx);
234 strcat(suffix,buff2);
236 sprintf(buff2,
"t%02d",
nt);
237 strcat(suffix,buff2);
238 for(
unsigned int i=iread;i<=ntraj;i+=icheck){
239 const unsigned int conf = i;
241 printf(
"Reading config %d\n",conf);
242 Par_sread(conf, beta, mu, kappa, jqq,c_sw,u[0],u[1],ut[0],ut[1]);
251 double hg, avplaqs, avplaqt;
256 double endenf=0, denf=0;
259 int measure_check=
Measure(&pbp,&endenf,&denf,&qq,&qbqb,
respbp,&itercg,ut,ut_f,iu,
id,\
260 gamval,gamval_f,gamin,sigval,sigval_f,sigin,dk,dk_f,jqq,kappa,c_sw,Phi);
261#pragma omp parallel for
262 for(
unsigned short j=0; j<3; j++)
268 char fortname[
FILELEN] =
"ext_fermi.";
269 strcat(fortname,suffix);
270 const char *fortop= (i==0) ?
"w" :
"a";
271 if(!(fortout=fopen(fortname, fortop) )){
272 fprintf(stderr,
"Error %i in %s: Failed to open file %s for %s.\nExiting\n\n",\
281 fprintf(fortout,
"pbp\tendenf\tdenf\n");
283 fprintf(fortout,
"%e\t%e\t%e\n", NAN, NAN, NAN);
285 fprintf(fortout,
"%e\t%e\t%e\n", pbp, endenf, denf);
295 char fortname[
FILELEN] =
"ext_bose.";
296 strcat(fortname,suffix);
297 const char *fortop= (i==0) ?
"w" :
"a";
298 if(!(fortout=fopen(fortname, fortop) )){
299 fprintf(stderr,
"Error %i in %s: Failed to open file %s for %s.\nExiting\n\n",\
303 fprintf(fortout,
"avplaqs\tavplaqt\tpoly\n");
304 fprintf(fortout,
"%e\t%e\t%e\n", avplaqs, avplaqt, poly);
311 char fortname[
FILELEN] =
"ext_diq.";
312 strcat(fortname,suffix);
313 const char *fortop= (i==0) ?
"w" :
"a";
314 if(!(fortout=fopen(fortname, fortop) )){
315 fprintf(stderr,
"Error %i in %s: Failed to open file %s for %s.\nExiting\n\n",\
324 fprintf(fortout,
"Re(qq)\n");
326 fprintf(fortout,
"%e\n", NAN);
328 fprintf(fortout,
"%e\n",
creal(qq));
337 cudaFree(dk[0]); cudaFree(dk[1]);
338 cudaFree(Phi); cudaFree(ut[0]); cudaFree(ut[1]);
339 cudaFree(u[0]); cudaFree(u[1]);
340 cudaFree(
id); cudaFree(iu);
341 cudaFree(dk_f[0]); cudaFree(dk_f[1]); cudaFree(ut_f[0]); cudaFree(ut_f[1]);
342 cudaFree(gamin); cudaFree(gamval); cudaFree(gamval_f);
344 cudaFree(sigval); cudaFree(sigval_f); cudaFree(sigin);
346 cublasDestroy(cublas_handle);
348 free(dk[0]); free(dk[1]);
349 free(Phi); free(ut[0]); free(ut[1]);
350 free(u[0]); free(u[1]);
352 free(dk_f[0]); free(dk_f[1]); free(ut_f[0]); free(ut_f[1]);
354 free(sigval); free(sigval_f); free(sigin);
Routines needed for Clover improved wilson fermions.
unsigned int * hd
Down halo indices.
unsigned int * hu
Up halo indices.
#define OPENERROR
Error opening file.
double Polyakov(Complex_f *ut[2])
Calculate the Polyakov loop (no prizes for guessing that one...).
int Average_Plaquette(double *hg, double *avplaqs, double *avplaqt, Complex_f *ut[2], unsigned int *iu, float beta)
Calculates the gauge action using new (how new?) lookup table Follows a routine called qedplaq in som...
int Init_clover(Complex **sigval, Complex_f **sigval_f, unsigned short **sigin, float c_sw)
Initialise values needed for the clover terms.
int Measure(double *pbp, double *endenf, double *denf, Complex *qq, Complex *qbqb, double res, int *itercg, 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], Complex_f jqq, float akappa, float c_sw, Complex *Phi)
Calculate fermion expectation values via a noisy estimator.
void blockInit(int x, int y, int z, int t, dim3 *dimBlock, dim3 *dimGrid)
Initialises the CUDA grid and block size for a given lattice.
void Init_CUDA(Complex *u11t, Complex *u12t, Complex gamval[20], Complex_f gamval_f[20], unsigned short gamin[16], double *dk4m, double *dk4p, unsigned int *iu, unsigned int *id)
Initialise CUDA cuInit was taken already by CUDA (unsurprisingly).
int Init(const int istart, const int ibound, const int iread, const float beta, const float fmu, const float akappa, const Complex_f ajq, const float c_sw, Complex *u[2], Complex *ut[2], Complex_f *ut_f[2], Complex gamval[20], Complex_f gamval_f[20], unsigned short gamin[16], double *dk[2], float *dk_f[2], unsigned int *iu, unsigned int *id)
Initialises the system.
int Reunitarise(Complex *ut[2])
Reunitarises u11t and u12t as in conj(u11t[i])*u11t[i]+conj(u12t[i])*u12t[i]=1.
int Check_addr(unsigned int *table, int lns, int lnt, int imin, int imax)
Checks that the addresses are within bounds before an update.
int Addrc(unsigned int *iu, unsigned int *id)
Loads the addresses required during the update.
int Par_begin(int argc, char *argv[])
Initialises the MPI configuration.
int Trial_Exchange(Complex *ut[2], Complex_f *ut_f[2])
Exchanges the trial fields.
int Par_sread(const int iread, const float beta, const float fmu, const float akappa, const Complex_f ajq, const float c_sw, Complex *u11, Complex *u12, Complex *u11t, Complex *u12t)
Reads and assigns the gauges from file.
Matrix multiplication and related declarations.
int * pcoord
The processor grid.
gsl_rng * ranlux_instd
RANLUX instance.
#define AVX
Alignment of arrays. 64 for AVX-512, 32 for AVX/AVX2. 16 for SSE. Since AVX is standard on modern x86...
#define nt
Lattice temporal extent. This also corresponds to the inverse temperature.
#define nx
Lattice x extent.
#define ksizet
Sublattice t extent.
#define kvol
Sublattice volume.
#define Complex
Double precision complex number.
#define kferm
sublattice size including Gor'kov indices
#define ksize
Sublattice spatial extent for a cubic lattice.
#define nf
Fermion flavours (double it).
#define cudaDeviceSynchronise()
Get rid of that bastardised yankee English.
#define respbp
Conjugate gradient residue for .
#define FILELEN
Default file name length.
#define Complex_f
Single precision complex number.
dim3 dimGrid
Default grid size. First component is normally nt. Second and third depend whatever is needed to get ...
#define kvolHalo
Subvolume + halo size.
#define kfermHalo
Gor'kov lattice and halo.
#define nz
Lattice z extent. We normally use cubic lattices so this is the same as nx.
#define ny
Lattice y extent. We normally use cubic lattices so this is the same as nx.
dim3 dimBlock
Default block size. Usually 128.
cudaStream_t streams[ndirac *ndim *nadj]
An array of concurrent GPU streams to keep it busy.
#define creal(z)
Extract Real Component using C standard notation.