chroma.cc

Go to the documentation of this file.
00001 // $Id: chroma.cc,v 3.11 2007/09/21 04:38:45 edwards Exp $
00002 /*! \file
00003  *  \brief Main program to run all measurement codes.
00004  */
00005 
00006 #include "chroma.h"
00007 
00008 using namespace Chroma;
00009 extern "C" { 
00010  void _mcleanup();
00011 };
00012 
00013 /*
00014  * Input 
00015  */
00016 struct Params_t
00017 {
00018   multi1d<int>    nrow;
00019   std::string     inline_measurement_xml;
00020 };
00021 
00022 struct Inline_input_t
00023 {
00024   Params_t        param;
00025   GroupXML_t      cfg;
00026   QDP::Seed       rng_seed;
00027 };
00028 
00029 
00030 void read(XMLReader& xml, const std::string& path, Params_t& p) 
00031 {
00032   XMLReader paramtop(xml, path);
00033   read(paramtop, "nrow", p.nrow);
00034 
00035   XMLReader measurements_xml(paramtop, "InlineMeasurements");
00036   std::ostringstream inline_os;
00037   measurements_xml.print(inline_os);
00038   p.inline_measurement_xml = inline_os.str();
00039   QDPIO::cout << "InlineMeasurements are: " << endl;
00040   QDPIO::cout << p.inline_measurement_xml << endl;
00041 }
00042 
00043 
00044 void read(XMLReader& xml, const std::string& path, Inline_input_t& p) 
00045 {
00046   try {
00047     XMLReader paramtop(xml, path);
00048       
00049     read(paramtop, "Param", p.param);
00050     p.cfg = readXMLGroup(paramtop, "Cfg", "cfg_type");
00051 
00052     if (paramtop.count("RNG") > 0)
00053       read(paramtop, "RNG", p.rng_seed);
00054     else
00055       p.rng_seed = 11;     // default seed
00056   }
00057   catch( const std::string& e ) 
00058   {
00059     QDPIO::cerr << "Error reading XML : " << e << endl;
00060     QDP_abort(1);
00061   }
00062 }
00063 
00064  
00065 
00066 bool linkageHack(void)
00067 {
00068   bool foo = true;
00069 
00070   // Inline Measurements
00071   foo &= InlineAggregateEnv::registerAll();
00072   foo &= GaugeInitEnv::registerAll();
00073 
00074   return foo;
00075 }
00076 
00077 //! Main program to run all measurement codes
00078 /*! \defgroup chromamain Main program to run all measurement codes.
00079  *  \ingroup main
00080  *
00081  * Main program to run all measurement codes.
00082  */
00083 
00084 int main(int argc, char *argv[]) 
00085 {
00086   // Chroma Init stuff
00087   Chroma::initialize(&argc, &argv);
00088   
00089   START_CODE();
00090 
00091   QDPIO::cout << "Linkage = " << linkageHack() << endl;
00092 
00093   StopWatch snoop;
00094   snoop.reset();
00095   snoop.start();
00096 
00097   XMLReader xml_in;
00098 
00099   // Input parameter structure
00100   Inline_input_t  input;
00101   try
00102   {
00103     xml_in.open(Chroma::getXMLInputFileName());
00104     read(xml_in, "/chroma", input);
00105   }
00106   catch(const std::string& e) 
00107   {
00108     QDPIO::cerr << "CHROMA: Caught Exception reading XML: " << e << endl;
00109     QDP_abort(1);
00110   }
00111   catch(std::exception& e) 
00112   {
00113     QDPIO::cerr << "CHROMA: Caught standard library exception: " << e.what() << endl;
00114     QDP_abort(1);
00115   }
00116   catch(...)
00117   {
00118     QDPIO::cerr << "CHROMA: caught generic exception reading XML" << endl;
00119     QDP_abort(1);
00120   }
00121 
00122   XMLFileWriter& xml_out = Chroma::getXMLOutputInstance();
00123   push(xml_out, "chroma");
00124 
00125   // Write out the input
00126   write(xml_out, "Input", xml_in);
00127 
00128   Layout::setLattSize(input.param.nrow);
00129   Layout::create();
00130 
00131   proginfo(xml_out);    // Print out basic program info
00132 
00133   // Initialise the RNG
00134   QDP::RNG::setrn(input.rng_seed);
00135   write(xml_out,"RNG", input.rng_seed);
00136 
00137   // Start up the config
00138   StopWatch swatch;
00139   swatch.reset();
00140   multi1d<LatticeColorMatrix> u(Nd);
00141   XMLReader gauge_file_xml, gauge_xml;
00142 
00143   // Start up the gauge field
00144   QDPIO::cout << "Attempt to read gauge field" << endl;
00145   swatch.start();
00146   try 
00147   {
00148     std::istringstream  xml_c(input.cfg.xml);
00149     XMLReader  cfgtop(xml_c);
00150     QDPIO::cout << "Gauge initialization: cfg_type = " << input.cfg.id << endl;
00151 
00152     Handle< GaugeInit >
00153       gaugeInit(TheGaugeInitFactory::Instance().createObject(input.cfg.id,
00154                                                              cfgtop,
00155                                                              input.cfg.path));
00156     (*gaugeInit)(gauge_file_xml, gauge_xml, u);
00157   }
00158   catch(std::bad_cast) 
00159   {
00160     QDPIO::cerr << "CHROMA: caught cast error" << endl;
00161     QDP_abort(1);
00162   }
00163   catch(std::bad_alloc) 
00164   { 
00165     // This might happen on any node, so report it
00166     cerr << "CHROMA: caught bad memory allocation" << endl;
00167     QDP_abort(1);
00168   }
00169   catch(const std::string& e) 
00170   {
00171     QDPIO::cerr << "CHROMA: Caught Exception: " << e << endl;
00172     QDP_abort(1);
00173   }
00174   catch(std::exception& e) 
00175   {
00176     QDPIO::cerr << "CHROMA: Caught standard library exception: " << e.what() << endl;
00177     QDP_abort(1);
00178   }
00179   catch(...)
00180   {
00181     // This might happen on any node, so report it
00182     cerr << "CHROMA: caught generic exception during gaugeInit" << endl;
00183     QDP_abort(1);
00184   }
00185   swatch.stop();
00186 
00187   QDPIO::cout << "Gauge field successfully read: time= " 
00188               << swatch.getTimeInSeconds() 
00189               << " secs" << endl;
00190 
00191   XMLBufferWriter config_xml;
00192   config_xml << gauge_xml;
00193 
00194   // Write out the config header
00195   write(xml_out, "Config_info", gauge_xml);
00196   
00197   // Calculate some gauge invariant observables
00198   MesPlq(xml_out, "Observables", u);
00199 
00200   // Get the measurements
00201   try 
00202   {
00203     std::istringstream Measurements_is(input.param.inline_measurement_xml);
00204     XMLReader MeasXML(Measurements_is);
00205     multi1d < Handle< AbsInlineMeasurement > > the_measurements;
00206     read(MeasXML, "/InlineMeasurements", the_measurements);
00207 
00208     QDPIO::cout << "There are " << the_measurements.size() << " measurements " << endl;
00209 
00210     // Reset and set the default gauge field
00211     InlineDefaultGaugeField::reset();
00212     InlineDefaultGaugeField::set(u, config_xml);
00213 
00214     // Measure inline observables 
00215     push(xml_out, "InlineObservables");
00216     xml_out.flush();
00217 
00218     QDPIO::cout << "Doing " << the_measurements.size() 
00219                 <<" measurements" << endl;
00220     swatch.start();
00221     unsigned long cur_update = 0;
00222     for(int m=0; m < the_measurements.size(); m++) 
00223     {
00224       AbsInlineMeasurement& the_meas = *(the_measurements[m]);
00225       if( cur_update % the_meas.getFrequency() == 0 ) 
00226       {
00227         // Caller writes elem rule
00228         push(xml_out, "elem");
00229         the_meas(cur_update, xml_out);
00230         pop(xml_out); 
00231 
00232         xml_out.flush();
00233       }
00234     }
00235     swatch.stop();
00236 
00237     QDPIO::cout << "CHROMA measurements: time= " 
00238                 << swatch.getTimeInSeconds() 
00239                 << " secs" << endl;
00240 
00241 
00242     pop(xml_out); // pop("InlineObservables");
00243 
00244     // Reset the default gauge field
00245     InlineDefaultGaugeField::reset();
00246   }
00247   catch(std::bad_cast) 
00248   {
00249     QDPIO::cerr << "CHROMA: caught cast error" << endl;
00250     QDP_abort(1);
00251   }
00252   catch(std::bad_alloc) 
00253   { 
00254     // This might happen on any node, so report it
00255     cerr << "CHROMA: caught bad memory allocation" << endl;
00256     QDP_abort(1);
00257   }
00258   catch(const std::string& e) 
00259   {
00260     QDPIO::cerr << "CHROMA: Caught Exception: " << e << endl;
00261     QDP_abort(1);
00262   }
00263   catch(std::exception& e) 
00264   {
00265     QDPIO::cerr << "CHROMA: Caught standard library exception: " << e.what() << endl;
00266     QDP_abort(1);
00267   }
00268   catch(...)
00269   {
00270     // This might happen on any node, so report it
00271     cerr << "CHROMA: caught generic exception during measurement" << endl;
00272     QDP_abort(1);
00273   }
00274   pop(xml_out);
00275 
00276   snoop.stop();
00277   QDPIO::cout << "CHROMA: total time = "
00278               << snoop.getTimeInSeconds() 
00279               << " secs" << endl;
00280 
00281   QDPIO::cout << "CHROMA: ran successfully" << endl;
00282 
00283   END_CODE();
00284 
00285   Chroma::finalize();
00286   exit(0);
00287 }
00288 

Generated on Sun Nov 22 04:28:57 2009 for CHROMA by  doxygen 1.4.7