39 XMLReader paramtop(xml, path);
41 read(paramtop,
"./RNG",
p.rng_seed);
42 read(paramtop,
"./StartUpdateNum",
p.start_update_num);
43 read(paramtop,
"./NWarmUpUpdates",
p.n_warm_up_updates);
44 read(paramtop,
"./NProductionUpdates",
p.n_production_updates);
45 read(paramtop,
"./NUpdatesThisRun",
p.n_updates_this_run);
46 read(paramtop,
"./SaveInterval",
p.save_interval);
47 read(paramtop,
"./SavePrefix",
p.save_prefix);
48 read(paramtop,
"./SaveVolfmt",
p.save_volfmt);
52 bool parioP = Layout::isIOGridDefined() && ( Layout::numIONodeGrid() > 1);
54 if ( paramtop.count(
"./parallel_io") > 0 ) {
55 read(paramtop,
"./parallel_io", parioP);
59 if ( paramtop.count(
"./ParallelIO") > 0 ) {
60 read(paramtop,
"./ParallelIO", parioP);
65 QDPIO::cout <<
"Setting parallel write mode for saving configurations" << std::endl;
66 p.save_pario = QDPIO_PARALLEL;
69 QDPIO::cout <<
"Setting serial write mode for saving configurations" << std::endl;
70 p.save_pario = QDPIO_SERIAL;
74 p.repro_checkP =
true;
75 p.repro_check_frequency = 10;
79 if( paramtop.count(
"./ReproCheckP") == 1 ) {
81 read(paramtop,
"./ReproCheckP",
p.repro_checkP);
85 if(
p.repro_checkP ) {
86 if( paramtop.count(
"./ReproCheckFrequency") == 1 ) {
88 read(paramtop,
"./ReproCheckFrequency",
p.repro_check_frequency);
94 p.rev_check_frequency = 10;
97 if( paramtop.count(
"./ReverseCheckP") == 1 ) {
99 read(paramtop,
"./ReverseCheckP",
p.rev_checkP);
104 if( paramtop.count(
"./ReverseCheckFrequency") == 1 ) {
106 read(paramtop,
"./ReverseCheckFrequency",
p.rev_check_frequency);
110 if( paramtop.count(
"./MonitorForces") == 1 ) {
111 read(paramtop,
"./MonitorForces",
p.monitorForcesP);
114 p.monitorForcesP =
true;
117 if( paramtop.count(
"./InlineMeasurements") == 0 ) {
118 XMLBufferWriter
dummy;
121 p.inline_measurement_xml =
dummy.printCurrentContext();
125 XMLReader measurements_xml(paramtop,
"./InlineMeasurements");
126 std::ostringstream inline_os;
127 measurements_xml.print(inline_os);
128 p.inline_measurement_xml = inline_os.str();
129 QDPIO::cout <<
"InlineMeasurements are: " << std::endl;
130 QDPIO::cout <<
p.inline_measurement_xml << std::endl;
136 QDPIO::cerr <<
"Caught Exception: " << e << std::endl;
150 write(xml,
"RNG",
p.rng_seed);
151 write(xml,
"StartUpdateNum",
p.start_update_num);
152 write(xml,
"NWarmUpUpdates",
p.n_warm_up_updates);
153 write(xml,
"NProductionUpdates",
p.n_production_updates);
154 write(xml,
"NUpdatesThisRun",
p.n_updates_this_run);
155 write(xml,
"SaveInterval",
p.save_interval);
156 write(xml,
"SavePrefix",
p.save_prefix);
157 write(xml,
"SaveVolfmt",
p.save_volfmt);
159 bool pario = (
p.save_pario == QDPIO_PARALLEL );
160 write(xml,
"ParallelIO", pario);
162 write(xml,
"ReproCheckP",
p.repro_checkP);
163 if(
p.repro_checkP ) {
164 write(xml,
"ReproCheckFrequency",
p.repro_check_frequency);
166 write(xml,
"ReverseCheckP",
p.rev_checkP);
168 write(xml,
"ReverseCheckFrequency",
p.rev_check_frequency);
170 write(xml,
"MonitorForces",
p.monitorForcesP);
172 xml <<
p.inline_measurement_xml;
178 QDPIO::cerr <<
"Caught Exception: " << e << std::endl;
202 write(xml,
"nrow",
p.nrow);
203 xml <<
p.Monomials_xml;
205 xml <<
p.Integrator_xml;
209 QDPIO::cerr <<
"Caught Exception: " << e << std::endl;
222 XMLReader paramtop(xml, path);
224 read(paramtop,
"./nrow",
p.nrow);
225 XMLReader Monomials_xml_reader(paramtop,
"./Monomials");
226 std::ostringstream os_Monomials;
227 Monomials_xml_reader.print(os_Monomials);
228 p.Monomials_xml = os_Monomials.str();
229 QDPIO::cout <<
"Monomials xml is:" << std::endl;
230 QDPIO::cout <<
p.Monomials_xml << std::endl;
233 XMLReader H_MC_xml(paramtop,
"./Hamiltonian");
234 std::ostringstream os_H_MC;
235 H_MC_xml.print(os_H_MC);
236 p.H_MC_xml = os_H_MC.str();
238 QDPIO::cout <<
"HMC_xml is: " << std::endl;
239 QDPIO::cout <<
p.H_MC_xml;
243 XMLReader MD_integrator_xml(paramtop,
"./MDIntegrator");
244 std::ostringstream os_integrator;
245 MD_integrator_xml.print(os_integrator);
246 p.Integrator_xml = os_integrator.str();
248 QDPIO::cout <<
"Integrator XML is: " << std::endl;
249 QDPIO::cout <<
p.Integrator_xml << std::endl;
252 QDPIO::cerr <<
"Error reading XML : " << e << std::endl;
259 template<
typename UpdateParams>
260 void saveState(
const UpdateParams& update_params,
262 unsigned long update_no,
263 const multi1d<LatticeColorMatrix>&
u) {
271 unsigned long update_no,
272 const multi1d<LatticeColorMatrix>&
u)
277 std::ostringstream restart_data_filename;
278 restart_data_filename << mc_control.
save_prefix <<
"_restart_" << update_no <<
".xml" ;
280 std::ostringstream restart_config_filename;
281 restart_config_filename << mc_control.
save_prefix <<
"_cfg_" << update_no <<
".lime";
283 XMLBufferWriter restart_data_buffer;
309 cfg.
cfg_file = restart_config_filename.str();
317 push(restart_data_buffer,
"Params");
318 write(restart_data_buffer,
"MCControl", p_new);
319 write(restart_data_buffer,
"HMCTrj", update_params);
320 pop(restart_data_buffer);
326 XMLBufferWriter file_xml;
327 push(file_xml,
"HMC");
336 restart_config_filename.str(),
347 XMLFileWriter restart_xml(restart_data_filename.str().c_str());
348 restart_xml << restart_data_buffer;
358 const multi1d<LatticeColorMatrix>& Q_new,
359 const QDP::Seed& seed_new,
360 const multi1d<LatticeColorMatrix>& P_old,
361 const multi1d<LatticeColorMatrix>& Q_old,
362 const QDP::Seed& seed_old );
364 template<
typename UpdateParams>
365 void doHMC(multi1d<LatticeColorMatrix>&
u,
367 multi1d<LatticeColorMatrix> >& theHMCTrj,
369 const UpdateParams& update_params,
376 QDPIO::cout <<
"Setting Force monitoring to " << mc_control.
monitorForcesP << std::endl;
378 QDP::StopWatch swatch;
383 push(xml_out,
"doHMC");
384 push(xml_log,
"doHMC");
386 multi1d< Handle< AbsInlineMeasurement > > default_measurements(1);
397 multi1d<LatticeColorMatrix>
p(
Nd);
409 unsigned long to_do = 0;
414 to_do = total_updates - cur_update ;
417 QDPIO::cout <<
"MC Control: About to do " << to_do <<
" updates" << std::endl;
420 push(xml_out,
"MCUpdates");
421 push(xml_log,
"MCUpdates");
423 for(
int i=0;
i < to_do;
i++)
425 push(xml_out,
"elem");
426 push(xml_log,
"elem");
428 push(xml_out,
"Update");
429 push(xml_log,
"Update");
435 QDPIO::cout <<
"Doing Update: " << cur_update <<
" warm_up_p = " << warm_up_p << std::endl;
438 write(xml_out,
"update_no", cur_update);
439 write(xml_log,
"update_no", cur_update);
441 write(xml_out,
"WarmUpP", warm_up_p);
442 write(xml_log,
"WarmUpP", warm_up_p);
444 bool do_reverse =
false;
448 QDPIO::cout <<
"Doing Reversibility Test this traj" << std::endl;
459 QDPIO::cout <<
"Saving start config and RNG seed for reproducability test" << std::endl;
461 GaugeFieldState repro_bkup_start( gauge_state.getP(), gauge_state.getQ());
462 QDP::Seed rng_seed_bkup_start;
466 QDPIO::cout <<
"Before HMC trajectory call" << std::endl;
471 theHMCTrj( gauge_state, warm_up_p, do_reverse );
474 QDPIO::cout <<
"After HMC trajectory call: time= "
475 << swatch.getTimeInSeconds()
476 <<
" secs" << std::endl;
478 write(xml_out,
"seconds_for_trajectory", swatch.getTimeInSeconds());
479 write(xml_log,
"seconds_for_trajectory", swatch.getTimeInSeconds());
482 QDPIO::cout <<
"Saving end config and RNG seed for reproducability test" << std::endl;
483 GaugeFieldState repro_bkup_end( gauge_state.getP(), gauge_state.getQ());
484 QDP::Seed rng_seed_bkup_end;
488 QDPIO::cout <<
"Restoring start config and RNG for reproducability test" << std::endl;
490 gauge_state.getP() = repro_bkup_start.getP();
491 gauge_state.getQ() = repro_bkup_start.getQ();
495 QDPIO::cout <<
"Before HMC repro trajectory call" << std::endl;
499 theHMCTrj( gauge_state, warm_up_p,
false );
502 QDPIO::cout <<
"After HMC repro trajectory call: time= "
503 << swatch.getTimeInSeconds()
504 <<
" secs" << std::endl;
506 write(xml_out,
"seconds_for_repro_trajectory", swatch.getTimeInSeconds());
507 write(xml_log,
"seconds_for_repro_trajectory", swatch.getTimeInSeconds());
510 QDP::Seed rng_seed_end2;
518 repro_bkup_end.getP(),
519 repro_bkup_end.getQ(),
524 QDPIO::cout <<
"Reproducability check failed on update " << cur_update << std::endl;
525 QDPIO::cout <<
"Aborting" << std::endl;
526 write(xml_out,
"ReproCheck", pass);
527 write(xml_log,
"ReproCheck", pass);
531 QDPIO::cout <<
"Reproducability check passed on update " << cur_update << std::endl;
532 write(xml_out,
"ReproCheck", pass);
533 write(xml_log,
"ReproCheck", pass);
541 QDPIO::cout <<
"Before HMC trajectory call" << std::endl;
544 theHMCTrj( gauge_state, warm_up_p, do_reverse );
547 QDPIO::cout <<
"After HMC trajectory call: time= "
548 << swatch.getTimeInSeconds()
549 <<
" secs" << std::endl;
551 write(xml_out,
"seconds_for_trajectory", swatch.getTimeInSeconds());
552 write(xml_log,
"seconds_for_trajectory", swatch.getTimeInSeconds());
564 QDPIO::cout <<
"HMC: start inline measurements" << std::endl;
566 XMLBufferWriter gauge_xml;
567 push(gauge_xml,
"ChromaHMC");
568 write(gauge_xml,
"update_no", cur_update);
569 write(gauge_xml,
"HMCTrj", update_params);
573 QDPIO::cout <<
"HMC: initial resetting default gauge field" << std::endl;
575 QDPIO::cout <<
"HMC: set default gauge field" << std::endl;
577 QDPIO::cout <<
"HMC: finished setting default gauge field" << std::endl;
580 push(xml_out,
"InlineObservables");
583 for(
int m=0;
m < default_measurements.size();
m++)
585 QDPIO::cout <<
"HMC: do default measurement = " <<
m << std::endl;
586 QDPIO::cout <<
"HMC: dump named objects" << std::endl;
591 push(xml_out,
"elem");
592 the_meas(cur_update, xml_out);
595 QDPIO::cout <<
"HMC: finished default measurement = " <<
m << std::endl;
603 QDPIO::cout <<
"Doing " << user_measurements.size()
604 <<
" user measurements" << std::endl;
605 for(
int m=0;
m < user_measurements.size();
m++) {
607 QDPIO::cout <<
"HMC: considering user measurement number = " <<
m << std::endl;
612 push(xml_out,
"elem");
613 QDPIO::cout <<
"HMC: calling user measurement number = " <<
m << std::endl;
614 the_meas(cur_update, xml_out);
615 QDPIO::cout <<
"HMC: finished user measurement number = " <<
m << std::endl;
619 QDPIO::cout <<
"HMC: finished user measurements" << std::endl;
624 QDPIO::cout <<
"HMC: final resetting default gauge field" << std::endl;
626 QDPIO::cout <<
"HMC: finished final resetting default gauge field" << std::endl;
630 QDPIO::cout <<
"After all measurements: time= "
631 << swatch.getTimeInSeconds()
632 <<
" secs" << std::endl;
634 write(xml_out,
"seconds_for_measurements", swatch.getTimeInSeconds());
635 write(xml_log,
"seconds_for_measurements", swatch.getTimeInSeconds());
643 saveState<UpdateParams>(update_params, mc_control, cur_update, gauge_state.getQ());
646 QDPIO::cout <<
"After saving state: time= "
647 << swatch.getTimeInSeconds()
648 <<
" secs" << std::endl;
659 saveState<UpdateParams>(update_params, mc_control, cur_update, gauge_state.getQ());
706 int main(
int argc,
char *argv[])
713 QDPIO::cout <<
"Linkage = " <<
linkageHack() << std::endl;
722 push(xml_out,
"hmc");
723 push(xml_log,
"hmc");
732 XMLReader paramtop(xml_in,
"/Params");
733 read( paramtop,
"./HMCTrj", trj_params);
734 read( paramtop,
"./MCControl", mc_control);
737 write(xml_out,
"Input", xml_in);
738 write(xml_log,
"Input", xml_in);
741 QDPIO::cerr <<
"hmc: Caught Exception while reading file: " << e << std::endl;
747 QDPIO::cout <<
"hmc: run is finished" << std::endl;
753 QDPIO::cout <<
"Call QDP create layout" << std::endl;
754 Layout::setLattSize(trj_params.
nrow);
756 QDPIO::cout <<
"Finished with QDP create layout" << std::endl;
762 multi1d<LatticeColorMatrix>
u(
Nd);
766 XMLReader config_xml;
768 QDPIO::cout <<
"Initialize gauge field" << std::endl;
773 std::istringstream xml_c(mc_control.
cfg.
xml);
774 XMLReader cfgtop(xml_c);
775 QDPIO::cout <<
"Gauge initialization: cfg_type = " << mc_control.
cfg.
id << std::endl;
781 (*gaugeInit)(file_xml, config_xml,
u);
784 QDPIO::cout <<
"Gauge field successfully initialized: time= "
785 << swatch.getTimeInSeconds()
786 <<
" secs" << std::endl;
799 QDPIO::cout <<
"Gauge field reunitarization found " <<
numbad <<
" unitarity violations" << std::endl;
800 QDPIO::cout <<
"Gauge field reunitarized: time="
801 << swatch.getTimeInSeconds()
802 <<
" secs" << std::endl;
805 write(xml_out,
"Config_info", config_xml);
806 write(xml_log,
"Config_info", config_xml);
810 QDPIO::cerr <<
"hmc: caught cast error" << std::endl;
815 QDPIO::cerr <<
"hmc: Caught Exception: " << e << std::endl;
818 catch(std::exception& e)
820 QDPIO::cerr <<
"hmc: Caught standard library exception: " << e.what() << std::endl;
825 QDPIO::cerr <<
"hmc: caught generic exception during measurement" << std::endl;
833 XMLReader monomial_reader(Monomial_is);
837 QDPIO::cout <<
"Caught Exception reading Monomials" << std::endl;
841 std::istringstream H_MC_is(trj_params.
H_MC_xml);
842 XMLReader H_MC_xml(H_MC_is);
850 XMLReader MDInt_xml(MDInt_is);
859 multi1d < Handle< AbsInlineMeasurement > > the_measurements;
866 XMLReader MeasXML(Measurements_is);
868 std::ostringstream os;
870 QDPIO::cout << os.str() << std::endl << std::flush;
872 read(MeasXML,
"/InlineMeasurements", the_measurements);
875 QDPIO::cerr <<
"hmc: Caught exception while reading measurements: " << e << std::endl
881 QDPIO::cout <<
"There are " << the_measurements.size() <<
" user measurements " << std::endl;
886 doHMC<HMCTrjParams>(
u, theHMCTrj, mc_control, trj_params, the_measurements);
890 QDPIO::cerr <<
"HMC: caught cast error" << std::endl;
893 catch(std::bad_alloc)
896 std::cerr <<
"HMC: caught bad memory allocation" << std::endl;
901 QDPIO::cerr <<
"HMC: Caught std::string exception: " << e << std::endl;
904 catch(std::exception& e)
906 QDPIO::cerr <<
"HMC: Caught standard library exception: " << e.what() << std::endl;
911 QDPIO::cerr <<
"HMC: Caught generic/unknown exception" << std::endl;
919 QDPIO::cout <<
"HMC: total time = "
920 << snoop.getTimeInSeconds()
921 <<
" secs" << std::endl;
935 const multi1d<LatticeColorMatrix>& Q_new,
936 const QDP::Seed& seed_new,
937 const multi1d<LatticeColorMatrix>& P_old,
938 const multi1d<LatticeColorMatrix>& Q_old,
939 const QDP::Seed& seed_old )
944 if ( P_new.size() != P_old.size() ) {
949 if ( Q_new.size() != Q_old.size() ) {
956 2*Nc*Nc*Layout::sitesOnNode()*
sizeof(WordType< LatticeColorMatrix >::Type_t);
959 for(
int mu=0;
mu < P_new.size();
mu++) {
960 const unsigned char *p1 = (
const unsigned char *)P_new[
mu].getF();
961 const unsigned char *p2 = (
const unsigned char *)P_old[
mu].getF();
962 for(
int b=0;
b < bytes;
b++) {
963 unsigned char diff = *p1 - *p2;
964 if( diff != 0 ) diffs_found++;
970 QDPInternal::globalSum(diffs_found);
972 if( diffs_found != 0 ) {
973 QDPIO::cout <<
"Found " << diffs_found <<
" different bytes in momentum repro check" << std::endl;
978 for(
int mu=0;
mu < P_new.size();
mu++) {
979 const unsigned char *p1 = (
const unsigned char *)Q_new[
mu].getF();
980 const unsigned char *p2 = (
const unsigned char *)Q_old[
mu].getF();
981 for(
int b=0;
b < bytes;
b++) {
982 unsigned char diff = *p1 - *p2;
983 if( diff != 0 ) diffs_found++;
989 QDPInternal::globalSum(diffs_found);
991 if( diffs_found != 0 ) {
992 QDPIO::cout <<
"Found " << diffs_found <<
" different bytes in gauge repro check" << std::endl;
996 if( ! toBool( seed_new == seed_old ) ) {
997 QDPIO::cout <<
"New and old RNG seeds do not match " << std::endl;
Primary include file for CHROMA in application codes.
virtual unsigned long getFrequency(void) const =0
Tell me how often I should measure this beastie.
The Exact Hamiltonian Class - supplies internal field refreshment and energy calculations.
Class for counted reference semantics.
void read(XMLReader &xml, const std::string &path, AsqtadFermActParams ¶m)
Read parameters.
void write(XMLWriter &xml, const std::string &path, const AsqtadFermActParams ¶m)
Writer parameters.
void proginfo(XMLWriter &xml)
Print out basic information about this program.
void reset()
Reset the default gauge field state.
void set(const multi1d< LatticeColorMatrix > &u, XMLBufferWriter &record_xml)
Set the default gauge field.
void readNamedMonomialArray(XMLReader &xml, const std::string &path)
Read an array of named monomials from an XML reader. use factory to create the monomials and put them...
void writeGauge(XMLBufferWriter &file_xml, XMLBufferWriter &record_xml, const multi1d< LatticeColorMatrix > &u, const std::string &file, QDP_volfmt_t volfmt, QDP_serialparallel_t serpar)
Write a gauge config in QIO format.
GroupXML_t readXMLGroup(XMLReader &xml_in, const std::string &path, const std::string &type_name)
Read group and return as a std::string.
int main(int argc, char *argv[])
void savern(int iseed[4])
bool registerAll()
Register all the factories.
bool registerAll()
Register all the factories.
bool registerAll()
Register all the factories.
bool registerAll()
Register all the factories.
GroupXML_t createXMLGroup(const Params &p)
Returns a link smearing group with these params.
bool registerAll()
Register all the factories.
Asqtad Staggered-Dirac operator.
XMLFileWriter & getXMLLogInstance()
Get xml log instance.
static multi1d< LatticeColorMatrix > u
push(xml_out,"Condensates")
void saveState(const UpdateParams &update_params, MCControl &mc_control, unsigned long update_no, const multi1d< LatticeColorMatrix > &u)
void initialize(int *argc, char ***argv)
Chroma initialisation routine.
void finalize(void)
Chroma finalization routine.
void reunit(LatticeColorMatrixF3 &xa)
void doHMC(multi1d< LatticeColorMatrix > &u, AbsHMCTrj< multi1d< LatticeColorMatrix >, multi1d< LatticeColorMatrix > > &theHMCTrj, MCControl &mc_control, const UpdateParams &update_params, multi1d< Handle< AbsInlineMeasurement > > &user_measurements)
void setForceMonitoring(bool monitorP)
std::string getXMLInputFileName()
Get input file name.
bool checkReproducability(const multi1d< LatticeColorMatrix > &P_new, const multi1d< LatticeColorMatrix > &Q_new, const QDP::Seed &seed_new, const multi1d< LatticeColorMatrix > &P_old, const multi1d< LatticeColorMatrix > &Q_old, const QDP::Seed &seed_old)
XMLFileWriter & getXMLOutputInstance()
Get xml output instance.
Parameter structure for new Hamiltonian.
Hold group xml and type id.
std::string Integrator_xml
std::string Monomials_xml
A Structure to hold the top level parameters.
Params controlling running of monte carlo.
unsigned long n_warm_up_updates
std::string inline_measurement_xml
unsigned long n_production_updates
QDP_serialparallel_t save_pario
unsigned int save_interval
unsigned int n_updates_this_run
int repro_check_frequency
unsigned long start_update_num
Params for initializing config.
QDP_serialparallel_t cfg_pario