QUDA  1.0.0
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
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 bool verify_results;
37 
38 extern char latfile[];
39 extern bool unit_gauge;
40 
42 
43 #define MAX(a,b) ((a)>(b)?(a):(b))
44 
48 
50 
51  gauge_param.X[0] = xdim;
52  gauge_param.X[1] = ydim;
53  gauge_param.X[2] = zdim;
54  gauge_param.X[3] = tdim;
55 
56  gauge_param.anisotropy = anisotropy;
57  gauge_param.type = QUDA_WILSON_LINKS;
58  gauge_param.gauge_order = QUDA_QDP_GAUGE_ORDER;
59  gauge_param.t_boundary = QUDA_PERIODIC_T;
60 
61  gauge_param.cpu_prec = cpu_prec;
62 
63  gauge_param.cuda_prec = cuda_prec;
64  gauge_param.reconstruct = link_recon;
65 
66  gauge_param.cuda_prec_sloppy = cuda_prec_sloppy;
68 
69  gauge_param.gauge_fix = QUDA_GAUGE_FIXED_NO;
70 
71  gauge_param.ga_pad = 0;
72  // For multi-GPU, ga_pad must be large enough to store a time-slice
73 #ifdef MULTI_GPU
74  int x_face_size = gauge_param.X[1]*gauge_param.X[2]*gauge_param.X[3]/2;
75  int y_face_size = gauge_param.X[0]*gauge_param.X[2]*gauge_param.X[3]/2;
76  int z_face_size = gauge_param.X[0]*gauge_param.X[1]*gauge_param.X[3]/2;
77  int t_face_size = gauge_param.X[0]*gauge_param.X[1]*gauge_param.X[2]/2;
78  int pad_size =MAX(x_face_size, y_face_size);
79  pad_size = MAX(pad_size, z_face_size);
80  pad_size = MAX(pad_size, t_face_size);
81  gauge_param.ga_pad = pad_size;
82 #endif
83 }
84 
85 
86 extern void usage(char**);
87 
88 void SU3test(int argc, char **argv) {
89 
90  for (int i = 1; i < argc; i++){
91  if(process_command_line_option(argc, argv, &i) == 0){
92  continue;
93  }
94  printf("ERROR: Invalid option:%s\n", argv[i]);
95  usage(argv);
96  }
97 
98  // initialize QMP/MPI, QUDA comms grid and RNG (test_util.cpp)
99  initComms(argc, argv, gridsize_from_cmdline);
100 
103  prec_sloppy = prec;
106 
107  setGaugeParam(gauge_param);
108  setDims(gauge_param.X);
109  size_t gSize = gauge_param.cpu_prec;
110 
111  void *gauge[4], *new_gauge[4];
112 
113  for (int dir = 0; dir < 4; dir++) {
114  gauge[dir] = malloc(V*gaugeSiteSize*gSize);
115  new_gauge[dir] = malloc(V*gaugeSiteSize*gSize);
116  }
117 
118  initQuda(device);
119 
121 
122  // call srand() with a rank-dependent seed
123  initRand();
124 
125  // load in the command line supplied gauge field
126  if (strcmp(latfile,"")) {
127  read_gauge_field(latfile, gauge, gauge_param.cpu_prec, gauge_param.X, argc, argv);
128  construct_gauge_field(gauge, 2, gauge_param.cpu_prec, &gauge_param);
129  } else { // else generate an SU(3) field
130  if (unit_gauge) {
131  // unit SU(3) field
132  construct_gauge_field(gauge, 0, gauge_param.cpu_prec, &gauge_param);
133  } else {
134  // random SU(3) field
135  construct_gauge_field(gauge, 1, gauge_param.cpu_prec, &gauge_param);
136  }
137  }
138 
139  loadGaugeQuda(gauge, &gauge_param);
140  saveGaugeQuda(new_gauge, &gauge_param);
141 
142  double plaq[3];
143  plaqQuda(plaq);
144  printfQuda("Computed plaquette gauge precise is %e (spatial = %e, temporal = %e)\n", plaq[0], plaq[1], plaq[2]);
145 
146 #ifdef GPU_GAUGE_TOOLS
147 
148  // Topological charge
149  double qCharge = 0.0, qChargeCheck = 0.0;
150  // start the timer
151  double time0 = -((double)clock());
152  qCharge = qChargeQuda();
153  // stop the timer
154  time0 += clock();
155  time0 /= CLOCKS_PER_SEC;
156  printfQuda("Computed topological charge gauge precise is %.16e Done in %g secs\n", qCharge, time0);
157 
158  // Size of floating point data
159  size_t sSize = prec == QUDA_DOUBLE_PRECISION ? sizeof(double) : sizeof(float);
160  size_t array_size = V * sSize;
161  // Void array passed to the GPU. QUDA will allocate GPU memory and pass back a populated host array.
162  void *qDensity = malloc(array_size);
163  qCharge = qChargeDensityQuda(qDensity);
164 
165  // Ensure host array sums to return value
166  if (prec == QUDA_DOUBLE_PRECISION) {
167  for (int i = 0; i < V; i++) qChargeCheck += ((double *)qDensity)[i];
168  } else {
169  for (int i = 0; i < V; i++) qChargeCheck += ((float *)qDensity)[i];
170  }
171  printfQuda("Computed topological charge gauge precise from density function is %.16e\n", qCharge);
172  printfQuda("GPU value %e and host density sum %e. Q charge deviation: %e\n", qCharge, qChargeCheck,
173  qCharge - qChargeCheck);
174 
175  // Stout smearing should be equivalent to APE smearing
176  // on D dimensional lattices for rho = alpha/2*(D-1).
177  // Typical APE values are aplha=0.6, rho=0.1 for Stout.
178  unsigned int nSteps = 50;
179  double coeff_APE = 0.6;
180  double coeff_STOUT = coeff_APE/(2*(4-1));
181 
182  //STOUT
183  // start the timer
184  time0 = -((double)clock());
185  performSTOUTnStep(nSteps, coeff_STOUT);
186  // stop the timer
187  time0 += clock();
188  time0 /= CLOCKS_PER_SEC;
189  printfQuda("Total time for STOUT = %g secs\n", time0);
190  qCharge = qChargeQuda();
191  printf("Computed topological charge after is %.16e \n", qCharge);
192 
193  //APE
194  // start the timer
195  time0 = -((double)clock());
196  performAPEnStep(nSteps, coeff_APE);
197  // stop the timer
198  time0 += clock();
199  time0 /= CLOCKS_PER_SEC;
200  printfQuda("Total time for APE = %g secs\n", time0);
201  qCharge = qChargeQuda();
202  printfQuda("Computed topological charge after smearing is %.16e \n", qCharge);
203 
204  //Over Improved STOUT
205  double epsilon = -0.25;
206  coeff_STOUT = 0.06;
207  nSteps = 200;
208  // start the timer
209  time0 = -((double)clock());
210  performOvrImpSTOUTnStep(nSteps, coeff_STOUT, epsilon);
211  // stop the timer
212  time0 += clock();
213  time0 /= CLOCKS_PER_SEC;
214  printfQuda("Total time for Over Improved STOUT = %g secs\n", time0);
215  qCharge = qChargeQuda();
216  printfQuda("Computed topological charge after smearing is %.16e \n", qCharge);
217 
218 #else
219  printfQuda("Skipping other gauge tests since gauge tools have not been compiled\n");
220 #endif
221 
222  if (verify_results) check_gauge(gauge, new_gauge, 1e-3, gauge_param.cpu_prec);
223 
224  freeGaugeQuda();
225  endQuda();
226 
227  // release memory
228  for (int dir = 0; dir < 4; dir++) {
229  free(gauge[dir]);
230  free(new_gauge[dir]);
231  }
232 
233  finalizeComms();
234 }
235 
236 int main(int argc, char **argv) {
237 
238  SU3test(argc, argv);
239 
240  return 0;
241 }
static size_t gSize
void performOvrImpSTOUTnStep(unsigned int nSteps, double rho, double epsilon)
QudaReconstructType reconstruct_sloppy
Definition: quda.h:53
double anisotropy
Definition: quda.h:38
void endQuda(void)
void construct_gauge_field(void **gauge, int type, QudaPrecision precision, QudaGaugeParam *param)
Definition: test_util.cpp:1047
enum QudaPrecision_s QudaPrecision
int ga_pad
Definition: quda.h:63
int tdim
Definition: test_util.cpp:1618
bool verify_results
Definition: test_util.cpp:1643
QudaGaugeFixed gauge_fix
Definition: quda.h:61
void usage(char **)
Definition: test_util.cpp:1783
QudaLinkType type
Definition: quda.h:42
QudaPrecision & cuda_prec_sloppy
Definition: su3_test.cpp:47
void performAPEnStep(unsigned int nSteps, double alpha)
void loadGaugeQuda(void *h_gauge, QudaGaugeParam *param)
double epsilon
Definition: test_util.cpp:1649
int process_command_line_option(int argc, char **argv, int *idx)
Definition: test_util.cpp:2019
void plaqQuda(double plaq[3])
int zdim
Definition: test_util.cpp:1617
void finalizeComms()
Definition: test_util.cpp:128
QudaGaugeParam gauge_param
QudaGaugeFieldOrder gauge_order
Definition: quda.h:43
int gridsize_from_cmdline[]
Definition: test_util.cpp:49
int ydim
Definition: test_util.cpp:1616
int device
Definition: test_util.cpp:1602
double anisotropy
Definition: test_util.cpp:1650
void setDims(int *)
Definition: test_util.cpp:151
void freeGaugeQuda(void)
bool unit_gauge
Definition: test_util.cpp:1624
#define MAX(a, b)
Definition: su3_test.cpp:43
void initQuda(int device)
int xdim
Definition: test_util.cpp:1615
void saveGaugeQuda(void *h_gauge, QudaGaugeParam *param)
void SU3test(int argc, char **argv)
Definition: su3_test.cpp:88
QudaPrecision cuda_prec_sloppy
Definition: quda.h:52
QudaPrecision prec_sloppy
Definition: test_util.cpp:1609
void setGaugeParam(QudaGaugeParam &gauge_param)
Definition: su3_test.cpp:49
QudaReconstructType reconstruct
Definition: quda.h:50
QudaPrecision cuda_prec
Definition: quda.h:49
QudaReconstructType link_recon_sloppy
Definition: test_util.cpp:1606
int X[4]
Definition: quda.h:36
QudaPrecision cpu_prec
Definition: su3_test.cpp:45
void check_gauge(void **oldG, void **newG, double epsilon, QudaPrecision precision)
Definition: test_util.cpp:1220
int V
Definition: test_util.cpp:27
void performSTOUTnStep(unsigned int nSteps, double rho)
QudaPrecision & cuda_prec
Definition: su3_test.cpp:46
char latfile[]
Definition: test_util.cpp:1623
enum QudaReconstructType_s QudaReconstructType
Main header file for the QUDA library.
void initRand()
Definition: test_util.cpp:138
QudaReconstructType link_recon
Definition: test_util.cpp:1605
#define printfQuda(...)
Definition: util_quda.h:115
QudaTboundary t_boundary
Definition: quda.h:45
double qChargeQuda()
QudaPrecision prec
Definition: test_util.cpp:1608
enum QudaVerbosity_s QudaVerbosity
QudaVerbosity verbosity
Definition: test_util.cpp:1614
bool tune
void initComms(int argc, char **argv, int *const commDims)
Definition: test_util.cpp:88
double qChargeDensityQuda(void *qDensity)
Calculates the topological charge from gaugeSmeared, if it exist, or from gaugePrecise if no smeared ...
void read_gauge_field(const char *filename, void *gauge[], QudaPrecision prec, const int *X, int argc, char *argv[])
Definition: qio_field.h:14
int main(int argc, char **argv)
Definition: su3_test.cpp:236
void setVerbosity(QudaVerbosity verbosity)
Definition: util_quda.cpp:25
QudaPrecision cpu_prec
Definition: quda.h:47
#define gaugeSiteSize
Definition: face_gauge.cpp:34
QudaGaugeParam newQudaGaugeParam(void)