QUDA  v0.7.0
A library for QCD on GPUs
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
qio_util.cpp
Go to the documentation of this file.
1 /* Utilities for testing QIO */
2 #include <stdio.h>
3 #include <string.h>
4 
5 #include <qio_util.h>
6 
8 {
9  int i;
10 
11  for ( i=0; i< NCLR; i++)
12  {
13  printf("%f %f %f %f %f %f\n",a->e[i][0].re,a->e[i][0].im,a->e[i][1].re,a->e[i][1].im,a->e[i][2].re,a->e[i][2].im);
14  }
15 
16  return;
17 }
18 
19 
20 void vfill_m(suN_matrix *a, int coords[], int rank)
21 {
22  int i,j;
23 
24  for ( j=0; j< NCLR; j++)
25  for ( i=0; i< NCLR; i++)
26  {
27  a->e[j][i].re = 0.0;
28  a->e[j][i].im = 0.0;
29  }
30 
31  for ( j=0; j< NCLR; j++)
32  a->e[j][j].re = 100*rank + coords[0] +
33  lattice_size[0]*(coords[1] + lattice_size[1]*
34  (coords[2] + lattice_size[2]*coords[3]));
35  return;
36 }
37 
38 
39 void vset_M(suN_matrix *field[], int count)
40 {
41  int x[4];
42  int index,i;
43 
44  for(i = 0; i < count; i++)
45  for(x[3] = 0; x[3] < lattice_size[3]; x[3]++)
46  for(x[2] = 0; x[2] < lattice_size[2]; x[2]++)
47  for(x[1] = 0; x[1] < lattice_size[1]; x[1]++)
48  for(x[0] = 0; x[0] < lattice_size[0]; x[0]++)
49  {
50  if(node_number(x) == this_node){
51  index = node_index(x);
52  vfill_m(field[i] + index, x, i);
53  }
54  }
55 }
56 
57 int vcreate_M(suN_matrix *field[], int count)
58 {
59  int i;
60  /* Create an output field */
61  for(i = 0; i < count; i++){
62  field[i] = (suN_matrix *)malloc(sizeof(suN_matrix)*num_sites(this_node));
63  if(field[i] == NULL){
64  printf("vcreate_M(%d): Can't malloc field\n",this_node);
65  return 1;
66  }
67  }
68 
69  return 0;
70 }
71 
72 /* destroy array of fields */
73 void vdestroy_M (suN_matrix *field[], int count)
74 {
75  int i;
76  for(i = 0; i < count; i++)
77  free(field[i]);
78 }
79 
80 
81 float vcompare_M (suN_matrix *fielda[], suN_matrix *fieldb[], int count)
82 {
83  int i,j,k,m;
84  float diff;
85  float sum2 = 0;
86 
87  for(k = 0; k < count; k++)for(m = 0; m < num_sites(this_node); m++)
88  {
89  for ( j=0; j< NCLR; j++)
90  for ( i=0; i< NCLR; i++)
91  {
92  diff = fielda[k][m].e[j][i].re - fieldb[k][m].e[j][i].re;
93  sum2 += diff*diff;
94  diff = fielda[k][m].e[j][i].im - fieldb[k][m].e[j][i].im;
95  sum2 += diff*diff;
96  }
97  }
98 
99  /* Global sum */
100  QMP_sum_float(&sum2);
101  return sum2;
102 }
103 
104 void vput_M(char *s1, size_t index, int count, void *s2)
105 {
106  suN_matrix **field = (suN_matrix **)s2;
107  suN_matrix *dest;
108  suN_matrix *src = (suN_matrix *)s1;
109  int i;
110 
111 /* For the site specified by "index", move an array of "count" data
112  from the read buffer to an array of fields */
113 
114  for (i=0;i<count;i++)
115  {
116  dest = field[i] + index;
117  *dest = *(src + i);
118  }
119 }
120 
121 void vget_M(char *s1, size_t index, int count, void *s2)
122 {
123  suN_matrix **field = (suN_matrix **)s2;
124  suN_matrix *src;
125  suN_matrix *dest = (suN_matrix *)s1;
126  int i;
127 
128 /* For the site specified by "index", move an array of "count" data
129  from the array of fields to the write buffer */
130  for (i=0; i<count; i++, dest++)
131  {
132  src = field[i] + index;
133  *dest = *src;
134  }
135 }
136 
137 /* Copy a subset */
138 int inside_subset(int x[], int lower[], int upper[])
139 {
140  int i;
141  int status = 1;
142 
143  for(i = 0; i < 4; i++)
144  if(lower[i] > x[i] || upper[i] < x[i]){
145  status = 0;
146  break;
147  }
148 
149  return status;
150 }
151 
void vset_M(suN_matrix *field[], int count)
Definition: qio_util.cpp:39
complex e[NCLR][NCLR]
Definition: qio_util.h:22
int inside_subset(int x[], int lower[], int upper[])
Definition: qio_util.cpp:138
void vput_M(char *s1, size_t index, int count, void *s2)
Definition: qio_util.cpp:104
void vdestroy_M(suN_matrix *field[], int count)
Definition: qio_util.cpp:73
void vget_M(char *s1, size_t index, int count, void *s2)
Definition: qio_util.cpp:121
__device__ unsigned int count
Definition: reduce_core.h:112
void vfill_m(suN_matrix *a, int coords[], int rank)
Definition: qio_util.cpp:20
int x[4]
#define NCLR
Definition: qio_util.h:14
int this_node
Definition: gauge_qio.cpp:9
int node_index(const int x[])
Definition: layout_hyper.c:204
float im
Definition: qio_util.h:19
void print_m(suN_matrix *a)
Definition: qio_util.cpp:7
int node_number(const int x[])
Definition: layout_hyper.c:194
int vcreate_M(suN_matrix *field[], int count)
Definition: qio_util.cpp:57
float vcompare_M(suN_matrix *fielda[], suN_matrix *fieldb[], int count)
Definition: qio_util.cpp:81
int num_sites(int node)
Definition: layout_hyper.c:272
float re
Definition: qio_util.h:18
int lattice_size[4]
Definition: gauge_qio.cpp:8