1
0
mirror of https://github.com/paboyle/Grid.git synced 2025-04-18 09:45:55 +01:00

Reverse changes not intended to be part of distillation release

This commit is contained in:
Michael Marshall 2019-11-18 12:34:49 +00:00
parent 18177d9709
commit 13a0db7162
5 changed files with 98 additions and 216 deletions

View File

@ -179,7 +179,7 @@ void Application::parseParameterFile(const std::string parameterFileName)
pop(reader); pop(reader);
} }
void Application::saveParameterFile(const std::string &parameterFileName, const std::vector<std::string> &Except, unsigned int prec) void Application::saveParameterFile(const std::string parameterFileName, unsigned int prec)
{ {
LOG(Message) << "Saving application to '" << parameterFileName << "'..." << std::endl; LOG(Message) << "Saving application to '" << parameterFileName << "'..." << std::endl;
if (env().getGrid()->IsBoss()) if (env().getGrid()->IsBoss())
@ -192,28 +192,19 @@ void Application::saveParameterFile(const std::string &parameterFileName, const
write(writer, "parameters", getPar()); write(writer, "parameters", getPar());
push(writer, "modules"); push(writer, "modules");
for (unsigned int i = 0; i < nMod; ++i) for (unsigned int i = 0; i < nMod; ++i)
{
id.name = vm().getModuleName(i);
if( std::find( Except.begin(), Except.end(), id.name ) == Except.end() )
{ {
push(writer, "module"); push(writer, "module");
id.name = vm().getModuleName(i);
id.type = vm().getModule(i)->getRegisteredName(); id.type = vm().getModule(i)->getRegisteredName();
write(writer, "id", id); write(writer, "id", id);
vm().getModule(i)->saveParameters(writer, "options"); vm().getModule(i)->saveParameters(writer, "options");
pop(writer); pop(writer);
} }
}
pop(writer); pop(writer);
pop(writer); pop(writer);
} }
} }
void Application::saveParameterFile(const std::string &parameterFileName, unsigned int prec)
{
const std::vector<std::string> Except;
saveParameterFile(parameterFileName, Except, prec);
}
// schedule computation //////////////////////////////////////////////////////// // schedule computation ////////////////////////////////////////////////////////
void Application::schedule(void) void Application::schedule(void)
{ {

View File

@ -81,8 +81,7 @@ public:
void run(void); void run(void);
// XML parameter file I/O // XML parameter file I/O
void parseParameterFile(const std::string parameterFileName); 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);
void saveParameterFile(const std::string &parameterFileName, const std::vector<std::string> &Except, unsigned int prec=15);
// schedule computation // schedule computation
void schedule(void); void schedule(void);
void saveSchedule(const std::string filename); void saveSchedule(const std::string filename);

View File

@ -25,10 +25,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
See the full license in the file "LICENSE" in the top level distribution directory See the full license in the file "LICENSE" in the top level distribution directory
*************************************************************************************/ *************************************************************************************/
/* END LEGAL */ /* END LEGAL */
#include <Hadrons/Global.hpp>
#include <chrono>
#include <ctime>
#include <Hadrons/Utilities/Contractor.hpp>
#include <Hadrons/A2AMatrix.hpp> #include <Hadrons/A2AMatrix.hpp>
#include <Hadrons/DiskVector.hpp> #include <Hadrons/DiskVector.hpp>
#include <Hadrons/TimerArray.hpp> #include <Hadrons/TimerArray.hpp>
@ -36,8 +33,66 @@ See the full license in the file "LICENSE" in the top level distribution directo
using namespace Grid; using namespace Grid;
using namespace Hadrons; using namespace Hadrons;
// Separator to be used between contraction terms only (underscores elsewhere) #define TIME_MOD(t) (((t) + par.global.nt) % par.global.nt)
std::string Separator{ "_" };
namespace Contractor
{
class TrajRange: Serializable
{
public:
GRID_SERIALIZABLE_CLASS_MEMBERS(TrajRange,
unsigned int, start,
unsigned int, end,
unsigned int, step);
};
class GlobalPar: Serializable
{
public:
GRID_SERIALIZABLE_CLASS_MEMBERS(GlobalPar,
TrajRange, trajCounter,
unsigned int, nt,
std::string, diskVectorDir,
std::string, output);
};
class A2AMatrixPar: Serializable
{
public:
GRID_SERIALIZABLE_CLASS_MEMBERS(A2AMatrixPar,
std::string, file,
std::string, dataset,
unsigned int, cacheSize,
std::string, name);
};
class ProductPar: Serializable
{
public:
GRID_SERIALIZABLE_CLASS_MEMBERS(ProductPar,
std::string, terms,
std::vector<std::string>, times,
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);
};
}
struct ContractorPar
{
Contractor::GlobalPar global;
std::vector<Contractor::A2AMatrixPar> a2aMatrix;
std::vector<Contractor::ProductPar> product;
};
void makeTimeSeq(std::vector<std::vector<unsigned int>> &timeSeq, void makeTimeSeq(std::vector<std::vector<unsigned int>> &timeSeq,
const std::vector<std::set<unsigned int>> &times, const std::vector<std::set<unsigned int>> &times,
@ -63,7 +118,7 @@ void makeTimeSeq(std::vector<std::vector<unsigned int>> &timeSeq,
{ {
std::vector<unsigned int> current(times.size()); std::vector<unsigned int> current(times.size());
makeTimeSeq(timeSeq, times, current, static_cast<unsigned int>(times.size())); makeTimeSeq(timeSeq, times, current, times.size());
} }
void saveCorrelator(const Contractor::CorrelatorResult &result, const std::string dir, void saveCorrelator(const Contractor::CorrelatorResult &result, const std::string dir,
@ -74,12 +129,12 @@ void saveCorrelator(const Contractor::CorrelatorResult &result, const std::strin
for (unsigned int i = 0; i < terms.size() - 1; i++) for (unsigned int i = 0; i < terms.size() - 1; i++)
{ {
fileStem += terms[i] + Separator + std::to_string(result.times[i]) + Separator; fileStem += terms[i] + "_" + std::to_string(result.times[i]) + "_";
} }
fileStem += terms.back(); fileStem += terms.back();
if (!result.contraction.translationAverage) if (!result.contraction.translationAverage)
{ {
fileStem += Separator + "dt" + Separator + std::to_string(dt); fileStem += "_dt_" + std::to_string(dt);
} }
filename = dir + "/" + RESULT_FILE_NAME(fileStem, traj); filename = dir + "/" + RESULT_FILE_NAME(fileStem, traj);
std::cout << "Saving correlator to '" << filename << "'" << std::endl; std::cout << "Saving correlator to '" << filename << "'" << std::endl;
@ -184,75 +239,30 @@ int main(int argc, char* argv[])
{ {
// parse command line // parse command line
std::string parFilename; std::string parFilename;
bool bOnlyWriteUsedA2AMatrices{ false };
int ArgCount{ 0 };
bool bCmdLineError{ false };
for( int i = 1; i < argc; i++ ) {
if( argv[i][0] == '-' ) {
// Switches
bool bSwitchOK = false;
switch( argv[i][1] ) {
case 'a':
if( argv[i][2] == 0 ) {
bOnlyWriteUsedA2AMatrices = true;
bSwitchOK = true;
std::cout << "Only A2AMatrices used in each contraction will be written" << std::endl;
}
break;
case 's':
if( argv[i][2] )
Separator = &argv[i][2];
else
Separator = ".";
bSwitchOK = true;
std::cout << "Using \"" << Separator << "\" as name separator" << std::endl;
break;
}
if( !bSwitchOK ) {
std::cerr << "Urecognised switch \"" << argv[i] << "\"" << std::endl;
bCmdLineError = true;
}
} else {
// Arguments
switch( ++ArgCount ) {
case 1:
parFilename = argv[i];
break;
default:
std::cerr << "Unused argument \"" << argv[i] << "\"" << std::endl;
break;
}
}
}
if (ArgCount != 1 or bCmdLineError) if (argc != 2)
{ {
std::cerr << "usage: " << argv[0] << " <parameter file>" std::cerr << "usage: " << argv[0] << " <parameter file>";
"\n\t-a\tSimple Correlators (only describe A2AMatrices used for contraction)" std::cerr << std::endl;
"\n\t-s[sep]\tSeparator \"sep\" used between name components."
"\n\t\tDefaults to \"_\", or \".\" if -s specified without sep"
<< std::endl;
return EXIT_FAILURE; return EXIT_FAILURE;
} }
parFilename = argv[1];
// Log what file we're processing and when we started
const std::chrono::system_clock::time_point start{ std::chrono::system_clock::now() };
std::time_t now = std::chrono::system_clock::to_time_t( start );
std::cout << "Start " << parFilename << " " << std::ctime( &now );
// parse parameter file // parse parameter file
Contractor::ContractorPar par; ContractorPar par;
// unsigned int nMat,nCont;
XmlReader reader(parFilename); XmlReader reader(parFilename);
read(reader, "global", par.global); read(reader, "global", par.global);
read(reader, "a2aMatrix", par.a2aMatrix); read(reader, "a2aMatrix", par.a2aMatrix);
read(reader, "product", par.product); read(reader, "product", par.product);
const unsigned int nMat { static_cast<unsigned int>(par.a2aMatrix.size()) }; // nMat = par.a2aMatrix.size();
const unsigned int nCont { static_cast<unsigned int>(par.product.size()) }; // nCont = par.product.size();
// create diskvectors // create diskvectors
std::map<std::string, EigenDiskVector<ComplexD>> a2aMat; std::map<std::string, EigenDiskVector<ComplexD>> a2aMat;
// unsigned int cacheSize;
for (auto &p: par.a2aMatrix) for (auto &p: par.a2aMatrix)
{ {
@ -268,15 +278,14 @@ int main(int argc, char* argv[])
std::cout << ":::::::: Trajectory " << traj << std::endl; std::cout << ":::::::: Trajectory " << traj << std::endl;
// load data // load data
int iSeq = 0;
for (auto &p: par.a2aMatrix) for (auto &p: par.a2aMatrix)
{ {
std::string filename = p.file; std::string filename = p.file;
double t; double t;
// double size;
tokenReplace(filename, "traj", traj); tokenReplace(filename, "traj", traj);
std::cout << "======== Loading '" << filename << "'" std::cout << "======== Loading '" << filename << "'" << std::endl;
<< "\nA2AMatrix " << ++iSeq << " of " << nMat << " = " << p.name << std::endl;
A2AMatrixIo<HADRONS_A2AM_IO_TYPE> a2aIo(filename, p.dataset, par.global.nt); A2AMatrixIo<HADRONS_A2AM_IO_TYPE> a2aIo(filename, p.dataset, par.global.nt);
@ -288,7 +297,6 @@ int main(int argc, char* argv[])
// contract // contract
EigenDiskVector<ComplexD>::Matrix buf; EigenDiskVector<ComplexD>::Matrix buf;
iSeq = 0;
for (auto &p: par.product) for (auto &p: par.product)
{ {
std::vector<std::string> term = strToVec<std::string>(p.terms); std::vector<std::string> term = strToVec<std::string>(p.terms);
@ -299,10 +307,11 @@ int main(int argc, char* argv[])
A2AMatrix<ComplexD> prod, buf, tmp; A2AMatrix<ComplexD> prod, buf, tmp;
TimerArray tAr; TimerArray tAr;
double fusec, busec, flops, bytes; double fusec, busec, flops, bytes;
// double tusec;
Contractor::CorrelatorResult result; Contractor::CorrelatorResult result;
tAr.startTimer("Total"); tAr.startTimer("Total");
std::cout << "======== Contraction " << ++iSeq << " of " << nCont << " tr("; std::cout << "======== Contraction tr(";
for (unsigned int g = 0; g < term.size(); ++g) for (unsigned int g = 0; g < term.size(); ++g)
{ {
std::cout << term[g] << ((g == term.size() - 1) ? ')' : '*'); std::cout << term[g] << ((g == term.size() - 1) ? ')' : '*');
@ -320,9 +329,7 @@ int main(int argc, char* argv[])
} }
for (auto &m: par.a2aMatrix) for (auto &m: par.a2aMatrix)
{ {
// For simple correlators, only include A2AMatrix info for correlators in this contraction if (std::find(result.a2aMatrix.begin(), result.a2aMatrix.end(), m) == result.a2aMatrix.end())
if ( ( !bOnlyWriteUsedA2AMatrices or std::find( term.begin(), term.end(), m.name ) != term.end() )
and std::find(result.a2aMatrix.begin(), result.a2aMatrix.end(), m) == result.a2aMatrix.end())
{ {
result.a2aMatrix.push_back(m); result.a2aMatrix.push_back(m);
tokenReplace(result.a2aMatrix.back().file, "traj", traj); tokenReplace(result.a2aMatrix.back().file, "traj", traj);
@ -446,12 +453,5 @@ int main(int argc, char* argv[])
} }
} }
// Mention that we're finished, what the time is and how long it took
const std::chrono::system_clock::time_point stop{ std::chrono::system_clock::now() };
now = std::chrono::system_clock::to_time_t( stop );
const std::chrono::duration<double> duration_seconds = stop - start;
const double hours{ ( duration_seconds.count() + 0.5 ) / 3600 };
std::cout << "Stop " << parFilename << " " << std::ctime( &now )
<< "Total duration " << std::fixed << std::setprecision(1) << hours << " hours." << std::endl;
return EXIT_SUCCESS; return EXIT_SUCCESS;
} }

View File

@ -36,74 +36,4 @@ BEGIN_HADRONS_NAMESPACE
END_HADRONS_NAMESPACE END_HADRONS_NAMESPACE
#define BEGIN_CONTRACTOR_NAMESPACE namespace Contractor{
BEGIN_CONTRACTOR_NAMESPACE
using Grid::Serializable;
using Grid::Reader;
using Grid::Writer;
using Grid::ComplexD;
class TrajRange: Serializable
{
public:
GRID_SERIALIZABLE_CLASS_MEMBERS(TrajRange,
unsigned int, start,
unsigned int, end,
unsigned int, step);
};
class GlobalPar: Serializable
{
public:
GRID_SERIALIZABLE_CLASS_MEMBERS(GlobalPar,
TrajRange, trajCounter,
unsigned int, nt,
std::string, diskVectorDir,
std::string, output);
};
class A2AMatrixPar: Serializable
{
public:
GRID_SERIALIZABLE_CLASS_MEMBERS(A2AMatrixPar,
std::string, file,
std::string, dataset,
unsigned int, cacheSize,
std::string, name);
};
class ProductPar: Serializable
{
public:
GRID_SERIALIZABLE_CLASS_MEMBERS(ProductPar,
std::string, terms,
std::vector<std::string>, times,
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);
};
struct ContractorPar
{
Contractor::GlobalPar global;
std::vector<Contractor::A2AMatrixPar> a2aMatrix;
std::vector<Contractor::ProductPar> product;
};
// Useful ... so long as there's a ContractorPar named par in scope
#define TIME_MOD(t) (((t) + par.global.nt) % par.global.nt)
#define END_CONTRACTOR_NAMESPACE }
END_CONTRACTOR_NAMESPACE
#endif // Hadrons_Contractor_hpp_ #endif // Hadrons_Contractor_hpp_

View File

@ -27,51 +27,24 @@ See the full license in the file "LICENSE" in the top level distribution directo
/* END LEGAL */ /* END LEGAL */
#include <Hadrons/Application.hpp> #include <Hadrons/Application.hpp>
#include <sys/stat.h>
#include <fstream>
#include <string>
using namespace Grid; using namespace Grid;
using namespace QCD;
using namespace Hadrons; using namespace Hadrons;
// Does the specified file exist?
bool FileExists(const std::string& Filename)
{
struct stat buf;
return stat(Filename.c_str(), &buf) != -1;
}
void Shorten( Application &app, const std::string &FileList, const std::string OutFileName )
{
std::vector<std::string> Except;
std::ifstream list{ FileList };
for( std::string s; std::getline(list, s); ) {
//const std::string::size_type l{ s.find_first_of( '.' ) };
//if( l != std::string::npos )
//s.resize( l );
if( s.length() )
Except.push_back( s );
}
std::sort( Except.begin(), Except.end() );
for( const std::string &s : Except )
std::cout << s << std::endl;
app.saveParameterFile( OutFileName, Except );
}
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
// parse command line // parse command line
std::string parameterFileName; std::string parameterFileName;
if (argc != 2 && argc != 4) if (argc != 2)
{ {
std::cerr << "usage: " << argv[0] << " <parameter file> [filelist.txt output.xml]"; std::cerr << "usage: " << argv[0] << " <parameter file>";
std::cerr << std::endl; std::cerr << std::endl;
std::exit(EXIT_FAILURE); std::exit(EXIT_FAILURE);
} }
parameterFileName = argv[1]; parameterFileName = argv[1];
if( argc == 4 )
Grid_init(&argc, &argv);
try try
{ {
Application application(parameterFileName); Application application(parameterFileName);
@ -81,22 +54,11 @@ int main(int argc, char *argv[])
vm.getModuleGraph(); vm.getModuleGraph();
LOG(Message) << "Application valid (check XML warnings though)" LOG(Message) << "Application valid (check XML warnings though)"
<< std::endl; << std::endl;
if( argc == 4 ) {
const std::string FileList{ argv[3] };
const std::string OutFileName{ argv[2] };
if( !FileExists( FileList ) )
std::cout << "File list \"" << FileList << "\" does not exist" << std::endl;
else {
Shorten( application, FileList, OutFileName );
}
}
} }
catch (const std::exception& e) catch (const std::exception& e)
{ {
Exceptions::abort(e); Exceptions::abort(e);
} }
if( argc == 4 )
Grid_finalize();
return EXIT_SUCCESS; return EXIT_SUCCESS;
} }