Skip to content

Commit

Permalink
Merge branch 'release/v1.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
aportelli committed Oct 2, 2020
2 parents c7847dc + 7872548 commit 69adeff
Show file tree
Hide file tree
Showing 101 changed files with 7,129 additions and 1,832 deletions.
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* @aportelli
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/build
/build*
/.buildutils
/.vscode
/autom4te.cache
Expand All @@ -11,3 +11,6 @@
/install-sh
/missing
Makefile.in
/Hadrons/sqlite
/Hadrons/Modules.hpp
/Hadrons/modules.inc
133 changes: 106 additions & 27 deletions Hadrons/Application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

#include <Hadrons/Application.hpp>
#include <Hadrons/GeneticScheduler.hpp>
#include <Hadrons/StatLogger.hpp>
#include <Hadrons/Modules.hpp>

using namespace Grid;
Expand All @@ -44,6 +45,7 @@ using namespace Hadrons;
Application::Application(void)
{
initLogger();
Grid::MemoryProfiler::stats = &memStats_;
auto dim = GridDefaultLatt(), mpi = GridDefaultMpi(), loc(dim);

if (dim.size())
Expand All @@ -67,12 +69,17 @@ Application::Application(void)
LOG(Message) << "Scalar implementation : " << MACOUTS(SIMPLBASE) << std::endl;
LOG(Message) << "Gauge implementation : " << MACOUTS(GIMPLBASE) << std::endl;
LOG(Message) << "Eigenvector base size : "
<< MACOUT(HADRONS_DEFAULT_LANCZOS_NBASIS) << std::endl;
<< MACOUT(HADRONS_DEFAULT_LANCZOS_NBASIS) << std::endl;
LOG(Message) << "Schur decomposition : " << MACOUTS(HADRONS_DEFAULT_SCHUR) << std::endl;
LOG(Message) << std::endl;
}
}

Application::~Application(void)
{
Grid::MemoryProfiler::stats = nullptr;
}

