1
0
mirror of https://github.com/paboyle/Grid.git synced 2025-04-27 22:25:56 +01:00

Hadrons: contractor trajectory loop and file output

This commit is contained in:
Antonin Portelli 2018-11-19 15:45:04 +00:00
parent f592ec8baa
commit f22a27d7f9
7 changed files with 210 additions and 138 deletions

View File

@ -166,7 +166,13 @@ std::string Hadrons::dirname(const std::string &s)
void Hadrons::makeFileDir(const std::string filename, GridBase *g) void Hadrons::makeFileDir(const std::string filename, GridBase *g)
{ {
if (g->IsBoss()) bool doIt = true;
if (g)
{
doIt = g->IsBoss();
}
if (doIt)
{ {
std::string dir = dirname(filename); std::string dir = dirname(filename);
int status = mkdir(dir); int status = mkdir(dir);

View File

@ -218,15 +218,15 @@ typedef XmlReader ResultReader;
typedef XmlWriter ResultWriter; typedef XmlWriter ResultWriter;
#endif #endif
#define RESULT_FILE_NAME(name) \ #define RESULT_FILE_NAME(name, traj) \
name + "." + std::to_string(vm().getTrajectory()) + "." + resultFileExt name + "." + std::to_string(traj) + "." + resultFileExt
// recursive mkdir // recursive mkdir
#define MAX_PATH_LENGTH 512u #define MAX_PATH_LENGTH 512u
int mkdir(const std::string dirName); int mkdir(const std::string dirName);
std::string basename(const std::string &s); std::string basename(const std::string &s);
std::string dirname(const std::string &s); std::string dirname(const std::string &s);
void makeFileDir(const std::string filename, GridBase *g); void makeFileDir(const std::string filename, GridBase *g = nullptr);
// default Schur convention // default Schur convention
#ifndef HADRONS_DEFAULT_SCHUR #ifndef HADRONS_DEFAULT_SCHUR

View File

@ -144,7 +144,7 @@ if (env().getGrid()->IsBoss() and !ioStem.empty())\
{\ {\
makeFileDir(ioStem, env().getGrid());\ makeFileDir(ioStem, env().getGrid());\
{\ {\
ResultWriter _writer(RESULT_FILE_NAME(ioStem));\ ResultWriter _writer(RESULT_FILE_NAME(ioStem, vm().getTrajectory()));\
write(_writer, name, result);\ write(_writer, name, result);\
}\ }\
} }

View File

@ -146,7 +146,7 @@ void TChargedProp::execute(void)
std::vector<int> siteCoor; std::vector<int> siteCoor;
LOG(Message) << "Saving momentum-projected propagator to '" LOG(Message) << "Saving momentum-projected propagator to '"
<< RESULT_FILE_NAME(par().output) << "'..." << RESULT_FILE_NAME(par().output, vm().getTrajectory()) << "'..."
<< std::endl; << std::endl;
result.projection.resize(par().outputMom.size()); result.projection.resize(par().outputMom.size());
result.lattice_size = env().getGrid()->_fdimensions; result.lattice_size = env().getGrid()->_fdimensions;

View File

@ -462,7 +462,7 @@ void TScalarVP::execute(void)
if (!par().output.empty()) if (!par().output.empty())
{ {
LOG(Message) << "Saving momentum-projected HVP to '" LOG(Message) << "Saving momentum-projected HVP to '"
<< RESULT_FILE_NAME(par().output) << "'..." << RESULT_FILE_NAME(par().output, vm().getTrajectory()) << "'..."
<< std::endl; << std::endl;
saveResult(par().output, "HVP", outputData); saveResult(par().output, "HVP", outputData);
} }

View File

@ -239,7 +239,7 @@ void TVPCounterTerms::execute(void)
if (!par().output.empty()) if (!par().output.empty())
{ {
LOG(Message) << "Saving momentum-projected correlators to '" LOG(Message) << "Saving momentum-projected correlators to '"
<< RESULT_FILE_NAME(par().output) << "'..." << RESULT_FILE_NAME(par().output, vm().getTrajectory()) << "'..."
<< std::endl; << std::endl;
saveResult(par().output, "scalar_loops", outputData); saveResult(par().output, "scalar_loops", outputData);
} }

View File

@ -37,10 +37,20 @@ using namespace Hadrons;
namespace Contractor namespace Contractor
{ {
class TrajRange: Serializable
{
public:
GRID_SERIALIZABLE_CLASS_MEMBERS(TrajRange,
unsigned int, start,
unsigned int, end,
unsigned int, step);
};
class GlobalPar: Serializable class GlobalPar: Serializable
{ {
public: public:
GRID_SERIALIZABLE_CLASS_MEMBERS(GlobalPar, GRID_SERIALIZABLE_CLASS_MEMBERS(GlobalPar,
TrajRange, trajCounter,
unsigned int, nt, unsigned int, nt,
std::string, diskVectorDir, std::string, diskVectorDir,
std::string, output); std::string, output);
@ -50,7 +60,7 @@ namespace Contractor
{ {
public: public:
GRID_SERIALIZABLE_CLASS_MEMBERS(A2AMatrixPar, GRID_SERIALIZABLE_CLASS_MEMBERS(A2AMatrixPar,
std::string, file, std::string, fileStem,
std::string, dataset, std::string, dataset,
unsigned int, cacheSize, unsigned int, cacheSize,
std::string, name); std::string, name);
@ -62,7 +72,18 @@ namespace Contractor
GRID_SERIALIZABLE_CLASS_MEMBERS(ProductPar, GRID_SERIALIZABLE_CLASS_MEMBERS(ProductPar,
std::string, terms, std::string, terms,
std::vector<std::string>, times, std::vector<std::string>, times,
std::string, translations); std::string, translations,
bool, translationAverage);
};
class CorrelatorResult: Serializable
{
public:
GRID_SERIALIZABLE_CLASS_MEMBERS(CorrelatorResult,
std::vector<Contractor::A2AMatrixPar>, a2aMatrix,
ProductPar, contraction,
std::vector<unsigned int>, times,
std::vector<ComplexD>, correlator);
}; };
} }
@ -100,6 +121,26 @@ void makeTimeSeq(std::vector<std::vector<unsigned int>> &timeSeq,
makeTimeSeq(timeSeq, times, current, times.size()); makeTimeSeq(timeSeq, times, current, times.size());
} }
void saveCorrelator(const Contractor::CorrelatorResult &result, const std::string dir,
const unsigned int dt, const unsigned int traj)
{
std::string fileStem = "", us = "_", filename;
for (unsigned int i = 0; i < result.contraction.terms.size() - 1; i++)
{
fileStem += result.contraction.terms[i] + us + std::to_string(result.times[i]) + us;
}
fileStem += result.contraction.terms.back();
if (!result.contraction.translationAverage)
{
fileStem += "_dt_" + std::to_string(dt);
}
filename = dir + "/" + RESULT_FILE_NAME(fileStem, traj);
std::cout << "Saving correlator to '" << filename << "'" << std::endl;
makeFileDir(dir);
ResultWriter writer(filename);
write(writer, fileStem, result);
}
std::set<unsigned int> parseTimeRange(const std::string str, const unsigned int nt) std::set<unsigned int> parseTimeRange(const std::string str, const unsigned int nt)
{ {
@ -108,7 +149,6 @@ std::set<unsigned int> parseTimeRange(const std::string str, const unsigned int
std::vector<std::string> rstr = strToVec<std::string>(str); std::vector<std::string> rstr = strToVec<std::string>(str);
std::set<unsigned int> tSet; std::set<unsigned int> tSet;
for (auto &s: rstr) for (auto &s: rstr)
{ {
std::regex_match(s, sm, rex); std::regex_match(s, sm, rex);
@ -230,15 +270,21 @@ int main(int argc, char* argv[])
a2aMat.emplace(p.name, EigenDiskVector<ComplexD>(dirName, par.global.nt, p.cacheSize)); a2aMat.emplace(p.name, EigenDiskVector<ComplexD>(dirName, par.global.nt, p.cacheSize));
} }
// load data // trajectory loop
for (unsigned int i = 0; i < a2aMat.size(); ++i) for (unsigned int traj = par.global.trajCounter.start;
traj < par.global.trajCounter.end; traj += par.global.trajCounter.step)
{ {
auto &p = par.a2aMatrix[i]; std::cout << ":::::::: Trajectory " << traj << std::endl;
// load data
for (auto &p: par.a2aMatrix)
{
std::string filename = RESULT_FILE_NAME(p.fileStem, traj);
double t, size; double t, size;
std::cout << "======== Loading '" << p.file << "'" << std::endl; std::cout << "======== Loading '" << filename << "'" << std::endl;
A2AMatrixIo<HADRONS_A2AM_IO_TYPE> a2aIo(p.file, p.dataset, par.global.nt); A2AMatrixIo<HADRONS_A2AM_IO_TYPE> a2aIo(filename, p.dataset, par.global.nt);
a2aIo.load(a2aMat.at(p.name), &t); a2aIo.load(a2aMat.at(p.name), &t);
std::cout << "Read " << a2aIo.getSize() << " bytes in " << t/1.0e6 std::cout << "Read " << a2aIo.getSize() << " bytes in " << t/1.0e6
@ -254,11 +300,11 @@ int main(int argc, char* argv[])
std::vector<std::set<unsigned int>> times; std::vector<std::set<unsigned int>> times;
std::vector<std::vector<unsigned int>> timeSeq; std::vector<std::vector<unsigned int>> timeSeq;
std::set<unsigned int> translations; std::set<unsigned int> translations;
std::vector<ComplexD> corr(par.global.nt);
std::vector<A2AMatrixTr<ComplexD>> lastTerm(par.global.nt); std::vector<A2AMatrixTr<ComplexD>> lastTerm(par.global.nt);
A2AMatrix<ComplexD> prod, buf, tmp; A2AMatrix<ComplexD> prod, buf, tmp;
TimerArray tAr; TimerArray tAr;
double fusec, busec, flops, bytes, tusec; double fusec, busec, flops, bytes, tusec;
Contractor::CorrelatorResult result;
tAr.startTimer("Total"); tAr.startTimer("Total");
std::cout << "======== Contraction tr("; std::cout << "======== Contraction tr(";
@ -277,6 +323,15 @@ int main(int argc, char* argv[])
{ {
times.push_back(parseTimeRange(s, par.global.nt)); times.push_back(parseTimeRange(s, par.global.nt));
} }
for (auto &m: par.a2aMatrix)
{
if (std::find(result.a2aMatrix.begin(), result.a2aMatrix.end(), m) == result.a2aMatrix.end())
{
result.a2aMatrix.push_back(m);
}
}
result.contraction = p;
result.correlator.resize(par.global.nt, 0.);
translations = parseTimeRange(p.translations, par.global.nt); translations = parseTimeRange(p.translations, par.global.nt);
makeTimeSeq(timeSeq, times); makeTimeSeq(timeSeq, times);
@ -309,9 +364,10 @@ int main(int argc, char* argv[])
unsigned int dti = 0; unsigned int dti = 0;
auto &t = timeSeq[i]; auto &t = timeSeq[i];
result.times = t;
for (unsigned int tLast = 0; tLast < par.global.nt; ++tLast) for (unsigned int tLast = 0; tLast < par.global.nt; ++tLast)
{ {
corr[tLast] = 0.; result.correlator[tLast] = 0.;
} }
for (auto &dt: translations) for (auto &dt: translations)
{ {
@ -359,7 +415,7 @@ int main(int argc, char* argv[])
for (unsigned int tLast = 0; tLast < par.global.nt; ++tLast) for (unsigned int tLast = 0; tLast < par.global.nt; ++tLast)
{ {
tAr.startTimer("tr(A*B)"); tAr.startTimer("tr(A*B)");
A2AContraction::accTrMul(corr[TIME_MOD(tLast - dt)], prod, lastTerm[tLast]); A2AContraction::accTrMul(result.correlator[TIME_MOD(tLast - dt)], prod, lastTerm[tLast]);
tAr.stopTimer("tr(A*B)"); tAr.stopTimer("tr(A*B)");
flops += A2AContraction::accTrMulFlops(prod, lastTerm[tLast]); flops += A2AContraction::accTrMulFlops(prod, lastTerm[tLast]);
bytes += 2.*prod.rows()*prod.cols()*sizeof(ComplexD); bytes += 2.*prod.rows()*prod.cols()*sizeof(ComplexD);
@ -368,20 +424,30 @@ int main(int argc, char* argv[])
std::cout << Sec(tAr.getDTimer("tr(A*B)") - busec) << " " std::cout << Sec(tAr.getDTimer("tr(A*B)") - busec) << " "
<< Flops(flops, tAr.getDTimer("tr(A*B)") - fusec) << " " << Flops(flops, tAr.getDTimer("tr(A*B)") - fusec) << " "
<< Bytes(bytes, tAr.getDTimer("tr(A*B)") - busec) << std::endl; << Bytes(bytes, tAr.getDTimer("tr(A*B)") - busec) << std::endl;
if (!p.translationAverage)
{
saveCorrelator(result, par.global.output, dt, traj);
for (unsigned int tLast = 0; tLast < par.global.nt; ++tLast)
{
result.correlator[tLast] = 0.;
}
}
dti++; dti++;
} }
if (p.translationAverage)
{
for (unsigned int tLast = 0; tLast < par.global.nt; ++tLast) for (unsigned int tLast = 0; tLast < par.global.nt; ++tLast)
{ {
corr[tLast] /= translations.size(); result.correlator[tLast] /= translations.size();
} }
for (unsigned int tLast = 0; tLast < par.global.nt; ++tLast) saveCorrelator(result, par.global.output, 0, traj);
{
std::cout << tLast << " " << corr[tLast] << std::endl;
} }
} }
tAr.stopTimer("Total"); tAr.stopTimer("Total");
printTimeProfile(tAr.getTimings(), tAr.getTimer("Total")); printTimeProfile(tAr.getTimings(), tAr.getTimer("Total"));
} }
}
return EXIT_SUCCESS; return EXIT_SUCCESS;
} }