#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; }