int read_lat_dim_scidac(char *filename, int *ndim, int dims[]) { QIO_Layout layout; QIO_Filesystem fs; int i; int *latsize; QIO_Reader *infile; QIO_verbose(QIO_VERB_REG); /* Build the layout structure */ nx = 0; ny = 0; nz = 0; nt = 0; build_qio_layout(&layout); /* Forces discovery */ layout.latdim = 0; /* Set the file system parameters */ build_qio_filesystem(&fs); /* Get lattice dimensions from file */ infile = open_scidac_input(filename, &layout, &fs, QIO_SERIAL); if(!infile)return 1; *ndim = QIO_get_reader_latdim(infile); latsize = QIO_get_reader_latsize(infile); for(i = 0; i < *ndim; i++) dims[i] = latsize[i]; QIO_close_read(infile); return 0; }
static gauge_file *restore_scidac(char *filename, int serpar){ QIO_Layout layout; QIO_Filesystem fs; QIO_Reader *infile; QIO_RecordInfo recinfo; QIO_String *recxml; int status; int typesize; field_offset dest = F_OFFSET(link[0]); gauge_file *gf; QIO_verbose(QIO_VERB_OFF); /* Build the layout structure */ build_qio_layout(&layout); /* Define the I/O nodes */ build_qio_filesystem(&fs); /* Make a dummy gauge file structure for MILC use */ gf = setup_input_gauge_file(filename); /* Set the filename in the gauge_file structure */ gf->filename = filename; /* Open file for reading */ infile = open_scidac_input(filename, &layout, &fs, serpar); if(infile == NULL)terminate(1); /* Check the record type (double or single precision) */ recxml = QIO_string_create(); status = QIO_read_record_info(infile, &recinfo, recxml); if(status)terminate(1); typesize = QIO_get_typesize(&recinfo); /* Read the lattice field as single or double precision according to the type size (bytes in a single SU(3) matrix) */ if(typesize == 72) status = read_F3_M_to_site(infile, recxml, dest, LATDIM); else if (typesize == 144) status = read_D3_M_to_site(infile, recxml, dest, LATDIM); else { node0_printf("restore_scidac: Bad typesize %d\n",typesize); terminate(1); } if(status)terminate(1); /* Discard for now */ QIO_string_destroy(recxml); /* Close the file */ QIO_close_read(infile); return gf; }
int main(int argc, char *argv[]) { int ndim,dims[4]; gauge_file *gf; gauge_header *gh; FILE *fp; char *filename_milc,*filename_scidac; QIO_Layout layout; QIO_Reader *infile; QIO_RecordInfo rec_info; char *datatype; int status; int datum_size; int input_prec; int count = 4; int word_size; int typesize; w_serial_site_writer state; if(argc < 3) { fprintf(stderr,"Usage %s <SciDAC file> <MILC file>\n",argv[0]); exit(1); } filename_scidac = argv[1]; filename_milc = argv[2]; if(this_node == 0)printf("Converting file %s to MILC v5 file %s\n", filename_scidac, filename_milc); initialize_machine(&argc,&argv); #ifdef HAVE_QDP QDP_initialize(&argc, &argv); #endif this_node = mynode(); number_of_nodes = numnodes(); if(number_of_nodes != 1){ printf("This is single-processor code. Please rebuild as such.\n"); terminate(1); } /* Open the SciDAC file and discover the lattice dimensions. Then close. */ status = read_lat_dim_scidac(filename_scidac, &ndim, dims); if(status)terminate(1); if(ndim != 4){ printf("Wanted ndims = 4 in %s but got %d\n",filename_scidac,ndim); terminate(1); } nx = dims[0]; ny = dims[1]; nz = dims[2]; nt = dims[3]; volume = nx*ny*nz*nt; /* Finish setting up, now we know the dimensions */ setup(); /* Build the QIO layout */ build_qio_layout(&layout); /* Open the SciDAC file for reading */ infile = open_scidac_input(filename_scidac, &layout, 0, QIO_SERIAL); if(infile == NULL)terminate(1); /* Open the MILC v5 file for writing */ fp = fopen(filename_milc, "wb"); if(fp == NULL) { printf("Can't open file %s, error %d\n", filename_milc,errno);fflush(stdout); terminate(1); } gf = setup_output_gauge_file(); gh = gf->header; /* Read the SciDAC record header. */ xml_record_in = QIO_string_create(); status = QIO_read_record_info(infile, &rec_info, xml_record_in); if(status != QIO_SUCCESS)terminate(1); node0_printf("Record info \n\"%s\"\n",QIO_string_ptr(xml_record_in)); /* Make sure this is a lattice field */ datatype = QIO_get_datatype(&rec_info); typesize = QIO_get_typesize(&rec_info); if(strcmp(datatype, "QDP_F3_ColorMatrix") == 0 || strcmp(datatype, "USQCD_F3_ColorMatrix") == 0 || typesize == 72){ datum_size = sizeof(fsu3_matrix); input_prec = 1; word_size = sizeof(float); } else if(strcmp(datatype, "QDP_D3_ColorMatrix") == 0 || strcmp(datatype, "USQCD_F3_ColorMatrix") == 0 || typesize == 144){ datum_size = sizeof(dsu3_matrix); input_prec = 2; word_size = sizeof(double); } else { printf("Unrecognized datatype %s\n",datatype); terminate(1); } /* Copy the time stamp from the SciDAC file */ strncpy(gh->time_stamp, QIO_get_record_date(&rec_info), MAX_TIME_STAMP); gh->time_stamp[MAX_TIME_STAMP-1] = '\0'; /* Write the MILC v5 header */ gh->order = NATURAL_ORDER; /* Node 0 writes the header */ swrite_gauge_hdr(fp,gh); /* Assign values to file structure */ gf->fp = fp; gf->filename = filename_milc; gf->byterevflag = 0; /* Not used for writing */ gf->rank2rcv = NULL; /* Not used for writing */ gf->parallel = 0; /* Initialize writing the lattice data */ w_serial_start_lattice(gf, &state, input_prec); /* Read the SciDAC record data. The factory function writes the site links to a file. */ status = QIO_read_record_data(infile, w_serial_site_links, datum_size*count, word_size, (void *)&state); if(status != QIO_SUCCESS)terminate(1); node0_printf("SciDAC checksums %x %x\n", QIO_get_reader_last_checksuma(infile), QIO_get_reader_last_checksumb(infile)); /* Close the SciDAC file */ QIO_close_read(infile); /* Finish the MILC v5 file */ w_serial_finish_lattice(&state); w_serial_f(gf); QIO_string_destroy(xml_record_in); #ifdef HAVE_QDP QDP_finalize(); #endif normal_exit(0); return 0; }
int qio_test(int output_volfmt, int output_serpar, int ildgstyle, int input_volfmt, int input_serpar, int argc, char *argv[]){ float array_in[NARRAY], array_out[NARRAY]; float *field_in[NREAL], *subset_in[NREAL], *field_out[NREAL], *subset_out[NREAL]; suN_matrix *field_su3_out[NMATRIX], *field_su3_in[NMATRIX]; QIO_Writer *outfile; QIO_Reader *infile; float diff_field = 0, diff_array = 0, diff_su3 = 0, diff_subset = 0; QMP_thread_level_t provided; int status; int sites_on_node = 0; int i,volume; char filename[] = "binary_test"; int dim = 4; int lower[4] = {1, 0, 0, 2}; int upper[4] = {2, 3, 3, 2}; char myname[] = "qio_test"; /* Start message passing */ QMP_init_msg_passing(&argc, &argv, QMP_THREAD_SINGLE, &provided); this_node = mynode(); printf("%s(%d) QMP_init_msg_passing done\n",myname,this_node); /* Lattice dimensions */ lattice_dim = 4; lattice_size[0] = 8; lattice_size[1] = 4; lattice_size[2] = 4; lattice_size[3] = 4; volume = 1; for(i = 0; i < lattice_dim; i++){ volume *= lattice_size[i]; } /* Set the mapping of coordinates to nodes */ if(setup_layout(lattice_size, 4, QMP_get_number_of_nodes())!=0) return 1; printf("%s(%d) layout set for %d nodes\n",myname,this_node, QMP_get_number_of_nodes()); sites_on_node = num_sites(this_node); /* Build the layout structure */ layout.node_number = node_number; layout.node_index = node_index; layout.get_coords = get_coords; layout.num_sites = num_sites; layout.latsize = lattice_size; layout.latdim = lattice_dim; layout.volume = volume; layout.sites_on_node = sites_on_node; layout.this_node = this_node; layout.number_of_nodes = QMP_get_number_of_nodes(); /* Open the test output file */ outfile = open_test_output(filename, output_volfmt, output_serpar, ildgstyle, myname); if(outfile == NULL)return 1; /* If this is not the ILDG file test */ if(ildgstyle == QIO_ILDGNO){ /* Create the test output field */ status = vcreate_R(field_out, NREAL); if(status)return status; /* Set some values for the field */ vset_R(field_out, NREAL); /* Write the real test field */ status = write_real_field(outfile, NREAL, field_out, myname); if(status)return status; /* Write a subset of the real test field */ status = write_real_field_subset(outfile, NREAL, field_out, lower, upper, dim, myname); if(status)return status; /* Set some values for the global array */ for(i = 0; i < NARRAY; i++) array_out[i] = i; /* Write the real global array */ status = write_real_global(outfile, NARRAY, array_out, myname); if(status)return status; } /* Create the test output su3 field */ status = vcreate_M(field_su3_out, NMATRIX); if(status)return status; /* Set some values for the su3 field */ vset_M(field_su3_out, NMATRIX); /* Write the su3 test field */ status = write_su3_field(outfile, NMATRIX, field_su3_out, myname); if(status)return status; /* Close the file */ QIO_close_write(outfile); printf("%s(%d): Closed file for writing\n",myname,this_node); /* Set up a dummy input field */ status = vcreate_R(field_in, NREAL); if(status)return status; /* Set up a dummy input field for subset */ status = vcreate_R(subset_in, NREAL); if(status)return status; /* Set up a dummy input SU(N) field */ status = vcreate_M(field_su3_in, NMATRIX); if(status)return status; /* Open the test file for reading */ infile = open_test_input(filename, input_volfmt, input_serpar, myname); if(infile == NULL)return 1; if(ildgstyle == QIO_ILDGNO){ /* Peek at the field record */ status = peek_record_info(infile, myname); if(status != QIO_SUCCESS)return status; /* Skip the record */ #if(0) /* Skip the field */ status = QIO_next_record(infile); if(status != QIO_SUCCESS)return status; #else /* Read the field record */ printf("%s(%d) reading real field\n",myname,this_node); fflush(stdout); status = read_real_field(infile, NREAL, field_in, myname); if(status)return status; #endif /* Read the subset of the field */ printf("%s(%d) reading subset of real field\n", myname,this_node); fflush(stdout); status = read_real_field_subset(infile, NREAL, subset_in, myname); if(status)return status; /* Read the global array record */ printf("%s(%d) reading global field\n",myname,this_node); fflush(stdout); status = read_real_global(infile, NARRAY, array_in, myname); if(status)return status; } /* Read the su3 field record */ printf("%s(%d) reading su3 field\n",myname,this_node); fflush(stdout); status = read_su3_field(infile, NMATRIX, field_su3_in, myname); if(status)return status; /* Close the file */ QIO_close_read(infile); printf("%s(%d): Closed file for reading\n",myname,this_node); if(ildgstyle == QIO_ILDGNO){ /* Compare the input and output fields */ diff_field = vcompare_R(field_out, field_in, NREAL); if(this_node == 0){ printf("%s(%d): Comparison of in and out real fields |in - out|^2 = %e\n", myname,this_node,diff_field); } /* Create the subset output field */ status = vcreate_R(subset_out, NREAL); if(status)return status; /* Copy the subset */ vsubset_R(subset_out, field_out, lower, upper, NREAL); /* Compare the input and output subsets */ diff_subset = vcompare_R(subset_out, subset_in, NREAL); if(this_node == 0){ printf("%s(%d): Comparison of subsets of in and out real fields |in - out|^2 = %e\n", myname,this_node,diff_subset); } /* Compare the input and output global arrays */ diff_array = vcompare_r(array_out, array_in, NREAL); if(this_node == 0){ printf("%s(%d): Comparison of in and out real global arrays |in - out|^2 = %e\n", myname, this_node, diff_array); } } /* Compare the input and output suN fields */ diff_su3 = vcompare_M(field_su3_out, field_su3_in, NMATRIX); if(this_node == 0){ printf("%s(%d): Comparison of in and out suN fields |in - out|^2 = %e\n", myname, this_node, diff_field); } /* Clean up */ if(ildgstyle == QIO_ILDGNO){ vdestroy_R(field_out, NREAL); vdestroy_R(field_in, NREAL); vdestroy_R(subset_in, NREAL); vdestroy_R(subset_out, NREAL); } vdestroy_M(field_su3_in, NMATRIX); vdestroy_M(field_su3_out, NMATRIX); /* Shut down QMP */ QMP_finalize_msg_passing(); /* Report result */ if(diff_field + diff_subset + diff_su3 + diff_array > 0){ printf("%s(%d): Test failed\n",myname,this_node); return 1; } printf("%s(%d): Test passed\n",myname,this_node); return 0; }
static gauge_file *file_scan_scidac(char *filename, int serpar){ QIO_Layout layout; QIO_Filesystem fs; QIO_Reader *infile; QIO_RecordInfo recinfo; QIO_String *recxml; int status; int typesize; su3_matrix *dest = NULL; gauge_file *gf; int ndim; int dims[4]; /* Read header to get lattice dimensions and close the file */ read_lat_dim_scidac(filename, &ndim, dims); nx = dims[0]; ny = dims[1]; nz = dims[2]; nt = dims[3]; volume = nx*ny*nz*nt; /* Finish setting up, now we know the dimensions */ broadcast_bytes((char *)&nx,sizeof(int)); broadcast_bytes((char *)&ny,sizeof(int)); broadcast_bytes((char *)&nz,sizeof(int)); broadcast_bytes((char *)&nt,sizeof(int)); setup_layout(); /* Build the layout structure */ build_qio_layout(&layout); /* Define the I/O nodes */ build_qio_filesystem(&fs); /* Make a dummy gauge file structure for MILC use */ gf = setup_input_gauge_file(filename); /* Set the filename in the gauge_file structure */ gf->filename = filename; /* Reopen file for reading */ QIO_verbose(QIO_VERB_OFF); infile = open_scidac_input(filename, &layout, &fs, serpar); if(infile == NULL)terminate(1); /* Check the record type (double or single precision) */ recxml = QIO_string_create(); status = QIO_read_record_info(infile, &recinfo, recxml); if(status)terminate(1); typesize = QIO_get_typesize(&recinfo); /* Read the lattice field as single or double precision according to the type size (bytes in a single SU(3) matrix) */ if(typesize == 72) status = read_F3_M_to_null(infile, recxml, dest, LATDIM); else if (typesize == 144) status = read_D3_M_to_null(infile, recxml, dest, LATDIM); else { node0_printf("file_scan_scidac: Bad typesize %d\n",typesize); terminate(1); } if(status){ node0_printf("ERROR scanning file\n"); } else { node0_printf("SUCCESS scanning file\n"); } /* Discard for now */ QIO_string_destroy(recxml); /* Close the file */ QIO_close_read(infile); return gf; }
void close_scidac_input(QIO_Reader *infile) { QIO_close_read(infile); }