CHROMA
readszin.cc
Go to the documentation of this file.
1 
2 /*! \file
3  * \brief Read in a configuration written by SZIN up to configuration version 7.
4  */
5 
6 #include "chromabase.h"
7 #include "io/szin_io.h"
8 #include "io/readszin.h"
9 // #include "io/param_io.h"
10 #include "qdp_util.h" // from QDP
11 
12 namespace Chroma {
13 
14 #define SZIN_WILSON_FERMIONS 1
15 
16 
17 //! Read a SZIN configuration file
18 /*!
19  * \ingroup io
20  *
21  * Gauge field layout is (fortran ordering)
22  * u(real/imag,color_row,color_col,site,cb,Nd)
23  * = u(2,Nc,Nc,VOL_CB,2,4)
24  *
25  *
26  * \param header structure holding config info ( Modify )
27  * \param u gauge configuration ( Modify )
28  * \param cfg_file path ( Read )
29  */
30 
31 void readSzin(SzinGauge_t& header, multi1d<LatticeColorMatrix>& u, const std::string& cfg_file)
32 {
33  START_CODE();
34 
35  int cfg_record_size; // must read but will ignore - not used
36  int date_size;
37  int banner_size;
38  Real32 bh = 0; // old beta used for higgs term - not used
39 
40  // Read in the configuration along with relevant information
41  BinaryFileReader cfg_in(cfg_file); // for now, cfg_io_location not used
42 
43  read(cfg_in,date_size);
44  read(cfg_in,banner_size);
45  read(cfg_in,cfg_record_size);
46 
47  if( date_size < 1 || date_size > 99)
48  {
49  QDPIO::cerr << __func__
50  << ": apparently wrong SZIN configuration file, date_size="
51  << date_size << std::endl;
52  QDP_abort(1);
53  }
54 
55  /*
56  * Read in the date & banner. They are written as int's. Use a new
57  * instead of declaring a size in the constructor for the std::strings
58  * to avoid extra space. I found that nulls in the std::strings made xmlreader
59  * blow up down below.
60  */
61  char *date_tmp = new char[date_size+1];
62  for(int i=0; i < date_size; ++i)
63  {
64  int j;
65  read(cfg_in,j);
66  date_tmp[i] = j;
67  }
68  date_tmp[date_size] = '\0';
69  header.date = date_tmp;
70  delete[] date_tmp;
71 
72  char *banner_tmp = new char[banner_size+1];
73  for(int i=0; i < banner_size; ++i)
74  {
75  int j;
76  read(cfg_in,j);
77  banner_tmp[i] = j;
78  }
79  banner_tmp[banner_size] = '\0';
80  header.banner = banner_tmp;
81  delete[] banner_tmp;
82 
83  read(cfg_in, header.cfg_version);
84 
85  switch(header.cfg_version) /* just add new cases if the CFG format changes */
86  {
87  case 1:
88  read(cfg_in, header.Nd);
89  read(cfg_in, header.Nc);
90  read(cfg_in, header.BetaMC);
91  read(cfg_in, bh);
92  read(cfg_in, header.dt);
93  read(cfg_in, header.MesTrj);
94  read(cfg_in, header.KappaMC);
95  header.BetaMD = header.BetaMC;
96  header.KappaMD = header.KappaMC;
98  break;
99 
100  case 2:
101  read(cfg_in, header.Nd);
102  read(cfg_in, header.Nc);
103  read(cfg_in, header.BetaMC);
104  read(cfg_in, bh);
105  read(cfg_in, header.dt);
106  read(cfg_in, header.MesTrj);
107  read(cfg_in, header.KappaMC);
108  read(cfg_in, header.TotalCG);
109  read(cfg_in, header.TotalTrj);
110  header.BetaMD = header.BetaMC;
111  header.KappaMD = header.KappaMC;
113  break;
114 
115  case 3:
116  read(cfg_in, header.Nd);
117  read(cfg_in, header.Nc);
118  read(cfg_in, header.BetaMC);
119  read(cfg_in, bh);
120  read(cfg_in, header.dt);
121  read(cfg_in, header.MesTrj);
122  read(cfg_in, header.KappaMC);
123  read(cfg_in, header.TotalCG);
124  read(cfg_in, header.TotalTrj);
125  read(cfg_in, header.spec_acc);
126  header.BetaMD = header.BetaMC;
127  header.KappaMD = header.KappaMC;
129  break;
130 
131  case 4:
132  read(cfg_in, header.Nd);
133  read(cfg_in, header.Nc);
134  read(cfg_in, header.BetaMC);
135  read(cfg_in, header.BetaMD);
136  read(cfg_in, bh);
137  read(cfg_in, header.dt);
138  read(cfg_in, header.MesTrj);
139  read(cfg_in, header.KappaMC);
140  read(cfg_in, header.KappaMD);
141  read(cfg_in, header.TotalCG);
142  read(cfg_in, header.TotalTrj);
143  read(cfg_in, header.spec_acc);
145  break;
146 
147  case 5:
148  read(cfg_in, header.FermTypeP);
149  read(cfg_in, header.Nd);
150  read(cfg_in, header.Nc);
151  read(cfg_in, header.BetaMC);
152  read(cfg_in, header.BetaMD);
153  read(cfg_in, header.KappaMC);
154  read(cfg_in, header.KappaMD);
155  read(cfg_in, header.MassMC);
156  read(cfg_in, header.MassMD);
157  read(cfg_in, header.dt);
158  read(cfg_in, header.MesTrj);
159  read(cfg_in, header.TotalCG);
160  read(cfg_in, header.TotalTrj);
161  break;
162 
163  case 6:
164  read(cfg_in, header.FermTypeP);
165  read(cfg_in, header.Nd);
166  read(cfg_in, header.Nc);
167  read(cfg_in, header.BetaMC);
168  read(cfg_in, header.BetaMD);
169  read(cfg_in, header.KappaMC);
170  read(cfg_in, header.KappaMD);
171  read(cfg_in, header.MassMC);
172  read(cfg_in, header.MassMD);
173  read(cfg_in, header.dt);
174  read(cfg_in, header.MesTrj);
175  read(cfg_in, header.TotalCG);
176  read(cfg_in, header.TotalTrj);
177  read(cfg_in, header.spec_acc);
178  read(cfg_in, header.NOver);
179  read(cfg_in, header.TotalTry);
180  read(cfg_in, header.TotalFail);
181  break;
182 
183  case 7:
184  read(cfg_in, header.FermTypeP);
185  read(cfg_in, header.Nd);
186  read(cfg_in, header.Nc);
187  read(cfg_in, header.BetaMC);
188  read(cfg_in, header.BetaMD);
189 
190  read(cfg_in, header.KappaMC);
191  read(cfg_in, header.KappaMD);
192  read(cfg_in, header.MassMC);
193  read(cfg_in, header.MassMD);
194  read(cfg_in, header.dt);
195  read(cfg_in, header.MesTrj);
196  read(cfg_in, header.TotalCG);
197  read(cfg_in, header.TotalTrj);
198  read(cfg_in, header.spec_acc);
199 
200  read(cfg_in, header.NOver);
201  read(cfg_in, header.TotalTry);
202  read(cfg_in, header.TotalFail);
203  read(cfg_in, header.Nf);
204  read(cfg_in, header.Npf);
205  read(cfg_in, header.RefMomTrj);
206  read(cfg_in, header.RefFnoiseTrj);
207  read(cfg_in, header.LamPl);
208  read(cfg_in, header.LamMi);
209  read(cfg_in, header.AlpLog);
210  read(cfg_in, header.AlpExp);
211  break;
212 
213  default:
214  QDPIO::cerr << __func__ << ": SZIN configuration file version is invalid: version"
215  << header.cfg_version << std::endl;
216  QDP_abort(1);
217  }
218 
219  // Check that old and new parameters are compatible
220  if ( Nd != header.Nd )
221  {
222  QDPIO::cerr << __func__
223  << ": num dimensions different from SZIN config file: header.Nd="
224  << header.Nd << std::endl;
225  QDP_abort(1);
226  }
227 
228  if ( Nc != header.Nc )
229  {
230  QDPIO::cerr << __func__
231  << ": number of colors specified different from SZIN config file: header.Nc="
232  << header.Nc << std::endl;
233  QDP_abort(1);
234  }
235 
236  header.nrow.resize(Nd);
237  read(cfg_in, header.nrow, Nd);
238 
239  for(int j = 0; j < Nd; ++j)
240  if ( header.nrow[j] != Layout::lattSize()[j] )
241  {
242  QDPIO::cerr << __func__
243  << ": lattice size specified different from configuration file: nrow["
244  << j << "]=" << header.nrow[j] << std::endl;
245  QDP_abort(1);
246  }
247 
248  read(cfg_in, header.seed);
249 
250  multi1d<Real32> wstat(41*20); /* On-line statistical accumulators - throw away */
251  read(cfg_in, wstat, wstat.size()); // will not use
252 
253 
254  /*
255  * Szin stores data "checkerboarded". We must therefore "undo" the checkerboarding
256  * We use as a model the propagator routines
257  */
258  u.resize(Nd);
259 
260  multi1d<int> lattsize_cb = Layout::lattSize();
261  lattsize_cb[0] /= 2; // Evaluate the coords on the checkerboard lattice
262 
263  // The slowest moving index is the direction
264  for(int j = 0; j < Nd; j++)
265  {
266  LatticeColorMatrixF u_old;
267 
268  for(int cb=0; cb < 2; ++cb) {
269  for(int sitecb=0; sitecb < Layout::vol()/2; ++sitecb)
270  {
271  multi1d<int> coord = crtesn(sitecb, lattsize_cb); // The coordinate
272 
273  // construct the checkerboard offset
274  int sum = 0;
275  for(int m=1; m<Nd; m++)
276  sum += coord[m];
277 
278  // The true lattice x-coord
279  coord[0] = 2*coord[0] + ((sum + cb) & 1);
280 
281  read(cfg_in, u_old, coord); // Read in an SU(3) matrix into coord
282  }
283  }
284  LatticeColorMatrix u_old_prec(u_old);
285 
286  u[j] = transpose(u_old_prec); // Take the transpose
287  }
288 
289  cfg_in.close();
290 
291  END_CODE();
292 }
293 
294 
295 
296 //! Read a SZIN configuration file
297 /*!
298  * \ingroup io
299  *
300  * Gauge field layout is (fortran ordering)
301  * u(real/imag,color_row,color_col,site,cb,Nd)
302  * = u(2,Nc,Nc,VOL_CB,2,4)
303  *
304  *
305  * \param xml xml reader holding config info ( Modify )
306  * \param u gauge configuration ( Modify )
307  * \param cfg_file path ( Read )
308  */
309 
310 void readSzin(XMLReader& xml, multi1d<LatticeColorMatrix>& u, const std::string& cfg_file)
311 {
312  START_CODE();
313 
314  SzinGauge_t header;
315 
316  // Read the config and its binary header
317  readSzin(header, u, cfg_file);
318 
319  // Now, set up the XML header. Do this by first making a buffer
320  // writer that is then used to make the reader
321  XMLBufferWriter xml_buf;
322  write(xml_buf, "szin", header);
323 
324  try
325  {
326  xml.open(xml_buf);
327  }
328  catch(const std::string& e)
329  {
330  QDPIO::cerr << __func__ << ": Error in readszin: " << e.c_str() << std::endl;
331  QDP_abort(1);
332  }
333 
334  END_CODE();
335 }
336 
337 } // end namespace Chroma
Primary include file for CHROMA library code.
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 readSzin(SzinGauge_t &header, multi1d< LatticeColorMatrix > &u, const std::string &cfg_file)
Read a SZIN configuration file.
Definition: readszin.cc:31
unsigned j
Definition: ldumul_w.cc:35
static int m[4]
Definition: make_seeds.cc:16
multi1d< int > coord(Nd)
Nd
Definition: meslate.cc:74
Asqtad Staggered-Dirac operator.
Definition: klein_gord.cc:10
static multi1d< LatticeColorMatrix > u
void transpose(multi2d< LatticeColorVector > &dist_rep, const multi2d< LatticeColorVector > &prop_rep)
Take transpose of a matrix in (explicit) spin space.
int i
Definition: pbg5p_w.cc:55
START_CODE()
int cb
Definition: invbicg.cc:120
::std::string string
Definition: gtest.h:1979
Double sum
Definition: qtopcor.cc:37
#define SZIN_WILSON_FERMIONS
Definition: readszin.cc:14
Read in a configuration written by SZIN up to configuration version 7.
Szin gauge field header.
Definition: szin_io.h:17
std::string date
Definition: szin_io.h:54
QDP::Seed seed
Definition: szin_io.h:49
std::string banner
Definition: szin_io.h:53
multi1d< int > nrow
Definition: szin_io.h:20
Routines associated with SZIN gauge field IO.