QUDA  v0.7.0
A library for QCD on GPUs
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
color_spinor_util.cu
Go to the documentation of this file.
1 #include <color_spinor_field.h>
3 
4 namespace quda {
5 
6  template <typename Float>
10  ptr = new SpaceSpinColorOrder<Float>(const_cast<cpuColorSpinorField&>(a));
12  ptr = new SpaceColorSpinOrder<Float>(const_cast<cpuColorSpinorField&>(a));
14  ptr = new QOPDomainWallOrder<Float>(const_cast<cpuColorSpinorField&>(a));
15  else
16  errorQuda("Order %d not supported in cpuColorSpinorField", a.FieldOrder());
17  return ptr;
18  }
19 
20  // Random number insertion over all field elements
21  template <class T>
22  void random(T &t) {
23  for (int x=0; x<t.Volume(); x++) {
24  for (int s=0; s<t.Nspin(); s++) {
25  for (int c=0; c<t.Ncolor(); c++) {
26  for (int z=0; z<2; z++) {
27  t(x,s,c,z) = comm_drand();
28  }
29  }
30  }
31  }
32  }
33 
34  // Create a point source at spacetime point x, spin s and colour c
35  template <class T>
36  void point(T &t, int x, int s, int c) { t(x, s, c, 0) = 1.0; }
37 
38  void genericSource(cpuColorSpinorField &a, QudaSourceType sourceType, int x, int s, int c) {
39 
40  if (a.Precision() == QUDA_DOUBLE_PRECISION) {
41  ColorSpinorFieldOrder<double> *A = createOrder<double>(a);
42  if (sourceType == QUDA_RANDOM_SOURCE) random(*A);
43  else if (sourceType == QUDA_POINT_SOURCE) point(*A, x, s, c);
44  else errorQuda("Unsupported source type %d", sourceType);
45  delete A;
46  } else if (a.Precision() == QUDA_SINGLE_PRECISION) {
47  ColorSpinorFieldOrder<float> *A = createOrder<float>(a);
48  if (sourceType == QUDA_RANDOM_SOURCE) random(*A);
49  else if (sourceType == QUDA_POINT_SOURCE) point(*A, x, s, c);
50  else errorQuda("Unsupported source type %d", sourceType);
51  delete A;
52  } else {
53  errorQuda("Precision not supported");
54  }
55 
56  }
57 
58 
59  template <class U, class V>
60  int compareSpinor(const U &u, const V &v, const int tol) {
61  int fail_check = 16*tol;
62  int *fail = new int[fail_check];
63  for (int f=0; f<fail_check; f++) fail[f] = 0;
64 
65  int N = 2*u.Nspin()*u.Ncolor();
66  int *iter = new int[N];
67  for (int i=0; i<N; i++) iter[i] = 0;
68 
69  for (int x=0; x<u.Volume(); x++) {
70  //int test[u.Nspin()*u.Ncolor()*2];
71 
72  //printf("x = %d (", x);
73  for (int s=0; s<u.Nspin(); s++) {
74  for (int c=0; c<u.Ncolor(); c++) {
75  for (int z=0; z<2; z++) {
76  int j = (s*u.Ncolor() + c)*2+z;
77  //test[j] = 0;
78 
79  double diff = fabs(u(x,s,c,z) - v(x,s,c,z));
80 
81  for (int f=0; f<fail_check; f++) {
82  if (diff > pow(10.0,-(f+1)/(double)tol)) {
83  fail[f]++;
84  }
85  }
86 
87  if (diff > 1e-3) {
88  iter[j]++;
89  //printf("%d %d %e %e\n", x, j, u(x,s,c,z), v(x,s,c,z));
90  //test[j] = 1;
91  }
92  //printf("%d ", test[j]);
93 
94  }
95  }
96  }
97  // printf(")\n");
98  }
99 
100  for (int i=0; i<N; i++) printfQuda("%d fails = %d\n", i, iter[i]);
101 
102  int accuracy_level =0;
103  for (int f=0; f<fail_check; f++) {
104  if (fail[f] == 0) accuracy_level = f+1;
105  }
106 
107  for (int f=0; f<fail_check; f++) {
108  printfQuda("%e Failures: %d / %d = %e\n", pow(10.0,-(f+1)/(double)tol),
109  fail[f], u.Volume()*N, fail[f] / (double)(u.Volume()*N));
110  }
111 
112  delete []iter;
113  delete []fail;
114 
115  return accuracy_level;
116  }
117 
118  int genericCompare(const cpuColorSpinorField &a, const cpuColorSpinorField &b, int tol) {
119  int ret = 0;
120  if (a.Precision() == QUDA_DOUBLE_PRECISION) {
121  ColorSpinorFieldOrder<double> *A = createOrder<double>(a);
122  if (b.Precision() == QUDA_DOUBLE_PRECISION) {
123  ColorSpinorFieldOrder<double> *B = createOrder<double>(b);
124  ret = compareSpinor(*A, *B, tol);
125  delete B;
126  } else {
127  ColorSpinorFieldOrder<float> *B = createOrder<float>(b);
128  ret = compareSpinor(*A, *B, tol);
129  delete B;
130  }
131  delete A;
132  } else {
133  ColorSpinorFieldOrder<float> *A = createOrder<float>(a);
134  if (b.Precision() == QUDA_DOUBLE_PRECISION) {
135  ColorSpinorFieldOrder<double> *B = createOrder<double>(b);
136  ret = compareSpinor(*A, *B, tol);
137  delete B;
138  } else {
139  ColorSpinorFieldOrder<float> *B = createOrder<float>(b);
140  ret = compareSpinor(*A, *B, tol);
141  delete B;
142  }
143  delete A;
144  }
145  return ret;
146  }
147 
148 
149  template <class Order>
150  void print_vector(const Order &o, unsigned int x) {
151 
152  for (int s=0; s<o.Nspin(); s++) {
153  std::cout << "x = " << x << ", s = " << s << ", { ";
154  for (int c=0; c<o.Ncolor(); c++) {
155  std::cout << " ( " << o(x, s, c, 0) << " , " ;
156  if (c<o.Ncolor()-1) std::cout << o(x, s, c, 1) << " ) ," ;
157  else std::cout << o(x, s, c, 1) << " ) " ;
158  }
159  std::cout << " } " << std::endl;
160  }
161 
162  }
163 
164  // print out the vector at volume point x
165  void genericPrintVector(cpuColorSpinorField &a, unsigned int x) {
166 
167  if (a.Precision() == QUDA_DOUBLE_PRECISION) {
168  ColorSpinorFieldOrder<double> *A = createOrder<double>(a);
169  print_vector(*A, x);
170  delete A;
171  } else if (a.Precision() == QUDA_SINGLE_PRECISION) {
172  ColorSpinorFieldOrder<float> *A = createOrder<float>(a);
173  print_vector(*A, x);
174  delete A;
175  } else {
176  errorQuda("Precision %d not implemented", a.Precision());
177  }
178 
179  }
180 
181 
182 
183 } // namespace quda
int genericCompare(const cpuColorSpinorField &a, const cpuColorSpinorField &b, int tol)
int V
Definition: test_util.cpp:29
void print_vector(const Order &o, unsigned int x)
#define errorQuda(...)
Definition: util_quda.h:73
int compareSpinor(const U &u, const V &v, const int tol)
enum QudaSourceType_s QudaSourceType
void random(T &t)
__host__ __device__ ValueType pow(ValueType x, ExponentType e)
Definition: complex_quda.h:100
double comm_drand(void)
Definition: comm_common.cpp:81
void genericSource(cpuColorSpinorField &a, QudaSourceType sourceType, int x, int s, int c)
int x[4]
QudaFieldOrder FieldOrder() const
void genericPrintVector(cpuColorSpinorField &a, unsigned int x)
void point(T &t, int x, int s, int c)
ColorSpinorFieldOrder< Float > * createOrder(const cpuColorSpinorField &a)
QudaPrecision Precision() const
#define printfQuda(...)
Definition: util_quda.h:67
VOLATILE spinorFloat * s