QUDA  0.9.0
su3_test.cpp
Go to the documentation of this file.
1 #include <stdlib.h>
2 #include <stdio.h>
3 #include <time.h>
4 #include <math.h>
5 #include <string.h>
6 
7 #include <util_quda.h>
8 #include <test_util.h>
9 #include <dslash_util.h>
10 #include "misc.h"
11 
12 #include <qio_field.h>
13 
14 #if defined(QMP_COMMS)
15 #include <qmp.h>
16 #elif defined(MPI_COMMS)
17 #include <mpi.h>
18 #endif
19 
20 // In a typical application, quda.h is the only QUDA header required.
21 #include <quda.h>
22 
23 extern bool tune;
24 extern int device;
25 extern int xdim;
26 extern int ydim;
27 extern int zdim;
28 extern int tdim;
29 extern int gridsize_from_cmdline[];
32 extern QudaPrecision prec;
34 extern double anisotropy;
35 
36 extern char latfile[];
37 
38 #define MAX(a,b) ((a)>(b)?(a):(b))
39 
43 
45 
46  gauge_param.X[0] = xdim;
47  gauge_param.X[1] = ydim;
48  gauge_param.X[2] = zdim;
49  gauge_param.X[3] = tdim;
50 
55 
57 
60 
63 
65 
66  gauge_param.ga_pad = 0;
67  // For multi-GPU, ga_pad must be large enough to store a time-slice
68 #ifdef MULTI_GPU
69  int x_face_size = gauge_param.X[1]*gauge_param.X[2]*gauge_param.X[3]/2;
70  int y_face_size = gauge_param.X[0]*gauge_param.X[2]*gauge_param.X[3]/2;
71  int z_face_size = gauge_param.X[0]*gauge_param.X[1]*gauge_param.X[3]/2;
72  int t_face_size = gauge_param.X[0]*gauge_param.X[1]*gauge_param.X[2]/2;
73  int pad_size =MAX(x_face_size, y_face_size);
74  pad_size = MAX(pad_size, z_face_size);
75  pad_size = MAX(pad_size, t_face_size);
76  gauge_param.ga_pad = pad_size;
77 #endif
78 }
79 
80 
81 extern void usage(char**);
82 
83 void SU3test(int argc, char **argv) {
84 
85  for (int i = 1; i < argc; i++){
86  if(process_command_line_option(argc, argv, &i) == 0){
87  continue;
88  }
89  printf("ERROR: Invalid option:%s\n", argv[i]);
90  usage(argv);
91  }
92 
93  // initialize QMP/MPI, QUDA comms grid and RNG (test_util.cpp)
94  initComms(argc, argv, gridsize_from_cmdline);
95 
98  prec_sloppy = prec;
101 
105  sizeof(double) : sizeof(float);
106 
107  void *gauge[4], *new_gauge[4];
108 
109  for (int dir = 0; dir < 4; dir++) {
110  gauge[dir] = malloc(V*gaugeSiteSize*gSize);
111  new_gauge[dir] = malloc(V*gaugeSiteSize*gSize);
112  }
113 
114  initQuda(device);
115 
116  // call srand() with a rank-dependent seed
117  initRand();
118 
119  // load in the command line supplied gauge field
120  if (strcmp(latfile,"")) {
123  } else {
124  // generate a random SU(3) field
125  printf("Randomizing fields...");
127  printf("done.\n");
128  }
129 
130  loadGaugeQuda(gauge, &gauge_param);
131  saveGaugeQuda(new_gauge, &gauge_param);
132 
133 #ifdef GPU_GAUGE_TOOLS
134  double plaq[3];
135  plaqQuda(plaq);
136  printf("Computed plaquette is %e (spatial = %e, temporal = %e)\n", plaq[0], plaq[1], plaq[2]);
137 
138  // Topological charge
139  double qCharge;
140  // start the timer
141  double time0 = -((double)clock());
142  qCharge = qChargeCuda();
143  // stop the timer
144  time0 += clock();
145  time0 /= CLOCKS_PER_SEC;
146  printf("Computed topological charge is %.16e Done in %g secs\n", qCharge, time0);
147 
148  // Stout smearing should be equivalent to APE smearing
149  // on D dimensional lattices for rho = alpha/2*(D-1).
150  // Typical APE values are aplha=0.6, rho=0.1 for Stout.
151  unsigned int nSteps = 50;
152  double coeff_APE = 0.6;
153  double coeff_STOUT = coeff_APE/(2*(4-1));
156 
157  //STOUT
158  // start the timer
159  time0 = -((double)clock());
160  performSTOUTnStep(nSteps, coeff_STOUT);
161  // stop the timer
162  time0 += clock();
163  time0 /= CLOCKS_PER_SEC;
164  printfQuda("Total time for STOUT = %g secs\n", time0);
165  qCharge = qChargeCuda();
166  printf("Computed topological charge after is %.16e \n", qCharge);
167 
168  //APE
169  // start the timer
170  time0 = -((double)clock());
171  performAPEnStep(nSteps, coeff_APE);
172  // stop the timer
173  time0 += clock();
174  time0 /= CLOCKS_PER_SEC;
175  printfQuda("Total time for APE = %g secs\n", time0);
176  qCharge = qChargeCuda();
177  printf("Computed topological charge after is %.16e \n", qCharge);
178 
179  //Over Improved STOUT
180  double epsilon = -0.25;
181  coeff_STOUT = 0.06;
182  nSteps = 200;
183  // start the timer
184  time0 = -((double)clock());
185  performOvrImpSTOUTnStep(nSteps, coeff_STOUT, epsilon);
186  // stop the timer
187  time0 += clock();
188  time0 /= CLOCKS_PER_SEC;
189  printfQuda("Total time for Over Improved STOUT = %g secs\n", time0);
190  qCharge = qChargeCuda();
191  printf("Computed topological charge after is %.16e \n", qCharge);
192 
193 #else
194  printf("Skipping plaquette tests since gauge tools have not been compiled\n");
195 #endif
196 
197  check_gauge(gauge, new_gauge, 1e-3, gauge_param.cpu_prec);
198  freeGaugeQuda();
199  endQuda();
200 
201  // release memory
202  for (int dir = 0; dir < 4; dir++) {
203  free(gauge[dir]);
204  free(new_gauge[dir]);
205  }
206 
207  finalizeComms();
208 }
209 
210 int main(int argc, char **argv) {
211 
212  SU3test(argc, argv);
213 
214  return 0;
215 }
void performOvrImpSTOUTnStep(unsigned int nSteps, double rho, double epsilon)
QudaReconstructType reconstruct_sloppy
Definition: quda.h:46
double anisotropy
Definition: quda.h:31
void endQuda(void)
void free(void *)
void construct_gauge_field(void **gauge, int type, QudaPrecision precision, QudaGaugeParam *param)
Definition: test_util.cpp:1054
QudaVerbosity verbosity
enum QudaPrecision_s QudaPrecision
int ga_pad
Definition: quda.h:53
int tdim
Definition: test_util.cpp:1623
QudaGaugeFixed gauge_fix
Definition: quda.h:51
void usage(char **)
Definition: test_util.cpp:1693
QudaLinkType type
Definition: quda.h:35
QudaPrecision & cuda_prec_sloppy
Definition: su3_test.cpp:42
void performAPEnStep(unsigned int nSteps, double alpha)
void loadGaugeQuda(void *h_gauge, QudaGaugeParam *param)
int process_command_line_option(int argc, char **argv, int *idx)
Definition: test_util.cpp:1795
void plaqQuda(double plaq[3])
int zdim
Definition: test_util.cpp:1622
void finalizeComms()
Definition: test_util.cpp:107
QudaGaugeParam gauge_param
QudaGaugeFieldOrder gauge_order
Definition: quda.h:36
int gridsize_from_cmdline[]
Definition: test_util.cpp:50
int ydim
Definition: test_util.cpp:1621
double anisotropy
Definition: test_util.cpp:1644
void setDims(int *)
Definition: test_util.cpp:130
void freeGaugeQuda(void)
static size_t gSize
Definition: llfat_test.cpp:36
#define MAX(a, b)
Definition: su3_test.cpp:38
int strcmp(const char *__s1, const char *__s2)
void initQuda(int device)
void * malloc(size_t __size) __attribute__((__warn_unused_result__)) __attribute__((alloc_size(1)))
int xdim
Definition: test_util.cpp:1620
int printf(const char *,...) __attribute__((__format__(__printf__
void saveGaugeQuda(void *h_gauge, QudaGaugeParam *param)
void SU3test(int argc, char **argv)
Definition: su3_test.cpp:83
int V
Definition: test_util.cpp:28
#define gaugeSiteSize
Definition: test_util.h:6
QudaPrecision cuda_prec_sloppy
Definition: quda.h:45
QudaPrecision prec_sloppy
Definition: test_util.cpp:1616
double qChargeCuda()
void setGaugeParam(QudaGaugeParam &gauge_param)
Definition: su3_test.cpp:44
QudaReconstructType reconstruct
Definition: quda.h:43
QudaPrecision cuda_prec
Definition: quda.h:42
QudaReconstructType link_recon_sloppy
Definition: test_util.cpp:1613
int X[4]
Definition: quda.h:29
void check_gauge(void **oldG, void **newG, double epsilon, QudaPrecision precision)
Definition: test_util.cpp:1219
void performSTOUTnStep(unsigned int nSteps, double rho)
QudaPrecision & cuda_prec
Definition: su3_test.cpp:41
char latfile[]
Definition: test_util.cpp:1627
enum QudaReconstructType_s QudaReconstructType
Main header file for the QUDA library.
void initRand()
Definition: test_util.cpp:117
QudaReconstructType link_recon
Definition: test_util.cpp:1612
#define printfQuda(...)
Definition: util_quda.h:84
QudaTboundary t_boundary
Definition: quda.h:38
QudaPrecision prec
Definition: test_util.cpp:1615
enum QudaVerbosity_s QudaVerbosity
clock_t clock(void) __asm("_" "clock")
QudaPrecision & cpu_prec
Definition: su3_test.cpp:40
bool tune
void read_gauge_field(const char *filename, void *gauge[], QudaPrecision prec, const int *X, int argc, char *argv[])
Definition: qio_field.h:12
int main(int argc, char **argv)
Definition: su3_test.cpp:210
void initComms(int argc, char **argv, const int *commDims)
Definition: test_util.cpp:72
void setVerbosity(const QudaVerbosity verbosity)
Definition: util_quda.cpp:24
QudaPrecision cpu_prec
Definition: quda.h:40
QudaGaugeParam newQudaGaugeParam(void)