Skip to content

Commit 86c44ad

Browse files
committed
Merge branch 'release/v1.4'
2 parents 76b37db + 42bf555 commit 86c44ad

283 files changed

Lines changed: 15739 additions & 3402 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,5 @@ Makefile.in
1414
/Hadrons/sqlite
1515
/Hadrons/Modules.hpp
1616
/Hadrons/modules.inc
17+
.DS_Store
18+
*~

Hadrons/A2AMatrix.hpp

Lines changed: 109 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* A2AMatrix.hpp, part of Hadrons (https://github.com/aportelli/Hadrons)
2+
* A2AMatrix.hpp, part of Hadrons ()
33
*
44
* Copyright (C) 2015 - 2020
55
*
@@ -45,6 +45,10 @@
4545
#define HADRONS_A2AM_IO_TYPE ComplexF
4646
#endif
4747

48+
#ifndef DISTIL_NT_CHUNK_SIZE
49+
#define DISTIL_NT_CHUNK_SIZE 1
50+
#endif
51+
4852
#define HADRONS_A2AM_PARALLEL_IO
4953

5054
BEGIN_HADRONS_NAMESPACE
@@ -104,11 +108,22 @@ class A2AMatrixIo
104108
void initFile(const MetadataType &d, const unsigned int chunkSize);
105109
// block I/O
106110
void saveBlock(const T *data, const unsigned int i, const unsigned int j,
107-
const unsigned int blockSizei, const unsigned int blockSizej);
111+
const unsigned int blockSizei, const unsigned int blockSizej, std::string datasetName="");
108112
void saveBlock(const A2AMatrixSet<T> &m, const unsigned int ext, const unsigned int str,
109113
const unsigned int i, const unsigned int j);
114+
//distillation overloads and new methods
115+
template <typename MetadataType>
116+
void initFile(const MetadataType &d);
117+
void createDilutionBlock(std::string datasetName, const unsigned int chunkSize, const std::vector<unsigned int> timeSlices);
118+
void saveBlock(const A2AMatrixSet<T> &m,
119+
const unsigned int ext, const unsigned int str,
120+
const unsigned int i, const unsigned int j, std::string datasetName,
121+
const std::vector<unsigned int> timeSlices, const unsigned int chunkSize);
122+
void saveBlock(const A2AMatrixSet<T> &m, const unsigned int ext, const unsigned int str,
123+
const unsigned int i, const unsigned int j,
124+
std::string datasetName);
110125
template <template <class> class Vec, typename VecT>
111-
void load(Vec<VecT> &v, double *tRead = nullptr, GridBase *grid = nullptr);
126+
void load(Vec<VecT> &v, double *tRead = nullptr, GridBase *grid = nullptr, std::string datasetName="");
112127
private:
113128
std::string filename_{""}, dataname_{""};
114129
unsigned int nt_{0}, ni_{0}, nj_{0};
@@ -460,13 +475,28 @@ void A2AMatrixIo<T>::initFile(const MetadataType &d, const unsigned int chunkSiz
460475
#endif
461476
}
462477

