1
0
mirror of https://github.com/paboyle/Grid.git synced 2024-11-09 23:45:36 +00:00

Eigenpack converter, to be tested, HadronsXmlRun moved to Utilities directory

This commit is contained in:
Antonin Portelli 2018-10-02 00:02:34 +01:00
parent 8fbb27ce13
commit aadd9f4468
6 changed files with 186 additions and 52 deletions

View File

@ -46,22 +46,24 @@ LOG(Message) << record.operatorXml << std::endl;\
LOG(Message) << "* solver" << std::endl;\ LOG(Message) << "* solver" << std::endl;\
LOG(Message) << record.solverXml << 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 <typename F> template <typename F>
class EigenPack class EigenPack
{ {
public: public:
typedef F Field; 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: public:
std::vector<RealD> eval; std::vector<RealD> eval;
std::vector<F> evec; std::vector<F> evec;
@ -115,6 +117,39 @@ public:
basicWrite(evecFilename(fileStem, -1, traj), evec, eval, evec.size()); 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 <typename T>
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 <typename T>
static void writeElement(ScidacWriter &binWriter, T &evec, VecRecord &vecRecord)
{
binWriter.writeScidacFieldRecord(evec, vecRecord, DEFAULT_ASCII_PREC);
}
protected: protected:
std::string evecFilename(const std::string stem, const int vec, const int traj) 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 <typename T>
void readElement(T &evec, VecRecord &vecRecord, ScidacReader &binReader)
{
binReader.readScidacFieldRecord(evec, vecRecord);
}
template <typename T> template <typename T>
void basicRead(std::vector<T> &evec, std::vector<RealD> &eval, void basicRead(std::vector<T> &evec, std::vector<RealD> &eval,
const std::string filename, const unsigned int size) const std::string filename, const unsigned int size)
@ -155,7 +172,7 @@ protected:
ScidacReader binReader; ScidacReader binReader;
binReader.open(filename); binReader.open(filename);
readHeader(binReader); readHeader(record, binReader);
for(int k = 0; k < size; ++k) for(int k = 0; k < size; ++k)
{ {
VecRecord vecRecord; VecRecord vecRecord;
@ -181,7 +198,7 @@ protected:
VecRecord vecRecord; VecRecord vecRecord;
binReader.open(filename); binReader.open(filename);
readHeader(binReader); readHeader(record, binReader);
LOG(Message) << "Reading eigenvector " << index << std::endl; LOG(Message) << "Reading eigenvector " << index << std::endl;
readElement(evec, vecRecord, binReader); readElement(evec, vecRecord, binReader);
if (vecRecord.index != index) if (vecRecord.index != index)
@ -194,21 +211,6 @@ protected:
binReader.close(); 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 <typename T>
void writeElement(ScidacWriter &binWriter, T &evec, VecRecord &vecRecord)
{
binWriter.writeScidacFieldRecord(evec, vecRecord, DEFAULT_ASCII_PREC);
}
template <typename T> template <typename T>
void basicWrite(const std::string filename, std::vector<T> &evec, void basicWrite(const std::string filename, std::vector<T> &evec,
const std::vector<RealD> &eval, const unsigned int size) const std::vector<RealD> &eval, const unsigned int size)
@ -217,7 +219,7 @@ protected:
makeFileDir(filename, evec[0]._grid); makeFileDir(filename, evec[0]._grid);
binWriter.open(filename); binWriter.open(filename);
writeHeader(binWriter); writeHeader(binWriter, record);
for(int k = 0; k < size; ++k) for(int k = 0; k < size; ++k)
{ {
VecRecord vecRecord; VecRecord vecRecord;
@ -239,7 +241,7 @@ protected:
makeFileDir(filename, evec._grid); makeFileDir(filename, evec._grid);
binWriter.open(filename); binWriter.open(filename);
writeHeader(binWriter); writeHeader(binWriter, record);
vecRecord.index = index; vecRecord.index = index;
vecRecord.eval = eval; vecRecord.eval = eval;
LOG(Message) << "Writing eigenvector " << index << std::endl; LOG(Message) << "Writing eigenvector " << index << std::endl;

View File

@ -1,5 +1,6 @@
SUBDIRS = . Utilities
lib_LIBRARIES = libHadrons.a lib_LIBRARIES = libHadrons.a
bin_PROGRAMS = HadronsXmlRun
include modules.inc include modules.inc
@ -31,6 +32,3 @@ nobase_libHadrons_a_HEADERS = \
ModuleFactory.hpp \ ModuleFactory.hpp \
Solver.hpp \ Solver.hpp \
VirtualMachine.hpp VirtualMachine.hpp
HadronsXmlRun_SOURCES = HadronsXmlRun.cc
HadronsXmlRun_LDADD = libHadrons.a -lGrid

View File

@ -0,0 +1,123 @@
#include <Hadrons/EigenPack.hpp>
#include <Hadrons/Environment.hpp>
using namespace Grid;
using namespace QCD;
using namespace Hadrons;
template <typename FOut, typename FIn>
void convert(const std::string outFilename, const std::string inFilename,
const unsigned int size, const bool multiFile)
{
assert(outFilename != inFilename);
typedef EigenPack<FOut> EPOut;
typedef EigenPack<FIn> EPIn;
typedef typename FOut::vector_type VTypeOut;
typedef typename FIn::vector_type VTypeIn;
std::shared_ptr<GridBase> 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] << " <out eigenpack> <in eigenpack> <size> <multifile (0|1)> [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<FOUT, FIN>(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;
}

View File

@ -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

View File

@ -562,6 +562,7 @@ AC_CONFIG_FILES(tests/qdpxx/Makefile)
AC_CONFIG_FILES(tests/testu01/Makefile) AC_CONFIG_FILES(tests/testu01/Makefile)
AC_CONFIG_FILES(benchmarks/Makefile) AC_CONFIG_FILES(benchmarks/Makefile)
AC_CONFIG_FILES(Hadrons/Makefile) AC_CONFIG_FILES(Hadrons/Makefile)
AC_CONFIG_FILES(Hadrons/Utilities/Makefile)
AC_OUTPUT AC_OUTPUT
echo "" echo ""