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);
51 p.save_pario = QDPIO_SERIAL;
54 if ( paramtop.count(
"./ParallelIO") > 0 ) {
57 read(paramtop,
"./ParallelIO", parioP);
59 QDPIO::cout <<
"Setting parallel write mode" << std::endl;
60 p.save_pario = QDPIO_PARALLEL;
65 p.repro_checkP =
true;
66 p.repro_check_frequency = 10;
70 if( paramtop.count(
"./ReproCheckP") == 1 ) {
72 read(paramtop,
"./ReproCheckP",
p.repro_checkP);
76 if(
p.repro_checkP ) {
77 if( paramtop.count(
"./ReproCheckFrequency") == 1 ) {
79 read(paramtop,
"./ReproCheckFrequency",
p.repro_check_frequency);
85 p.rev_check_frequency = 10;
88 if( paramtop.count(
"./ReverseCheckP") == 1 ) {
90 read(paramtop,
"./ReverseCheckP",
p.rev_checkP);
95 if( paramtop.count(
"./ReverseCheckFrequency") == 1 ) {
97 read(paramtop,
"./ReverseCheckFrequency",
p.rev_check_frequency);
101 if( paramtop.count(
"./MonitorForces") == 1 ) {
102 read(paramtop,
"./MonitorForces",
p.monitorForcesP);
105 p.monitorForcesP =
true;
108 if( paramtop.count(
"./InlineMeasurements") == 0 ) {
109 XMLBufferWriter
dummy;
112 p.inline_measurement_xml =
dummy.printCurrentContext();
116 XMLReader measurements_xml(paramtop,
"./InlineMeasurements");
117 std::ostringstream inline_os;
118 measurements_xml.print(inline_os);
119 p.inline_measurement_xml = inline_os.str();
120 QDPIO::cout <<
"InlineMeasurements are: " << std::endl;
121 QDPIO::cout <<
p.inline_measurement_xml << std::endl;
127 QDPIO::cerr <<
"Caught Exception: " << e << std::endl;
141 write(xml,
"RNG",
p.rng_seed);
142 write(xml,
"StartUpdateNum",
p.start_update_num);
143 write(xml,
"NWarmUpUpdates",
p.n_warm_up_updates);
144 write(xml,
"NProductionUpdates",
p.n_production_updates);
145 write(xml,
"NUpdatesThisRun",
p.n_updates_this_run);
146 write(xml,
"SaveInterval",
p.save_interval);
147 write(xml,
"SavePrefix",
p.save_prefix);
148 write(xml,
"SaveVolfmt",
p.save_volfmt);
150 bool pario = (
p.save_pario == QDPIO_PARALLEL );
151 write(xml,
"ParallelIO", pario);
153 write(xml,
"ReproCheckP",
p.repro_checkP);
154 if(
p.repro_checkP ) {
155 write(xml,
"ReproCheckFrequency",
p.repro_check_frequency);
157 write(xml,
"ReverseCheckP",
p.rev_checkP);
159 write(xml,
"ReverseCheckFrequency",
p.rev_check_frequency);
161 write(xml,
"MonitorForces",
p.monitorForcesP);
163 xml <<
p.inline_measurement_xml;
169 QDPIO::cerr <<
"Caught Exception: " << e << std::endl;
193 write(xml,
"nrow",
p.nrow);
194 xml <<
p.Monomials_xml;
196 xml <<
p.Integrator_xml;
200 QDPIO::cerr <<
"Caught Exception: " << e << std::endl;
213 XMLReader paramtop(xml, path);
215 read(paramtop,
"./nrow",
p.nrow);
216 XMLReader Monomials_xml_reader(paramtop,
"./Monomials");
217 std::ostringstream os_Monomials;
218 Monomials_xml_reader.print(os_Monomials);
219 p.Monomials_xml = os_Monomials.str();
220 QDPIO::cout <<
"Monomials xml is:" << std::endl;
221 QDPIO::cout <<
p.Monomials_xml << std::endl;
224 XMLReader H_MC_xml(paramtop,
"./Hamiltonian");
225 std::ostringstream os_H_MC;
226 H_MC_xml.print(os_H_MC);
227 p.H_MC_xml = os_H_MC.str();
229 QDPIO::cout <<
"HMC_xml is: " << std::endl;
230 QDPIO::cout <<
p.H_MC_xml;
234 XMLReader MD_integrator_xml(paramtop,
"./MDIntegrator");
235 std::ostringstream os_integrator;
236 MD_integrator_xml.print(os_integrator);
237 p.Integrator_xml = os_integrator.str();
239 QDPIO::cout <<
"Integrator XML is: " << std::endl;
240 QDPIO::cout <<
p.Integrator_xml << std::endl;
243 QDPIO::cerr <<
"Error reading XML : " << e << std::endl;
250 template<
typename UpdateParams>
253 unsigned long update_no,
254 const multi1d<LatticeColorMatrix>&
u) {
262 unsigned long update_no,
263 const multi1d<LatticeColorMatrix>&
u)
268 std::ostringstream restart_data_filename;
269 restart_data_filename << mc_control.
save_prefix <<
"_restart_" << update_no <<
".xml" ;
271 std::ostringstream restart_config_filename;
272 restart_config_filename << mc_control.
save_prefix <<
"_cfg_" << update_no <<
".lime";
274 XMLBufferWriter restart_data_buffer;
300 cfg.
cfg_file = restart_config_filename.str();
308 push(restart_data_buffer,
"Params");
309 write(restart_data_buffer,
"MCControl", p_new);
310 write(restart_data_buffer,
"HMCTrj", update_params);
311 pop(restart_data_buffer);
317 XMLBufferWriter file_xml;
318 push(file_xml,
"HMC");
327 restart_config_filename.str(),
338 XMLFileWriter restart_xml(restart_data_filename.str().c_str());
339 restart_xml << restart_data_buffer;
349 const multi1d<LatticeColorMatrix>& Q_new,
350 const QDP::Seed& seed_new,
351 const multi1d<LatticeColorMatrix>& P_old,
352 const multi1d<LatticeColorMatrix>& Q_old,
353 const QDP::Seed& seed_old );
355 template<
typename UpdateParams>
356 void doHMC(multi1d<LatticeColorMatrix>&
u,
358 multi1d<LatticeColorMatrix> >& theHMCTrj,
360 const UpdateParams& update_params,
367 QDPIO::cout <<
"Setting Force monitoring to " << mc_control.
monitorForcesP << std::endl;
369 QDP::StopWatch swatch;
374 push(xml_out,
"doHMC");
375 push(xml_log,
"doHMC");
377 multi1d< Handle< AbsInlineMeasurement > > default_measurements(1);
388 multi1d<LatticeColorMatrix>
p(
Nd);
400 unsigned long to_do = 0;
405 to_do = total_updates - cur_update ;
408 QDPIO::cout <<
"MC Control: About to do " << to_do <<
" updates" << std::endl;
411 push(xml_out,
"MCUpdates");
412 push(xml_log,
"MCUpdates");
414 for(
int i=0;
i < to_do;
i++)
416 push(xml_out,
"elem");
417 push(xml_log,
"elem");
419 push(xml_out,
"Update");
420 push(xml_log,
"Update");
426 QDPIO::cout <<
"Doing Update: " << cur_update <<
" warm_up_p = " << warm_up_p << std::endl;
429 write(xml_out,
"update_no", cur_update);
430 write(xml_log,
"update_no", cur_update);
432 write(xml_out,
"WarmUpP", warm_up_p);
433 write(xml_log,
"WarmUpP", warm_up_p);
435 bool do_reverse =
false;
439 QDPIO::cout <<
"Doing Reversibility Test this traj" << std::endl;
450 QDPIO::cout <<
"Saving start config and RNG seed for reproducability test" << std::endl;
453 QDP::Seed rng_seed_bkup_start;
457 QDPIO::cout <<
"Before HMC trajectory call" << std::endl;
462 theHMCTrj( gauge_state, warm_up_p, do_reverse );
465 QDPIO::cout <<
"After HMC trajectory call: time= "
466 << swatch.getTimeInSeconds()
467 <<
" secs" << std::endl;
469 write(xml_out,
"seconds_for_trajectory", swatch.getTimeInSeconds());
470 write(xml_log,
"seconds_for_trajectory", swatch.getTimeInSeconds());
473 QDPIO::cout <<
"Saving end config and RNG seed for reproducability test" << std::endl;
475 QDP::Seed rng_seed_bkup_end;
479 QDPIO::cout <<
"Restoring start config and RNG for reproducability test" << std::endl;
481 gauge_state.
getP() = repro_bkup_start.
getP();
482 gauge_state.
getQ() = repro_bkup_start.
getQ();
486 QDPIO::cout <<
"Before HMC repro trajectory call" << std::endl;
490 theHMCTrj( gauge_state, warm_up_p,
false );
493 QDPIO::cout <<
"After HMC repro trajectory call: time= "
494 << swatch.getTimeInSeconds()
495 <<
" secs" << std::endl;
497 write(xml_out,
"seconds_for_repro_trajectory", swatch.getTimeInSeconds());
498 write(xml_log,
"seconds_for_repro_trajectory", swatch.getTimeInSeconds());
501 QDP::Seed rng_seed_end2;
509 repro_bkup_end.
getP(),
510 repro_bkup_end.
getQ(),
515 QDPIO::cout <<
"Reproducability check failed on update " << cur_update << std::endl;
516 QDPIO::cout <<
"Aborting" << std::endl;
517 write(xml_out,
"ReproCheck", pass);
518 write(xml_log,
"ReproCheck", pass);
522 QDPIO::cout <<
"Reproducability check passed on update " << cur_update << std::endl;
523 write(xml_out,
"ReproCheck", pass);
524 write(xml_log,
"ReproCheck", pass);
532 QDPIO::cout <<
"Before HMC trajectory call" << std::endl;
535 theHMCTrj( gauge_state, warm_up_p, do_reverse );
538 QDPIO::cout <<
"After HMC trajectory call: time= "
539 << swatch.getTimeInSeconds()
540 <<
" secs" << std::endl;
542 write(xml_out,
"seconds_for_trajectory", swatch.getTimeInSeconds());
543 write(xml_log,
"seconds_for_trajectory", swatch.getTimeInSeconds());
555 QDPIO::cout <<
"HMC: start inline measurements" << std::endl;
557 XMLBufferWriter gauge_xml;
558 push(gauge_xml,
"ChromaHMC");
559 write(gauge_xml,
"update_no", cur_update);
560 write(gauge_xml,
"HMCTrj", update_params);
564 QDPIO::cout <<
"HMC: initial resetting default gauge field" << std::endl;
566 QDPIO::cout <<
"HMC: set default gauge field" << std::endl;
568 QDPIO::cout <<
"HMC: finished setting default gauge field" << std::endl;
571 push(xml_out,
"InlineObservables");
574 for(
int m=0;
m < default_measurements.size();
m++)
576 QDPIO::cout <<
"HMC: do default measurement = " <<
m << std::endl;
577 QDPIO::cout <<
"HMC: dump named objects" << std::endl;
582 push(xml_out,
"elem");
583 the_meas(cur_update, xml_out);
586 QDPIO::cout <<
"HMC: finished default measurement = " <<
m << std::endl;
592 QDPIO::cout <<
"Doing " << user_measurements.size()
593 <<
" user measurements" << std::endl;
594 for(
int m=0;
m < user_measurements.size();
m++)
596 QDPIO::cout <<
"HMC: considering user measurement number = " <<
m << std::endl;
601 push(xml_out,
"elem");
602 QDPIO::cout <<
"HMC: calling user measurement number = " <<
m << std::endl;
603 the_meas(cur_update, xml_out);
604 QDPIO::cout <<
"HMC: finished user measurement number = " <<
m << std::endl;
608 QDPIO::cout <<
"HMC: finished user measurements" << std::endl;
613 QDPIO::cout <<
"HMC: final resetting default gauge field" << std::endl;
615 QDPIO::cout <<
"HMC: finished final resetting default gauge field" << std::endl;
619 QDPIO::cout <<
"After all measurements: time= "
620 << swatch.getTimeInSeconds()
621 <<
" secs" << std::endl;
623 write(xml_out,
"seconds_for_measurements", swatch.getTimeInSeconds());
624 write(xml_log,
"seconds_for_measurements", swatch.getTimeInSeconds());
632 saveState<UpdateParams>(update_params, mc_control, cur_update, gauge_state.
getQ());
635 QDPIO::cout <<
"After saving state: time= "
636 << swatch.getTimeInSeconds()
637 <<
" secs" << std::endl;
648 saveState<UpdateParams>(update_params, mc_control, cur_update, gauge_state.
getQ());
696 int main(
int argc,
char *argv[])
703 QDPIO::cout <<
"Linkage = " <<
linkageHack() << std::endl;
712 push(xml_out,
"hmc");
713 push(xml_log,
"hmc");
722 XMLReader paramtop(xml_in,
"/Params");
723 read( paramtop,
"./HMCTrj", trj_params);
724 read( paramtop,
"./MCControl", mc_control);
727 write(xml_out,
"Input", xml_in);
728 write(xml_log,
"Input", xml_in);
731 QDPIO::cerr <<
"hmc: Caught Exception while reading file: " << e << std::endl;
737 QDPIO::cout <<
"hmc: run is finished" << std::endl;
743 QDPIO::cout <<
"Call QDP create layout" << std::endl;
744 Layout::setLattSize(trj_params.
nrow);
746 QDPIO::cout <<
"Finished with QDP create layout" << std::endl;
752 multi1d<LatticeColorMatrix>
u(
Nd);
756 XMLReader config_xml;
758 QDPIO::cout <<
"Initialize gauge field" << std::endl;
763 std::istringstream xml_c(mc_control.
cfg.
xml);
764 XMLReader cfgtop(xml_c);
765 QDPIO::cout <<
"Gauge initialization: cfg_type = " << mc_control.
cfg.
id << std::endl;
771 (*gaugeInit)(file_xml, config_xml,
u);
774 QDPIO::cout <<
"Gauge field successfully initialized: time= "
775 << swatch.getTimeInSeconds()
776 <<
" secs" << std::endl;
786 QDPIO::cout <<
"Gauge field reunitarized: time="
787 << swatch.getTimeInSeconds()
788 <<
" secs" << std::endl;
791 write(xml_out,
"Config_info", config_xml);
792 write(xml_log,
"Config_info", config_xml);
796 QDPIO::cerr <<
"hmc: caught cast error" << std::endl;
801 QDPIO::cerr <<
"hmc: Caught Exception: " << e << std::endl;
804 catch(std::exception& e)
806 QDPIO::cerr <<
"hmc: Caught standard library exception: " << e.what() << std::endl;
811 QDPIO::cerr <<
"hmc: caught generic exception during measurement" << std::endl;
819 XMLReader monomial_reader(Monomial_is);
823 QDPIO::cout <<
"Caught Exception reading Monomials" << std::endl;
827 std::istringstream H_MC_is(trj_params.
H_MC_xml);
828 XMLReader H_MC_xml(H_MC_is);
836 XMLReader MDInt_xml(MDInt_is);
845 multi1d < Handle< AbsInlineMeasurement > > the_measurements;
852 XMLReader MeasXML(Measurements_is);
854 std::ostringstream os;
856 QDPIO::cout << os.str() << std::endl << std::flush;
858 read(MeasXML,
"/InlineMeasurements", the_measurements);
861 QDPIO::cerr <<
"hmc: Caught exception while reading measurements: " << e << std::endl
867 QDPIO::cout <<
"There are " << the_measurements.size() <<
" user measurements " << std::endl;
872 doHMC<HMCTrjParams>(
u, theHMCTrj, mc_control, trj_params, the_measurements);
876 QDPIO::cerr <<
"HMC: caught cast error" << std::endl;
879 catch(std::bad_alloc)
882 std::cerr <<
"HMC: caught bad memory allocation" << std::endl;
887 QDPIO::cerr <<
"HMC: Caught std::string exception: " << e << std::endl;
890 catch(std::exception& e)
892 QDPIO::cerr <<
"HMC: Caught standard library exception: " << e.what() << std::endl;
897 QDPIO::cerr <<
"HMC: Caught generic/unknown exception" << std::endl;
905 QDPIO::cout <<
"HMC: total time = "
906 << snoop.getTimeInSeconds()
907 <<
" secs" << std::endl;
921 const multi1d<LatticeColorMatrix>& Q_new,
922 const QDP::Seed& seed_new,
923 const multi1d<LatticeColorMatrix>& P_old,
924 const multi1d<LatticeColorMatrix>& Q_old,
925 const QDP::Seed& seed_old )
930 if ( P_new.size() != P_old.size() ) {
935 if ( Q_new.size() != Q_old.size() ) {
942 2*Nc*Nc*Layout::sitesOnNode()*
sizeof(WordType< LatticeColorMatrix >::Type_t);
945 for(
int mu=0;
mu < P_new.size();
mu++) {
946 const unsigned char *p1 = (
const unsigned char *)P_new[
mu].getF();
947 const unsigned char *p2 = (
const unsigned char *)P_old[
mu].getF();
948 for(
int b=0;
b < bytes;
b++) {
949 unsigned char diff = *p1 - *p2;
950 if( diff != 0 ) diffs_found++;
956 QDPInternal::globalSum(diffs_found);
958 if( diffs_found != 0 ) {
959 QDPIO::cout <<
"Found " << diffs_found <<
" different bytes in momentum repro check" << std::endl;
964 for(
int mu=0;
mu < P_new.size();
mu++) {
965 const unsigned char *p1 = (
const unsigned char *)Q_new[
mu].getF();
966 const unsigned char *p2 = (
const unsigned char *)Q_old[
mu].getF();
967 for(
int b=0;
b < bytes;
b++) {
968 unsigned char diff = *p1 - *p2;
969 if( diff != 0 ) diffs_found++;
975 QDPInternal::globalSum(diffs_found);
977 if( diffs_found != 0 ) {
978 QDPIO::cout <<
"Found " << diffs_found <<
" different bytes in gauge repro check" << std::endl;
982 if( ! toBool( seed_new == seed_old ) ) {
983 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.
const multi1d< LatticeColorMatrix > & getP(void) const
Accessors.
const multi1d< LatticeColorMatrix > & getQ(void) const
Class for counted reference semantics.
int main(int argc, char *argv[])
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.
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.
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