478+
//distillation overloads
479+
template <typename T>
480+
template <typename MetadataType>
481+
void A2AMatrixIo<T>::initFile(const MetadataType &d)
482+
{
483+
#ifdef HAVE_HDF5
484+
Hdf5Writer writer(filename_);
485+
push(writer, dataname_); //creates main h5 group
486+
write(writer, "Metadata", d);
487+
#else
488+
HADRONS_ERROR(Implementation, "all-to-all matrix I/O needs HDF5 library");
489+
#endif
490+
}
491+
463492
// block I/O ///////////////////////////////////////////////////////////////////
464493
template <typename T>
465494
void A2AMatrixIo<T>::saveBlock(const T *data,
466495
const unsigned int i,
467496
const unsigned int j,
468497
const unsigned int blockSizei,
469-
const unsigned int blockSizej)
498+
const unsigned int blockSizej,
499+
std::string datasetName)
470500
{
471501
#ifdef HAVE_HDF5
472502
Hdf5Reader reader(filename_, false);
@@ -479,9 +509,13 @@ void A2AMatrixIo<T>::saveBlock(const T *data,
479509
H5NS::DataSet dataset;
480510
// size_t shift;
481511

512+
if(datasetName.empty()){
513+
datasetName = HADRONS_A2AM_NAME;
514+
}
515+
482516
push(reader, dataname_);
483517
auto &group = reader.getGroup();
484-
dataset = group.openDataSet(HADRONS_A2AM_NAME);
518+
dataset = group.openDataSet(datasetName);
485519
dataspace = dataset.getSpace();
486520
dataspace.selectHyperslab(H5S_SELECT_SET, count.data(), offset.data(),
487521
stride.data(), block.data());
@@ -504,22 +538,90 @@ void A2AMatrixIo<T>::saveBlock(const A2AMatrixSet<T> &m,
504538
saveBlock(m.data() + offset, i, j, blockSizei, blockSizej);
505539
}
506540

541+
//distillation overloads and new methods
542+
template <typename T>
543+
void A2AMatrixIo<T>::createDilutionBlock(std::string datasetName, const unsigned int chunkSize, const std::vector<unsigned int> timeSlices)
544+
{
545+
#ifdef HAVE_HDF5
546+
Hdf5Reader reader(filename_, false);
547+
H5NS::DataSpace dataspace;
548+
H5NS::DataSet dataset;
549+
550+
push(reader, dataname_);
551+
auto &group = reader.getGroup();
552+
unsigned int ntchunk = (nt_ > DISTIL_NT_CHUNK_SIZE) ? DISTIL_NT_CHUNK_SIZE : nt_;
553+
554+
//creates new dataset with custom name and certain chunk
555+
std::vector<hsize_t> dim = {static_cast<hsize_t>(nt_),
556+
static_cast<hsize_t>(ni_),
557+
static_cast<hsize_t>(nj_)},
558+
chunk = {static_cast<hsize_t>(ntchunk),
559+
static_cast<hsize_t>(chunkSize),
560+
static_cast<hsize_t>(chunkSize)};
561+
dataspace.setExtentSimple(dim.size(), dim.data());
562+
H5NS::DSetCreatPropList plist;
563+
plist.setChunk(chunk.size(), chunk.data());
564+
plist.setFletcher32();
565+
dataset = group.createDataSet(datasetName, Hdf5Type<T>::type(), dataspace, plist);
566+
567+
//save timeslice metadata
568+
hsize_t attrDim = timeSlices.size();
569+
H5NS::DataSpace attrSpace(1, &attrDim);
570+
H5NS::Attribute attr = dataset.createAttribute("TimeSlices", Hdf5Type<unsigned int>::type(), attrSpace);
571+
attr.write(Hdf5Type<unsigned int>::type(), timeSlices.data());
572+
#else
573+
HADRONS_ERROR(Implementation, "all-to-all matrix I/O needs HDF5 library");
574+
#endif
575+
}
576+
577+
template <typename T>
578+
void A2AMatrixIo<T>::saveBlock(const A2AMatrixSet<T> &m,
579+
const unsigned int ext, const unsigned int str,
580+
const unsigned int i, const unsigned int j, std::string datasetName,
581+
const std::vector<unsigned int> timeSlices, const unsigned int chunkSize)
582+
{
583+
unsigned int blockSizei = m.dimension(3);
584+
unsigned int blockSizej = m.dimension(4);
585+
unsigned int nstr = m.dimension(1);
586+
size_t offset = (ext*nstr + str)*nt_*blockSizei*blockSizej;
587+
588+
createDilutionBlock(datasetName, chunkSize, timeSlices);
589+
saveBlock(m.data() + offset, i, j, blockSizei, blockSizej, datasetName);
590+
}
591+
592+
template <typename T>
593+
void A2AMatrixIo<T>::saveBlock(const A2AMatrixSet<T> &m,
594+
const unsigned int ext, const unsigned int str,
595+
const unsigned int i, const unsigned int j, std::string datasetName)
596+
{
597+
unsigned int blockSizei = m.dimension(3);
598+
unsigned int blockSizej = m.dimension(4);
599+
unsigned int nstr = m.dimension(1);
600+
size_t offset = (ext*nstr + str)*nt_*blockSizei*blockSizej;
601+
602+
saveBlock(m.data() + offset, i, j, blockSizei, blockSizej, datasetName);
603+
}
604+
507605
template <typename T>
508606
template <template <class> class Vec, typename VecT>
509-
void A2AMatrixIo<T>::load(Vec<VecT> &v, double *tRead, GridBase *grid)
607+
void A2AMatrixIo<T>::load(Vec<VecT> &v, double *tRead, GridBase *grid, std::string datasetName)
510608
{
511609
#ifdef HAVE_HDF5
512610
std::vector<hsize_t> hdim;
513611
H5NS::DataSet dataset;
514612
H5NS::DataSpace dataspace;
515613
H5NS::CompType datatype;
516614

615+
if(datasetName.empty()){
616+
datasetName = HADRONS_A2AM_NAME;
617+
}
618+
517619
if (!(grid) || grid->IsBoss())
518620
{
519621
Hdf5Reader reader(filename_);
520622
push(reader, dataname_);
521623
auto &group = reader.getGroup();
522-
dataset = group.openDataSet(HADRONS_A2AM_NAME);
624+
dataset = group.openDataSet(datasetName);
523625
datatype = dataset.getCompType();
524626
dataspace = dataset.getSpace();
525627
hdim.resize(dataspace.getSimpleExtentNdims());

Hadrons/Application.cpp

Lines changed: 46 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,12 @@ void Application::createModule(const std::string name, const std::string type,
140140
vm().createModule(name, type, reader);
141141
}
142142

143+
// test if module exists ///////////////////////////////////////////////////////
144+
bool Application::hasModule(const std::string name) const
145+
{
146+
return vm().hasModule(name);
147+
}
148+
143149
// generate result DB //////////////////////////////////////////////////////////
144150
void Application::generateResultDb(void)
145151
{
@@ -172,26 +178,39 @@ void Application::run(void)
172178
LOG(Message) << "Attempt(s) for resilient parallel I/O: "
173179
<< BinaryIO::latticeWriteMaxRetry << std::endl;
174180
vm().setRunId(getPar().runId);
175-
if (getPar().database.makeStatDb)
181+
if (!getPar().database.statDbBase.empty())
176182
{
177183
std::string statDbFilename;
178184
std::ostringstream oss;
179185
auto now = std::chrono::system_clock::to_time_t(std::chrono::system_clock::now());
180186
auto nowLocal = *std::localtime(&now);
181187

182188
oss << std::put_time(&nowLocal, "%Y%m%d-%H%M%S");
183-
statDbFilename = getPar().runId + "-stat-" + oss.str() + ".db";
189+
statDbFilename = getPar().database.statDbBase + "-stat-" + oss.str() + ".db";
184190
LOG(Message) << "Logging run statistics in '" << statDbFilename << "'" << std::endl;
185191
if (env().getGrid()->IsBoss())
186192
{
187193
statDb.setFilename(statDbFilename);
194+
statLogger.setPeriod(getPar().database.statDbPeriodMs);
188195
statLogger.setDatabase(statDb);
189-
statLogger.start(500);
196+
statLogger.start();
190197
}
191198
}
192199
if (getPar().saveSchedule or getPar().scheduleFile.empty())
193200
{
194-
schedule();
201+
if (getPar().scheduler.schedulerType == "genetic")
202+
{
203+
schedule();
204+
}
205+
else if (getPar().scheduler.schedulerType == "naive")
206+
{
207+
naiveSchedule();
208+
}
209+
else
210+
{
211+
HADRONS_ERROR(Parsing, "Unkown scheduler '"
212+
+ getPar().scheduler.schedulerType + "'");
213+
}
195214
if (getPar().saveSchedule)
196215
{
197216
std::string filename;
@@ -213,7 +232,7 @@ void Application::run(void)
213232
vm().dumpModuleGraph(getPar().graphFile);
214233
}
215234
configLoop();
216-
if (getPar().database.makeStatDb and env().getGrid()->IsBoss())
235+
if (!getPar().database.statDbBase.empty() and env().getGrid()->IsBoss())
217236
{
218237
statLogger.stop();
219238
}
@@ -292,6 +311,15 @@ void Application::schedule(void)
292311
}
293312
}
294313

314+
void Application::naiveSchedule(void)
315+
{
316+
if (!scheduled_ and !loadedSchedule_)
317+
{
318+
program_ = vm().naiveSchedule();
319+
scheduled_ = true;
320+
}
321+
}
322+
295323
void Application::saveSchedule(const std::string filename)
296324
{
297325
LOG(Message) << "Saving current schedule to '" << filename << "'..."
@@ -337,9 +365,19 @@ void Application::printSchedule(void)
337365
{
338366
HADRONS_ERROR(Definition, "Computation not scheduled");
339367
}
340-
auto peak = vm().memoryNeeded(program_);
341-
LOG(Message) << "Schedule (memory needed: " << sizeString(peak) << "):"
342-
<< std::endl;
368+
369+
if (getPar().scheduler.schedulerType == "naive")
370+
{
371+
LOG(Message) << "Schedule:"
372+
<< std::endl;
373+
}
374+
else
375+
{
376+
auto peak = vm().memoryNeeded(program_);
377+
LOG(Message) << "Schedule (memory needed: " << sizeString(peak) << "):"
378+
<< std::endl;
379+
}
380+
343381
for (unsigned int i = 0; i < program_.size(); ++i)
344382
{
345383
LOG(Message) << std::setw(4) << i + 1 << ": "

Hadrons/Application.hpp

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -53,15 +53,23 @@ class Application
5353
struct DatabasePar: Serializable
5454
{
5555
GRID_SERIALIZABLE_CLASS_MEMBERS(DatabasePar,
56-
std::string, applicationDb,
57-
std::string, resultDb,
58-
bool, restoreModules,
59-
bool, restoreMemoryProfile,
60-
bool, restoreSchedule,
61-
bool, makeStatDb);
56+
std::string, applicationDb,
57+
std::string, resultDb,
58+
bool, restoreModules,
59+
bool, restoreMemoryProfile,
60+
bool, restoreSchedule,
61+
std::string, statDbBase,
62+
unsigned int, statDbPeriodMs);
6263
DatabasePar(void):
6364
restoreModules{false}, restoreMemoryProfile{false},
64-
restoreSchedule{false}, makeStatDb{false} {}
65+
restoreSchedule{false}, statDbBase{""} {}
66+
};
67+
68+
struct SchedulerPar: Serializable
69+
{
70+
GRID_SERIALIZABLE_CLASS_MEMBERS(SchedulerPar,
71+
std::string, schedulerType,);
72+
SchedulerPar(void): schedulerType{"genetic"} {}
6573
};
6674

6775
struct GlobalPar: Serializable
@@ -70,6 +78,7 @@ class Application
7078
TrajRange, trajCounter,
7179
DatabasePar, database,
7280
VirtualMachine::GeneticPar, genetic,
81+
SchedulerPar, scheduler,
7382
std::string, runId,
7483
std::string, graphFile,
7584
std::string, scheduleFile,
@@ -101,6 +110,8 @@ class Application
101110
template <typename M>
102111
void createModule(const std::string name, const typename M::Par &par);
103112
void createModule(const std::string name, const std::string type, XmlReader &reader);
113+
// test if module exists
114+
bool hasModule(const std::string name) const;
104115
// module DB entry for result files
105116
template <typename EntryType>
106117
void setResultMetadata(const std::string moduleName, const std::string tableName, const EntryType &entry);
@@ -113,6 +124,7 @@ class Application
113124
void saveParameterFile(const std::string parameterFileName, unsigned int prec = 15);
114125
// schedule computation
115126
void schedule(void);
127+
void naiveSchedule(void);
116128
void saveSchedule(const std::string filename);
117129
void loadSchedule(const std::string filename);
118130
void printSchedule(void);

Hadrons/Archive/Modules/TestSeqConserved.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,5 +29,5 @@ using namespace Grid;
2929
using namespace Hadrons;
3030
using namespace MUtilities;
3131

32-
template class Grid::Hadrons::MUtilities::TTestSeqConserved<FIMPL>;
32+
template class HADRONS_NAMESPACE::MUtilities::TTestSeqConserved<FIMPL>;
3333

Hadrons/Archive/Modules/TestSeqGamma.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,5 +29,5 @@ using namespace Grid;
2929
using namespace Hadrons;
3030
using namespace MUtilities;
3131

32-
template class Grid::Hadrons::MUtilities::TTestSeqGamma<FIMPL>;
32+
template class HADRONS_NAMESPACE::MUtilities::TTestSeqGamma<FIMPL>;
3333

Hadrons/Database.cpp

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -289,12 +289,24 @@ QueryResult Database::getTable(const std::string tableName, const std::string ex
289289
}
290290

291291
void Database::insert(const std::string tableName, const SqlEntry &entry, const bool replace)
292+
{
293+
std::vector<const SqlEntry *> entryPtVec;
294+
295+
entryPtVec.push_back(&entry);
296+
insert(tableName, entryPtVec, replace);
297+
}
298+
299+
void Database::insert(const std::string tableName, const std::vector<const SqlEntry *> &entryPtVec, const bool replace)
292300
{
293301
std::string query;
294302

295303
query += (replace ? "REPLACE" : "INSERT");
296-
query += " INTO \"" + tableName + "\" VALUES(";
297-
query += entry.sqlInsert() + ");";
304+
query += " INTO \"" + tableName + "\" VALUES";
305+
for (unsigned int i = 0; i < entryPtVec.size() - 1; ++i)
306+
{
307+
query += " (" + entryPtVec[i]->sqlInsert() + "),";
308+
}
309+
query += " (" + entryPtVec.back()->sqlInsert() + ");";
298310
execute(query);
299311
}
300312

Hadrons/Database.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ class Database
9999
template <typename EntryType>
100100
std::vector<EntryType> getTable(const std::string tableName, const std::string extra = "");
101101
void insert(const std::string tableName, const SqlEntry &entry, const bool replace = false);
102+
void insert(const std::string tableName, const std::vector<const SqlEntry *> &entryPtVec, const bool replace = false);
102103
// key-value tables interface
103104
void createKeyValueTable(const std::string tableName);
104105
std::map<std::string, std::string> getKeyValueTable(const std::string tableName);

0 commit comments

Comments
 (0)