From 6448fe712196729e6ead92ea2ba88aeca34ddc46 Mon Sep 17 00:00:00 2001 From: Antonin Portelli Date: Mon, 1 Oct 2018 19:32:50 +0100 Subject: [PATCH 1/9] More flexible XML control in Lime files --- Grid/parallelIO/IldgIO.h | 17 ++++++++++++----- Grid/serialisation/XmlIO.cc | 37 +++++++++++++++++++++++++++---------- Grid/serialisation/XmlIO.h | 6 ++++-- 3 files changed, 43 insertions(+), 17 deletions(-) diff --git a/Grid/parallelIO/IldgIO.h b/Grid/parallelIO/IldgIO.h index 3cfc1349..16951a26 100644 --- a/Grid/parallelIO/IldgIO.h +++ b/Grid/parallelIO/IldgIO.h @@ -250,8 +250,7 @@ class GridLimeReader : public BinaryIO { //////////////////////////////////////////// // Read a generic serialisable object //////////////////////////////////////////// - template - void readLimeObject(serialisable_object &object,std::string object_name,std::string record_name) + void readLimeObject(std::string &xmlstring,std::string record_name) { // should this be a do while; can we miss a first record?? while ( limeReaderNextRecord(LimeR) == LIME_SUCCESS ) { @@ -266,15 +265,23 @@ class GridLimeReader : public BinaryIO { limeReaderReadData((void *)&xmlc[0], &nbytes, LimeR); // std::cout << GridLogMessage<< " readLimeObject matches XML " << &xmlc[0] < + void readLimeObject(serialisable_object &object,std::string object_name,std::string record_name) + { + std::string xmlstring; + + readLimeObject(xmlstring, record_name); + XmlReader RD(xmlstring, true, ""); + read(RD,object_name,object); + } }; class GridLimeWriter : public BinaryIO diff --git a/Grid/serialisation/XmlIO.cc b/Grid/serialisation/XmlIO.cc index e793c2f9..96f07f34 100644 --- a/Grid/serialisation/XmlIO.cc +++ b/Grid/serialisation/XmlIO.cc @@ -121,17 +121,26 @@ XmlReader::XmlReader(const std::string &s, const bool isBuffer, } } +#define XML_SAFE_NODE(expr)\ +if (expr)\ +{\ + node_ = expr;\ + return true;\ +}\ +else\ +{\ + return false;\ +} + bool XmlReader::push(const std::string &s) { - if (node_.child(s.c_str())) + if (s.empty()) { - node_ = node_.child(s.c_str()); - - return true; + XML_SAFE_NODE(node_.first_child()); } else { - return false; + XML_SAFE_NODE(node_.child(s.c_str())); } } @@ -142,18 +151,26 @@ void XmlReader::pop(void) bool XmlReader::nextElement(const std::string &s) { - if (node_.next_sibling(s.c_str())) + if (s.empty()) { - node_ = node_.next_sibling(s.c_str()); - - return true; + XML_SAFE_NODE(node_.next_sibling()); } else { - return false; + XML_SAFE_NODE(node_.next_sibling(s.c_str())); } } +void XmlReader::readCurrentSubtree(std::string &s) +{ + std::ostringstream oss; + pugi::xml_document doc; + + doc.append_copy(node_); + doc.save(oss, indent_.c_str(), pugi::format_default | pugi::format_no_declaration); + s = oss.str(); +} + template <> void XmlReader::readDefault(const std::string &s, std::string &output) { diff --git a/Grid/serialisation/XmlIO.h b/Grid/serialisation/XmlIO.h index 17ccb32e..a26a33c5 100644 --- a/Grid/serialisation/XmlIO.h +++ b/Grid/serialisation/XmlIO.h @@ -72,16 +72,18 @@ namespace Grid XmlReader(const std::string &fileName, const bool isBuffer = false, std::string toplev = std::string("grid") ); virtual ~XmlReader(void) = default; - bool push(const std::string &s); + bool push(const std::string &s = ""); void pop(void); - bool nextElement(const std::string &s); + bool nextElement(const std::string &s = ""); template void readDefault(const std::string &s, U &output); template void readDefault(const std::string &s, std::vector &output); + void readCurrentSubtree(std::string &s); private: void checkParse(const pugi::xml_parse_result &result, const std::string name); private: + const std::string indent_{" "}; pugi::xml_document doc_; pugi::xml_node node_; std::string fileName_; From 21bba95909a320a9477452d761fbe58e1c894418 Mon Sep 17 00:00:00 2001 From: Antonin Portelli Date: Mon, 1 Oct 2018 19:33:45 +0100 Subject: [PATCH 2/9] Hadrons: eigenpack metadata is no ignored anymore when reading --- Hadrons/EigenPack.hpp | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/Hadrons/EigenPack.hpp b/Hadrons/EigenPack.hpp index 49fecc34..3e0a6fb4 100644 --- a/Hadrons/EigenPack.hpp +++ b/Hadrons/EigenPack.hpp @@ -122,10 +122,16 @@ protected: void basicRead(std::vector &evec, std::vector &eval, const std::string filename, const unsigned int size) { - ScidacReader binReader; + ScidacReader binReader; + std::string recordXml; binReader.open(filename); - binReader.skipPastObjectRecord(SCIDAC_FILE_XML); + binReader.readLimeObject(recordXml, SCIDAC_FILE_XML); + XmlReader xmlReader(recordXml, true, "eigenPackPar"); + xmlReader.push(); + xmlReader.readCurrentSubtree(record.operatorXml); + xmlReader.nextElement(); + xmlReader.readCurrentSubtree(record.solverXml); for(int k = 0; k < size; ++k) { VecRecord vecRecord; @@ -149,9 +155,15 @@ protected: { ScidacReader binReader; VecRecord vecRecord; + std::string recordXml; binReader.open(filename); - binReader.skipPastObjectRecord(SCIDAC_FILE_XML); + binReader.readLimeObject(recordXml, SCIDAC_FILE_XML); + XmlReader xmlReader(recordXml, true, "eigenPackPar"); + xmlReader.push(); + xmlReader.readCurrentSubtree(record.operatorXml); + xmlReader.nextElement(); + xmlReader.readCurrentSubtree(record.solverXml); LOG(Message) << "Reading eigenvector " << index << std::endl; binReader.readScidacFieldRecord(evec, vecRecord); if (vecRecord.index != index) From 8fbb27ce1383b5d0515c2754d8b54f4c6290290f Mon Sep 17 00:00:00 2001 From: Antonin Portelli Date: Mon, 1 Oct 2018 20:15:21 +0100 Subject: [PATCH 3/9] Hadrons: less code duplication in eigenpack IO --- Hadrons/EigenPack.hpp | 77 +++++++++++++++++++++++++++++-------------- 1 file changed, 53 insertions(+), 24 deletions(-) diff --git a/Hadrons/EigenPack.hpp b/Hadrons/EigenPack.hpp index 3e0a6fb4..44836ef3 100644 --- a/Hadrons/EigenPack.hpp +++ b/Hadrons/EigenPack.hpp @@ -39,6 +39,13 @@ BEGIN_HADRONS_NAMESPACE #define HADRONS_DEFAULT_LANCZOS_NBASIS 60 #endif +#define HADRONS_DUMP_EP_METADATA \ +LOG(Message) << "Eigenpack metadata:" << std::endl;\ +LOG(Message) << "* operator" << std::endl;\ +LOG(Message) << record.operatorXml << std::endl;\ +LOG(Message) << "* solver" << std::endl;\ +LOG(Message) << record.solverXml << std::endl; + template class EigenPack { @@ -81,11 +88,16 @@ public: for(int k = 0; k < evec.size(); ++k) { basicReadSingle(evec[k], eval[k], evecFilename(fileStem, k, traj), k); + if (k == 0) + { + HADRONS_DUMP_EP_METADATA; + } } } else { basicRead(evec, eval, evecFilename(fileStem, -1, traj), evec.size()); + HADRONS_DUMP_EP_METADATA; } } @@ -118,26 +130,38 @@ protected: } } - template - void basicRead(std::vector &evec, std::vector &eval, - const std::string filename, const unsigned int size) + void readHeader(ScidacReader &binReader) { - ScidacReader binReader; std::string recordXml; - binReader.open(filename); binReader.readLimeObject(recordXml, SCIDAC_FILE_XML); XmlReader xmlReader(recordXml, true, "eigenPackPar"); xmlReader.push(); xmlReader.readCurrentSubtree(record.operatorXml); xmlReader.nextElement(); xmlReader.readCurrentSubtree(record.solverXml); + } + + template + void readElement(T &evec, VecRecord &vecRecord, ScidacReader &binReader) + { + binReader.readScidacFieldRecord(evec, vecRecord); + } + + template + void basicRead(std::vector &evec, std::vector &eval, + const std::string filename, const unsigned int size) + { + ScidacReader binReader; + + binReader.open(filename); + readHeader(binReader); for(int k = 0; k < size; ++k) { VecRecord vecRecord; LOG(Message) << "Reading eigenvector " << k << std::endl; - binReader.readScidacFieldRecord(evec[k], vecRecord); + readElement(evec[k], vecRecord, binReader); if (vecRecord.index != k) { HADRONS_ERROR(Io, "Eigenvector " + std::to_string(k) + " has a" @@ -155,17 +179,11 @@ protected: { ScidacReader binReader; VecRecord vecRecord; - std::string recordXml; binReader.open(filename); - binReader.readLimeObject(recordXml, SCIDAC_FILE_XML); - XmlReader xmlReader(recordXml, true, "eigenPackPar"); - xmlReader.push(); - xmlReader.readCurrentSubtree(record.operatorXml); - xmlReader.nextElement(); - xmlReader.readCurrentSubtree(record.solverXml); + readHeader(binReader); LOG(Message) << "Reading eigenvector " << index << std::endl; - binReader.readScidacFieldRecord(evec, vecRecord); + readElement(evec, vecRecord, binReader); if (vecRecord.index != index) { HADRONS_ERROR(Io, "Eigenvector " + std::to_string(index) + " has a" @@ -176,18 +194,30 @@ protected: binReader.close(); } + void writeHeader(ScidacWriter &binWriter) + { + XmlWriter xmlWriter("", "eigenPackPar"); + + xmlWriter.pushXmlString(record.operatorXml); + xmlWriter.pushXmlString(record.solverXml); + binWriter.writeLimeObject(1, 1, xmlWriter, "parameters", SCIDAC_FILE_XML); + } + + template + void writeElement(ScidacWriter &binWriter, T &evec, VecRecord &vecRecord) + { + binWriter.writeScidacFieldRecord(evec, vecRecord, DEFAULT_ASCII_PREC); + } + template void basicWrite(const std::string filename, std::vector &evec, const std::vector &eval, const unsigned int size) { ScidacWriter binWriter(evec[0]._grid->IsBoss()); - XmlWriter xmlWriter("", "eigenPackPar"); makeFileDir(filename, evec[0]._grid); - xmlWriter.pushXmlString(record.operatorXml); - xmlWriter.pushXmlString(record.solverXml); binWriter.open(filename); - binWriter.writeLimeObject(1, 1, xmlWriter, "parameters", SCIDAC_FILE_XML); + writeHeader(binWriter); for(int k = 0; k < size; ++k) { VecRecord vecRecord; @@ -195,7 +225,7 @@ protected: vecRecord.index = k; vecRecord.eval = eval[k]; LOG(Message) << "Writing eigenvector " << k << std::endl; - binWriter.writeScidacFieldRecord(evec[k], vecRecord, DEFAULT_ASCII_PREC); + writeElement(binWriter, evec[k], vecRecord); } binWriter.close(); } @@ -205,18 +235,15 @@ protected: const RealD eval, const unsigned int index) { ScidacWriter binWriter(evec._grid->IsBoss()); - XmlWriter xmlWriter("", "eigenPackPar"); VecRecord vecRecord; makeFileDir(filename, evec._grid); - xmlWriter.pushXmlString(record.operatorXml); - xmlWriter.pushXmlString(record.solverXml); binWriter.open(filename); - binWriter.writeLimeObject(1, 1, xmlWriter, "parameters", SCIDAC_FILE_XML); + writeHeader(binWriter); vecRecord.index = index; vecRecord.eval = eval; LOG(Message) << "Writing eigenvector " << index << std::endl; - binWriter.writeScidacFieldRecord(evec, vecRecord, DEFAULT_ASCII_PREC); + writeElement(binWriter, evec, vecRecord); binWriter.close(); } }; @@ -330,6 +357,8 @@ using CoarseFermionEigenPack = CoarseEigenPack< typename FImpl::SiteComplex, nBasis>::CoarseField>; +#undef HADRONS_DUMP_EP_METADATA + END_HADRONS_NAMESPACE #endif // Hadrons_EigenPack_hpp_ From aadd9f4468d0e13cc9fd06cdf18c7ecea4519e2b Mon Sep 17 00:00:00 2001 From: Antonin Portelli Date: Tue, 2 Oct 2018 00:02:34 +0100 Subject: [PATCH 4/9] Eigenpack converter, to be tested, HadronsXmlRun moved to Utilities directory --- Hadrons/EigenPack.hpp | 98 +++++++++--------- Hadrons/Makefile.am | 6 +- Hadrons/Utilities/EigenPackCast.cc | 123 +++++++++++++++++++++++ Hadrons/{ => Utilities}/HadronsXmlRun.cc | 0 Hadrons/Utilities/Makefile.am | 10 ++ configure.ac | 1 + 6 files changed, 186 insertions(+), 52 deletions(-) create mode 100644 Hadrons/Utilities/EigenPackCast.cc rename Hadrons/{ => Utilities}/HadronsXmlRun.cc (100%) create mode 100644 Hadrons/Utilities/Makefile.am diff --git a/Hadrons/EigenPack.hpp b/Hadrons/EigenPack.hpp index 44836ef3..0be998b7 100644 --- a/Hadrons/EigenPack.hpp +++ b/Hadrons/EigenPack.hpp @@ -46,22 +46,24 @@ LOG(Message) << record.operatorXml << std::endl;\ LOG(Message) << "* solver" << std::endl;\ LOG(Message) << record.solverXml << std::endl; +struct PackRecord +{ + std::string operatorXml, solverXml; +}; + +struct VecRecord: Serializable +{ + GRID_SERIALIZABLE_CLASS_MEMBERS(VecRecord, + unsigned int, index, + double, eval); + VecRecord(void): index(0), eval(0.) {} +}; + template class EigenPack { public: typedef F Field; - struct PackRecord - { - std::string operatorXml, solverXml; - }; - struct VecRecord: Serializable - { - GRID_SERIALIZABLE_CLASS_MEMBERS(VecRecord, - unsigned int, index, - double, eval); - VecRecord(void): index(0), eval(0.) {} - }; public: std::vector eval; std::vector evec; @@ -115,6 +117,39 @@ public: basicWrite(evecFilename(fileStem, -1, traj), evec, eval, evec.size()); } } + + static void readHeader(PackRecord &record, ScidacReader &binReader) + { + std::string recordXml; + + binReader.readLimeObject(recordXml, SCIDAC_FILE_XML); + XmlReader xmlReader(recordXml, true, "eigenPackPar"); + xmlReader.push(); + xmlReader.readCurrentSubtree(record.operatorXml); + xmlReader.nextElement(); + xmlReader.readCurrentSubtree(record.solverXml); + } + + template + static void readElement(T &evec, VecRecord &vecRecord, ScidacReader &binReader) + { + binReader.readScidacFieldRecord(evec, vecRecord); + } + + static void writeHeader(ScidacWriter &binWriter, PackRecord &record) + { + XmlWriter xmlWriter("", "eigenPackPar"); + + xmlWriter.pushXmlString(record.operatorXml); + xmlWriter.pushXmlString(record.solverXml); + binWriter.writeLimeObject(1, 1, xmlWriter, "parameters", SCIDAC_FILE_XML); + } + + template + static void writeElement(ScidacWriter &binWriter, T &evec, VecRecord &vecRecord) + { + binWriter.writeScidacFieldRecord(evec, vecRecord, DEFAULT_ASCII_PREC); + } protected: std::string evecFilename(const std::string stem, const int vec, const int traj) { @@ -130,24 +165,6 @@ protected: } } - void readHeader(ScidacReader &binReader) - { - std::string recordXml; - - binReader.readLimeObject(recordXml, SCIDAC_FILE_XML); - XmlReader xmlReader(recordXml, true, "eigenPackPar"); - xmlReader.push(); - xmlReader.readCurrentSubtree(record.operatorXml); - xmlReader.nextElement(); - xmlReader.readCurrentSubtree(record.solverXml); - } - - template - void readElement(T &evec, VecRecord &vecRecord, ScidacReader &binReader) - { - binReader.readScidacFieldRecord(evec, vecRecord); - } - template void basicRead(std::vector &evec, std::vector &eval, const std::string filename, const unsigned int size) @@ -155,7 +172,7 @@ protected: ScidacReader binReader; binReader.open(filename); - readHeader(binReader); + readHeader(record, binReader); for(int k = 0; k < size; ++k) { VecRecord vecRecord; @@ -181,7 +198,7 @@ protected: VecRecord vecRecord; binReader.open(filename); - readHeader(binReader); + readHeader(record, binReader); LOG(Message) << "Reading eigenvector " << index << std::endl; readElement(evec, vecRecord, binReader); if (vecRecord.index != index) @@ -194,21 +211,6 @@ protected: binReader.close(); } - void writeHeader(ScidacWriter &binWriter) - { - XmlWriter xmlWriter("", "eigenPackPar"); - - xmlWriter.pushXmlString(record.operatorXml); - xmlWriter.pushXmlString(record.solverXml); - binWriter.writeLimeObject(1, 1, xmlWriter, "parameters", SCIDAC_FILE_XML); - } - - template - void writeElement(ScidacWriter &binWriter, T &evec, VecRecord &vecRecord) - { - binWriter.writeScidacFieldRecord(evec, vecRecord, DEFAULT_ASCII_PREC); - } - template void basicWrite(const std::string filename, std::vector &evec, const std::vector &eval, const unsigned int size) @@ -217,7 +219,7 @@ protected: makeFileDir(filename, evec[0]._grid); binWriter.open(filename); - writeHeader(binWriter); + writeHeader(binWriter, record); for(int k = 0; k < size; ++k) { VecRecord vecRecord; @@ -239,7 +241,7 @@ protected: makeFileDir(filename, evec._grid); binWriter.open(filename); - writeHeader(binWriter); + writeHeader(binWriter, record); vecRecord.index = index; vecRecord.eval = eval; LOG(Message) << "Writing eigenvector " << index << std::endl; diff --git a/Hadrons/Makefile.am b/Hadrons/Makefile.am index fe851aee..4ec45c03 100644 --- a/Hadrons/Makefile.am +++ b/Hadrons/Makefile.am @@ -1,5 +1,6 @@ +SUBDIRS = . Utilities + lib_LIBRARIES = libHadrons.a -bin_PROGRAMS = HadronsXmlRun include modules.inc @@ -31,6 +32,3 @@ nobase_libHadrons_a_HEADERS = \ ModuleFactory.hpp \ Solver.hpp \ VirtualMachine.hpp - -HadronsXmlRun_SOURCES = HadronsXmlRun.cc -HadronsXmlRun_LDADD = libHadrons.a -lGrid diff --git a/Hadrons/Utilities/EigenPackCast.cc b/Hadrons/Utilities/EigenPackCast.cc new file mode 100644 index 00000000..cf1480dc --- /dev/null +++ b/Hadrons/Utilities/EigenPackCast.cc @@ -0,0 +1,123 @@ +#include +#include + +using namespace Grid; +using namespace QCD; +using namespace Hadrons; + +template +void convert(const std::string outFilename, const std::string inFilename, + const unsigned int size, const bool multiFile) +{ + assert(outFilename != inFilename); + + typedef EigenPack EPOut; + typedef EigenPack EPIn; + typedef typename FOut::vector_type VTypeOut; + typedef typename FIn::vector_type VTypeIn; + + std::shared_ptr gIn, gOut; + auto dim = GridDefaultLatt(); + unsigned int nd = dim.size(); + auto simdOut = GridDefaultSimd(nd, VTypeOut::Nsimd()); + auto simdIn = GridDefaultSimd(nd, VTypeIn::Nsimd()); + + gOut.reset(SpaceTimeGrid::makeFourDimGrid(dim, simdOut, GridDefaultMpi())); + gIn.reset(SpaceTimeGrid::makeFourDimGrid(dim, simdIn, GridDefaultMpi())); + + FOut bufOut(gOut.get()); + FIn bufIn(gIn.get()); + + if (multiFile) + { + for(unsigned int k = 0; k < size; ++k) + { + ScidacWriter binWriter(gOut->IsBoss()); + ScidacReader binReader; + PackRecord record; + VecRecord vecRecord; + std::string outV = outFilename + "/v" + std::to_string(k) + ".bin"; + std::string inV = inFilename + "/v" + std::to_string(k) + ".bin"; + + makeFileDir(outV, gOut.get()); + binWriter.open(outV); + binReader.open(inV); + EPIn::readHeader(record, binReader); + EPOut::writeHeader(binWriter, record); + EPIn::readElement(bufIn, vecRecord, binReader); + precisionChange(bufOut, bufIn); + EPOut::writeElement(binWriter, bufOut, vecRecord); + binWriter.close(); + binReader.close(); + } + } + else + { + ScidacWriter binWriter(gOut->IsBoss()); + ScidacReader binReader; + PackRecord record; + + makeFileDir(outFilename, gOut.get()); + binWriter.open(outFilename); + binReader.open(inFilename); + EPIn::readHeader(record, binReader); + EPOut::writeHeader(binWriter, record); + for(unsigned int k = 0; k < size; ++k) + { + VecRecord vecRecord; + + EPIn::readElement(bufIn, vecRecord, binReader); + precisionChange(bufOut, bufIn); + EPOut::writeElement(binWriter, bufOut, vecRecord); + } + binWriter.close(); + binReader.close(); + } +} + +#ifndef FOUT +#warning "FOUT undefined (set to WilsonImplF::FermionField by default)" +#define FOUT WilsonImplF::FermionField +#endif +#ifndef FIN +#warning "FIN undefined (set to WilsonImplD::FermionField by default)" +#define FIN WilsonImplD::FermionField +#endif + +int main(int argc, char *argv[]) +{ + // parse command line + std::string outFilename, inFilename; + unsigned int size; + bool multiFile; + + if (argc < 5) + { + std::cerr << "usage: " << argv[0] << " [Grid options]"; + std::cerr << std::endl; + std::exit(EXIT_FAILURE); + } + outFilename = argv[1]; + inFilename = argv[2]; + size = std::stoi(std::string(argv[3])); + multiFile = (std::string(argv[4]) != "0"); + + // initialization + Grid_init(&argc, &argv); + + // execution + try + { + convert(outFilename, inFilename, size, multiFile); + } + catch (const std::exception& e) + { + Exceptions::abort(e); + } + + // epilogue + LOG(Message) << "Grid is finalizing now" << std::endl; + Grid_finalize(); + + return EXIT_SUCCESS; +} diff --git a/Hadrons/HadronsXmlRun.cc b/Hadrons/Utilities/HadronsXmlRun.cc similarity index 100% rename from Hadrons/HadronsXmlRun.cc rename to Hadrons/Utilities/HadronsXmlRun.cc diff --git a/Hadrons/Utilities/Makefile.am b/Hadrons/Utilities/Makefile.am new file mode 100644 index 00000000..62c29ef9 --- /dev/null +++ b/Hadrons/Utilities/Makefile.am @@ -0,0 +1,10 @@ +AM_LDFLAGS += -L../../Hadrons + +bin_PROGRAMS = HadronsXmlRun FermionEigenPackCastToSingle + +HadronsXmlRun_SOURCES = HadronsXmlRun.cc +HadronsXmlRun_LDADD = -lHadrons -lGrid + +FermionEigenPackCastToSingle_SOURCES = EigenPackCast.cc +FermionEigenPackCastToSingle_CXXFLAGS = $(AM_CXXFLAGS) -DFIN=WilsonImplD::FermionField -DFOUT=WilsonImplF::FermionField +FermionEigenPackCastToSingle_LDADD = -lHadrons -lGrid diff --git a/configure.ac b/configure.ac index f57b00ad..d362ed5a 100644 --- a/configure.ac +++ b/configure.ac @@ -562,6 +562,7 @@ AC_CONFIG_FILES(tests/qdpxx/Makefile) AC_CONFIG_FILES(tests/testu01/Makefile) AC_CONFIG_FILES(benchmarks/Makefile) AC_CONFIG_FILES(Hadrons/Makefile) +AC_CONFIG_FILES(Hadrons/Utilities/Makefile) AC_OUTPUT echo "" From 4ab8cfbe2ab74141f1cc7bcb53ac0da8f39cc316 Mon Sep 17 00:00:00 2001 From: Antonin Portelli Date: Tue, 2 Oct 2018 12:24:45 +0100 Subject: [PATCH 5/9] Hadrons: more verbose eigenpack convert --- Hadrons/Utilities/EigenPackCast.cc | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/Hadrons/Utilities/EigenPackCast.cc b/Hadrons/Utilities/EigenPackCast.cc index cf1480dc..3d74a3aa 100644 --- a/Hadrons/Utilities/EigenPackCast.cc +++ b/Hadrons/Utilities/EigenPackCast.cc @@ -26,8 +26,14 @@ void convert(const std::string outFilename, const std::string inFilename, gIn.reset(SpaceTimeGrid::makeFourDimGrid(dim, simdIn, GridDefaultMpi())); FOut bufOut(gOut.get()); - FIn bufIn(gIn.get()); + FIn bufIn(gIn.get()), testIn(gIn.get()); + LOG(Message) << "==== EIGENPACK CONVERSION" << std::endl; + LOG(Message) << "In path : " << inFilename << std::endl; + LOG(Message) << "In type : " << typeName() << std::endl; + LOG(Message) << "Out path : " << outFilename << std::endl; + LOG(Message) << "Out type : " << typeName() << std::endl; + LOG(Message) << "Multifile: " << (multiFile ? "yes" : "no") << std::endl; if (multiFile) { for(unsigned int k = 0; k < size; ++k) @@ -39,6 +45,9 @@ void convert(const std::string outFilename, const std::string inFilename, std::string outV = outFilename + "/v" + std::to_string(k) + ".bin"; std::string inV = inFilename + "/v" + std::to_string(k) + ".bin"; + LOG(Message) << "==== Converting vector " << k << std::endl; + LOG(Message) << "In : " << inV << std::endl; + LOG(Message) << "Out: " << outV << std::endl; makeFileDir(outV, gOut.get()); binWriter.open(outV); binReader.open(inV); @@ -46,6 +55,9 @@ void convert(const std::string outFilename, const std::string inFilename, EPOut::writeHeader(binWriter, record); EPIn::readElement(bufIn, vecRecord, binReader); precisionChange(bufOut, bufIn); + precisionChange(testIn, bufOut); + testIn -= bufIn; + LOG(Message) << "Diff norm^2: " << norm2(testIn) << std::endl; EPOut::writeElement(binWriter, bufOut, vecRecord); binWriter.close(); binReader.close(); @@ -66,8 +78,12 @@ void convert(const std::string outFilename, const std::string inFilename, { VecRecord vecRecord; + LOG(Message) << "==== Converting vector " << k << std::endl; EPIn::readElement(bufIn, vecRecord, binReader); precisionChange(bufOut, bufIn); + precisionChange(testIn, bufOut); + testIn -= bufIn; + LOG(Message) << "Diff norm^2: " << norm2(testIn) << std::endl; EPOut::writeElement(binWriter, bufOut, vecRecord); } binWriter.close(); From 84189867ef5257df5e93b6a0bce333609623f001 Mon Sep 17 00:00:00 2001 From: Antonin Portelli Date: Tue, 2 Oct 2018 13:05:05 +0100 Subject: [PATCH 6/9] Hadrons: eigenpack converter with RB grids (to be generalised) --- Hadrons/Utilities/EigenPackCast.cc | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/Hadrons/Utilities/EigenPackCast.cc b/Hadrons/Utilities/EigenPackCast.cc index 3d74a3aa..e9be2c15 100644 --- a/Hadrons/Utilities/EigenPackCast.cc +++ b/Hadrons/Utilities/EigenPackCast.cc @@ -16,15 +16,17 @@ void convert(const std::string outFilename, const std::string inFilename, typedef typename FOut::vector_type VTypeOut; typedef typename FIn::vector_type VTypeIn; - std::shared_ptr gIn, gOut; + std::shared_ptr fgIn, fgOut, gIn, gOut; auto dim = GridDefaultLatt(); unsigned int nd = dim.size(); auto simdOut = GridDefaultSimd(nd, VTypeOut::Nsimd()); auto simdIn = GridDefaultSimd(nd, VTypeIn::Nsimd()); - gOut.reset(SpaceTimeGrid::makeFourDimGrid(dim, simdOut, GridDefaultMpi())); - gIn.reset(SpaceTimeGrid::makeFourDimGrid(dim, simdIn, GridDefaultMpi())); - + fgOut.reset(SpaceTimeGrid::makeFourDimGrid(dim, simdOut, GridDefaultMpi())); + gOut.reset(SpaceTimeGrid::makeFourDimRedBlackGrid(fgOut.get())); + fgIn.reset(SpaceTimeGrid::makeFourDimGrid(dim, simdIn, GridDefaultMpi())); + gIn.reset(SpaceTimeGrid::makeFourDimRedBlackGrid(fgOut.get())); + FOut bufOut(gOut.get()); FIn bufIn(gIn.get()), testIn(gIn.get()); From 430b98b35474e67ee9a7743d930d69a62f5e9a9b Mon Sep 17 00:00:00 2001 From: Antonin Portelli Date: Tue, 2 Oct 2018 13:12:46 +0100 Subject: [PATCH 7/9] fix previous commit --- Hadrons/Utilities/EigenPackCast.cc | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/Hadrons/Utilities/EigenPackCast.cc b/Hadrons/Utilities/EigenPackCast.cc index e9be2c15..c35a3321 100644 --- a/Hadrons/Utilities/EigenPackCast.cc +++ b/Hadrons/Utilities/EigenPackCast.cc @@ -16,7 +16,9 @@ void convert(const std::string outFilename, const std::string inFilename, typedef typename FOut::vector_type VTypeOut; typedef typename FIn::vector_type VTypeIn; - std::shared_ptr fgIn, fgOut, gIn, gOut; + std::shared_ptr fgIn, fgOut; + std::shared_ptr gIn, gOut; + auto dim = GridDefaultLatt(); unsigned int nd = dim.size(); auto simdOut = GridDefaultSimd(nd, VTypeOut::Nsimd()); @@ -25,8 +27,8 @@ void convert(const std::string outFilename, const std::string inFilename, fgOut.reset(SpaceTimeGrid::makeFourDimGrid(dim, simdOut, GridDefaultMpi())); gOut.reset(SpaceTimeGrid::makeFourDimRedBlackGrid(fgOut.get())); fgIn.reset(SpaceTimeGrid::makeFourDimGrid(dim, simdIn, GridDefaultMpi())); - gIn.reset(SpaceTimeGrid::makeFourDimRedBlackGrid(fgOut.get())); - + gIn.reset(SpaceTimeGrid::makeFourDimRedBlackGrid(fgIn.get())); + FOut bufOut(gOut.get()); FIn bufIn(gIn.get()), testIn(gIn.get()); From 9aafa8ee60a1830c5a630c8738c8ee1a6f14d3b0 Mon Sep 17 00:00:00 2001 From: Antonin Portelli Date: Tue, 2 Oct 2018 13:34:17 +0100 Subject: [PATCH 8/9] Hadrons: eigenpack converter generalised for RB/5d grids --- Hadrons/Utilities/EigenPackCast.cc | 89 +++++++++++++++++++++--------- 1 file changed, 62 insertions(+), 27 deletions(-) diff --git a/Hadrons/Utilities/EigenPackCast.cc b/Hadrons/Utilities/EigenPackCast.cc index c35a3321..07c37a7c 100644 --- a/Hadrons/Utilities/EigenPackCast.cc +++ b/Hadrons/Utilities/EigenPackCast.cc @@ -7,7 +7,8 @@ using namespace Hadrons; template void convert(const std::string outFilename, const std::string inFilename, - const unsigned int size, const bool multiFile) + const unsigned int Ls, const bool rb, const unsigned int size, + const bool multiFile) { assert(outFilename != inFilename); @@ -16,28 +17,60 @@ void convert(const std::string outFilename, const std::string inFilename, typedef typename FOut::vector_type VTypeOut; typedef typename FIn::vector_type VTypeIn; - std::shared_ptr fgIn, fgOut; - std::shared_ptr gIn, gOut; + std::shared_ptr gInBase, gOutBase, gIn5, gOut5; + std::shared_ptr rbgIn, rbgOut; + GridBase *gIn, *gOut; - auto dim = GridDefaultLatt(); - unsigned int nd = dim.size(); - auto simdOut = GridDefaultSimd(nd, VTypeOut::Nsimd()); - auto simdIn = GridDefaultSimd(nd, VTypeIn::Nsimd()); + auto dim = GridDefaultLatt(); + unsigned int nd = dim.size(); + auto simdOut = GridDefaultSimd(nd, VTypeOut::Nsimd()); + auto simdIn = GridDefaultSimd(nd, VTypeIn::Nsimd()); - fgOut.reset(SpaceTimeGrid::makeFourDimGrid(dim, simdOut, GridDefaultMpi())); - gOut.reset(SpaceTimeGrid::makeFourDimRedBlackGrid(fgOut.get())); - fgIn.reset(SpaceTimeGrid::makeFourDimGrid(dim, simdIn, GridDefaultMpi())); - gIn.reset(SpaceTimeGrid::makeFourDimRedBlackGrid(fgIn.get())); + gOutBase.reset(SpaceTimeGrid::makeFourDimGrid(dim, simdOut, GridDefaultMpi())); + gInBase.reset(SpaceTimeGrid::makeFourDimGrid(dim, simdIn, GridDefaultMpi())); + if (rb) + { + if (Ls > 1) + { + rbgOut.reset(SpaceTimeGrid::makeFiveDimRedBlackGrid(Ls, gOutBase.get())); + rbgIn.reset(SpaceTimeGrid::makeFiveDimRedBlackGrid(Ls, gInBase.get())); + } + else + { + rbgOut.reset(SpaceTimeGrid::makeFourDimRedBlackGrid(gOutBase.get())); + rbgIn.reset(SpaceTimeGrid::makeFourDimRedBlackGrid(gInBase.get())); + } + gOut = rbgOut.get(); + gIn = rbgIn.get(); + } + else + { + if (Ls > 1) + { + gOut5.reset(SpaceTimeGrid::makeFiveDimGrid(Ls, gOutBase.get())); + gIn5.reset(SpaceTimeGrid::makeFiveDimGrid(Ls, gInBase.get())); + gOut = gOut5.get(); + gIn = gIn5.get(); + } + else + { + gOut = gOutBase.get(); + gIn = gInBase.get(); + } + } - FOut bufOut(gOut.get()); - FIn bufIn(gIn.get()), testIn(gIn.get()); + FOut bufOut(gOut); + FIn bufIn(gIn), testIn(gIn); LOG(Message) << "==== EIGENPACK CONVERSION" << std::endl; - LOG(Message) << "In path : " << inFilename << std::endl; - LOG(Message) << "In type : " << typeName() << std::endl; - LOG(Message) << "Out path : " << outFilename << std::endl; - LOG(Message) << "Out type : " << typeName() << std::endl; - LOG(Message) << "Multifile: " << (multiFile ? "yes" : "no") << std::endl; + LOG(Message) << "Lattice : " << gIn->GlobalDimensions() << std::endl; + LOG(Message) << "Checkerboarded: " << (rb ? "yes" : "no") << std::endl; + LOG(Message) << "In path : " << inFilename << std::endl; + LOG(Message) << "In type : " << typeName() << std::endl; + LOG(Message) << "Out path : " << outFilename << std::endl; + LOG(Message) << "Out type : " << typeName() << std::endl; + LOG(Message) << "#vectors : " << size << std::endl; + LOG(Message) << "Multifile : " << (multiFile ? "yes" : "no") << std::endl; if (multiFile) { for(unsigned int k = 0; k < size; ++k) @@ -52,7 +85,7 @@ void convert(const std::string outFilename, const std::string inFilename, LOG(Message) << "==== Converting vector " << k << std::endl; LOG(Message) << "In : " << inV << std::endl; LOG(Message) << "Out: " << outV << std::endl; - makeFileDir(outV, gOut.get()); + makeFileDir(outV, gOut); binWriter.open(outV); binReader.open(inV); EPIn::readHeader(record, binReader); @@ -73,7 +106,7 @@ void convert(const std::string outFilename, const std::string inFilename, ScidacReader binReader; PackRecord record; - makeFileDir(outFilename, gOut.get()); + makeFileDir(outFilename, gOut); binWriter.open(outFilename); binReader.open(inFilename); EPIn::readHeader(record, binReader); @@ -108,19 +141,21 @@ int main(int argc, char *argv[]) { // parse command line std::string outFilename, inFilename; - unsigned int size; - bool multiFile; + unsigned int size, Ls; + bool rb, multiFile; - if (argc < 5) + if (argc < 7) { - std::cerr << "usage: " << argv[0] << " [Grid options]"; + std::cerr << "usage: " << argv[0] << " <#vector> [Grid options]"; std::cerr << std::endl; std::exit(EXIT_FAILURE); } outFilename = argv[1]; inFilename = argv[2]; - size = std::stoi(std::string(argv[3])); - multiFile = (std::string(argv[4]) != "0"); + Ls = std::stoi(std::string(argv[3])); + rb = (std::string(argv[4]) != "0"); + size = std::stoi(std::string(argv[5])); + multiFile = (std::string(argv[6]) != "0"); // initialization Grid_init(&argc, &argv); @@ -128,7 +163,7 @@ int main(int argc, char *argv[]) // execution try { - convert(outFilename, inFilename, size, multiFile); + convert(outFilename, inFilename, Ls, rb, size, multiFile); } catch (const std::exception& e) { From 02aa4bd7622ee7f9408c8cfb59f5459a75dfe845 Mon Sep 17 00:00:00 2001 From: Antonin Portelli Date: Tue, 2 Oct 2018 13:43:25 +0100 Subject: [PATCH 9/9] Hadrons: cleaner eigenpack convert log --- Hadrons/Utilities/EigenPackCast.cc | 1 + 1 file changed, 1 insertion(+) diff --git a/Hadrons/Utilities/EigenPackCast.cc b/Hadrons/Utilities/EigenPackCast.cc index 07c37a7c..cf35a550 100644 --- a/Hadrons/Utilities/EigenPackCast.cc +++ b/Hadrons/Utilities/EigenPackCast.cc @@ -159,6 +159,7 @@ int main(int argc, char *argv[]) // initialization Grid_init(&argc, &argv); + initLogger(); // execution try