2018-10-15 15:51:45 +01:00
|
|
|
/*************************************************************************************
|
|
|
|
|
|
|
|
Grid physics library, www.github.com/paboyle/Grid
|
|
|
|
|
|
|
|
Source file: Hadrons/Utilities/EigenPackCast.cc
|
|
|
|
|
2019-02-05 18:55:24 +00:00
|
|
|
Copyright (C) 2015-2019
|
2018-10-15 15:51:45 +01:00
|
|
|
|
|
|
|
Author: Antonin Portelli <antonin.portelli@me.com>
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation; either version 2 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License along
|
|
|
|
with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
|
|
|
|
See the full license in the file "LICENSE" in the top level distribution directory
|
|
|
|
*************************************************************************************/
|
|
|
|
/* END LEGAL */
|
2018-10-02 00:02:34 +01:00
|
|
|
#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,
|
2018-10-02 13:34:17 +01:00
|
|
|
const unsigned int Ls, const bool rb, const unsigned int size,
|
2018-10-22 11:10:18 +01:00
|
|
|
const bool multiFile, const bool testRead)
|
2018-10-02 00:02:34 +01:00
|
|
|
{
|
|
|
|
assert(outFilename != inFilename);
|
|
|
|
|
|
|
|
typedef EigenPack<FOut> EPOut;
|
|
|
|
typedef EigenPack<FIn> EPIn;
|
|
|
|
typedef typename FOut::vector_type VTypeOut;
|
|
|
|
typedef typename FIn::vector_type VTypeIn;
|
|
|
|
|
2018-10-02 13:34:17 +01:00
|
|
|
std::shared_ptr<GridCartesian> gInBase, gOutBase, gIn5, gOut5;
|
|
|
|
std::shared_ptr<GridRedBlackCartesian> rbgIn, rbgOut;
|
|
|
|
GridBase *gIn, *gOut;
|
2018-10-02 13:12:46 +01:00
|
|
|
|
2018-10-02 13:34:17 +01:00
|
|
|
auto dim = GridDefaultLatt();
|
|
|
|
unsigned int nd = dim.size();
|
|
|
|
auto simdOut = GridDefaultSimd(nd, VTypeOut::Nsimd());
|
|
|
|
auto simdIn = GridDefaultSimd(nd, VTypeIn::Nsimd());
|
2018-10-02 00:02:34 +01:00
|
|
|
|
2018-10-02 13:34:17 +01:00
|
|
|
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();
|
|
|
|
}
|
|
|
|
}
|
2018-10-02 13:12:46 +01:00
|
|
|
|
2018-10-02 19:51:09 +01:00
|
|
|
FOut bufOut(gOut);
|
|
|
|
FIn bufIn(gIn), testIn(gIn);
|
|
|
|
ScidacWriter binWriter(gOut->IsBoss());
|
|
|
|
ScidacReader binReader;
|
|
|
|
PackRecord record;
|
|
|
|
RealD eval;
|
2018-10-02 00:02:34 +01:00
|
|
|
|
2018-10-02 12:24:45 +01:00
|
|
|
LOG(Message) << "==== EIGENPACK CONVERSION" << std::endl;
|
2018-10-02 13:34:17 +01:00
|
|
|
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<FIn>() << std::endl;
|
|
|
|
LOG(Message) << "Out path : " << outFilename << std::endl;
|
|
|
|
LOG(Message) << "Out type : " << typeName<FOut>() << std::endl;
|
|
|
|
LOG(Message) << "#vectors : " << size << std::endl;
|
|
|
|
LOG(Message) << "Multifile : " << (multiFile ? "yes" : "no") << std::endl;
|
2018-10-22 11:10:18 +01:00
|
|
|
LOG(Message) << "Test read : " << (testRead ? "yes" : "no") << std::endl;
|
2018-10-02 00:02:34 +01:00
|
|
|
if (multiFile)
|
|
|
|
{
|
|
|
|
for(unsigned int k = 0; k < size; ++k)
|
|
|
|
{
|
|
|
|
std::string outV = outFilename + "/v" + std::to_string(k) + ".bin";
|
|
|
|
std::string inV = inFilename + "/v" + std::to_string(k) + ".bin";
|
|
|
|
|
2018-10-02 12:24:45 +01:00
|
|
|
LOG(Message) << "==== Converting vector " << k << std::endl;
|
|
|
|
LOG(Message) << "In : " << inV << std::endl;
|
|
|
|
LOG(Message) << "Out: " << outV << std::endl;
|
2018-10-22 11:10:18 +01:00
|
|
|
// conversion
|
|
|
|
LOG(Message) << "-- Doing conversion" << std::endl;
|
2018-10-02 13:34:17 +01:00
|
|
|
makeFileDir(outV, gOut);
|
2018-10-02 00:02:34 +01:00
|
|
|
binWriter.open(outV);
|
|
|
|
binReader.open(inV);
|
2018-10-02 19:51:09 +01:00
|
|
|
EigenPackIo::readHeader(record, binReader);
|
|
|
|
EigenPackIo::writeHeader(binWriter, record);
|
|
|
|
EigenPackIo::readElement<FIn>(bufIn, eval, k, binReader);
|
|
|
|
EigenPackIo::writeElement<FIn, FOut>(binWriter, bufIn, eval, k, &bufOut, &testIn);
|
2018-10-02 00:02:34 +01:00
|
|
|
binWriter.close();
|
|
|
|
binReader.close();
|
2018-10-22 11:10:18 +01:00
|
|
|
// read test
|
|
|
|
if (testRead)
|
|
|
|
{
|
|
|
|
LOG(Message) << "-- Test read" << std::endl;
|
|
|
|
binReader.open(outV);
|
|
|
|
EigenPackIo::readElement<FOut>(bufOut, eval, k, binReader);
|
|
|
|
binReader.close();
|
|
|
|
}
|
2018-10-02 00:02:34 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-10-22 11:10:18 +01:00
|
|
|
// conversion
|
|
|
|
LOG(Message) << "-- Doing conversion" << std::endl;
|
2018-10-02 13:34:17 +01:00
|
|
|
makeFileDir(outFilename, gOut);
|
2018-10-02 00:02:34 +01:00
|
|
|
binWriter.open(outFilename);
|
|
|
|
binReader.open(inFilename);
|
2018-10-02 19:51:09 +01:00
|
|
|
EigenPackIo::readHeader(record, binReader);
|
|
|
|
EigenPackIo::writeHeader(binWriter, record);
|
2018-10-02 00:02:34 +01:00
|
|
|
for(unsigned int k = 0; k < size; ++k)
|
|
|
|
{
|
2018-10-02 19:51:09 +01:00
|
|
|
EigenPackIo::readElement<FIn>(bufIn, eval, k, binReader);
|
|
|
|
EigenPackIo::writeElement<FIn, FOut>(binWriter, bufIn, eval, k, &bufOut, &testIn);
|
2018-10-02 00:02:34 +01:00
|
|
|
}
|
|
|
|
binWriter.close();
|
|
|
|
binReader.close();
|
2018-10-22 11:10:18 +01:00
|
|
|
// 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();
|
|
|
|
}
|
2018-10-02 00:02:34 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#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;
|
2018-10-02 13:34:17 +01:00
|
|
|
unsigned int size, Ls;
|
2018-10-22 11:10:18 +01:00
|
|
|
bool rb, multiFile, testRead;
|
2018-10-02 00:02:34 +01:00
|
|
|
|
2018-10-22 11:10:18 +01:00
|
|
|
if (argc < 8)
|
2018-10-02 00:02:34 +01:00
|
|
|
{
|
2018-10-22 11:10:18 +01:00
|
|
|
std::cerr << "usage: " << argv[0] << " <out eigenpack> <in eigenpack> <Ls> <red-black {0|1}> <#vector> <multifile {0|1}> <test read {0|1}> [Grid options]";
|
2018-10-02 00:02:34 +01:00
|
|
|
std::cerr << std::endl;
|
|
|
|
std::exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
outFilename = argv[1];
|
|
|
|
inFilename = argv[2];
|
2018-10-02 13:34:17 +01:00
|
|
|
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");
|
2018-10-22 11:10:18 +01:00
|
|
|
testRead = (std::string(argv[7]) != "0");
|
2018-10-02 00:02:34 +01:00
|
|
|
|
|
|
|
// initialization
|
|
|
|
Grid_init(&argc, &argv);
|
2018-10-02 13:43:25 +01:00
|
|
|
initLogger();
|
2018-10-02 00:02:34 +01:00
|
|
|
|
|
|
|
// execution
|
|
|
|
try
|
|
|
|
{
|
2018-10-22 11:10:18 +01:00
|
|
|
convert<FOUT, FIN>(outFilename, inFilename, Ls, rb, size, multiFile, testRead);
|
2018-10-02 00:02:34 +01:00
|
|
|
}
|
|
|
|
catch (const std::exception& e)
|
|
|
|
{
|
|
|
|
Exceptions::abort(e);
|
|
|
|
}
|
|
|
|
|
|
|
|
// epilogue
|
|
|
|
LOG(Message) << "Grid is finalizing now" << std::endl;
|
|
|
|
Grid_finalize();
|
|
|
|
|
|
|
|
return EXIT_SUCCESS;
|
|
|
|
}
|