CHROMA
szinqio_gauge_init.cc
Go to the documentation of this file.
1 /*! \file
2  * \brief Read a SZINQIO config
3  */
4 
7 
9 #include "io/gauge_io.h"
10 #include "util/gauge/reunit.h"
11 
12 namespace Chroma
13 {
14 
15  // Read parameters
16  void read(XMLReader& xml, const std::string& path, SZINQIOGaugeInitEnv::Params& param)
17  {
19  param = tmp;
20  }
21 
22  //! Parameters for running code
23  void write(XMLWriter& xml, const std::string& path, const SZINQIOGaugeInitEnv::Params& param)
24  {
25  param.writeXML(xml, path);
26  }
27 
28 
29  //! Hooks to register the class
30  namespace SZINQIOGaugeInitEnv
31  {
32  //! Callback function
33  GaugeInit* createSource(XMLReader& xml_in,
34  const std::string& path)
35  {
36  return new GaugeIniter(Params(xml_in, path));
37  }
38 
39  //! Name to be used
40  const std::string name = "SZINQIO";
41  const std::string alternate_name = "SCIDAC";
42 
43  //! Local registration flag
44  static bool registered = false;
45 
46  //! Register all the factories
47  bool registerAll()
48  {
49  bool success = true;
50  if (! registered)
51  {
52  success &= Chroma::TheGaugeInitFactory::Instance().registerObject(name, createSource);
54  registered = true;
55  }
56  return success;
57  }
58 
59 
60  // Parameters for running code
61  Params::Params(XMLReader& xml, const std::string& path)
62  {
63  XMLReader paramtop(xml, path);
64 
65  read(paramtop, "cfg_file", cfg_file);
66  // Default
67  cfg_pario = QDPIO_SERIAL;
68 
69  // If the IO Node grid has more than 1 node then do parallel io
70  // as a default
71  bool pario = Layout::isIOGridDefined() && ( Layout::numIONodeGrid() > 1 );
72 
73  // Attempt to read option with either tag
74  if ( paramtop.count("parallel_io") > 0 ) {
75  read(paramtop, "parallel_io", pario);
76  }
77  else {
78  if ( paramtop.count("ParallelIO") > 0 ) {
79  read(paramtop, "ParallelIO", pario);
80  }
81  }
82 
83  if ( paramtop.count("reunit") > 0 ) {
84  read(paramtop, "reunit", reunitP );
85  }
86  else {
87  reunitP = false;
88  }
89 
90  if ( pario ) {
91  cfg_pario = QDPIO_PARALLEL;
92  }
93  else {
94  cfg_pario = QDPIO_SERIAL;
95  }
96 
97 
98  }
99 
100 
101  //! Parameters for running code
102  void Params::writeXML(XMLWriter& xml, const std::string& path) const
103  {
104  push(xml, path);
105 
106  int version = 1;
107  write(xml, "cfg_type", SZINQIOGaugeInitEnv::name);
108  write(xml, "cfg_file", cfg_file);
109 
110  bool pario = false;
111 
112  if ( cfg_pario == QDPIO_PARALLEL ) {
113  pario = true;
114  }
115  write(xml, "parallel_io", pario);
116  write(xml, "reunit", reunitP);
117 
118  pop(xml);
119  }
120 
121 
122  //! Returns a link smearing group with these params
124  {
125  GroupXML_t foo;
126 
127  XMLBufferWriter xml_tmp;
128  write(xml_tmp, "Cfg", p);
129  foo.xml = xml_tmp.printCurrentContext();
130  foo.id = name;
131  foo.path = "/Cfg";
132 
133  return foo;
134  }
135 
136 
137  // Initialize the gauge field
138  void
139  GaugeIniter::operator()(XMLReader& gauge_file_xml,
140  XMLReader& gauge_xml,
141  multi1d<LatticeColorMatrix>& u) const
142  {
143  u.resize(Nd);
144  if( params.cfg_pario == QDPIO_PARALLEL ) {
145  QDPIO::cout << "Parallel IO read" << std::endl;
146  }
147  readGauge(gauge_file_xml, gauge_xml, u, params.cfg_file, params.cfg_pario);
148  if( params.reunitP == true ) {
149  QDPIO::cout << "Reunitarizing After read" << std::endl;
150  int numbad=0;
151  for(int mu=0; mu < Nd; ++mu) {
152  int numbad_mu=0;
153  reunit(u[mu], numbad_mu, REUNITARIZE_LABEL);
154  numbad += numbad_mu;
155  }
156  QDPIO::cout << "Reunitarize reported " << numbad << " unitarity violations" << std::endl;
157  }
158  }
159  }
160 }
Base class for gauge initialization.
Definition: gauge_init.h:19
void operator()(XMLReader &gauge_file_xml, XMLReader &gauge_xml, multi1d< LatticeColorMatrix > &u) const
Initialize the gauge field.
static T & Instance()
Definition: singleton.h:432
int numbad
Definition: cool.cc:28
int mu
Definition: cool.cc:24
All gauge field initializers.
Factory for producing gauge initializer objects.
Gauge reader/writers in QIO format.
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 readGauge(XMLReader &file_xml, XMLReader &record_xml, multi1d< LatticeColorMatrix > &u, const std::string &file, QDP_serialparallel_t serpar)
Read a gauge config in QIO format.
Definition: gauge_io.cc:19
Nd
Definition: meslate.cc:74
const std::string name
Name to be used.
GaugeInit * createSource(XMLReader &xml_in, const std::string &path)
Callback function.
static bool registered
Local registration flag.
GroupXML_t createXMLGroup(const Params &p)
Returns a link smearing group with these params.
bool registerAll()
Register all the factories.
Asqtad Staggered-Dirac operator.
Definition: klein_gord.cc:10
static multi1d< LatticeColorMatrix > u
LatticeFermion tmp
Definition: mespbg5p_w.cc:36
push(xml_out,"Condensates")
void reunit(LatticeColorMatrixF3 &xa)
Definition: reunit.cc:467
@ REUNITARIZE_LABEL
Definition: reunit.h:29
pop(xml_out)
::std::string string
Definition: gtest.h:1979
Reunitarize in place a color matrix to SU(N)
Hold group xml and type id.
Params for initializing config.
void writeXML(XMLWriter &in, const std::string &path) const
Parameters for running code.
Read a SZINQIO config.