From 09001aedca2e15547e38521e00bc9bc626479489 Mon Sep 17 00:00:00 2001 From: Antonin Portelli Date: Tue, 14 Aug 2018 17:19:38 +0100 Subject: [PATCH] Hadrons: meson fields saved in single precision --- .../Modules/MContraction/A2AMesonField.hpp | 53 ++++++++++--------- .../MContraction/A2AMesonFieldKernels.hpp | 4 +- 2 files changed, 30 insertions(+), 27 deletions(-) diff --git a/extras/Hadrons/Modules/MContraction/A2AMesonField.hpp b/extras/Hadrons/Modules/MContraction/A2AMesonField.hpp index 6123491a..e30f966b 100644 --- a/extras/Hadrons/Modules/MContraction/A2AMesonField.hpp +++ b/extras/Hadrons/Modules/MContraction/A2AMesonField.hpp @@ -38,6 +38,9 @@ See the full license in the file "LICENSE" in the top level distribution directo #include #define MF_PARALLEL_IO +#ifndef MF_IO_TYPE +#define MF_IO_TYPE ComplexF +#endif BEGIN_HADRONS_NAMESPACE @@ -65,6 +68,8 @@ class TA2AMesonField : public Module public: FERM_TYPE_ALIASES(FImpl,); SOLVER_TYPE_ALIASES(FImpl,); + typedef Eigen::TensorMap> MesonField; + typedef Eigen::TensorMap> MesonFieldIo; public: // constructor TA2AMesonField(const std::string name); @@ -82,14 +87,14 @@ private: std::string ioname(unsigned int m, unsigned int g) const; std::string filename(unsigned int m, unsigned int g) const; void initFile(unsigned int m, unsigned int g); - void saveBlock(const MesonField &mf, + void saveBlock(const MesonFieldIo &mf, unsigned int m, unsigned int g, unsigned int i, unsigned int j); private: - bool hasPhase_{false}; - std::string momphName_; - std::vector gamma_; - std::vector> mom_; + bool hasPhase_{false}; + std::string momphName_; + std::vector gamma_; + std::vector> mom_; std::vector> nodeFile_; }; @@ -174,7 +179,7 @@ void TA2AMesonField::setup(void) // preallocate memory for meson field block auto tgp = env().getDim().back()*gamma_.size()*mom_.size(); - envTmp(Vector, "mfBuf", 1, tgp*par().block*par().block); + envTmp(Vector, "mfBuf", 1, tgp*par().block*par().block); envTmp(Vector, "mfCache", 1, tgp*par().cacheBlock*par().cacheBlock); } @@ -195,18 +200,19 @@ void TA2AMesonField::execute(void) LOG(Message) << "Computing all-to-all meson fields" << std::endl; LOG(Message) << "W: '" << par().w << "' V: '" << par().v << "'" << std::endl; - LOG(Message) << "Meson field size: " << nt << "*" << N_i << "*" << N_j - << " (" << sizeString(nt*N_i*N_j*sizeof(Complex)) << ")" << std::endl; LOG(Message) << "Momenta:" << std::endl; for (auto &p: mom_) { LOG(Message) << " " << p << std::endl; } - LOG(Message) << "Spin structures:" << std::endl; + LOG(Message) << "Spin bilinears:" << std::endl; for (auto &g: gamma_) { LOG(Message) << " " << g << std::endl; } + LOG(Message) << "Meson field size: " << nt << "*" << N_i << "*" << N_j + << " (filesize " << sizeString(nt*N_i*N_j*sizeof(MF_IO_TYPE)) + << "/momentum/bilinear)" << std::endl; /////////////////////////////////////////////// // Momentum setup @@ -246,8 +252,7 @@ void TA2AMesonField::execute(void) double vol = env().getVolume(); double t_contr=0; - - envGetTmp(Vector, mfBuf); + envGetTmp(Vector, mfBuf); envGetTmp(Vector, mfCache); double t0 = usecond(); @@ -267,7 +272,7 @@ void TA2AMesonField::execute(void) << i+N_ii-1 << ", " << j <<" .. " << j+N_jj-1 << "]" << std::endl; - MesonField mfBlock(mfBuf.data(),nmom,ngamma,nt,N_ii,N_jj); + MesonFieldIo mfBlock(mfBuf.data(),nmom,ngamma,nt,N_ii,N_jj); // Series of cache blocked chunks of the contractions within this block for(int ii=0;ii::execute(void) } #endif stopTimer("IO: total"); - blockSize = static_cast(nmom*ngamma*nt*N_ii*N_jj*sizeof(Complex)); + blockSize = static_cast(nmom*ngamma*nt*N_ii*N_jj*sizeof(MF_IO_TYPE)); ioTime += getDTimer("IO: write block"); LOG(Message) << "HDF5 IO done " << sizeString(blockSize) << " in " << ioTime << " us (" @@ -427,7 +432,7 @@ void TA2AMesonField::initFile(unsigned int m, unsigned int g) write(writer, "gamma", gamma_[g]); auto &group = writer.getGroup(); plist.setChunk(chunk.size(), chunk.data()); - dataset = group.createDataSet("mesonField", Hdf5Type::type(), + dataset = group.createDataSet("mesonField", Hdf5Type::type(), dataspace, plist); #else HADRONS_ERROR(Implementation, "meson field I/O needs HDF5 library"); @@ -435,7 +440,7 @@ void TA2AMesonField::initFile(unsigned int m, unsigned int g) } template -void TA2AMesonField::saveBlock(const MesonField &mf, +void TA2AMesonField::saveBlock(const MesonFieldIo &mf, unsigned int m, unsigned int g, unsigned int i, unsigned int j) { @@ -443,13 +448,13 @@ void TA2AMesonField::saveBlock(const MesonField &mf, std::string f = filename(m, g); Hdf5Reader reader(f); hsize_t nt = mf.dimension(2), - Ni = mf.dimension(3), - Nj = mf.dimension(4); + Ni = mf.dimension(3), + Nj = mf.dimension(4); std::vector count = {nt, Ni, Nj}, - offset = {0, static_cast(i), - static_cast(j)}, - stride = {1, 1, 1}, - block = {1, 1, 1}; + offset = {0, static_cast(i), + static_cast(j)}, + stride = {1, 1, 1}, + block = {1, 1, 1}; H5NS::DataSpace memspace(count.size(), count.data()), dataspace; H5NS::DataSet dataset; size_t shift; @@ -459,10 +464,10 @@ void TA2AMesonField::saveBlock(const MesonField &mf, dataset = group.openDataSet("mesonField"); dataspace = dataset.getSpace(); dataspace.selectHyperslab(H5S_SELECT_SET, count.data(), offset.data(), - stride.data(), block.data()); + stride.data(), block.data()); shift = (m*mf.dimension(1) + g)*nt*Ni*Nj; - dataset.write(mf.data() + shift, Hdf5Type::type(), memspace, - dataspace); + dataset.write(mf.data() + shift, Hdf5Type::type(), memspace, + dataspace); #else HADRONS_ERROR(Implementation, "meson field I/O needs HDF5 library"); #endif diff --git a/extras/Hadrons/Modules/MContraction/A2AMesonFieldKernels.hpp b/extras/Hadrons/Modules/MContraction/A2AMesonFieldKernels.hpp index 4d06f796..649f9fdf 100644 --- a/extras/Hadrons/Modules/MContraction/A2AMesonFieldKernels.hpp +++ b/extras/Hadrons/Modules/MContraction/A2AMesonFieldKernels.hpp @@ -37,13 +37,11 @@ BEGIN_HADRONS_NAMESPACE BEGIN_MODULE_NAMESPACE(MContraction) -typedef Eigen::TensorMap> MesonField; - //////////////////////////////////////////////////////////////////////////////// // Cache blocked arithmetic routine // Could move to Grid ??? //////////////////////////////////////////////////////////////////////////////// -template +template void makeMesonFieldBlock(MesonField &mat, const Field *lhs_wi, const Field *rhs_vj,