mirror of
https://github.com/paboyle/Grid.git
synced 2025-04-04 11:15:55 +01:00
Making sure Hdf5 is an optional dependency (default to binary writer if not present)
This commit is contained in:
parent
adc1eaee68
commit
fb74de0798
@ -242,14 +242,24 @@ inline GridCartesian * MakeLowerDimGrid( GridCartesian * gridHD )
|
|||||||
return gridLD;
|
return gridLD;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef HAVE_HDF5
|
||||||
|
using Default_Reader = Grid::Hdf5Reader;
|
||||||
|
using Default_Writer = Grid::Hdf5Writer;
|
||||||
|
static const char * FileExtension = ".h5";
|
||||||
|
#else
|
||||||
|
using Default_Reader = Grid::BinaryReader;
|
||||||
|
using Default_Writer = Grid::BinaryWriter;
|
||||||
|
static const char * FileExtension = ".dat";
|
||||||
|
#endif
|
||||||
|
|
||||||
/******************************************************************************
|
/******************************************************************************
|
||||||
Perambulator object
|
NamedTensor object
|
||||||
This is an Eigen::Tensor of type Scalar_ and rank NumIndices_ (row-major order)
|
This is an Eigen::Tensor of type Scalar_ and rank NumIndices_ (row-major order)
|
||||||
They can be persisted to disk, with the on-disk format being big endian.
|
They can be persisted to disk
|
||||||
Scalar_ objects are assumed to be composite objects of size Endian_Scalar_Size.
|
Scalar_ objects are assumed to be composite objects of size Endian_Scalar_Size.
|
||||||
(Disable big-endian by setting Endian_Scalar_Size=1)
|
(Disable big-endian by setting Endian_Scalar_Size=1).
|
||||||
|
NB: Endian_Scalar_Size will disappear when ReadBinary & WriteBinary retired
|
||||||
IndexNames contains one name for each index, and IndexNames are validated on load.
|
IndexNames contains one name for each index, and IndexNames are validated on load.
|
||||||
(NB: Indices of dimension 1 are not saved, and not validated on load)
|
|
||||||
WHAT TO SAVE / VALIDATE ON LOAD (Override to warn instead of assert on load)
|
WHAT TO SAVE / VALIDATE ON LOAD (Override to warn instead of assert on load)
|
||||||
Ensemble string
|
Ensemble string
|
||||||
Configuration number
|
Configuration number
|
||||||
@ -324,8 +334,8 @@ public:
|
|||||||
// load and save - not virtual - probably all changes
|
// load and save - not virtual - probably all changes
|
||||||
template<typename Reader> inline void read (Reader &r, const char * pszTag = nullptr);
|
template<typename Reader> inline void read (Reader &r, const char * pszTag = nullptr);
|
||||||
template<typename Writer> inline void write(Writer &w, const char * pszTag = nullptr) const;
|
template<typename Writer> inline void write(Writer &w, const char * pszTag = nullptr) const;
|
||||||
template<typename Reader> inline void read (const char * filename, const char * pszTag = nullptr);
|
inline void read (const char * filename, const char * pszTag = nullptr);
|
||||||
template<typename Writer> inline void write(const char * filename, const char * pszTag = nullptr) const;
|
inline void write(const char * filename, const char * pszTag = nullptr) const;
|
||||||
EIGEN_DEPRECATED inline void ReadBinary (const std::string filename); // To be removed
|
EIGEN_DEPRECATED inline void ReadBinary (const std::string filename); // To be removed
|
||||||
EIGEN_DEPRECATED inline void WriteBinary(const std::string filename); // To be removed
|
EIGEN_DEPRECATED inline void WriteBinary(const std::string filename); // To be removed
|
||||||
};
|
};
|
||||||
@ -506,11 +516,13 @@ void NamedTensor<Scalar_, NumIndices_, Endian_Scalar_Size>::write(Writer &w, con
|
|||||||
}
|
}
|
||||||
|
|
||||||
template<typename Scalar_, int NumIndices_, uint16_t Endian_Scalar_Size>
|
template<typename Scalar_, int NumIndices_, uint16_t Endian_Scalar_Size>
|
||||||
template<typename Writer>
|
|
||||||
void NamedTensor<Scalar_, NumIndices_, Endian_Scalar_Size>::write(const char * filename, const char * pszTag)const{
|
void NamedTensor<Scalar_, NumIndices_, Endian_Scalar_Size>::write(const char * filename, const char * pszTag)const{
|
||||||
LOG(Message) << "Writing NamedTensor to \"" << filename << "\"" << std::endl;
|
const std::string sTag{pszTag == nullptr ? filename : pszTag};
|
||||||
Writer w(filename);
|
std::string sFileName{filename};
|
||||||
write(w, pszTag);
|
sFileName.append( MDistil::FileExtension );
|
||||||
|
LOG(Message) << "Writing NamedTensor to " << sFileName << ", tag " << sTag << std::endl;
|
||||||
|
MDistil::Default_Writer w(sFileName);
|
||||||
|
write(w, sTag.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
/******************************************************************************
|
/******************************************************************************
|
||||||
@ -534,11 +546,13 @@ void NamedTensor<Scalar_, NumIndices_, Endian_Scalar_Size>::read(Reader &r, cons
|
|||||||
}
|
}
|
||||||
|
|
||||||
template<typename Scalar_, int NumIndices_, uint16_t Endian_Scalar_Size>
|
template<typename Scalar_, int NumIndices_, uint16_t Endian_Scalar_Size>
|
||||||
template<typename Reader>
|
|
||||||
void NamedTensor<Scalar_, NumIndices_, Endian_Scalar_Size>::read(const char * filename, const char * pszTag) {
|
void NamedTensor<Scalar_, NumIndices_, Endian_Scalar_Size>::read(const char * filename, const char * pszTag) {
|
||||||
LOG(Message) << "Reading NamedTensor from \"" << filename << "\"" << std::endl;
|
const std::string sTag{pszTag == nullptr ? filename : pszTag};
|
||||||
Reader r(filename);
|
std::string sFileName{filename};
|
||||||
read(r, pszTag);
|
sFileName.append( MDistil::FileExtension );
|
||||||
|
LOG(Message) << "Reading NamedTensor from " << sFileName << ", tag " << sTag << std::endl;
|
||||||
|
MDistil::Default_Reader r(sFileName);
|
||||||
|
read(r, sTag.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
/******************************************************************************
|
/******************************************************************************
|
||||||
|
@ -241,7 +241,7 @@ void TPerambFromSolve<FImpl>::execute(void)
|
|||||||
if(PerambFileName.length()) {
|
if(PerambFileName.length()) {
|
||||||
std::string sPerambName{PerambFileName + "." + std::to_string(vm().getTrajectory())};
|
std::string sPerambName{PerambFileName + "." + std::to_string(vm().getTrajectory())};
|
||||||
//perambulator.WriteBinary(sPerambName);
|
//perambulator.WriteBinary(sPerambName);
|
||||||
perambulator.template write<Hdf5Writer>((sPerambName + ".h5").c_str(), sPerambName.c_str());
|
perambulator.write(sPerambName.c_str());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -289,7 +289,7 @@ void TPerambulator<FImpl>::execute(void)
|
|||||||
if(PerambFileName.length()) {
|
if(PerambFileName.length()) {
|
||||||
std::string sPerambName{PerambFileName + "." + std::to_string(vm().getTrajectory())};
|
std::string sPerambName{PerambFileName + "." + std::to_string(vm().getTrajectory())};
|
||||||
//perambulator.WriteBinary(sPerambName);
|
//perambulator.WriteBinary(sPerambName);
|
||||||
perambulator.template write<Hdf5Writer>((sPerambName + ".h5").c_str(), sPerambName.c_str());
|
perambulator.write(sPerambName.c_str());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -120,9 +120,7 @@ void TLoadPerambulator<FImpl>::execute(void)
|
|||||||
{
|
{
|
||||||
auto &perambulator = envGet(MDistil::Perambulator<SpinVector COMMA 6 COMMA sizeof(Real)>, getName());
|
auto &perambulator = envGet(MDistil::Perambulator<SpinVector COMMA 6 COMMA sizeof(Real)>, getName());
|
||||||
const std::string sPerambName{par().PerambFileName + "." + std::to_string(vm().getTrajectory())};
|
const std::string sPerambName{par().PerambFileName + "." + std::to_string(vm().getTrajectory())};
|
||||||
const std::string PerambFileName{sPerambName + ".h5"};
|
perambulator.read(sPerambName.c_str());
|
||||||
std::cout << "reading perambulator from file " << PerambFileName << std::endl;
|
|
||||||
perambulator.template read<Hdf5Reader>(PerambFileName.c_str(), sPerambName.c_str());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
END_MODULE_NAMESPACE
|
END_MODULE_NAMESPACE
|
||||||
|
@ -784,20 +784,34 @@ bool DebugEigenTest()
|
|||||||
DebugShowTensor(y, "y");
|
DebugShowTensor(y, "y");
|
||||||
|
|
||||||
// Now see whether we can read a tensor back from an hdf5 file
|
// Now see whether we can read a tensor back from an hdf5 file
|
||||||
const char * pszH5Name = "test.h5";
|
const char * pszFileName = "test";
|
||||||
y.write<Hdf5Writer>(pszH5Name);
|
y.write(pszFileName);
|
||||||
{
|
{
|
||||||
MyTensor z;
|
MyTensor z;
|
||||||
const char * pszName = "z1";
|
const char * pszName = "z1";
|
||||||
DebugShowTensor(z, pszName);
|
DebugShowTensor(z, pszName);
|
||||||
z.read<Hdf5Reader>(pszH5Name);
|
z.read(pszFileName);
|
||||||
DebugShowTensor(z, pszName);
|
DebugShowTensor(z, pszName);
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
MyTensor z(Names2,2,0,0);
|
MyTensor z(Names2,2,0,0);
|
||||||
const char * pszName = "z2";
|
const char * pszName = "z2";
|
||||||
DebugShowTensor(z, pszName);
|
DebugShowTensor(z, pszName);
|
||||||
z.read<Hdf5Reader>(pszH5Name);
|
z.read(pszFileName);
|
||||||
|
DebugShowTensor(z, pszName);
|
||||||
|
}
|
||||||
|
{
|
||||||
|
// Now see whether we can read a tensor back from an xml file
|
||||||
|
const char * pszXmlName = "test.xml";
|
||||||
|
{
|
||||||
|
XmlWriter w(pszXmlName);
|
||||||
|
y.write<XmlWriter>(w);
|
||||||
|
}
|
||||||
|
MyTensor z;
|
||||||
|
const char * pszName = "xml1";
|
||||||
|
DebugShowTensor(z, pszName);
|
||||||
|
XmlReader r(pszXmlName);
|
||||||
|
z.read<XmlReader>(r);
|
||||||
DebugShowTensor(z, pszName);
|
DebugShowTensor(z, pszName);
|
||||||
}
|
}
|
||||||
if((0)) // The following tests would fail
|
if((0)) // The following tests would fail
|
||||||
@ -807,17 +821,7 @@ bool DebugEigenTest()
|
|||||||
//MyTensor z(NamesBad);
|
//MyTensor z(NamesBad);
|
||||||
const char * pszName = "zFail";
|
const char * pszName = "zFail";
|
||||||
DebugShowTensor(z, pszName);
|
DebugShowTensor(z, pszName);
|
||||||
z.read<Hdf5Reader>(pszH5Name);
|
z.read(pszFileName);
|
||||||
DebugShowTensor(z, pszName);
|
|
||||||
}
|
|
||||||
// Now see whether we can read a tensor back from an xml file
|
|
||||||
const char * pszXmlName = "test.xml";
|
|
||||||
y.write<XmlWriter>(pszXmlName);
|
|
||||||
{
|
|
||||||
MyTensor z;
|
|
||||||
const char * pszName = "xml1";
|
|
||||||
DebugShowTensor(z, pszName);
|
|
||||||
z.read<XmlReader>(pszXmlName);
|
|
||||||
DebugShowTensor(z, pszName);
|
DebugShowTensor(z, pszName);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1027,7 +1031,7 @@ int main(int argc, char *argv[])
|
|||||||
<< ", sizeof(hsize_t) = " << sizeof(hsize_t)
|
<< ", sizeof(hsize_t) = " << sizeof(hsize_t)
|
||||||
<< ", sizeof(unsigned long long) = " << sizeof(unsigned long long)
|
<< ", sizeof(unsigned long long) = " << sizeof(unsigned long long)
|
||||||
<< std::endl;
|
<< std::endl;
|
||||||
//if( DebugEigenTest() ) return 0;
|
if( DebugEigenTest() ) return 0;
|
||||||
//if(DebugGridTensorTest()) return 0;
|
//if(DebugGridTensorTest()) return 0;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user