CHROMA
readmilc.cc
Go to the documentation of this file.
1 
2 /*! \file
3  * \brief Read a MILC gauge configuration written in the 1997 format
4  */
5 
6 #include "chromabase.h"
7 #include "io/milc_io.h"
8 #include "io/readmilc.h"
9 #include "qdp_util.h" // from QDP
10 
11 namespace Chroma {
12 
13 //! Read a MILC configuration file
14 /*!
15  * \ingroup io
16  *
17  * \param header structure holding config info ( Modify )
18  * \param u gauge configuration ( Modify )
19  * \param cfg_file path ( Read )
20  */
21 
22 void readMILC(MILCGauge_t& header, multi1d<LatticeColorMatrixF>& u, const std::string& cfg_file)
23 {
24  START_CODE();
25 
26  u.resize(Nd);
27 
28  BinaryFileReader cfg_in(cfg_file); // for now, cfg_io_location not used
29 
30  int magic_number;
31  read(cfg_in, magic_number);
32 
33  bool byterev = false ;
34  if( magic_number != 20103){
35  //need byte reversal
36  byterev = true ;
37  //QDP_error_exit("readMILC: unexpected byte order of file");
38  QDPUtil::byte_swap((void *)&magic_number, sizeof(int), 1 );
39  }
40  if( magic_number != 20103){
41  QDP_error_exit("readMILC: unexpected magic number");
42  }
43 
44 
45  // Check lattice size
46  header.nrow.resize(Nd);
47  read(cfg_in, header.nrow, Nd);
48  if(byterev){
49  QDPUtil::byte_swap((void *)&header.nrow[0], sizeof(int), Nd );
50  }
51  for(int j = 0; j < Nd; ++j)
52  if ( header.nrow[j] != Layout::lattSize()[j] )
53  QDP_error_exit("readMILC: unexpected lattice size: header.nrow[%d]=%d",
54  j,header.nrow[j]);
55 
56  // Time stamp
57  char date_tmp[65];
58  cfg_in.readArray(date_tmp, 1, 64);
59  date_tmp[64] = '\0';
60  header.date = date_tmp;
61 
62  // Site order - only support non-sitelist format
63  int order;
64  read(cfg_in, order);
65  if( order != 0)
66  QDP_error_exit("readMILC: only support non-sitelist format");
67 
68 
69  // Go ahead an read checksums, but will not use for now
70  unsigned int sum29, sum31;
71  read(cfg_in, sum29);
72  read(cfg_in, sum31);
73  if(byterev){
74  QDPUtil::byte_swap((void *)&sum29,sizeof(int),1);
75  QDPUtil::byte_swap((void *)&sum31,sizeof(int),1);
76  }
77  QDPIO::cout<<"Global sums (sum29, sum31): "<<sum29<<" "<<sum31<<std::endl;
78 
79  /*
80  * Read away...
81  */
82 
83  // MILC format has the directions inside the sites
84  for(int site=0; site < Layout::vol(); ++site)
85  {
86  multi1d<int> coord = crtesn(site, Layout::lattSize()); // The coordinate
87 
88  // Read in Nd SU(3) matrices.
89  // NOTE: the su3_matrix layout should be the same as in QDP
90  for(int mu=0; mu < Nd; ++mu)
91  read(cfg_in, u[mu], coord); // read in a single site
92  }
93 
94  cfg_in.close();
95 
96  //QDPUtil::byte_swap((void *)&buf[0], sizeof(Real64), latt_size[0]*Nc*Nc*2 );
97  if(byterev){
98  QDPIO::cout<<"Doing bytereversal on the links...\n" ;
99  for(int mu(0);mu<Nd;mu++)
100  //slow but hopefully it works
101  for(int s(0); s < Layout::sitesOnNode(); s++)
102  QDPUtil::byte_swap((void *)&u[mu].elem(s).elem(),sizeof(RealF),2*Nc*Nc);
103  }
104 
105  END_CODE();
106 }
107 
108 
109 
110 //! Read a MILC configuration file
111 /*!
112  * \ingroup io
113  *
114  * \param xml xml reader holding config info ( Modify )
115  * \param u gauge configuration ( Modify )
116  * \param cfg_file path ( Read )
117  */
118 
119 void readMILC(XMLReader& xml, multi1d<LatticeColorMatrixF>& u, const std::string& cfg_file)
120 {
121  START_CODE();
122 
123  MILCGauge_t header;
124 
125  // Read the config and its binary header
126  readMILC(header, u, cfg_file);
127 
128  // Now, set up the XML header. Do this by first making a buffer
129  // writer that is then used to make the reader
130  XMLBufferWriter xml_buf;
131  write(xml_buf, "MILC", header);
132 
133  try
134  {
135  xml.open(xml_buf);
136  }
137  catch(const std::string& e)
138  {
139  QDP_error_exit("Error in readMILC: %s",e.c_str());
140  }
141 
142  END_CODE();
143 }
144 
145 //! Read a MILC configuration file
146 /*!
147  * \ingroup io
148  *
149  * \param xml xml reader holding config info ( Modify )
150  * \param u gauge configuration ( Modify )
151  * \param cfg_file path ( Read )
152  */
153 
154 void readMILC(XMLReader& xml, multi1d<LatticeColorMatrixD>& u, const std::string& cfg_file)
155 {
156  START_CODE();
157 
158  // MILC configs only in single-prec,
159  multi1d<LatticeColorMatrixF> uu;
160  readMILC(xml, uu, cfg_file);
161 
162  u.resize(uu.size());
163  for(int mu=0; mu<uu.size(); ++mu)
164  u[mu] = uu[mu];
165 
166  END_CODE();
167 }
168 
169 } // end namespace Chroma
Primary include file for CHROMA library code.
int mu
Definition: cool.cc:24
void read(XMLReader &xml, const std::string &path, AsqtadFermActParams &param)
Read parameters.
void write(XMLWriter &xml, const std::string &path, const AsqtadFermActParams &param)
Writer parameters.
void readMILC(MILCGauge_t &header, multi1d< LatticeColorMatrixF > &u, const std::string &cfg_file)
Read a MILC configuration file.
Definition: readmilc.cc:22
unsigned j
Definition: ldumul_w.cc:35
multi1d< int > coord(Nd)
Nd
Definition: meslate.cc:74
MILC gauge format routines.
Asqtad Staggered-Dirac operator.
Definition: klein_gord.cc:10
QDP_error_exit("too many BiCG iterations", n_count, rsd_sq, cp, c, re_rvr, im_rvr, re_a, im_a, re_b, im_b)
static multi1d< LatticeColorMatrix > u
START_CODE()
multi1d< LatticeFermion > s(Ncb)
::std::string string
Definition: gtest.h:1979
Read a MILC gauge configuration written in the 1997 format.
MILC gauge field header.
Definition: milc_io.h:17
multi1d< int > nrow
Definition: milc_io.h:19
std::string date
Definition: milc_io.h:20