QUDA v0.4.0
A library for QCD on GPUs
|
00001 /* Utilities for testing QIO */ 00002 #include <stdio.h> 00003 #include <string.h> 00004 00005 #include <qio_util.h> 00006 00007 void print_m(suN_matrix *a) 00008 { 00009 int i; 00010 00011 for ( i=0; i< NCLR; i++) 00012 { 00013 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); 00014 } 00015 00016 return; 00017 } 00018 00019 00020 void vfill_m(suN_matrix *a, int coords[], int rank) 00021 { 00022 int i,j; 00023 00024 for ( j=0; j< NCLR; j++) 00025 for ( i=0; i< NCLR; i++) 00026 { 00027 a->e[j][i].re = 0.0; 00028 a->e[j][i].im = 0.0; 00029 } 00030 00031 for ( j=0; j< NCLR; j++) 00032 a->e[j][j].re = 100*rank + coords[0] + 00033 lattice_size[0]*(coords[1] + lattice_size[1]* 00034 (coords[2] + lattice_size[2]*coords[3])); 00035 return; 00036 } 00037 00038 00039 void vset_M(suN_matrix *field[], int count) 00040 { 00041 int x[4]; 00042 int index,i; 00043 00044 for(i = 0; i < count; i++) 00045 for(x[3] = 0; x[3] < lattice_size[3]; x[3]++) 00046 for(x[2] = 0; x[2] < lattice_size[2]; x[2]++) 00047 for(x[1] = 0; x[1] < lattice_size[1]; x[1]++) 00048 for(x[0] = 0; x[0] < lattice_size[0]; x[0]++) 00049 { 00050 if(node_number(x) == this_node){ 00051 index = node_index(x); 00052 vfill_m(field[i] + index, x, i); 00053 } 00054 } 00055 } 00056 00057 int vcreate_M(suN_matrix *field[], int count) 00058 { 00059 int i; 00060 /* Create an output field */ 00061 for(i = 0; i < count; i++){ 00062 field[i] = (suN_matrix *)malloc(sizeof(suN_matrix)*num_sites(this_node)); 00063 if(field[i] == NULL){ 00064 printf("vcreate_M(%d): Can't malloc field\n",this_node); 00065 return 1; 00066 } 00067 } 00068 00069 return 0; 00070 } 00071 00072 /* destroy array of fields */ 00073 void vdestroy_M (suN_matrix *field[], int count) 00074 { 00075 int i; 00076 for(i = 0; i < count; i++) 00077 free(field[i]); 00078 } 00079 00080 00081 float vcompare_M (suN_matrix *fielda[], suN_matrix *fieldb[], int count) 00082 { 00083 int i,j,k,m; 00084 float diff; 00085 float sum2 = 0; 00086 00087 for(k = 0; k < count; k++)for(m = 0; m < num_sites(this_node); m++) 00088 { 00089 for ( j=0; j< NCLR; j++) 00090 for ( i=0; i< NCLR; i++) 00091 { 00092 diff = fielda[k][m].e[j][i].re - fieldb[k][m].e[j][i].re; 00093 sum2 += diff*diff; 00094 diff = fielda[k][m].e[j][i].im - fieldb[k][m].e[j][i].im; 00095 sum2 += diff*diff; 00096 } 00097 } 00098 00099 /* Global sum */ 00100 QMP_sum_float(&sum2); 00101 return sum2; 00102 } 00103 00104 void vput_M(char *s1, size_t index, int count, void *s2) 00105 { 00106 suN_matrix **field = (suN_matrix **)s2; 00107 suN_matrix *dest; 00108 suN_matrix *src = (suN_matrix *)s1; 00109 int i; 00110 00111 /* For the site specified by "index", move an array of "count" data 00112 from the read buffer to an array of fields */ 00113 00114 for (i=0;i<count;i++) 00115 { 00116 dest = field[i] + index; 00117 *dest = *(src + i); 00118 } 00119 } 00120 00121 void vget_M(char *s1, size_t index, int count, void *s2) 00122 { 00123 suN_matrix **field = (suN_matrix **)s2; 00124 suN_matrix *src; 00125 suN_matrix *dest = (suN_matrix *)s1; 00126 int i; 00127 00128 /* For the site specified by "index", move an array of "count" data 00129 from the array of fields to the write buffer */ 00130 for (i=0; i<count; i++, dest++) 00131 { 00132 src = field[i] + index; 00133 *dest = *src; 00134 } 00135 } 00136 00137 /* Copy a subset */ 00138 int inside_subset(int x[], int lower[], int upper[]) 00139 { 00140 int i; 00141 int status = 1; 00142 00143 for(i = 0; i < 4; i++) 00144 if(lower[i] > x[i] || upper[i] < x[i]){ 00145 status = 0; 00146 break; 00147 } 00148 00149 return status; 00150 } 00151