1
0
mirror of https://github.com/paboyle/Grid.git synced 2024-11-10 07:55:35 +00:00

Hadrons: eigenpack converter can do test reads

This commit is contained in:
Antonin Portelli 2018-10-22 11:10:18 +01:00
parent 1982cc58dd
commit 6b559d68aa

View File

@ -35,7 +35,7 @@ using namespace Hadrons;
template <typename FOut, typename FIn>
void convert(const std::string outFilename, const std::string inFilename,
const unsigned int Ls, const bool rb, const unsigned int size,
const bool multiFile)
const bool multiFile, const bool testRead)
{
assert(outFilename != inFilename);
@ -102,6 +102,7 @@ void convert(const std::string outFilename, const std::string inFilename,
LOG(Message) << "Out type : " << typeName<FOut>() << std::endl;
LOG(Message) << "#vectors : " << size << std::endl;
LOG(Message) << "Multifile : " << (multiFile ? "yes" : "no") << std::endl;
LOG(Message) << "Test read : " << (testRead ? "yes" : "no") << std::endl;
if (multiFile)
{
for(unsigned int k = 0; k < size; ++k)
@ -112,6 +113,8 @@ 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;
// conversion
LOG(Message) << "-- Doing conversion" << std::endl;
makeFileDir(outV, gOut);
binWriter.open(outV);
binReader.open(inV);
@ -121,10 +124,20 @@ void convert(const std::string outFilename, const std::string inFilename,
EigenPackIo::writeElement<FIn, FOut>(binWriter, bufIn, eval, k, &bufOut, &testIn);
binWriter.close();
binReader.close();
// read test
if (testRead)
{
LOG(Message) << "-- Test read" << std::endl;
binReader.open(outV);
EigenPackIo::readElement<FOut>(bufOut, eval, k, binReader);
binReader.close();
}
}
}
else
{
// conversion
LOG(Message) << "-- Doing conversion" << std::endl;
makeFileDir(outFilename, gOut);
binWriter.open(outFilename);
binReader.open(inFilename);
@ -137,6 +150,18 @@ void convert(const std::string outFilename, const std::string inFilename,
}
binWriter.close();
binReader.close();
// read test
if (testRead)
{
LOG(Message) << "-- Test read" << std::endl;
binReader.open(outFilename);
EigenPackIo::readHeader(record, binReader);
for(unsigned int k = 0; k < size; ++k)
{
EigenPackIo::readElement<FOut>(bufOut, eval, k, binReader);
}
binReader.close();
}
}
}
@ -154,11 +179,11 @@ int main(int argc, char *argv[])
// parse command line
std::string outFilename, inFilename;
unsigned int size, Ls;
bool rb, multiFile;
bool rb, multiFile, testRead;
if (argc < 7)
if (argc < 8)
{
std::cerr << "usage: " << argv[0] << " <out eigenpack> <in eigenpack> <Ls> <red-black (0|1)> <#vector> <multifile (0|1)> [Grid options]";
std::cerr << "usage: " << argv[0] << " <out eigenpack> <in eigenpack> <Ls> <red-black {0|1}> <#vector> <multifile {0|1}> <test read {0|1}> [Grid options]";
std::cerr << std::endl;
std::exit(EXIT_FAILURE);
}
@ -168,6 +193,7 @@ int main(int argc, char *argv[])
rb = (std::string(argv[4]) != "0");
size = std::stoi(std::string(argv[5]));
multiFile = (std::string(argv[6]) != "0");
testRead = (std::string(argv[7]) != "0");
// initialization
Grid_init(&argc, &argv);
@ -176,7 +202,7 @@ int main(int argc, char *argv[])
// execution
try
{
convert<FOUT, FIN>(outFilename, inFilename, Ls, rb, size, multiFile);
convert<FOUT, FIN>(outFilename, inFilename, Ls, rb, size, multiFile, testRead);
}
catch (const std::exception& e)
{