mirror of
https://github.com/paboyle/Grid.git
synced 2024-11-10 07:55:35 +00:00
Reverse changes not intended to be part of distillation release
This commit is contained in:
parent
18177d9709
commit
13a0db7162
@ -179,7 +179,7 @@ void Application::parseParameterFile(const std::string parameterFileName)
|
||||
pop(reader);
|
||||
}
|
||||
|
||||
void Application::saveParameterFile(const std::string ¶meterFileName, 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;
|
||||
if (env().getGrid()->IsBoss())
|
||||
@ -193,27 +193,18 @@ void Application::saveParameterFile(const std::string ¶meterFileName, const
|
||||
push(writer, "modules");
|
||||
for (unsigned int i = 0; i < nMod; ++i)
|
||||
{
|
||||
push(writer, "module");
|
||||
id.name = vm().getModuleName(i);
|
||||
if( std::find( Except.begin(), Except.end(), id.name ) == Except.end() )
|
||||
{
|
||||
push(writer, "module");
|
||||
id.type = vm().getModule(i)->getRegisteredName();
|
||||
write(writer, "id", id);
|
||||
vm().getModule(i)->saveParameters(writer, "options");
|
||||
pop(writer);
|
||||
}
|
||||
id.type = vm().getModule(i)->getRegisteredName();
|
||||
write(writer, "id", id);
|
||||
vm().getModule(i)->saveParameters(writer, "options");
|
||||
pop(writer);
|
||||
}
|
||||
pop(writer);
|
||||
pop(writer);
|
||||
}
|
||||
}
|
||||
|
||||
void Application::saveParameterFile(const std::string ¶meterFileName, unsigned int prec)
|
||||
{
|
||||
const std::vector<std::string> Except;
|
||||
saveParameterFile(parameterFileName, Except, prec);
|
||||
}
|
||||
|
||||
// schedule computation ////////////////////////////////////////////////////////
|
||||
void Application::schedule(void)
|
||||
{
|
||||
|
@ -81,8 +81,7 @@ public:
|
||||
void run(void);
|
||||
// XML parameter file I/O
|
||||
void parseParameterFile(const std::string parameterFileName);
|
||||
void saveParameterFile(const std::string ¶meterFileName, unsigned int prec=15);
|
||||
void saveParameterFile(const std::string ¶meterFileName, const std::vector<std::string> &Except, 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);
|
||||
|
@ -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
|
||||
*************************************************************************************/
|
||||
/* END LEGAL */
|
||||
|
||||
#include <chrono>
|
||||
#include <ctime>
|
||||
#include <Hadrons/Utilities/Contractor.hpp>
|
||||
#include <Hadrons/Global.hpp>
|
||||
#include <Hadrons/A2AMatrix.hpp>
|
||||
#include <Hadrons/DiskVector.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 Hadrons;
|
||||
|
||||
// Separator to be used between contraction terms only (underscores elsewhere)
|
||||
std::string Separator{ "_" };
|
||||
#define TIME_MOD(t) (((t) + par.global.nt) % par.global.nt)
|
||||
|
||||
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,
|
||||
const std::vector<std::set<unsigned int>> ×,
|
||||
@ -63,10 +118,10 @@ void makeTimeSeq(std::vector<std::vector<unsigned int>> &timeSeq,
|
||||
{
|
||||
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,
|
||||
const unsigned int dt, const unsigned int traj)
|
||||
{
|
||||
std::string fileStem = "", filename;
|
||||
@ -74,12 +129,12 @@ void saveCorrelator(const Contractor::CorrelatorResult &result, const std::strin
|
||||
|
||||
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();
|
||||
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);
|
||||
std::cout << "Saving correlator to '" << filename << "'" << std::endl;
|
||||
@ -183,76 +238,31 @@ inline std::ostream & operator<< (std::ostream& s, const Bytes &&b)
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
// parse command line
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
std::string parFilename;
|
||||
|
||||
if (ArgCount != 1 or bCmdLineError)
|
||||
if (argc != 2)
|
||||
{
|
||||
std::cerr << "usage: " << argv[0] << " <parameter file>"
|
||||
"\n\t-a\tSimple Correlators (only describe A2AMatrices used for contraction)"
|
||||
"\n\t-s[sep]\tSeparator \"sep\" used between name components."
|
||||
"\n\t\tDefaults to \"_\", or \".\" if -s specified without sep"
|
||||
<< std::endl;
|
||||
std::cerr << "usage: " << argv[0] << " <parameter file>";
|
||||
std::cerr << std::endl;
|
||||
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
// 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 );
|
||||
parFilename = argv[1];
|
||||
|
||||
// parse parameter file
|
||||
Contractor::ContractorPar par;
|
||||
ContractorPar par;
|
||||
// unsigned int nMat,nCont;
|
||||
XmlReader reader(parFilename);
|
||||
|
||||
read(reader, "global", par.global);
|
||||
read(reader, "a2aMatrix", par.a2aMatrix);
|
||||
read(reader, "product", par.product);
|
||||
const unsigned int nMat { static_cast<unsigned int>(par.a2aMatrix.size()) };
|
||||
const unsigned int nCont { static_cast<unsigned int>(par.product.size()) };
|
||||
// nMat = par.a2aMatrix.size();
|
||||
// nCont = par.product.size();
|
||||
|
||||
// create diskvectors
|
||||
std::map<std::string, EigenDiskVector<ComplexD>> a2aMat;
|
||||
// unsigned int cacheSize;
|
||||
|
||||
for (auto &p: par.a2aMatrix)
|
||||
{
|
||||
@ -268,15 +278,14 @@ int main(int argc, char* argv[])
|
||||
std::cout << ":::::::: Trajectory " << traj << std::endl;
|
||||
|
||||
// load data
|
||||
int iSeq = 0;
|
||||
for (auto &p: par.a2aMatrix)
|
||||
{
|
||||
std::string filename = p.file;
|
||||
double t;
|
||||
// double size;
|
||||
|
||||
tokenReplace(filename, "traj", traj);
|
||||
std::cout << "======== Loading '" << filename << "'"
|
||||
<< "\nA2AMatrix " << ++iSeq << " of " << nMat << " = " << p.name << std::endl;
|
||||
std::cout << "======== Loading '" << filename << "'" << std::endl;
|
||||
|
||||
A2AMatrixIo<HADRONS_A2AM_IO_TYPE> a2aIo(filename, p.dataset, par.global.nt);
|
||||
|
||||
@ -288,7 +297,6 @@ int main(int argc, char* argv[])
|
||||
// contract
|
||||
EigenDiskVector<ComplexD>::Matrix buf;
|
||||
|
||||
iSeq = 0;
|
||||
for (auto &p: par.product)
|
||||
{
|
||||
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;
|
||||
TimerArray tAr;
|
||||
double fusec, busec, flops, bytes;
|
||||
// double tusec;
|
||||
Contractor::CorrelatorResult result;
|
||||
|
||||
tAr.startTimer("Total");
|
||||
std::cout << "======== Contraction " << ++iSeq << " of " << nCont << " tr(";
|
||||
std::cout << "======== Contraction tr(";
|
||||
for (unsigned int g = 0; g < term.size(); ++g)
|
||||
{
|
||||
std::cout << term[g] << ((g == term.size() - 1) ? ')' : '*');
|
||||
@ -320,9 +329,7 @@ int main(int argc, char* argv[])
|
||||
}
|
||||
for (auto &m: par.a2aMatrix)
|
||||
{
|
||||
// For simple correlators, only include A2AMatrix info for correlators in this contraction
|
||||
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())
|
||||
if (std::find(result.a2aMatrix.begin(), result.a2aMatrix.end(), m) == result.a2aMatrix.end())
|
||||
{
|
||||
result.a2aMatrix.push_back(m);
|
||||
tokenReplace(result.a2aMatrix.back().file, "traj", traj);
|
||||
@ -347,11 +354,11 @@ int main(int argc, char* argv[])
|
||||
tAr.startTimer("Transpose caching");
|
||||
lastTerm[t].resize(ref.rows(), ref.cols());
|
||||
thread_for( j,ref.cols(),{
|
||||
for (unsigned int i = 0; i < ref.rows(); ++i)
|
||||
{
|
||||
lastTerm[t](i, j) = ref(i, j);
|
||||
}
|
||||
});
|
||||
for (unsigned int i = 0; i < ref.rows(); ++i)
|
||||
{
|
||||
lastTerm[t](i, j) = ref(i, j);
|
||||
}
|
||||
});
|
||||
tAr.stopTimer("Transpose caching");
|
||||
}
|
||||
bytes = par.global.nt*lastTerm[0].rows()*lastTerm[0].cols()*sizeof(ComplexD);
|
||||
@ -445,13 +452,6 @@ int main(int argc, char* argv[])
|
||||
printTimeProfile(tAr.getTimings(), tAr.getTimer("Total"));
|
||||
}
|
||||
}
|
||||
|
||||
// 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;
|
||||
}
|
||||
|
@ -36,74 +36,4 @@ BEGIN_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_
|
||||
|
@ -27,51 +27,24 @@ See the full license in the file "LICENSE" in the top level distribution directo
|
||||
/* END LEGAL */
|
||||
|
||||
#include <Hadrons/Application.hpp>
|
||||
#include <sys/stat.h>
|
||||
#include <fstream>
|
||||
#include <string>
|
||||
|
||||
using namespace Grid;
|
||||
using namespace QCD;
|
||||
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[])
|
||||
{
|
||||
// parse command line
|
||||
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::exit(EXIT_FAILURE);
|
||||
}
|
||||
parameterFileName = argv[1];
|
||||
if( argc == 4 )
|
||||
Grid_init(&argc, &argv);
|
||||
|
||||
try
|
||||
{
|
||||
Application application(parameterFileName);
|
||||
@ -81,22 +54,11 @@ int main(int argc, char *argv[])
|
||||
vm.getModuleGraph();
|
||||
LOG(Message) << "Application valid (check XML warnings though)"
|
||||
<< 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)
|
||||
{
|
||||
Exceptions::abort(e);
|
||||
}
|
||||
if( argc == 4 )
|
||||
Grid_finalize();
|
||||
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user