QUDA v0.4.0
A library for QCD on GPUs
quda/tests/gauge_qio.cpp
Go to the documentation of this file.
00001 #include <qio.h>
00002 #include <qio_util.h>
00003 #include <quda.h>
00004 #include <util_quda.h>
00005 
00006 QIO_Layout layout;
00007 int lattice_dim;
00008 int lattice_size[4];
00009 int this_node;
00010 
00011 QIO_Reader *open_test_input(char *filename, int volfmt, int serpar,
00012                             char *myname){
00013   QIO_String *xml_file_in;
00014   QIO_Reader *infile;
00015   QIO_Iflag iflag;
00016 
00017   iflag.serpar = serpar;
00018   iflag.volfmt = volfmt;
00019 
00020   /* Create the file XML */
00021   xml_file_in = QIO_string_create();
00022 
00023   /* Open the file for reading */
00024   infile = QIO_open_read(xml_file_in, filename, &layout, NULL, &iflag);
00025   if(infile == NULL){
00026     printf("%s(%d): QIO_open_read returns NULL.\n",myname,this_node);
00027     return NULL;
00028   }
00029 
00030   printfQuda("%s: QIO_open_read done.\n",myname,this_node);
00031   printfQuda("%s: User file info is \"%s\"\n", myname, QIO_string_ptr(xml_file_in));
00032 
00033   QIO_string_destroy(xml_file_in);
00034   return infile;
00035 }
00036 
00037 /* get QIO record precision */
00038 QudaPrecision get_prec(QIO_Reader *infile) {
00039   QIO_RecordInfo *rec_info = QIO_create_record_info(0, NULL, NULL, 0, "", "", 0, 0, 0, 0);
00040   QIO_String *xml_file = QIO_string_create();
00041   int status = QIO_read_record_info(infile, rec_info, xml_file);
00042   int prec = *QIO_get_precision(rec_info);
00043   QIO_destroy_record_info(rec_info);
00044   QIO_string_destroy(xml_file);
00045 
00046   return (prec == 70) ? QUDA_SINGLE_PRECISION : QUDA_DOUBLE_PRECISION;
00047 }
00048 
00049 int read_su3_field(QIO_Reader *infile, int count, void *field_in[], QudaPrecision cpu_prec, char *myname)
00050 {
00051   QIO_String *xml_record_in;
00052   QIO_RecordInfo rec_info;
00053   int status;
00054   
00055   /* Query the precision */
00056   QudaPrecision file_prec = get_prec(infile);
00057   size_t rec_size = file_prec*count*18;
00058 
00059   /* Create the record XML */
00060   xml_record_in = QIO_string_create();
00061 
00062   /* Read the field record and convert to cpu precision*/
00063   if (cpu_prec == QUDA_DOUBLE_PRECISION) {
00064     if (file_prec == QUDA_DOUBLE_PRECISION) {
00065       status = QIO_read(infile, &rec_info, xml_record_in, vputM<double,double,18>, 
00066                         rec_size, QUDA_DOUBLE_PRECISION, field_in);
00067     } else {
00068       status = QIO_read(infile, &rec_info, xml_record_in, vputM<double,float,18>, 
00069                         rec_size, QUDA_SINGLE_PRECISION, field_in);
00070     }
00071   } else {
00072     if (file_prec == QUDA_DOUBLE_PRECISION) {
00073       status = QIO_read(infile, &rec_info, xml_record_in, vputM<float,double,18>, 
00074                         rec_size, QUDA_DOUBLE_PRECISION, field_in);
00075     } else {
00076       status = QIO_read(infile, &rec_info, xml_record_in, vputM<float,float,18>, 
00077                         rec_size, QUDA_SINGLE_PRECISION, field_in);
00078     }
00079   }
00080 
00081   printfQuda("%s: QIO_read_record_data returns status %d\n", myname, status);
00082   if(status != QIO_SUCCESS)return 1;
00083   return 0;
00084 }
00085 
00086 void read_gauge_field(char *filename, void *gauge[], QudaPrecision precision, int *X, int argc, char *argv[]) {
00087   QIO_Reader *infile;
00088   int status;
00089   int sites_on_node = 0;
00090   QMP_thread_level_t provided;
00091   char myname[] = "qio_load";
00092 
00093   this_node = mynode();
00094 
00095   /* Lattice dimensions */
00096   lattice_dim = 4;
00097   int lattice_volume = 1;
00098   for (int d=0; d<4; d++) {
00099     lattice_size[d] = QMP_get_logical_dimensions()[d]*X[d];
00100     lattice_volume *= lattice_size[d];
00101   }
00102 
00103   /* Set the mapping of coordinates to nodes */
00104   if(setup_layout(lattice_size, 4, QMP_get_number_of_nodes())!=0)
00105     { printfQuda("Setup layout failed\n"); exit(0); }
00106   printfQuda("%s layout set for %d nodes\n", myname, QMP_get_number_of_nodes());
00107   sites_on_node = num_sites(this_node);
00108 
00109   /* Build the layout structure */
00110   layout.node_number     = node_number;
00111   layout.node_index      = node_index;
00112   layout.get_coords      = get_coords;
00113   layout.num_sites       = num_sites;
00114   layout.latsize         = lattice_size;
00115   layout.latdim          = lattice_dim;
00116   layout.volume          = lattice_volume;
00117   layout.sites_on_node   = sites_on_node;
00118   layout.this_node       = this_node;
00119   layout.number_of_nodes = QMP_get_number_of_nodes();
00120 
00121   /* Open the test file for reading */
00122   infile = open_test_input(filename, QIO_UNKNOWN, QIO_PARALLEL, myname);
00123   if(infile == NULL) { printf("Open file failed\n"); exit(0); }
00124 
00125   /* Read the su3 field record */
00126   printfQuda("%s: reading su3 field\n",myname); fflush(stdout);
00127   status = read_su3_field(infile, 4, gauge, precision, myname);
00128   if(status) { printf("read_su3_field failed %d\n", status); exit(0); }
00129 
00130   /* Close the file */
00131   QIO_close_read(infile);
00132   printfQuda("%s: Closed file for reading\n",myname);  
00133     
00134 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines