mirror of
https://github.com/paboyle/Grid.git
synced 2025-04-10 14:10:46 +01:00
Hadrons: meson field IO fix
This commit is contained in:
parent
c012899ed5
commit
c632455129
@ -39,13 +39,14 @@ public:
|
||||
A2AMatrixIo(void) = default;
|
||||
A2AMatrixIo(std::string filename, std::string dataname,
|
||||
const unsigned int nt, const unsigned int ni,
|
||||
const unsigned int nj, const unsigned int blockSize);
|
||||
const unsigned int nj);
|
||||
~A2AMatrixIo(void) = default;
|
||||
void initFile(const MetadataType &d);
|
||||
void saveBlock(const T *data, const unsigned int i, const unsigned int j);
|
||||
void initFile(const MetadataType &d, const unsigned int chunkSize);
|
||||
void saveBlock(const T *data, const unsigned int i, const unsigned int j,
|
||||
const unsigned int blockSizei, const unsigned int blockSizej);
|
||||
private:
|
||||
std::string filename_, dataname_;
|
||||
unsigned int nt_, ni_, nj_, blockSize_;
|
||||
unsigned int nt_, ni_, nj_;
|
||||
};
|
||||
|
||||
template <typename T, typename MetadataType>
|
||||
@ -53,22 +54,21 @@ A2AMatrixIo<T, MetadataType>::A2AMatrixIo(std::string filename,
|
||||
std::string dataname,
|
||||
const unsigned int nt,
|
||||
const unsigned int ni,
|
||||
const unsigned int nj,
|
||||
const unsigned int blockSize)
|
||||
const unsigned int nj)
|
||||
: filename_(filename), dataname_(dataname)
|
||||
, nt_(nt), ni_(ni), nj_(nj), blockSize_(blockSize)
|
||||
, nt_(nt), ni_(ni), nj_(nj)
|
||||
{}
|
||||
|
||||
template <typename T, typename MetadataType>
|
||||
void A2AMatrixIo<T, MetadataType>::initFile(const MetadataType &d)
|
||||
void A2AMatrixIo<T, MetadataType>::initFile(const MetadataType &d, const unsigned int chunkSize)
|
||||
{
|
||||
#ifdef HAVE_HDF5
|
||||
std::vector<hsize_t> dim = {static_cast<hsize_t>(nt_),
|
||||
static_cast<hsize_t>(ni_),
|
||||
static_cast<hsize_t>(nj_)},
|
||||
chunk = {static_cast<hsize_t>(nt_),
|
||||
static_cast<hsize_t>(blockSize_),
|
||||
static_cast<hsize_t>(blockSize_)};
|
||||
static_cast<hsize_t>(chunkSize),
|
||||
static_cast<hsize_t>(chunkSize)};
|
||||
H5NS::DataSpace dataspace(dim.size(), dim.data());
|
||||
H5NS::DataSet dataset;
|
||||
H5NS::DSetCreatPropList plist;
|
||||
@ -94,11 +94,13 @@ void A2AMatrixIo<T, MetadataType>::initFile(const MetadataType &d)
|
||||
template <typename T, typename MetadataType>
|
||||
void A2AMatrixIo<T, MetadataType>::saveBlock(const T *data,
|
||||
const unsigned int i,
|
||||
const unsigned int j)
|
||||
const unsigned int j,
|
||||
const unsigned int blockSizei,
|
||||
const unsigned int blockSizej)
|
||||
{
|
||||
#ifdef HAVE_HDF5
|
||||
Hdf5Reader reader(filename_);
|
||||
std::vector<hsize_t> count = {nt_, blockSize_, blockSize_},
|
||||
std::vector<hsize_t> count = {nt_, blockSizei, blockSizej},
|
||||
offset = {0, static_cast<hsize_t>(i),
|
||||
static_cast<hsize_t>(j)},
|
||||
stride = {1, 1, 1},
|
||||
|
@ -85,6 +85,7 @@ public:
|
||||
MatrixIo io;
|
||||
A2AMesonFieldMetadata metadata;
|
||||
size_t offset;
|
||||
unsigned int i, j, blockSizei, blockSizej;
|
||||
};
|
||||
public:
|
||||
// constructor
|
||||
@ -100,9 +101,9 @@ public:
|
||||
virtual void execute(void);
|
||||
private:
|
||||
// IO
|
||||
std::string ioname(unsigned int m, unsigned int g) const;
|
||||
std::string filename(unsigned int m, unsigned int g) const;
|
||||
void saveBlock(const MF_IO_TYPE *data, IoHelper &h, unsigned int i, unsigned int j);
|
||||
std::string ioname(const unsigned int m, const unsigned int g) const;
|
||||
std::string filename(const unsigned int m, const unsigned int g) const;
|
||||
void saveBlock(const MF_IO_TYPE *data, IoHelper &h);
|
||||
private:
|
||||
bool hasPhase_{false};
|
||||
std::string momphName_;
|
||||
@ -350,19 +351,23 @@ void TA2AMesonField<FImpl>::execute(void)
|
||||
const unsigned int m = f/ngamma, g = f % ngamma;
|
||||
IoHelper h;
|
||||
|
||||
h.io = MatrixIo(filename(m, g), ioname(m, g), nt, N_i, N_j, block);
|
||||
h.io = MatrixIo(filename(m, g), ioname(m, g), nt, N_i, N_j);
|
||||
for (auto pmu: mom_[m])
|
||||
{
|
||||
h.metadata.momentum.push_back(pmu);
|
||||
}
|
||||
h.metadata.gamma = gamma_[g];
|
||||
h.offset = (m*ngamma + g)*nt*block*block;
|
||||
h.i = i;
|
||||
h.j = j;
|
||||
h.blockSizei = mfBlock.dimension(3);
|
||||
h.blockSizej = mfBlock.dimension(4);
|
||||
h.offset = (m*ngamma + g)*nt*h.blockSizei*h.blockSizej;
|
||||
nodeIo_.push_back(h);
|
||||
}
|
||||
// parallel IO
|
||||
for (auto &h: nodeIo_)
|
||||
{
|
||||
saveBlock(mfBlock.data(), h, i, j);
|
||||
saveBlock(mfBlock.data(), h);
|
||||
}
|
||||
env().getGrid()->Barrier();
|
||||
#else
|
||||
@ -372,14 +377,18 @@ void TA2AMesonField<FImpl>::execute(void)
|
||||
{
|
||||
IoHelper h;
|
||||
|
||||
h.io = MatrixIo(filename(m, g), ioname(m, g), nt, N_i, N_j, block);
|
||||
h.io = MatrixIo(filename(m, g), ioname(m, g), nt, N_i, N_j);
|
||||
for (auto pmu: mom_[m])
|
||||
{
|
||||
h.metadata.momentum.push_back(pmu);
|
||||
}
|
||||
h.metadata.gamma = gamma_[g];
|
||||
h.offset = (m*ngamma + g)*nt*block*block;
|
||||
saveBlock(mfBlock.data(), h, i, j);
|
||||
h.i = i;
|
||||
h.j = j;
|
||||
h.blockSizei = mfBlock.dimension(3);
|
||||
h.blockSizej = mfBlock.dimension(4);
|
||||
h.offset = (m*ngamma + g)*nt*h.blockSizei*h.blockSizej;
|
||||
saveBlock(mfBlock.data(), h);
|
||||
}
|
||||
#endif
|
||||
stopTimer("IO: total");
|
||||
@ -416,17 +425,16 @@ std::string TA2AMesonField<FImpl>::filename(unsigned int m, unsigned int g) cons
|
||||
}
|
||||
|
||||
template <typename FImpl>
|
||||
void TA2AMesonField<FImpl>::saveBlock(const MF_IO_TYPE *data, IoHelper &h,
|
||||
unsigned int i, unsigned int j)
|
||||
void TA2AMesonField<FImpl>::saveBlock(const MF_IO_TYPE *data, IoHelper &h)
|
||||
{
|
||||
if ((i == 0) and (j == 0))
|
||||
if ((h.i == 0) and (h.j == 0))
|
||||
{
|
||||
startTimer("IO: file creation");
|
||||
h.io.initFile(h.metadata);
|
||||
h.io.initFile(h.metadata, par().block);
|
||||
stopTimer("IO: file creation");
|
||||
}
|
||||
startTimer("IO: write block");
|
||||
h.io.saveBlock(data + h.offset, i, j);
|
||||
h.io.saveBlock(data + h.offset, h.i, h.j, h.blockSizei, h.blockSizej);
|
||||
stopTimer("IO: write block");
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user