Example #1
0
// -----------------------------------------------------------------
// Open a binary file for serial writing by node0
// Return a file structure describing the opened file
static gauge_file *w_serial_i(char *filename) {
  FILE *fp;
  gauge_file *gf;
  gauge_header *gh;

  // Set up gauge file and gauge header structures and load header values
  gf = setup_output_gauge_file();
  gh = gf->header;

  // Set number of nodes to zero to indicate coordinate natural ordering
  gh->order = NATURAL_ORDER;

  // Only node0 opens the requested file
  if (this_node == 0) {
    fp = fopen(filename, "wb");
    if (fp == NULL) {
      printf("w_serial_i: node%d can't open file %s, error %d\n",
             this_node, filename, errno);
      fflush(stdout);
      terminate(1);
    }
    swrite_gauge_hdr(fp, gh);   // Write the header
  }

  // Assign values to file structure
  if (this_node == 0)   // Only node 0 knows about this file
    gf->fp = fp;
  else
    gf->fp = NULL;

  gf->filename = filename;
  gf->byterevflag = 0;    // Not used for writing
  gf->rank2rcv = NULL;    // Not used for writing
  gf->parallel = 0;
  return gf;
}
Example #2
0
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;
}
Example #3
0
/* The QIO file is closed after writing the lattice */
gauge_file *save_scidac(char *filename, int volfmt, int serpar, int ildgstyle,
			char *stringLFN){
  QIO_Layout layout;
  QIO_Filesystem fs;
  QIO_Writer *outfile;
  int status;
  field_offset src = F_OFFSET(link[0]);
  gauge_file *gf;
  char *info;
  QIO_String *filexml;
  QIO_String *recxml;
  char default_file_xml[] = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><title>MILC ILDG archival gauge configuration</title>";

  QIO_verbose(QIO_VERB_OFF);

  /* Build the layout structure */
  build_qio_layout(&layout);

  /* Define the I/O system */
  build_qio_filesystem(&fs);

  /* Make a dummy gauge file structure for MILC use */
  gf = setup_output_gauge_file();

  /* Set the filename in the gauge_file structure */
  gf->filename = filename;

  /* Open file for writing */
  filexml = QIO_string_create();
  QIO_string_set(filexml, default_file_xml);
  outfile = open_scidac_output(filename, volfmt, serpar, ildgstyle, 
			       stringLFN, &layout, &fs, filexml);
  if(outfile == NULL)terminate(1);
  QIO_string_destroy(filexml);

  /* Create the QCDML string for this configuration */
  info = create_QCDML();
  recxml = QIO_string_create();
  QIO_string_set(recxml, info);

  /* Write the lattice field */
  status = write_F3_M_from_site(outfile, recxml, src, LATDIM);
  if(status)terminate(1);

  /* Discard for now */
  QIO_string_destroy(recxml);
  
  /* Write information */
  if(volfmt == QIO_SINGLEFILE){
    node0_printf("Saved gauge configuration serially to binary file %s\n",
		 filename);
  }
  else if(volfmt == QIO_MULTIFILE){
    node0_printf("Saved gauge configuration as multifile to binary file %s\n",
	   filename);
  }
  else if(volfmt == QIO_PARTFILE){
    node0_printf("Saved gauge configuration in partition format to binary file %s\n",
	   filename);
  }

  node0_printf("Time stamp %s\n",gf->header->time_stamp);
  node0_printf("Checksums %x %x\n",
	       QIO_get_writer_last_checksuma(outfile),
	       QIO_get_writer_last_checksumb(outfile));

  /* Close the file */
  QIO_close_write(outfile);

  free_QCDML(info);
  return gf;
}