CHROMA
writeszin.cc
Go to the documentation of this file.
1 
2 /*! \file
3  * \brief Write out 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/writeszin.h"
9 #include "qdp_util.h" // from QDP
10 
11 #include <string>
12 using std::string;
13 
14 namespace Chroma {
15 
16 //! Write a SZIN header to a binary file
17 /*!
18  * \ingroup io
19  *
20  * Writes a version 7 header
21  *
22  * \param cfg_out binary writer object ( Modify )
23  * \param header structure holding config info ( Modify )
24  */
25 
26 static void writeSzinHeader(BinaryWriter& cfg_out, const SzinGauge_t& header)
27 {
28  START_CODE();
29 
30  int cfg_record_size = 0;
31 
32  int date_size = header.date.length() + 1;
33  int banner_size = header.banner.length() + 1;
34 
35  if( date_size < 1 || date_size > 99)
36  QDP_error_exit("Apparently wrong configuration file, date_size=%d",date_size);
37 
38  write(cfg_out, date_size);
39  write(cfg_out, banner_size);
40  write(cfg_out, cfg_record_size);
41 
42  /*
43  * Write out the date & banner. They are written as int's
44  */
45  for(int i=0; i < date_size; ++i)
46  {
47  int j = header.date.c_str()[i];
48  write(cfg_out, j);
49  }
50 
51  for(int i=0; i < banner_size; ++i)
52  {
53  int j = header.banner.c_str()[i];
54  write(cfg_out, j);
55  }
56 
57  write(cfg_out, header.cfg_version);
58  write(cfg_out, header.FermTypeP);
59  write(cfg_out, header.Nd);
60  write(cfg_out, header.Nc);
61  write(cfg_out, header.BetaMC);
62  write(cfg_out, header.BetaMD);
63 
64  write(cfg_out, header.KappaMC);
65  write(cfg_out, header.KappaMD);
66  write(cfg_out, header.MassMC);
67  write(cfg_out, header.MassMD);
68  write(cfg_out, header.dt);
69  write(cfg_out, header.MesTrj);
70  write(cfg_out, header.TotalCG);
71  write(cfg_out, header.TotalTrj);
72  write(cfg_out, header.spec_acc);
73 
74  write(cfg_out, header.NOver);
75  write(cfg_out, header.TotalTry);
76  write(cfg_out, header.TotalFail);
77  write(cfg_out, header.Nf);
78  write(cfg_out, header.Npf);
79  write(cfg_out, header.RefMomTrj);
80  write(cfg_out, header.RefFnoiseTrj);
81  write(cfg_out, header.LamPl);
82  write(cfg_out, header.LamMi);
83  write(cfg_out, header.AlpLog);
84  write(cfg_out, header.AlpExp);
85 
86  write(cfg_out, header.nrow, Nd);
87  write(cfg_out, header.seed);
88 
89  multi1d<Real32> wstat(41*20); /* On-line statistical accumulators - write junk */
90  wstat = 0.0;
91  write(cfg_out, wstat, wstat.size());
92 
93  END_CODE();
94 }
95 
96 
97 
98 //! Write a SZIN configuration file
99 /*!
100  * \ingroup io
101  *
102  * Gauge field layout is (fortran ordering)
103  * u(real/imag,color_row,color_col,site,cb,Nd)
104  * = u(2,Nc,Nc,VOL_CB,2,4)
105  *
106  *
107  * \param header structure holding config info ( Modify )
108  * \param u gauge configuration ( Read )
109  * \param cfg_file path ( Read )
110  */
111 
112 void writeSzin(const SzinGauge_t& header, const multi1d<LatticeColorMatrix>& u,
113  const std::string& cfg_file)
114 {
115  START_CODE();
116 
117  // The object where data is written
118  BinaryFileWriter cfg_out(cfg_file); // for now, cfg_io_location not used
119 
120  // Dump the header
121  writeSzinHeader(cfg_out, header);
122 
123  /*
124  * SZIN stores data "checkerboarded". We must therefore "fake" a checkerboarding
125  */
126 
127  multi1d<int> lattsize_cb = Layout::lattSize();
128  lattsize_cb[0] /= 2; // Evaluate the coords on the checkerboard lattice
129 
130  // The slowest moving index is the direction
131  for(int j = 0; j < Nd; j++)
132  {
133  LatticeColorMatrix u_old = transpose(u[j]); // Take the transpose
134  LatticeColorMatrixF u_old_prec(u_old); // Cast to fixed 32 bit prec
135 
136  for(int cb=0; cb < 2; ++cb)
137  for(int sitecb=0; sitecb < Layout::vol()/2; ++sitecb)
138  {
139  multi1d<int> coord = crtesn(sitecb, lattsize_cb); // The coordinate
140 
141  // construct the checkerboard offset
142  int sum = 0;
143  for(int m=1; m<Nd; m++)
144  sum += coord[m];
145 
146  // The true lattice x-coord
147  coord[0] = 2*coord[0] + ((sum + cb) & 1);
148 
149  write(cfg_out, u_old_prec, coord); // Write out a single SU(3) matrix
150  }
151  }
152 
153  cfg_out.close();
154  END_CODE();
155 }
156 
157 
158 //! Write a SZIN configuration file
159 /*!
160  * \ingroup io
161  *
162  * Gauge field layout is (fortran ordering)
163  * u(real/imag,color_row,color_col,site,cb,Nd)
164  * = u(2,Nc,Nc,VOL_CB,2,4)
165  *
166  *
167  * \param xml xml writer holding config info ( Read )
168  * \param u gauge configuration ( Read )
169  * \param cfg_file path ( Read )
170  */
171 
172 void writeSzin(XMLBufferWriter& xml, multi1d<LatticeColorMatrix>& u, const std::string& cfg_file)
173 {
174  START_CODE();
175 
176  SzinGauge_t header;
177  XMLReader xml_in(xml); // use the buffer writer to instantiate a reader
178  read(xml_in, "/szin", header);
179 
180  writeSzin(header, u, cfg_file);
181 
182  END_CODE();
183 }
184 
185 
186 //! Write a truncated SZIN configuration file
187 /*!
188  * \ingroup io
189  *
190  * \param header structure holding config info ( Modify )
191  * \param u gauge configuration ( Read )
192  * \param j_decay direction which will be truncated ( Read )
193  * \param t_start starting slice in j_decay direction ( Read )
194  * \param t_end ending slice in j_decay direction ( Read )
195  * \param cfg_file path ( Read )
196  */
197 
198 void writeSzinTrunc(const SzinGauge_t& header0, const multi1d<LatticeColorMatrix>& u,
199  int j_decay, int t_start, int t_end,
200  const std::string& cfg_file)
201 {
202  START_CODE();
203 
204  // The object where data is written
205  BinaryFileWriter cfg_out(cfg_file); // for now, cfg_io_location not used
206 
207  SzinGauge_t header(header0); // a local copy
208 
209  // Force nrow in header to be correct truncated size
210  header.nrow = Layout::lattSize();
211  if (j_decay < 0 || j_decay >= Nd)
212  QDP_error_exit("writeSzinTrunc: invalid direction for truncation, j_decay=%d",j_decay);
213 
214  if (t_start < 0 || t_start >= header.nrow[j_decay])
215  QDP_error_exit("writeSzinTrunc: invalid t_start=%d", t_start);
216 
217  if (t_end < 0 || t_end >= header.nrow[j_decay])
218  QDP_error_exit("writeSzinTrunc: invalid t_end=%d", t_end);
219 
220  if (t_start == t_end)
221  QDP_error_exit("writeSzinTrunc: invalid t_start=%d t_end=%d", t_start, t_end);
222 
223  if (t_start < t_end)
224  {
225  // Within the lattice
226  header.nrow[j_decay] = t_end - t_start + 1;
227  }
228  else
229  {
230  // Consider the t_end outside the lattice
231  header.nrow[j_decay] = Layout::lattSize()[j_decay] + t_end - t_start + 1;
232  }
233 
234  // Dump the header
235  writeSzinHeader(cfg_out, header);
236 
237  /*
238  * SZIN stores data "checkerboarded". We must therefore "fake" a checkerboarding
239  * Force a truncation along the j_decay direction
240  */
241 
242  QDPIO::cout << __func__ << ": trunc lattice = ";
243  for(int j = 0; j < Nd; j++)
244  {
245  QDPIO::cout << " " << header.nrow[j];
246  }
247  QDPIO::cout << std::endl;
248 
249  multi1d<int> lattsize_cb = header.nrow;
250  lattsize_cb[0] /= 2; // Evaluate the coords on the checkerboard lattice
251 
252  // Construct the volume of this truncated problem
253  int vol_cb = 1;
254  for(int j = 0; j < Nd; j++)
255  vol_cb *= lattsize_cb[j];
256 
257  // The slowest moving index is the direction
258  for(int j = 0; j < Nd; j++)
259  {
260  LatticeColorMatrix u_tt = transpose(u[j]); // Take the transpose
261  LatticeColorMatrixF u_old(u_tt); // Cast to fixed 32 bit prec
262 
263  for(int cb=0; cb < 2; ++cb)
264  for(int sitecb=0; sitecb < vol_cb; ++sitecb)
265  {
266  multi1d<int> coord = crtesn(sitecb, lattsize_cb); // The coordinate
267 
268  // construct the checkerboard offset
269  int sum = 0;
270  for(int m=1; m<Nd; m++)
271  sum += coord[m];
272 
273  // The true lattice x-coord
274  coord[0] = 2*coord[0] + ((sum + cb) & 1);
275 
276  // Adjust to find the lattice coordinate within the original problem
277  coord[j_decay] = (coord[j_decay] + t_start) % Layout::lattSize()[j_decay];
278 
279  write(cfg_out, u_old, coord); // Write out a SU(3) matrix
280  }
281  }
282 
283  cfg_out.close();
284 
285  END_CODE();
286 }
287 
288 
289 //! Write a replicated (in time direction) SZIN configuration file
290 /*!
291  * \ingroup io
292  *
293  * \param header structure holding config info ( Modify )
294  * \param u gauge configuration ( Read )
295  * \param j_decay direction for replication ( Read )
296  * \param n_replica number of replicas in j_decay direction ( Read )
297  * \param cfg_file path ( Read )
298  */
299 
300 void writeSzinReplica(SzinGauge_t& header, const multi1d<LatticeColorMatrix>& u,
301  int j_decay, int n_replica,
302  const std::string& cfg_file)
303 {
304  START_CODE();
305 
306  // The object where data is written
307  BinaryFileWriter cfg_out(cfg_file); // for now, cfg_io_location not used
308 
309  // Force nrow in header to be correct replicated size
310  header.nrow = Layout::lattSize();
311  if (j_decay < 0 || j_decay >= Nd)
312  QDP_error_exit("writeSzinReplica: invalid direction for replication, j_decay=%d",j_decay);
313 
314  if (n_replica < 1)
315  QDP_error_exit("writeSzinReplica: invalid n_replica=%d", n_replica);
316 
317  header.nrow[j_decay] *= n_replica; // replicate in j_decay direction
318 
319  // Dump the header
320  writeSzinHeader(cfg_out, header);
321 
322  /*
323  * SZIN stores data "checkerboarded". We must therefore "fake" a checkerboarding
324  * Force a replication along the j_decay direction
325  */
326 
327  multi1d<int> lattsize_cb = header.nrow;
328  lattsize_cb[0] /= 2; // Evaluate the coords on the checkerboard lattice
329 
330  // Construct the volume of this replicated problem
331  int vol_cb = 1;
332  for(int j = 0; j < Nd; j++)
333  vol_cb *= lattsize_cb[j];
334 
335  // The slowest moving index is the direction
336  for(int j = 0; j < Nd; j++)
337  {
338  LatticeColorMatrix u_old = transpose(u[j]); // Take the transpose
339 
340  for(int cb=0; cb < 2; ++cb)
341  for(int sitecb=0; sitecb < vol_cb; ++sitecb)
342  {
343  multi1d<int> coord = crtesn(sitecb, lattsize_cb); // The coordinate
344 
345  // construct the checkerboard offset
346  int sum = 0;
347  for(int m=1; m<Nd; m++)
348  sum += coord[m];
349 
350  // The true lattice x-coord
351  coord[0] = 2*coord[0] + ((sum + cb) & 1);
352 
353  // Adjust to find the lattice coordinate within the original problem
354  coord[j_decay] = coord[j_decay] % Layout::lattSize()[j_decay];
355 
356  write(cfg_out, u_old, coord); // Write out a SU(3) matrix
357  }
358  }
359 
360  cfg_out.close();
361 
362  header.nrow[j_decay] = Layout::lattSize()[j_decay]; // restore the header
363 
364  END_CODE();
365 }
366 
367 } // 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 writeSzinReplica(SzinGauge_t &header, const multi1d< LatticeColorMatrix > &u, int j_decay, int n_replica, const std::string &cfg_file)
Write a replicated (in time direction) SZIN configuration file.
Definition: writeszin.cc:300
static void writeSzinHeader(BinaryWriter &cfg_out, const SzinGauge_t &header)
Write a SZIN header to a binary file.
Definition: writeszin.cc:26
void writeSzin(const SzinGauge_t &header, const multi1d< LatticeColorMatrix > &u, const std::string &cfg_file)
Write a SZIN configuration file.
Definition: writeszin.cc:112
void writeSzinTrunc(const SzinGauge_t &header0, const multi1d< LatticeColorMatrix > &u, int j_decay, int t_start, int t_end, const std::string &cfg_file)
Write a truncated SZIN configuration file.
Definition: writeszin.cc:198
unsigned j
Definition: ldumul_w.cc:35
static int m[4]
Definition: make_seeds.cc:16
multi1d< int > coord(Nd)
int j_decay
Definition: meslate.cc:22
Nd
Definition: meslate.cc:74
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
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
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.
Write a SZIN configuration written at configuration version 7.