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