Application::Application(const Application::GlobalPar &par)
: Application()
{
Expand All @@ -89,16 +96,68 @@ Application::Application(const std::string parameterFileName)
void Application::setPar(const Application::GlobalPar &par)
{
par_ = par;
if (!getPar().database.applicationDb.empty())
{
LOG(Message) << "Connecting to application database in file '"
<< getPar().database.applicationDb << "'..." << std::endl;
db_.setFilename(getPar().database.applicationDb, isGridInit() ? env().getGrid() : nullptr);
vm().setDatabase(db_);
if (getPar().database.restoreMemoryProfile)
{
vm().dbRestoreMemoryProfile();
LOG(Message) << "Memory profile restored from application database" << std::endl;
}
if (getPar().database.restoreModules)
{
vm().dbRestoreModules();
LOG(Message) << "Modules restored from application database" << std::endl;
}
if (getPar().database.restoreSchedule)
{
program_ = vm().dbRestoreSchedule();
loadedSchedule_ = true;
scheduled_ = true;
LOG(Message) << "Schedule restored from application database" << std::endl;
}
}
if (!getPar().database.resultDb.empty())
{
LOG(Message) << "Connecting to result database in file '"
<< getPar().database.resultDb << "'..." << std::endl;
resultDb_.setFilename(getPar().database.resultDb, isGridInit() ? env().getGrid() : nullptr);
}
}

const Application::GlobalPar & Application::getPar(void)
{
return par_;
}

// module creation /////////////////////////////////////////////////////////////
void Application::createModule(const std::string name, const std::string type,
XmlReader &reader)
{
vm().createModule(name, type, reader);
}

// generate result DB //////////////////////////////////////////////////////////
void Application::generateResultDb(void)
{
auto range = par_.trajCounter;

for (unsigned int t = range.start; t < range.end; t += range.step)
{
vm().setTrajectory(t);
vm().generateResultDb();
}
}

// execute /////////////////////////////////////////////////////////////////////
void Application::run(void)
{
Database statDb;
StatLogger statLogger;

LOG(Message) << "====== HADRONS APPLICATION START ======" << std::endl;
if (!parameterFileName_.empty() and (vm().getNModule() == 0))
{
Expand All @@ -113,8 +172,23 @@ void Application::run(void)
LOG(Message) << "Attempt(s) for resilient parallel I/O: "
<< BinaryIO::latticeWriteMaxRetry << std::endl;
vm().setRunId(getPar().runId);
vm().printContent();
env().printContent();
if (getPar().database.makeStatDb)
{
std::string statDbFilename;
std::ostringstream oss;
auto now = std::chrono::system_clock::to_time_t(std::chrono::system_clock::now());
auto nowLocal = *std::localtime(&now);

oss << std::put_time(&nowLocal, "%Y%m%d-%H%M%S");
statDbFilename = getPar().runId + "-stat-" + oss.str() + ".db";
LOG(Message) << "Logging run statistics in '" << statDbFilename << "'" << std::endl;
if (env().getGrid()->IsBoss())
{
statDb.setFilename(statDbFilename);
statLogger.setDatabase(statDb);
statLogger.start(500);
}
}
if (getPar().saveSchedule or getPar().scheduleFile.empty())
{
schedule();
Expand All @@ -132,61 +206,66 @@ void Application::run(void)
loadSchedule(getPar().scheduleFile);
}
printSchedule();
vm().printMemoryProfile();
if (!getPar().graphFile.empty())
{
makeFileDir(getPar().graphFile, env().getGrid());
vm().dumpModuleGraph(getPar().graphFile);
}
configLoop();
if (getPar().database.makeStatDb and env().getGrid()->IsBoss())
{
statLogger.stop();
}
}

// parse parameter file ////////////////////////////////////////////////////////
class ObjectId: Serializable
{
public:
GRID_SERIALIZABLE_CLASS_MEMBERS(ObjectId,
std::string, name,
std::string, type);
};

void Application::parseParameterFile(const std::string parameterFileName)
{
XmlReader reader(parameterFileName);
XmlReader reader(parameterFileName, false, HADRONS_XML_TOPLEV);
GlobalPar par;
ObjectId id;

LOG(Message) << "Building application from '" << parameterFileName << "'..." << std::endl;
read(reader, "parameters", par);
setPar(par);
if (!push(reader, "modules"))
if (!par.database.restoreModules)
{
HADRONS_ERROR(Parsing, "Cannot open node 'modules' in parameter file '"
+ parameterFileName + "'");
if (!push(reader, "modules"))
{
HADRONS_ERROR(Parsing, "Cannot open node 'modules' in parameter file '"
+ parameterFileName + "'");
}
if (!push(reader, "module"))
{
HADRONS_ERROR(Parsing, "Cannot open node 'modules/module' in parameter file '"
+ parameterFileName + "'");
}
do
{
read(reader, "id", id);
createModule(id.name, id.type, reader);
} while (reader.nextElement("module"));
pop(reader);
pop(reader);
}
if (!push(reader, "module"))
else
{
HADRONS_ERROR(Parsing, "Cannot open node 'modules/module' in parameter file '"
+ parameterFileName + "'");
LOG(Message) << "XML module list ignored (restored from database '"
<< par.database.applicationDb << "')" << std::endl;
}
do
{
read(reader, "id", id);
vm().createModule(id.name, id.type, reader);
} while (reader.nextElement("module"));
pop(reader);
pop(reader);
}

void Application::saveParameterFile(const std::string parameterFileName, unsigned int prec)
{
LOG(Message) << "Saving application to '" << parameterFileName << "'..." << std::endl;
if (env().getGrid()->IsBoss())
{
XmlWriter writer(parameterFileName);
writer.setPrecision(prec);
XmlWriter writer(parameterFileName, HADRONS_XML_TOPLEV);
ObjectId id;
const unsigned int nMod = vm().getNModule();

writer.setPrecision(prec);
write(writer, "parameters", getPar());
push(writer, "modules");
for (unsigned int i = 0; i < nMod; ++i)
Expand Down
59 changes: 51 additions & 8 deletions Hadrons/Application.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,9 @@
#define Hadrons_Application_hpp_

#include <Hadrons/Global.hpp>
#include <Hadrons/VirtualMachine.hpp>
#include <Hadrons/Database.hpp>
#include <Hadrons/Module.hpp>
#include <Hadrons/VirtualMachine.hpp>

BEGIN_HADRONS_NAMESPACE

Expand All @@ -40,34 +41,57 @@ BEGIN_HADRONS_NAMESPACE
class Application
{
public:
class TrajRange: Serializable
// serializable classes for parameter input
struct TrajRange: Serializable
{
public:
GRID_SERIALIZABLE_CLASS_MEMBERS(TrajRange,
unsigned int, start,
unsigned int, end,
unsigned int, step);
};
class GlobalPar: Serializable

struct DatabasePar: Serializable
{
GRID_SERIALIZABLE_CLASS_MEMBERS(DatabasePar,
std::string, applicationDb,
std::string, resultDb,
bool, restoreModules,
bool, restoreMemoryProfile,
bool, restoreSchedule,
bool, makeStatDb);
DatabasePar(void):
restoreModules{false}, restoreMemoryProfile{false},
restoreSchedule{false}, makeStatDb{false} {}
};

struct GlobalPar: Serializable
{
public:
GRID_SERIALIZABLE_CLASS_MEMBERS(GlobalPar,
TrajRange, trajCounter,
DatabasePar, database,
VirtualMachine::GeneticPar, genetic,
std::string, runId,
std::string, graphFile,
std::string, scheduleFile,
bool, saveSchedule,
int, parallelWriteMaxRetry);
GlobalPar(void): parallelWriteMaxRetry{-1} {}
GlobalPar(void): parallelWriteMaxRetry{-1}, saveSchedule{false} {}
};

struct ObjectId: Serializable
{
GRID_SERIALIZABLE_CLASS_MEMBERS(ObjectId,
std::string, name,
std::string, type);
};

public:
// constructors
Application(void);
Application(const GlobalPar &par);
Application(const std::string parameterFileName);
// destructor
virtual ~Application(void) = default;
virtual ~Application(void);
// access
void setPar(const GlobalPar &par);
const GlobalPar & getPar(void);
Expand All @@ -76,11 +100,17 @@ class Application
void createModule(const std::string name);
template <typename M>
void createModule(const std::string name, const typename M::Par &par);
void createModule(const std::string name, const std::string type, XmlReader &reader);
// module DB entry for result files
template <typename EntryType>
void setResultMetadata(const std::string moduleName, const std::string tableName, const EntryType &entry);
// generate result DB
void generateResultDb(void);
// execute
void run(void);
// XML parameter file I/O
void parseParameterFile(const std::string parameterFileName);
void saveParameterFile(const std::string parameterFileName, unsigned int prec=15);
void saveParameterFile(const std::string parameterFileName, unsigned int prec = 15);
// schedule computation
void schedule(void);
void saveSchedule(const std::string filename);
Expand All @@ -98,6 +128,8 @@ class Application
std::string parameterFileName_{""};
GlobalPar par_;
VirtualMachine::Program program_;
Database db_, resultDb_;
Grid::MemoryStats memStats_;
bool scheduled_{false}, loadedSchedule_{false};
};

Expand All @@ -120,6 +152,17 @@ void Application::createModule(const std::string name,
scheduled_ = false;
}

// module DB entry /////////////////////////////////////////////////////////////
template <typename EntryType>
void Application::setResultMetadata(const std::string moduleName,
const std::string tableName,
const EntryType &entry)
{
auto m = vm().getModule(moduleName);

m->setResultDbEntry(resultDb_, tableName, entry);
}

END_HADRONS_NAMESPACE

#endif // Hadrons_Application_hpp_
2 changes: 1 addition & 1 deletion Hadrons/Archive/Modules/ScalarVP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,7 @@ void TScalarVP::execute(void)
if (!par().output.empty())
{
LOG(Message) << "Saving momentum-projected HVP to '"
<< RESULT_FILE_NAME(par().output, vm().getTrajectory()) << "'..."
<< resultFilename(par().output) << "'..."
<< std::endl;
saveResult(par().output, "HVP", outputData);
}
Expand Down
2 changes: 1 addition & 1 deletion Hadrons/Archive/Modules/VPCounterTerms.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ void TVPCounterTerms::execute(void)
if (!par().output.empty())
{
LOG(Message) << "Saving momentum-projected correlators to '"
<< RESULT_FILE_NAME(par().output, vm().getTrajectory()) << "'..."
<< resultFilename(par().output) << "'..."
<< std::endl;
saveResult(par().output, "scalar_loops", outputData);
}
Expand Down
Loading

0 comments on commit 69adeff

Please sign in to comment.