From 44de727cd2e6a19ab64c1a36a86f40cb1f4db099 Mon Sep 17 00:00:00 2001 From: Antonin Portelli Date: Tue, 2 Oct 2018 19:51:09 +0100 Subject: [PATCH 1/6] Hadrons: eigenpack support for multiprecision I/O --- Hadrons/EigenPack.hpp | 441 +++++++++++++++-------------- Hadrons/Utilities/EigenPackCast.cc | 43 +-- 2 files changed, 249 insertions(+), 235 deletions(-) diff --git a/Hadrons/EigenPack.hpp b/Hadrons/EigenPack.hpp index 0be998b7..0e6f95d7 100644 --- a/Hadrons/EigenPack.hpp +++ b/Hadrons/EigenPack.hpp @@ -39,12 +39,12 @@ BEGIN_HADRONS_NAMESPACE #define HADRONS_DEFAULT_LANCZOS_NBASIS 60 #endif -#define HADRONS_DUMP_EP_METADATA \ +#define HADRONS_DUMP_EP_METADATA(record) \ LOG(Message) << "Eigenpack metadata:" << std::endl;\ LOG(Message) << "* operator" << std::endl;\ -LOG(Message) << record.operatorXml << std::endl;\ +LOG(Message) << (record).operatorXml << std::endl;\ LOG(Message) << "* solver" << std::endl;\ -LOG(Message) << record.solverXml << std::endl; +LOG(Message) << (record).solverXml << std::endl; struct PackRecord { @@ -59,7 +59,172 @@ struct VecRecord: Serializable VecRecord(void): index(0), eval(0.) {} }; -template +namespace EigenPackIo +{ + 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 + void readElement(T &evec, RealD &eval, const unsigned int index, + ScidacReader &binReader, TIo *ioBuf = nullptr) + { + VecRecord vecRecord; + + LOG(Message) << "Reading eigenvector " << index << std::endl; + if (ioBuf == nullptr) + { + binReader.readScidacFieldRecord(evec, vecRecord); + } + else + { + binReader.readScidacFieldRecord(*ioBuf, vecRecord); + precisionChange(evec, *ioBuf); + } + if (vecRecord.index != index) + { + HADRONS_ERROR(Io, "Eigenvector " + std::to_string(index) + " has a" + + " wrong index (expected " + std::to_string(vecRecord.index) + + ")"); + } + eval = vecRecord.eval; + } + + template + static void readPack(std::vector &evec, std::vector &eval, + PackRecord &record, const std::string filename, + const unsigned int size, bool multiFile, + GridBase *gridIo = nullptr) + { + std::unique_ptr ioBuf{nullptr}; + ScidacReader binReader; + + if (typeHash() != typeHash()) + { + if (gridIo == nullptr) + { + HADRONS_ERROR(Definition, + "I/O type different from vector type but null I/O grid passed"); + } + ioBuf.reset(new TIo(gridIo)); + } + if (multiFile) + { + std::string fullFilename; + + for(int k = 0; k < size; ++k) + { + fullFilename = filename + "/v" + std::to_string(k) + ".bin"; + binReader.open(fullFilename); + readHeader(record, binReader); + readElement(evec[k], eval[k], k, binReader, ioBuf.get()); + binReader.close(); + } + } + else + { + binReader.open(filename); + readHeader(record, binReader); + for(int k = 0; k < size; ++k) + { + readElement(evec[k], eval[k], k, binReader, ioBuf.get()); + } + binReader.close(); + } + } + + 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 + void writeElement(ScidacWriter &binWriter, T &evec, RealD &eval, + const unsigned int index, TIo *ioBuf, + T *testBuf = nullptr) + { + VecRecord vecRecord; + + LOG(Message) << "Writing eigenvector " << index << std::endl; + vecRecord.eval = eval; + vecRecord.index = index; + if ((ioBuf == nullptr) || (testBuf == nullptr)) + { + binWriter.writeScidacFieldRecord(evec, vecRecord, DEFAULT_ASCII_PREC); + } + else + { + precisionChange(*ioBuf, evec); + precisionChange(*testBuf, *ioBuf); + *testBuf -= evec; + LOG(Message) << "Precision diff norm^2 " << norm2(*testBuf) << std::endl; + binWriter.writeScidacFieldRecord(*ioBuf, vecRecord, DEFAULT_ASCII_PREC); + } + } + + template + static void writePack(const std::string filename, std::vector &evec, + std::vector &eval, PackRecord &record, + const unsigned int size, bool multiFile, + GridBase *gridIo = nullptr) + { + GridBase *grid = evec[0]._grid; + std::unique_ptr ioBuf{nullptr}; + std::unique_ptr testBuf{nullptr}; + ScidacWriter binWriter(grid->IsBoss()); + + if (typeHash() != typeHash()) + { + if (gridIo == nullptr) + { + HADRONS_ERROR(Definition, + "I/O type different from vector type but null I/O grid passed"); + } + ioBuf.reset(new TIo(gridIo)); + testBuf.reset(new T(grid)); + } + if (multiFile) + { + std::string fullFilename; + + for(int k = 0; k < size; ++k) + { + fullFilename = filename + "/v" + std::to_string(k) + ".bin"; + + makeFileDir(fullFilename, grid); + binWriter.open(fullFilename); + writeHeader(binWriter, record); + writeElement(binWriter, evec[k], eval[k], k, ioBuf.get(), testBuf.get()); + binWriter.close(); + } + } + else + { + makeFileDir(filename, grid); + binWriter.open(filename); + writeHeader(binWriter, record); + for(int k = 0; k < size; ++k) + { + writeElement(binWriter, evec[k], eval[k], k, ioBuf.get(), testBuf.get()); + } + binWriter.close(); + } + } +} + +template class EigenPack { public: @@ -72,8 +237,17 @@ public: EigenPack(void) = default; virtual ~EigenPack(void) = default; - EigenPack(const size_t size, GridBase *grid) + EigenPack(const size_t size, GridBase *grid, GridBase *gridIo = nullptr) { + if (typeHash() != typeHash()) + { + if (gridIo == nullptr) + { + HADRONS_ERROR(Definition, + "I/O type different from vector type but null I/O grid passed"); + } + } + gridIo_ = gridIo; resize(size, grid); } @@ -85,225 +259,92 @@ public: virtual void read(const std::string fileStem, const bool multiFile, const int traj = -1) { - if (multiFile) - { - 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; - } + EigenPackIo::readPack(evec, eval, record, evecFilename(fileStem, traj, multiFile), evec.size(), multiFile, gridIo_); + HADRONS_DUMP_EP_METADATA(record); } virtual void write(const std::string fileStem, const bool multiFile, const int traj = -1) { - if (multiFile) - { - for(int k = 0; k < evec.size(); ++k) - { - basicWriteSingle(evecFilename(fileStem, k, traj), evec[k], eval[k], k); - } - } - else - { - 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); + EigenPackIo::writePack(evecFilename(fileStem, traj, multiFile), evec, eval, record, evec.size(), multiFile, gridIo_); } protected: - std::string evecFilename(const std::string stem, const int vec, const int traj) + std::string evecFilename(const std::string stem, const int traj, const bool multiFile) { std::string t = (traj < 0) ? "" : ("." + std::to_string(traj)); - if (vec == -1) + if (multiFile) { - return stem + t + ".bin"; + return stem + t; } else { - return stem + t + "/v" + std::to_string(vec) + ".bin"; + return stem + t + ".bin"; } } - template - void basicRead(std::vector &evec, std::vector &eval, - const std::string filename, const unsigned int size) - { - ScidacReader binReader; - - binReader.open(filename); - readHeader(record, binReader); - for(int k = 0; k < size; ++k) - { - VecRecord vecRecord; - - LOG(Message) << "Reading eigenvector " << k << std::endl; - readElement(evec[k], vecRecord, binReader); - if (vecRecord.index != k) - { - HADRONS_ERROR(Io, "Eigenvector " + std::to_string(k) + " has a" - + " wrong index (expected " + std::to_string(vecRecord.index) - + ") in file '" + filename + "'"); - } - eval[k] = vecRecord.eval; - } - binReader.close(); - } - - template - void basicReadSingle(T &evec, RealD &eval, const std::string filename, - const unsigned int index) - { - ScidacReader binReader; - VecRecord vecRecord; - - binReader.open(filename); - readHeader(record, binReader); - LOG(Message) << "Reading eigenvector " << index << std::endl; - readElement(evec, vecRecord, binReader); - if (vecRecord.index != index) - { - HADRONS_ERROR(Io, "Eigenvector " + std::to_string(index) + " has a" - + " wrong index (expected " + std::to_string(vecRecord.index) - + ") in file '" + filename + "'"); - } - eval = vecRecord.eval; - binReader.close(); - } - - template - void basicWrite(const std::string filename, std::vector &evec, - const std::vector &eval, const unsigned int size) - { - ScidacWriter binWriter(evec[0]._grid->IsBoss()); - - makeFileDir(filename, evec[0]._grid); - binWriter.open(filename); - writeHeader(binWriter, record); - for(int k = 0; k < size; ++k) - { - VecRecord vecRecord; - - vecRecord.index = k; - vecRecord.eval = eval[k]; - LOG(Message) << "Writing eigenvector " << k << std::endl; - writeElement(binWriter, evec[k], vecRecord); - } - binWriter.close(); - } - - template - void basicWriteSingle(const std::string filename, T &evec, - const RealD eval, const unsigned int index) - { - ScidacWriter binWriter(evec._grid->IsBoss()); - VecRecord vecRecord; - - makeFileDir(filename, evec._grid); - binWriter.open(filename); - writeHeader(binWriter, record); - vecRecord.index = index; - vecRecord.eval = eval; - LOG(Message) << "Writing eigenvector " << index << std::endl; - writeElement(binWriter, evec, vecRecord); - binWriter.close(); - } + +protected: + GridBase *gridIo_; }; -template -class CoarseEigenPack: public EigenPack +template +class CoarseEigenPack: public EigenPack { public: - typedef CoarseF CoarseField; -public: - std::vector evalCoarse; + typedef CoarseF CoarseField; std::vector evecCoarse; + std::vector evalCoarse; public: CoarseEigenPack(void) = default; virtual ~CoarseEigenPack(void) = default; CoarseEigenPack(const size_t sizeFine, const size_t sizeCoarse, - GridBase *gridFine, GridBase *gridCoarse) + GridBase *gridFine, GridBase *gridCoarse, + GridBase *gridFineIo = nullptr, + GridBase *gridCoarseIo = nullptr) { + if (typeHash() != typeHash()) + { + if (gridFineIo == nullptr) + { + HADRONS_ERROR(Definition, + "Fine I/O type different from vector type but null fine I/O grid passed"); + } + } + if (typeHash() != typeHash()) + { + if (gridCoarseIo == nullptr) + { + HADRONS_ERROR(Definition, + "Coarse I/O type different from vector type but null coarse I/O grid passed"); + } + } + this->gridIo_ = gridFineIo; + gridCoarseIo_ = gridCoarseIo; resize(sizeFine, sizeCoarse, gridFine, gridCoarse); } void resize(const size_t sizeFine, const size_t sizeCoarse, GridBase *gridFine, GridBase *gridCoarse) { - EigenPack::resize(sizeFine, gridFine); + EigenPack::resize(sizeFine, gridFine); evalCoarse.resize(sizeCoarse); evecCoarse.resize(sizeCoarse, gridCoarse); } void readFine(const std::string fileStem, const bool multiFile, const int traj = -1) { - if (multiFile) - { - for(int k = 0; k < this->evec.size(); ++k) - { - this->basicReadSingle(this->evec[k], this->eval[k], this->evecFilename(fileStem + "_fine", k, traj), k); - } - } - else - { - this->basicRead(this->evec, this->eval, this->evecFilename(fileStem + "_fine", -1, traj), this->evec.size()); - } + EigenPack::read(fileStem + "_fine", multiFile, traj); } void readCoarse(const std::string fileStem, const bool multiFile, const int traj = -1) { - if (multiFile) - { - for(int k = 0; k < evecCoarse.size(); ++k) - { - this->basicReadSingle(evecCoarse[k], evalCoarse[k], this->evecFilename(fileStem + "_coarse", k, traj), k); - } - } - else - { - this->basicRead(evecCoarse, evalCoarse, this->evecFilename(fileStem + "_coarse", -1, traj), evecCoarse.size()); - } + PackRecord dummy; + + EigenPackIo::readPack(evecCoarse, evalCoarse, dummy, + this->evecFilename(fileStem + "_coarse", traj, multiFile), + evecCoarse.size(), multiFile, gridCoarseIo_); } virtual void read(const std::string fileStem, const bool multiFile, const int traj = -1) @@ -314,32 +355,14 @@ public: void writeFine(const std::string fileStem, const bool multiFile, const int traj = -1) { - if (multiFile) - { - for(int k = 0; k < this->evec.size(); ++k) - { - this->basicWriteSingle(this->evecFilename(fileStem + "_fine", k, traj), this->evec[k], this->eval[k], k); - } - } - else - { - this->basicWrite(this->evecFilename(fileStem + "_fine", -1, traj), this->evec, this->eval, this->evec.size()); - } + EigenPack::write(fileStem + "_fine", multiFile, traj); } void writeCoarse(const std::string fileStem, const bool multiFile, const int traj = -1) { - if (multiFile) - { - for(int k = 0; k < evecCoarse.size(); ++k) - { - this->basicWriteSingle(this->evecFilename(fileStem + "_coarse", k, traj), evecCoarse[k], evalCoarse[k], k); - } - } - else - { - this->basicWrite(this->evecFilename(fileStem + "_coarse", -1, traj), evecCoarse, evalCoarse, evecCoarse.size()); - } + EigenPackIo::writePack(this->evecFilename(fileStem + "_coarse", traj, multiFile), + evecCoarse, evalCoarse, this->record, + evecCoarse.size(), multiFile, gridCoarseIo_); } virtual void write(const std::string fileStem, const bool multiFile, const int traj = -1) @@ -347,16 +370,22 @@ public: writeFine(fileStem, multiFile, traj); writeCoarse(fileStem, multiFile, traj); } +private: + GridBase *gridCoarseIo_; }; -template -using FermionEigenPack = EigenPack; +template +using FermionEigenPack = EigenPack; -template +template using CoarseFermionEigenPack = CoarseEigenPack< typename FImpl::FermionField, typename LocalCoherenceLanczos::CoarseField, + typename FImplIo::FermionField, + typename LocalCoherenceLanczos::CoarseField>; #undef HADRONS_DUMP_EP_METADATA diff --git a/Hadrons/Utilities/EigenPackCast.cc b/Hadrons/Utilities/EigenPackCast.cc index cf35a550..7247c92d 100644 --- a/Hadrons/Utilities/EigenPackCast.cc +++ b/Hadrons/Utilities/EigenPackCast.cc @@ -59,8 +59,12 @@ void convert(const std::string outFilename, const std::string inFilename, } } - FOut bufOut(gOut); - FIn bufIn(gIn), testIn(gIn); + FOut bufOut(gOut); + FIn bufIn(gIn), testIn(gIn); + ScidacWriter binWriter(gOut->IsBoss()); + ScidacReader binReader; + PackRecord record; + RealD eval; LOG(Message) << "==== EIGENPACK CONVERSION" << std::endl; LOG(Message) << "Lattice : " << gIn->GlobalDimensions() << std::endl; @@ -75,10 +79,6 @@ void convert(const std::string outFilename, const std::string inFilename, { 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"; @@ -88,40 +88,25 @@ void convert(const std::string outFilename, const std::string inFilename, makeFileDir(outV, gOut); binWriter.open(outV); binReader.open(inV); - EPIn::readHeader(record, binReader); - 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); + EigenPackIo::readHeader(record, binReader); + EigenPackIo::writeHeader(binWriter, record); + EigenPackIo::readElement(bufIn, eval, k, binReader); + EigenPackIo::writeElement(binWriter, bufIn, eval, k, &bufOut, &testIn); binWriter.close(); binReader.close(); } } else { - ScidacWriter binWriter(gOut->IsBoss()); - ScidacReader binReader; - PackRecord record; - makeFileDir(outFilename, gOut); binWriter.open(outFilename); binReader.open(inFilename); - EPIn::readHeader(record, binReader); - EPOut::writeHeader(binWriter, record); + EigenPackIo::readHeader(record, binReader); + EigenPackIo::writeHeader(binWriter, record); for(unsigned int k = 0; k < size; ++k) { - 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); + EigenPackIo::readElement(bufIn, eval, k, binReader); + EigenPackIo::writeElement(binWriter, bufIn, eval, k, &bufOut, &testIn); } binWriter.close(); binReader.close(); From 118cca4681a9f23f532d890266ec0a41fd16f032 Mon Sep 17 00:00:00 2001 From: Antonin Portelli Date: Tue, 2 Oct 2018 20:08:49 +0100 Subject: [PATCH 2/6] Hadrons: linking fix --- Hadrons/EigenPack.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Hadrons/EigenPack.hpp b/Hadrons/EigenPack.hpp index 0e6f95d7..5388851d 100644 --- a/Hadrons/EigenPack.hpp +++ b/Hadrons/EigenPack.hpp @@ -61,7 +61,7 @@ struct VecRecord: Serializable namespace EigenPackIo { - void readHeader(PackRecord &record, ScidacReader &binReader) + inline void readHeader(PackRecord &record, ScidacReader &binReader) { std::string recordXml; @@ -141,7 +141,7 @@ namespace EigenPackIo } } - void writeHeader(ScidacWriter &binWriter, PackRecord &record) + inline void writeHeader(ScidacWriter &binWriter, PackRecord &record) { XmlWriter xmlWriter("", "eigenPackPar"); From b351103c292542bebc49ff9b1ed928923b373223 Mon Sep 17 00:00:00 2001 From: Antonin Portelli Date: Tue, 2 Oct 2018 21:07:56 +0100 Subject: [PATCH 3/6] Hadrons: eigenpack load module with 32bit I/O --- Hadrons/EigenPack.hpp | 3 ++- Hadrons/Modules/MIO/LoadEigenPack.cc | 2 +- Hadrons/Modules/MIO/LoadEigenPack.hpp | 3 ++- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/Hadrons/EigenPack.hpp b/Hadrons/EigenPack.hpp index 5388851d..4c122a37 100644 --- a/Hadrons/EigenPack.hpp +++ b/Hadrons/EigenPack.hpp @@ -228,7 +228,8 @@ template class EigenPack { public: - typedef F Field; + typedef F Field; + typedef FIo FieldIo; public: std::vector eval; std::vector evec; diff --git a/Hadrons/Modules/MIO/LoadEigenPack.cc b/Hadrons/Modules/MIO/LoadEigenPack.cc index 7da4e14a..f0ae63c3 100644 --- a/Hadrons/Modules/MIO/LoadEigenPack.cc +++ b/Hadrons/Modules/MIO/LoadEigenPack.cc @@ -32,4 +32,4 @@ using namespace Hadrons; using namespace MIO; template class Grid::Hadrons::MIO::TLoadEigenPack>; - +template class Grid::Hadrons::MIO::TLoadEigenPack>; diff --git a/Hadrons/Modules/MIO/LoadEigenPack.hpp b/Hadrons/Modules/MIO/LoadEigenPack.hpp index 83ef1d0c..330d35ad 100644 --- a/Hadrons/Modules/MIO/LoadEigenPack.hpp +++ b/Hadrons/Modules/MIO/LoadEigenPack.hpp @@ -54,7 +54,7 @@ template class TLoadEigenPack: public Module { public: - typedef EigenPack BasePack; + typedef EigenPack BasePack; public: // constructor TLoadEigenPack(const std::string name); @@ -70,6 +70,7 @@ public: }; MODULE_REGISTER_TMP(LoadFermionEigenPack, TLoadEigenPack>, MIO); +MODULE_REGISTER_TMP(LoadFermionEigenPackIo32, ARG(TLoadEigenPack>), MIO); /****************************************************************************** * TLoadEigenPack implementation * From 52569d98d8d46d5b248eaff0d06c9df042d0c1fb Mon Sep 17 00:00:00 2001 From: Antonin Portelli Date: Wed, 3 Oct 2018 14:24:43 +0100 Subject: [PATCH 4/6] Hadrons: multiprec eigenpack I/O fix --- Hadrons/Modules/MIO/LoadEigenPack.hpp | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/Hadrons/Modules/MIO/LoadEigenPack.hpp b/Hadrons/Modules/MIO/LoadEigenPack.hpp index 330d35ad..99b6d866 100644 --- a/Hadrons/Modules/MIO/LoadEigenPack.hpp +++ b/Hadrons/Modules/MIO/LoadEigenPack.hpp @@ -54,7 +54,9 @@ template class TLoadEigenPack: public Module { public: - typedef EigenPack BasePack; + typedef typename Pack::Field Field; + typedef typename Pack::FieldIo FieldIo; + typedef EigenPack BasePack; public: // constructor TLoadEigenPack(const std::string name); @@ -102,9 +104,14 @@ std::vector TLoadEigenPack::getOutput(void) template void TLoadEigenPack::setup(void) { - env().createGrid(par().Ls); + GridBase *gridIo = nullptr; + + if (typeHash() != typeHash()) + { + gridIo = envGetRbGrid(FieldIo, par().Ls); + } envCreateDerived(BasePack, Pack, getName(), par().Ls, par().size, - env().getRbGrid(par().Ls)); + envGetRbGrid(Field, par().Ls), gridIo); } // execution /////////////////////////////////////////////////////////////////// From 5a3e83ff7b85f74a728c3b07960c6ac4445adc49 Mon Sep 17 00:00:00 2001 From: Antonin Portelli Date: Wed, 3 Oct 2018 14:45:01 +0100 Subject: [PATCH 5/6] Hadrons: new layer in eigenpacks class hierarchy --- Hadrons/EigenPack.hpp | 50 +++++++++++++------ Hadrons/Modules/MIO/LoadEigenPack.hpp | 6 +-- Hadrons/Modules/MSolver/A2AVectors.cc | 4 +- Hadrons/Modules/MSolver/A2AVectors.hpp | 4 +- Hadrons/Modules/MSolver/Guesser.hpp | 2 +- .../Modules/MSolver/LocalCoherenceLanczos.hpp | 2 +- 6 files changed, 43 insertions(+), 25 deletions(-) diff --git a/Hadrons/EigenPack.hpp b/Hadrons/EigenPack.hpp index 4c122a37..44dd84ff 100644 --- a/Hadrons/EigenPack.hpp +++ b/Hadrons/EigenPack.hpp @@ -224,21 +224,41 @@ namespace EigenPackIo } } -template -class EigenPack +template +class BaseEigenPack { public: - typedef F Field; - typedef FIo FieldIo; + typedef F Field; public: std::vector eval; std::vector evec; PackRecord record; +public: + BaseEigenPack(void) = default; + BaseEigenPack(const size_t size, GridBase *grid) + { + resize(size, grid); + } + virtual ~BaseEigenPack(void) = default; + void resize(const size_t size, GridBase *grid) + { + eval.resize(size); + evec.resize(size, grid); + } +}; + +template +class EigenPack: public BaseEigenPack +{ +public: + typedef F Field; + typedef FIo FieldIo; public: EigenPack(void) = default; virtual ~EigenPack(void) = default; EigenPack(const size_t size, GridBase *grid, GridBase *gridIo = nullptr) + : BaseEigenPack(size, grid) { if (typeHash() != typeHash()) { @@ -249,24 +269,21 @@ public: } } gridIo_ = gridIo; - resize(size, grid); - } - - void resize(const size_t size, GridBase *grid) - { - eval.resize(size); - evec.resize(size, grid); } virtual void read(const std::string fileStem, const bool multiFile, const int traj = -1) { - EigenPackIo::readPack(evec, eval, record, evecFilename(fileStem, traj, multiFile), evec.size(), multiFile, gridIo_); - HADRONS_DUMP_EP_METADATA(record); + EigenPackIo::readPack(this->evec, this->eval, this->record, + evecFilename(fileStem, traj, multiFile), + this->evec.size(), multiFile, gridIo_); + HADRONS_DUMP_EP_METADATA(this->record); } virtual void write(const std::string fileStem, const bool multiFile, const int traj = -1) { - EigenPackIo::writePack(evecFilename(fileStem, traj, multiFile), evec, eval, record, evec.size(), multiFile, gridIo_); + EigenPackIo::writePack(evecFilename(fileStem, traj, multiFile), + this->evec, this->eval, this->record, + this->evec.size(), multiFile, gridIo_); } protected: std::string evecFilename(const std::string stem, const int traj, const bool multiFile) @@ -282,8 +299,6 @@ protected: return stem + t + ".bin"; } } - - protected: GridBase *gridIo_; }; @@ -375,6 +390,9 @@ private: GridBase *gridCoarseIo_; }; +template +using BaseFermionEigenPack = BaseEigenPack; + template using FermionEigenPack = EigenPack; diff --git a/Hadrons/Modules/MIO/LoadEigenPack.hpp b/Hadrons/Modules/MIO/LoadEigenPack.hpp index 99b6d866..2302b15d 100644 --- a/Hadrons/Modules/MIO/LoadEigenPack.hpp +++ b/Hadrons/Modules/MIO/LoadEigenPack.hpp @@ -54,9 +54,9 @@ template class TLoadEigenPack: public Module { public: - typedef typename Pack::Field Field; - typedef typename Pack::FieldIo FieldIo; - typedef EigenPack BasePack; + typedef typename Pack::Field Field; + typedef typename Pack::FieldIo FieldIo; + typedef BaseEigenPack BasePack; public: // constructor TLoadEigenPack(const std::string name); diff --git a/Hadrons/Modules/MSolver/A2AVectors.cc b/Hadrons/Modules/MSolver/A2AVectors.cc index 808a49e8..f5e9fd6c 100644 --- a/Hadrons/Modules/MSolver/A2AVectors.cc +++ b/Hadrons/Modules/MSolver/A2AVectors.cc @@ -32,5 +32,5 @@ using namespace Grid; using namespace Hadrons; using namespace MSolver; -template class Grid::Hadrons::MSolver::TA2AVectors>; -template class Grid::Hadrons::MSolver::TA2AVectors>; +template class Grid::Hadrons::MSolver::TA2AVectors>; +template class Grid::Hadrons::MSolver::TA2AVectors>; diff --git a/Hadrons/Modules/MSolver/A2AVectors.hpp b/Hadrons/Modules/MSolver/A2AVectors.hpp index 608e05b9..ee7cfa30 100644 --- a/Hadrons/Modules/MSolver/A2AVectors.hpp +++ b/Hadrons/Modules/MSolver/A2AVectors.hpp @@ -79,9 +79,9 @@ private: }; MODULE_REGISTER_TMP(A2AVectors, - ARG(TA2AVectors>), MSolver); + ARG(TA2AVectors>), MSolver); MODULE_REGISTER_TMP(ZA2AVectors, - ARG(TA2AVectors>), MSolver); + ARG(TA2AVectors>), MSolver); /****************************************************************************** * TA2AVectors implementation * diff --git a/Hadrons/Modules/MSolver/Guesser.hpp b/Hadrons/Modules/MSolver/Guesser.hpp index 5b4582d6..7063198d 100644 --- a/Hadrons/Modules/MSolver/Guesser.hpp +++ b/Hadrons/Modules/MSolver/Guesser.hpp @@ -39,7 +39,7 @@ std::shared_ptr> makeGuesser(const std::string epackName) { typedef typename FImpl::FermionField FermionField; - typedef FermionEigenPack EPack; + typedef BaseFermionEigenPack EPack; typedef CoarseFermionEigenPack CoarseEPack; typedef DeflatedGuesser FineGuesser; typedef LocalCoherenceDeflatedGuesser< diff --git a/Hadrons/Modules/MSolver/LocalCoherenceLanczos.hpp b/Hadrons/Modules/MSolver/LocalCoherenceLanczos.hpp index 4d942e45..7242eaf9 100644 --- a/Hadrons/Modules/MSolver/LocalCoherenceLanczos.hpp +++ b/Hadrons/Modules/MSolver/LocalCoherenceLanczos.hpp @@ -63,7 +63,7 @@ public: typedef LocalCoherenceLanczos LCL; - typedef FermionEigenPack BasePack; + typedef BaseFermionEigenPack BasePack; typedef CoarseFermionEigenPack CoarsePack; typedef HADRONS_DEFAULT_SCHUR_OP SchurFMat; public: From a1825d1f59de715337a736d81d28f98bfd8b8d53 Mon Sep 17 00:00:00 2001 From: Antonin Portelli Date: Thu, 4 Oct 2018 18:25:26 +0100 Subject: [PATCH 6/6] Hadrons: final fix for multiprec eigenpacks --- Hadrons/Modules/MSource/Point.hpp | 5 +++++ Hadrons/Utilities/Makefile.am | 6 ++---- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/Hadrons/Modules/MSource/Point.hpp b/Hadrons/Modules/MSource/Point.hpp index 082c04e8..2cc1bcd1 100644 --- a/Hadrons/Modules/MSource/Point.hpp +++ b/Hadrons/Modules/MSource/Point.hpp @@ -126,6 +126,11 @@ void TPoint::execute(void) auto &src = envGet(PropagatorField, getName()); SitePropagator id; + if (position.size() != env().getNd()) + { + HADRONS_ERROR(Size, "position has " + std::to_string(position.size()) + + " components (must have " + std::to_string(env().getNd()) + ")"); + } id = 1.; src = zero; pokeSite(id, src, position); diff --git a/Hadrons/Utilities/Makefile.am b/Hadrons/Utilities/Makefile.am index 7655b2e2..529def24 100644 --- a/Hadrons/Utilities/Makefile.am +++ b/Hadrons/Utilities/Makefile.am @@ -1,10 +1,8 @@ -AM_LDFLAGS += -L../../Hadrons - bin_PROGRAMS = HadronsXmlRun HadronsFermionEP64To32 HadronsXmlRun_SOURCES = HadronsXmlRun.cc -HadronsXmlRun_LDADD = -lHadrons -lGrid +HadronsXmlRun_LDADD = ../libHadrons.a ../../Grid/libGrid.a HadronsFermionEP64To32_SOURCES = EigenPackCast.cc HadronsFermionEP64To32_CXXFLAGS = $(AM_CXXFLAGS) -DFIN=WilsonImplD::FermionField -DFOUT=WilsonImplF::FermionField -HadronsFermionEP64To32_LDADD = -lHadrons -lGrid +HadronsFermionEP64To32_LDADD = ../libHadrons.a ../../Grid/libGrid.a