From 7a85fddc7e4082b17500edb7fc08cf68efcda984 Mon Sep 17 00:00:00 2001 From: Antonin Portelli Date: Thu, 22 Dec 2016 00:25:36 +0100 Subject: [PATCH 01/27] Hadrons: modification of registration mechanism to allow for persistent caches --- extras/Hadrons/Application.cc | 2 +- extras/Hadrons/Environment.cc | 47 +++++++++++++++++++++++++++++----- extras/Hadrons/Environment.hpp | 4 ++- 3 files changed, 45 insertions(+), 8 deletions(-) diff --git a/extras/Hadrons/Application.cc b/extras/Hadrons/Application.cc index cf7906eb..4bb3b383 100644 --- a/extras/Hadrons/Application.cc +++ b/extras/Hadrons/Application.cc @@ -306,7 +306,7 @@ void Application::configLoop(void) << " " << BIG_SEP << std::endl; env_.setTrajectory(t); env_.executeProgram(program_); - env_.freeAll(); } LOG(Message) << BIG_SEP << " End of measurement " << BIG_SEP << std::endl; + env_.freeAll(); } diff --git a/extras/Hadrons/Environment.cc b/extras/Hadrons/Environment.cc index 4b230e20..68c170b8 100644 --- a/extras/Hadrons/Environment.cc +++ b/extras/Hadrons/Environment.cc @@ -410,12 +410,19 @@ Environment::Size Environment::executeProgram(const std::vector &p) // general memory management /////////////////////////////////////////////////// void Environment::addObject(const std::string name, const int moduleAddress) { - ObjInfo info; - - info.name = name; - info.module = moduleAddress; - object_.push_back(std::move(info)); - objectAddress_[name] = static_cast(object_.size() - 1); + if (!hasObject(name)) + { + ObjInfo info; + + info.name = name; + info.module = moduleAddress; + object_.push_back(std::move(info)); + objectAddress_[name] = static_cast(object_.size() - 1); + } + else + { + HADRON_ERROR("object '" + name + "' already exists"); + } } void Environment::registerObject(const unsigned int address, @@ -444,6 +451,10 @@ void Environment::registerObject(const unsigned int address, void Environment::registerObject(const std::string name, const unsigned int size, const unsigned int Ls) { + if (!hasObject(name)) + { + addObject(name); + } registerObject(getObjectAddress(name), size, Ls); } @@ -573,6 +584,30 @@ bool Environment::hasRegisteredObject(const std::string name) const } } +bool Environment::hasCreatedObject(const unsigned int address) const +{ + if (hasObject(address)) + { + return (object_[address].data != nullptr); + } + else + { + return false; + } +} + +bool Environment::hasCreatedObject(const std::string name) const +{ + if (hasObject(name)) + { + return hasCreatedObject(getObjectAddress(name)); + } + else + { + return false; + } +} + bool Environment::isObject5d(const unsigned int address) const { return (getObjectLs(address) > 1); diff --git a/extras/Hadrons/Environment.hpp b/extras/Hadrons/Environment.hpp index 41a7a008..041bcc0e 100644 --- a/extras/Hadrons/Environment.hpp +++ b/extras/Hadrons/Environment.hpp @@ -137,7 +137,7 @@ public: Size executeProgram(const std::vector &p); // general memory management void addObject(const std::string name, - const int moduleAddress); + const int moduleAddress = -1); void registerObject(const unsigned int address, const unsigned int size, const unsigned int Ls = 1); @@ -176,6 +176,8 @@ public: bool hasObject(const std::string name) const; bool hasRegisteredObject(const unsigned int address) const; bool hasRegisteredObject(const std::string name) const; + bool hasCreatedObject(const unsigned int address) const; + bool hasCreatedObject(const std::string name) const; bool isObject5d(const unsigned int address) const; bool isObject5d(const std::string name) const; Environment::Size getTotalSize(void) const; From 3215ae6b7e82acb91caa42d2799d63e6a3676461 Mon Sep 17 00:00:00 2001 From: Antonin Portelli Date: Thu, 22 Dec 2016 00:26:30 +0100 Subject: [PATCH 02/27] Hadrons: genetic scheduler crashes in multi-thread with 1 module, multi-threading deactivated for now --- extras/Hadrons/GeneticScheduler.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/extras/Hadrons/GeneticScheduler.hpp b/extras/Hadrons/GeneticScheduler.hpp index 7b5fc183..c9256d96 100644 --- a/extras/Hadrons/GeneticScheduler.hpp +++ b/extras/Hadrons/GeneticScheduler.hpp @@ -134,7 +134,7 @@ void GeneticScheduler::nextGeneration(void) LOG(Debug) << "Starting population:\n" << *this << std::endl; // random mutations - PARALLEL_FOR_LOOP + //PARALLEL_FOR_LOOP for (unsigned int i = 0; i < par_.popSize; ++i) { doMutation(); @@ -142,7 +142,7 @@ void GeneticScheduler::nextGeneration(void) LOG(Debug) << "After mutations:\n" << *this << std::endl; // mating - PARALLEL_FOR_LOOP + //PARALLEL_FOR_LOOP for (unsigned int i = 0; i < par_.popSize/2; ++i) { doCrossover(); From 41df1db811dacca67cead6c7ca5512b72ba40fbe Mon Sep 17 00:00:00 2001 From: Antonin Portelli Date: Wed, 11 Jan 2017 18:37:49 +0000 Subject: [PATCH 03/27] Hadrons: number of dimensions entirely determined by the initial grid --- extras/Hadrons/Environment.cc | 8 +++++++- extras/Hadrons/Environment.hpp | 2 ++ extras/Hadrons/Modules/MSource/SeqGamma.hpp | 2 +- 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/extras/Hadrons/Environment.cc b/extras/Hadrons/Environment.cc index 68c170b8..37f2a3d7 100644 --- a/extras/Hadrons/Environment.cc +++ b/extras/Hadrons/Environment.cc @@ -41,8 +41,9 @@ using namespace Hadrons; // constructor ///////////////////////////////////////////////////////////////// Environment::Environment(void) { + nd_ = GridDefaultLatt().size(); grid4d_.reset(SpaceTimeGrid::makeFourDimGrid( - GridDefaultLatt(), GridDefaultSimd(Nd, vComplex::Nsimd()), + GridDefaultLatt(), GridDefaultSimd(nd_, vComplex::Nsimd()), GridDefaultMpi())); gridRb4d_.reset(SpaceTimeGrid::makeFourDimRedBlackGrid(grid4d_.get())); auto loc = getGrid()->LocalDimensions(); @@ -126,6 +127,11 @@ GridRedBlackCartesian * Environment::getRbGrid(const unsigned int Ls) const } } +unsigned int Environment::getNd(void) const +{ + return nd_; +} + // random number generator ///////////////////////////////////////////////////// void Environment::setSeed(const std::vector &seed) { diff --git a/extras/Hadrons/Environment.hpp b/extras/Hadrons/Environment.hpp index 041bcc0e..2628e5a0 100644 --- a/extras/Hadrons/Environment.hpp +++ b/extras/Hadrons/Environment.hpp @@ -106,6 +106,7 @@ public: void createGrid(const unsigned int Ls); GridCartesian * getGrid(const unsigned int Ls = 1) const; GridRedBlackCartesian * getRbGrid(const unsigned int Ls = 1) const; + unsigned int getNd(void) const; // random number generator void setSeed(const std::vector &seed); GridParallelRNG * get4dRng(void) const; @@ -200,6 +201,7 @@ private: std::map grid5d_; GridRbPt gridRb4d_; std::map gridRb5d_; + unsigned int nd_; // random number generator RngPt rng4d_; // module and related maps diff --git a/extras/Hadrons/Modules/MSource/SeqGamma.hpp b/extras/Hadrons/Modules/MSource/SeqGamma.hpp index 181f9532..611b0108 100644 --- a/extras/Hadrons/Modules/MSource/SeqGamma.hpp +++ b/extras/Hadrons/Modules/MSource/SeqGamma.hpp @@ -147,7 +147,7 @@ void TSeqGamma::execute(void) g = makeGammaProd(par().gamma); p = strToVec(par().mom); ph = zero; - for(unsigned int mu = 0; mu < Nd; mu++) + for(unsigned int mu = 0; mu < env().getNd(); mu++) { LatticeCoordinate(coor, mu); ph = ph + p[mu]*coor; From 16a8e3d0d432bb71183c05c09cde3de86a7eff83 Mon Sep 17 00:00:00 2001 From: Antonin Portelli Date: Mon, 16 Jan 2017 06:32:05 +0000 Subject: [PATCH 04/27] gitignore update for ST3 --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index da7de5e4..5838caf7 100644 --- a/.gitignore +++ b/.gitignore @@ -9,6 +9,7 @@ ################ *~ *# +*.sublime-* # Precompiled Headers # ####################### From 91a35340543217dbb7ed6a0a3ab049cbd575976f Mon Sep 17 00:00:00 2001 From: Antonin Portelli Date: Mon, 16 Jan 2017 06:32:25 +0000 Subject: [PATCH 05/27] Lattice slice utilities now thread safe --- lib/lattice/Lattice_transfer.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/lattice/Lattice_transfer.h b/lib/lattice/Lattice_transfer.h index cc4617de..a49b1b5f 100644 --- a/lib/lattice/Lattice_transfer.h +++ b/lib/lattice/Lattice_transfer.h @@ -386,7 +386,7 @@ void InsertSlice(Lattice &lowDim,Lattice & higherDim,int slice, int } // the above should guarantee that the operations are local - //PARALLEL_FOR_LOOP + PARALLEL_FOR_LOOP for(int idx=0;idxlSites();idx++){ std::vector lcoor(nl); std::vector hcoor(nh); @@ -428,7 +428,7 @@ void ExtractSlice(Lattice &lowDim, Lattice & higherDim,int slice, in } } // the above should guarantee that the operations are local - //PARALLEL_FOR_LOOP + PARALLEL_FOR_LOOP for(int idx=0;idxlSites();idx++){ std::vector lcoor(nl); std::vector hcoor(nh); From 7cf833dfe911eb81246b060fb4d3abdc7e91f78e Mon Sep 17 00:00:00 2001 From: Guido Cossu Date: Tue, 17 Jan 2017 11:00:54 +0000 Subject: [PATCH 06/27] Fixed compilation error in tests hadrons (capital letter in dir name) --- tests/hadrons/Makefile.am | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/hadrons/Makefile.am b/tests/hadrons/Makefile.am index fae0d212..c8ec1612 100644 --- a/tests/hadrons/Makefile.am +++ b/tests/hadrons/Makefile.am @@ -1,3 +1,3 @@ -AM_LDFLAGS += -L../../extras/hadrons +AM_LDFLAGS += -L../../extras/Hadrons include Make.inc From 5803933aea55df67c733cf1e4201f354d8a8965b Mon Sep 17 00:00:00 2001 From: Antonin Portelli Date: Tue, 17 Jan 2017 16:21:18 -0800 Subject: [PATCH 07/27] First implementation of HDF5 serial IO writer, reader is still empty --- configure.ac | 14 +++ lib/Grid.h | 2 +- lib/Makefile.am | 13 ++- lib/serialisation/Hdf5IO.cc | 84 +++++++++++++++ lib/serialisation/Hdf5IO.h | 169 ++++++++++++++++++++++++++++++ lib/serialisation/Hdf5Type.cc | 8 ++ lib/serialisation/Hdf5Type.h | 48 +++++++++ lib/serialisation/Serialisation.h | 3 + scripts/filelist | 5 +- tests/IO/Test_serialisation.cc | 16 +++ 10 files changed, 357 insertions(+), 5 deletions(-) create mode 100644 lib/serialisation/Hdf5IO.cc create mode 100644 lib/serialisation/Hdf5IO.h create mode 100644 lib/serialisation/Hdf5Type.cc create mode 100644 lib/serialisation/Hdf5Type.h diff --git a/configure.ac b/configure.ac index f413cde8..f848bd23 100644 --- a/configure.ac +++ b/configure.ac @@ -99,6 +99,13 @@ case ${ac_MKL} in AC_DEFINE([USE_MKL], [1], [Define to 1 if you use the Intel MKL]);; esac +############### HDF5 +AC_ARG_WITH([hdf5], + [AS_HELP_STRING([--with-hdf5=prefix], + [try this for a non-standard install prefix of the HDF5 library])], + [AM_CXXFLAGS="-I$with_hdf5/include $AM_CXXFLAGS"] + [AM_LDFLAGS="-L$with_hdf5/lib $AM_LDFLAGS"]) + ############### first-touch AC_ARG_ENABLE([numa], [AC_HELP_STRING([--enable-numa=yes|no|prefix], [enable first touch numa opt])], @@ -145,6 +152,12 @@ AC_SEARCH_LIBS([fftw_execute], [fftw3], [AC_DEFINE([HAVE_FFTW], [1], [Define to 1 if you have the `FFTW' library])] [have_fftw=true]) +AC_SEARCH_LIBS([H5Fopen], [hdf5_cpp], + [AC_DEFINE([HAVE_HDF5], [1], [Define to 1 if you have the `HDF5' library])] + [have_hdf5=true] + [LIBS="${LIBS} -lhdf5"], [], [-lhdf5]) +AM_CONDITIONAL(BUILD_HDF5, [ test "${have_hdf5}X" == "trueX" ]) + CXXFLAGS=$CXXFLAGS_CPY LDFLAGS=$LDFLAGS_CPY @@ -410,6 +423,7 @@ RNG choice : ${ac_RNG} GMP : `if test "x$have_gmp" = xtrue; then echo yes; else echo no; fi` LAPACK : ${ac_LAPACK} FFTW : `if test "x$have_fftw" = xtrue; then echo yes; else echo no; fi` +HDF5 : `if test "x$have_hdf5" = xtrue; then echo yes; else echo no; fi` build DOXYGEN documentation : `if test "$DX_FLAG_doc" = '1'; then echo yes; else echo no; fi` ----- BUILD FLAGS ------------------------------------- CXXFLAGS: diff --git a/lib/Grid.h b/lib/Grid.h index 0c5983f3..0f57c8a6 100644 --- a/lib/Grid.h +++ b/lib/Grid.h @@ -59,8 +59,8 @@ Author: paboyle /////////////////// // Grid headers /////////////////// -#include #include "Config.h" +#include #include #include #include diff --git a/lib/Makefile.am b/lib/Makefile.am index a779135f..9aa6af92 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -1,4 +1,5 @@ extra_sources= +extra_headers= if BUILD_COMMS_MPI extra_sources+=communicator/Communicator_mpi.cc extra_sources+=communicator/Communicator_base.cc @@ -24,6 +25,13 @@ if BUILD_COMMS_NONE extra_sources+=communicator/Communicator_base.cc endif +if BUILD_HDF5 + extra_sources+=serialisation/Hdf5IO.cc + extra_sources+=serialisation/Hdf5Type.cc + extra_headers+=serialisation/Hdf5IO.h + extra_headers+=serialisation/Hdf5Type.h +endif + # # Libraries # @@ -32,6 +40,9 @@ include Eigen.inc lib_LIBRARIES = libGrid.a -libGrid_a_SOURCES = $(CCFILES) $(extra_sources) +CCFILES += $(extra_sources) +HFILES += $(extra_headers) + +libGrid_a_SOURCES = $(CCFILES) libGrid_adir = $(pkgincludedir) nobase_dist_pkginclude_HEADERS = $(HFILES) $(eigen_files) Config.h diff --git a/lib/serialisation/Hdf5IO.cc b/lib/serialisation/Hdf5IO.cc new file mode 100644 index 00000000..0d62fdd8 --- /dev/null +++ b/lib/serialisation/Hdf5IO.cc @@ -0,0 +1,84 @@ +#include + +using namespace Grid; +#ifndef H5_NO_NAMESPACE +using namespace H5NS; +#endif + +// Writer implementation /////////////////////////////////////////////////////// +Hdf5Writer::Hdf5Writer(const std::string &fileName) +: fileName_(fileName) +, file_(fileName.c_str(), H5F_ACC_TRUNC) +{ + group_ = file_.openGroup("/"); +} + +Hdf5Writer::~Hdf5Writer(void) +{ + file_.close(); +} + +void Hdf5Writer::push(const std::string &s) +{ + group_ = group_.createGroup(s); + path_.push_back(s); +} + +void Hdf5Writer::pop(void) +{ + path_.pop_back(); + if (path_.empty()) + { + group_ = file_.openGroup("/"); + } + else + { + auto binOp = [](const std::string &a, const std::string &b)->std::string + { + return a + "/" + b; + }; + + group_ = group_.openGroup(std::accumulate(path_.begin(), path_.end(), + std::string(""), binOp)); + } +} + +template <> +void Hdf5Writer::writeDefault(const std::string &s, const std::string &x) +{ + StrType strType(PredType::C_S1, x.size()); + Attribute attribute; + hsize_t attrDim = 1; + DataSpace attrSpace(1, &attrDim); + + attribute = group_.createAttribute(s, strType, attrSpace); + attribute.write(strType, x.data()); +} + +void Hdf5Writer::writeDefault(const std::string &s, const char *x) +{ + std::string sx(x); + + writeDefault(s, sx); +} + +// Reader implementation /////////////////////////////////////////////////////// +Hdf5Reader::Hdf5Reader(const std::string &fileName) +{ + +} + +Hdf5Reader::~Hdf5Reader(void) +{ + +} + +void Hdf5Reader::push(const std::string &s) +{ + +} + +void Hdf5Reader::pop(void) +{ + +} diff --git a/lib/serialisation/Hdf5IO.h b/lib/serialisation/Hdf5IO.h new file mode 100644 index 00000000..481fa1cf --- /dev/null +++ b/lib/serialisation/Hdf5IO.h @@ -0,0 +1,169 @@ +#ifndef GRID_SERIALISATION_HDF5_H +#define GRID_SERIALISATION_HDF5_H + +#include +#include +#include +#include +#include "Hdf5Type.h" + +#ifndef H5_NO_NAMESPACE +#define H5NS H5 +#endif + +// default thresold above which datasets are used instead of attributes +#ifndef H5_DEF_DATASET_THRES +#define H5_DEF_DATASET_THRES 6u +#endif + +namespace Grid +{ + template + struct is_arithmetic_vector + { + static constexpr bool value = false; + }; + + template + struct is_arithmetic_vector> + { + static constexpr bool value = std::is_arithmetic::value + or is_arithmetic_vector::value; + }; + + class Hdf5Writer: public Writer + { + public: + Hdf5Writer(const std::string &fileName); + virtual ~Hdf5Writer(void); + void push(const std::string &s); + void pop(void); + void writeDefault(const std::string &s, const char *x); + template + void writeDefault(const std::string &s, const U &x); + template + typename std::enable_if>::value + and std::is_arithmetic::value, void>::type + writeDefault(const std::string &s, const std::vector &x); + template + typename std::enable_if>::value + and !std::is_arithmetic::value, void>::type + writeDefault(const std::string &s, const std::vector &x); + template + typename std::enable_if>::value, void>::type + writeDefault(const std::string &s, const std::vector &x); + private: + std::string fileName_; + std::vector path_; + std::vector dim_; + bool multiDim_{true}; + H5NS::H5File file_; + H5NS::Group group_; + unsigned int datasetThres_{H5_DEF_DATASET_THRES}; + }; + + class Hdf5Reader: public Reader + { + public: + Hdf5Reader(const std::string &fileName); + virtual ~Hdf5Reader(void); + void push(const std::string &s); + void pop(void); + template + void readDefault(const std::string &s, U &output); + template + void readDefault(const std::string &s, std::vector &output); + private: + }; + + // Writer template implementation //////////////////////////////////////////// + template + void Hdf5Writer::writeDefault(const std::string &s, const U &x) + { + H5NS::Attribute attribute; + hsize_t attrDim = 1; + H5NS::DataSpace attrSpace(1, &attrDim); + + attribute = group_.createAttribute(s, *Hdf5Type::type, attrSpace); + attribute.write(*Hdf5Type::type, &x); + } + + template <> + void Hdf5Writer::writeDefault(const std::string &s, const std::string &x); + + template + typename std::enable_if>::value + and std::is_arithmetic::value, void>::type + Hdf5Writer::writeDefault(const std::string &s, const std::vector &x) + { + hsize_t size = 1; + + dim_.push_back(x.size()); + for (auto d: dim_) + { + size *= d; + } + + H5NS::DataSpace dataspace(dim_.size(), dim_.data()); + + if (size > datasetThres_) + { + H5NS::DataSet dataset; + + dataset = group_.createDataSet(s, *Hdf5Type::type, dataspace); + dataset.write(x.data(), *Hdf5Type::type); + } + else + { + H5NS::Attribute attribute; + + attribute = group_.createAttribute(s, *Hdf5Type::type, dataspace); + attribute.write(*Hdf5Type::type, x.data()); + } + dim_.clear(); + multiDim_ = true; + } + + template + typename std::enable_if>::value + and !std::is_arithmetic::value, void>::type + Hdf5Writer::writeDefault(const std::string &s, const std::vector &x) + { + hsize_t firstSize = x[0].size(); + + for (auto &v: x) + { + multiDim_ = (multiDim_ and (v.size() == firstSize)); + } + assert(multiDim_); + dim_.push_back(x.size()); + writeDefault(s, x[0]); + } + + template + typename std::enable_if>::value, void>::type + Hdf5Writer::writeDefault(const std::string &s, const std::vector &x) + { + push(s); + for (hsize_t i = 0; i < x.size(); ++i) + { + write(s + "_" + std::to_string(i), x[i]); + } + pop(); + } + + // Reader template implementation //////////////////////////////////////////// + template + void Hdf5Reader::readDefault(const std::string &s, U &output) + { + + } + + template + void Hdf5Reader::readDefault(const std::string &s, std::vector &output) + { + + } +} + +#endif diff --git a/lib/serialisation/Hdf5Type.cc b/lib/serialisation/Hdf5Type.cc new file mode 100644 index 00000000..75c7692e --- /dev/null +++ b/lib/serialisation/Hdf5Type.cc @@ -0,0 +1,8 @@ +#include "Hdf5Type.h" + +using namespace Grid; + +#define HDF5_NATIVE_TYPE(predType, cType)\ +const H5NS::PredType * Hdf5Type::type = &H5NS::PredType::predType; + +DEFINE_HDF5_NATIVE_TYPES; diff --git a/lib/serialisation/Hdf5Type.h b/lib/serialisation/Hdf5Type.h new file mode 100644 index 00000000..beb509c2 --- /dev/null +++ b/lib/serialisation/Hdf5Type.h @@ -0,0 +1,48 @@ +#ifndef GRID_SERIALISATION_HDF5_TYPE_H +#define GRID_SERIALISATION_HDF5_TYPE_H + +#include +#include + +#ifndef H5_NO_NAMESPACE +#define H5NS H5 +#endif + +#define HDF5_NATIVE_TYPE(predType, cType)\ +template <>\ +struct Hdf5Type\ +{\ +static const H5NS::PredType *type;\ +static constexpr bool isNative = true;\ +}; + +#define DEFINE_HDF5_NATIVE_TYPES \ +HDF5_NATIVE_TYPE(NATIVE_B8, bool);\ +HDF5_NATIVE_TYPE(NATIVE_CHAR, char);\ +HDF5_NATIVE_TYPE(NATIVE_SCHAR, signed char);\ +HDF5_NATIVE_TYPE(NATIVE_UCHAR, unsigned char);\ +HDF5_NATIVE_TYPE(NATIVE_SHORT, short);\ +HDF5_NATIVE_TYPE(NATIVE_USHORT, unsigned short);\ +HDF5_NATIVE_TYPE(NATIVE_INT, int);\ +HDF5_NATIVE_TYPE(NATIVE_UINT, unsigned int);\ +HDF5_NATIVE_TYPE(NATIVE_LONG, long);\ +HDF5_NATIVE_TYPE(NATIVE_ULONG, unsigned long);\ +HDF5_NATIVE_TYPE(NATIVE_LLONG, long long);\ +HDF5_NATIVE_TYPE(NATIVE_ULLONG, unsigned long long);\ +HDF5_NATIVE_TYPE(NATIVE_FLOAT, float);\ +HDF5_NATIVE_TYPE(NATIVE_DOUBLE, double);\ +HDF5_NATIVE_TYPE(NATIVE_LDOUBLE, long double); + +namespace Grid +{ + template struct Hdf5Type + { + static constexpr bool isNative = false; + }; + + DEFINE_HDF5_NATIVE_TYPES; +} + +#undef HDF5_NATIVE_TYPE + +#endif /* GRID_SERIALISATION_HDF5_TYPE_H */ diff --git a/lib/serialisation/Serialisation.h b/lib/serialisation/Serialisation.h index 8f405d73..aa84e989 100644 --- a/lib/serialisation/Serialisation.h +++ b/lib/serialisation/Serialisation.h @@ -36,6 +36,9 @@ Author: Peter Boyle #include "BinaryIO.h" #include "TextIO.h" #include "XmlIO.h" +#ifdef HAVE_HDF5 +#include "Hdf5IO.h" +#endif ////////////////////////////////////////// // Todo: ////////////////////////////////////////// diff --git a/scripts/filelist b/scripts/filelist index 1ab95c7c..bf2fbc41 100755 --- a/scripts/filelist +++ b/scripts/filelist @@ -4,9 +4,8 @@ home=`pwd` # library Make.inc cd $home/lib -HFILES=`find . -type f -name '*.h' -not -path '*/Old/*' -not -path '*/Eigen/*'` -HFILES="$HFILES" -CCFILES=`find . -type f -name '*.cc' -not -name '*ommunicator*.cc'` +HFILES=`find . -type f -name '*.h' -not -name '*Hdf5*' -not -path '*/Old/*' -not -path '*/Eigen/*'` +CCFILES=`find . -type f -name '*.cc' -not -name '*Communicator*.cc' -not -name '*Hdf5*'` echo HFILES=$HFILES > Make.inc echo >> Make.inc echo CCFILES=$CCFILES >> Make.inc diff --git a/tests/IO/Test_serialisation.cc b/tests/IO/Test_serialisation.cc index e23aa1a3..7250d618 100644 --- a/tests/IO/Test_serialisation.cc +++ b/tests/IO/Test_serialisation.cc @@ -140,6 +140,22 @@ int main(int argc,char **argv) std::cout << "Loaded (txt) -----------------" << std::endl; std::cout << copy3 << std::endl << veccopy3 << std::endl; } +#ifdef HAVE_HDF5 + //// HDF5 + //// HDF5 does not accept elements with the duplicated names, hence "discard2" + { + Hdf5Writer TWR("bother.h5"); + write(TWR,"discard",copy1 ); + write(TWR,"discard2",veccopy1 ); + } + { + Hdf5Reader TRD("bother.h5"); + read (TRD,"discard",copy3 ); + read (TRD,"discard2",veccopy3 ); + std::cout << "Loaded (h5) -----------------" << std::endl; + std::cout << copy3 << std::endl << veccopy3 << std::endl; + } +#endif std::vector iv = strToVec("1 2 2 4"); std::vector sv = strToVec("bli bla blu"); From f599cb5b177ce38a2f4acc5a97bbf556cc6d0784 Mon Sep 17 00:00:00 2001 From: Antonin Portelli Date: Wed, 18 Jan 2017 16:50:21 -0800 Subject: [PATCH 08/27] HDF5 serial IO implemented and tested --- lib/serialisation/BaseIO.h | 196 ++++++++++++++++++++++++++++++- lib/serialisation/Hdf5IO.cc | 61 +++++++--- lib/serialisation/Hdf5IO.h | 206 +++++++++++++++++++++++---------- tests/IO/Test_serialisation.cc | 47 +++++--- 4 files changed, 412 insertions(+), 98 deletions(-) diff --git a/lib/serialisation/BaseIO.h b/lib/serialisation/BaseIO.h index 1095baf1..5b5ef427 100644 --- a/lib/serialisation/BaseIO.h +++ b/lib/serialisation/BaseIO.h @@ -32,6 +32,7 @@ Author: Peter Boyle #include namespace Grid { + // Vector IO utilities /////////////////////////////////////////////////////// // helper function to read space-separated values template std::vector strToVec(const std::string s) @@ -67,6 +68,76 @@ namespace Grid { return os; } + // Vector element trait ////////////////////////////////////////////////////// + template + struct element + { + typedef T type; + static constexpr bool is_arithmetic = false; + }; + + template + struct element> + { + typedef typename element::type type; + static constexpr bool is_arithmetic = std::is_arithmetic::value + or element::is_arithmetic; + }; + + // Vector flatening utility class //////////////////////////////////////////// + // Class to flatten a multidimensional std::vector + template + class Flatten + { + public: + typedef typename element::type Element; + public: + explicit Flatten(const V &vector); + const V & getVector(void); + const std::vector & getFlatVector(void); + const std::vector & getDim(void); + private: + void accumulate(const Element &e); + template + void accumulate(const W &v); + void accumulateDim(const Element &e); + template + void accumulateDim(const W &v); + private: + const V &vector_; + std::vector flatVector_; + std::vector dim_; + }; + + + // Class to reconstruct a multidimensional std::vector + template + class Reconstruct + { + public: + typedef typename element::type Element; + public: + Reconstruct(const std::vector &flatVector, + const std::vector &dim); + const V & getVector(void); + const std::vector & getFlatVector(void); + const std::vector & getDim(void); + private: + void fill(std::vector &v); + template + void fill(W &v); + void resize(std::vector &v, const unsigned int dim); + template + void resize(W &v, const unsigned int dim); + private: + V vector_; + const std::vector &flatVector_; + std::vector dim_; + size_t ind_{0}; + unsigned int dimInd_{0}; + }; + + // Abstract writer/reader classes //////////////////////////////////////////// // static polymorphism implemented using CRTP idiom class Serializable; @@ -132,7 +203,128 @@ namespace Grid { } }; - // Generic writer interface + // Flatten class template implementation ///////////////////////////////////// + template + void Flatten::accumulate(const Element &e) + { + flatVector_.push_back(e); + } + + template + template + void Flatten::accumulate(const W &v) + { + for (auto &e: v) + { + accumulate(e); + } + } + + template + void Flatten::accumulateDim(const Element &e) {}; + + template + template + void Flatten::accumulateDim(const W &v) + { + dim_.push_back(v.size()); + accumulateDim(v[0]); + } + + template + Flatten::Flatten(const V &vector) + : vector_(vector) + { + accumulate(vector_); + accumulateDim(vector_); + } + + template + const V & Flatten::getVector(void) + { + return vector_; + } + + template + const std::vector::Element> & + Flatten::getFlatVector(void) + { + return flatVector_; + } + + template + const std::vector & Flatten::getDim(void) + { + return dim_; + } + + // Reconstruct class template implementation ///////////////////////////////// + template + void Reconstruct::fill(std::vector &v) + { + for (auto &e: v) + { + e = flatVector_[ind_++]; + } + } + + template + template + void Reconstruct::fill(W &v) + { + for (auto &e: v) + { + fill(e); + } + } + + template + void Reconstruct::resize(std::vector &v, const unsigned int dim) + { + v.resize(dim_[dim]); + } + + template + template + void Reconstruct::resize(W &v, const unsigned int dim) + { + v.resize(dim_[dim]); + for (auto &e: v) + { + resize(e, dim + 1); + } + } + + template + Reconstruct::Reconstruct(const std::vector &flatVector, + const std::vector &dim) + : flatVector_(flatVector) + , dim_(dim) + { + resize(vector_, 0); + fill(vector_); + } + + template + const V & Reconstruct::Reconstruct::getVector(void) + { + return vector_; + } + + template + const std::vector::Element> & + Reconstruct::getFlatVector(void) + { + return flatVector_; + } + + template + const std::vector & Reconstruct::getDim(void) + { + return dim_; + } + + // Generic writer interface ////////////////////////////////////////////////// template inline void push(Writer &w, const std::string &s) { @@ -217,7 +409,7 @@ namespace Grid { upcast->writeDefault(s, output); } - // Reader template implementation //////////////////////////////////////////// + // Reader template implementation template Reader::Reader(void) { diff --git a/lib/serialisation/Hdf5IO.cc b/lib/serialisation/Hdf5IO.cc index 0d62fdd8..02356220 100644 --- a/lib/serialisation/Hdf5IO.cc +++ b/lib/serialisation/Hdf5IO.cc @@ -11,11 +11,8 @@ Hdf5Writer::Hdf5Writer(const std::string &fileName) , file_(fileName.c_str(), H5F_ACC_TRUNC) { group_ = file_.openGroup("/"); -} - -Hdf5Writer::~Hdf5Writer(void) -{ - file_.close(); + writeSingleAttribute(dataSetThres_, HDF5_GRID_GUARD "dataset_threshold", + *Hdf5Type::type); } void Hdf5Writer::push(const std::string &s) @@ -47,12 +44,8 @@ template <> void Hdf5Writer::writeDefault(const std::string &s, const std::string &x) { StrType strType(PredType::C_S1, x.size()); - Attribute attribute; - hsize_t attrDim = 1; - DataSpace attrSpace(1, &attrDim); - attribute = group_.createAttribute(s, strType, attrSpace); - attribute.write(strType, x.data()); + writeSingleAttribute(*(x.data()), s, strType); } void Hdf5Writer::writeDefault(const std::string &s, const char *x) @@ -64,21 +57,55 @@ void Hdf5Writer::writeDefault(const std::string &s, const char *x) // Reader implementation /////////////////////////////////////////////////////// Hdf5Reader::Hdf5Reader(const std::string &fileName) +: fileName_(fileName) +, file_(fileName.c_str(), H5F_ACC_RDONLY) { - -} - -Hdf5Reader::~Hdf5Reader(void) -{ - + group_ = file_.openGroup("/"); + readSingleAttribute(dataSetThres_, HDF5_GRID_GUARD "dataset_threshold", + *Hdf5Type::type); } void Hdf5Reader::push(const std::string &s) { - + group_ = group_.openGroup(s); + path_.push_back(s); } void Hdf5Reader::pop(void) { + path_.pop_back(); + if (path_.empty()) + { + group_ = file_.openGroup("/"); + } + else + { + auto binOp = [](const std::string &a, const std::string &b)->std::string + { + return a + "/" + b; + }; + group_ = group_.openGroup(std::accumulate(path_.begin(), path_.end(), + std::string(""), binOp)); + } +} + +template <> +void Hdf5Reader::readDefault(const std::string &s, std::string &x) +{ + Attribute attribute; + + attribute = group_.openAttribute(s); + StrType strType = attribute.getStrType(); + + x.resize(strType.getSize()); + attribute.read(strType, &(x[0])); + + std::cout << "length: " << strType.getSize() << std::endl; + std::cout << "string: |"; + for (auto &c: x) + { + std::cout << "'" << c << "'|"; + } + std::cout << std::endl; } diff --git a/lib/serialisation/Hdf5IO.h b/lib/serialisation/Hdf5IO.h index 481fa1cf..b58c86ed 100644 --- a/lib/serialisation/Hdf5IO.h +++ b/lib/serialisation/Hdf5IO.h @@ -12,139 +12,135 @@ #endif // default thresold above which datasets are used instead of attributes -#ifndef H5_DEF_DATASET_THRES -#define H5_DEF_DATASET_THRES 6u +#ifndef HDF5_DEF_DATASET_THRES +#define HDF5_DEF_DATASET_THRES 6u #endif +// name guard for Grid metadata +#define HDF5_GRID_GUARD "_Grid_" + namespace Grid { - template - struct is_arithmetic_vector - { - static constexpr bool value = false; - }; - - template - struct is_arithmetic_vector> - { - static constexpr bool value = std::is_arithmetic::value - or is_arithmetic_vector::value; - }; - class Hdf5Writer: public Writer { public: Hdf5Writer(const std::string &fileName); - virtual ~Hdf5Writer(void); + virtual ~Hdf5Writer(void) = default; void push(const std::string &s); void pop(void); void writeDefault(const std::string &s, const char *x); template void writeDefault(const std::string &s, const U &x); template - typename std::enable_if>::value - and std::is_arithmetic::value, void>::type + typename std::enable_if>::is_arithmetic, void>::type writeDefault(const std::string &s, const std::vector &x); template - typename std::enable_if>::value - and !std::is_arithmetic::value, void>::type + typename std::enable_if>::is_arithmetic, void>::type writeDefault(const std::string &s, const std::vector &x); + private: template - typename std::enable_if>::value, void>::type - writeDefault(const std::string &s, const std::vector &x); + void writeSingleAttribute(const U &x, const std::string &name, + const H5NS::DataType &type); private: std::string fileName_; std::vector path_; - std::vector dim_; - bool multiDim_{true}; H5NS::H5File file_; H5NS::Group group_; - unsigned int datasetThres_{H5_DEF_DATASET_THRES}; + unsigned int dataSetThres_{HDF5_DEF_DATASET_THRES}; }; class Hdf5Reader: public Reader { public: Hdf5Reader(const std::string &fileName); - virtual ~Hdf5Reader(void); + virtual ~Hdf5Reader(void) = default; void push(const std::string &s); void pop(void); template void readDefault(const std::string &s, U &output); template - void readDefault(const std::string &s, std::vector &output); + typename std::enable_if>::is_arithmetic, void>::type + readDefault(const std::string &s, std::vector &x); + template + typename std::enable_if>::is_arithmetic, void>::type + readDefault(const std::string &s, std::vector &x); private: + template + void readSingleAttribute(U &x, const std::string &name, + const H5NS::DataType &type); + private: + std::string fileName_; + std::vector path_; + H5NS::H5File file_; + H5NS::Group group_; + unsigned int dataSetThres_; }; // Writer template implementation //////////////////////////////////////////// template - void Hdf5Writer::writeDefault(const std::string &s, const U &x) + void Hdf5Writer::writeSingleAttribute(const U &x, const std::string &name, + const H5NS::DataType &type) { H5NS::Attribute attribute; hsize_t attrDim = 1; H5NS::DataSpace attrSpace(1, &attrDim); - attribute = group_.createAttribute(s, *Hdf5Type::type, attrSpace); - attribute.write(*Hdf5Type::type, &x); + attribute = group_.createAttribute(name, type, attrSpace); + attribute.write(type, &x); + } + + template + void Hdf5Writer::writeDefault(const std::string &s, const U &x) + { + writeSingleAttribute(x, s, *Hdf5Type::type); } template <> void Hdf5Writer::writeDefault(const std::string &s, const std::string &x); template - typename std::enable_if>::value - and std::is_arithmetic::value, void>::type + typename std::enable_if>::is_arithmetic, void>::type Hdf5Writer::writeDefault(const std::string &s, const std::vector &x) { - hsize_t size = 1; + // alias to element type + typedef typename element>::type Element; - dim_.push_back(x.size()); - for (auto d: dim_) + // flatten the vector and getting dimensions + Flatten> flat(x); + std::vector dim; + const auto &flatx = flat.getFlatVector(); + + for (auto &d: flat.getDim()) { - size *= d; + dim.push_back(d); } - H5NS::DataSpace dataspace(dim_.size(), dim_.data()); + // write to file + H5NS::DataSpace dataSpace(dim.size(), dim.data()); - if (size > datasetThres_) + if (flatx.size() > dataSetThres_) { - H5NS::DataSet dataset; + H5NS::DataSet dataSet; - dataset = group_.createDataSet(s, *Hdf5Type::type, dataspace); - dataset.write(x.data(), *Hdf5Type::type); + dataSet = group_.createDataSet(s, *Hdf5Type::type, dataSpace); + dataSet.write(flatx.data(), *Hdf5Type::type); } else { H5NS::Attribute attribute; - attribute = group_.createAttribute(s, *Hdf5Type::type, dataspace); - attribute.write(*Hdf5Type::type, x.data()); + attribute = group_.createAttribute(s, *Hdf5Type::type, dataSpace); + attribute.write(*Hdf5Type::type, flatx.data()); } - dim_.clear(); - multiDim_ = true; } template - typename std::enable_if>::value - and !std::is_arithmetic::value, void>::type - Hdf5Writer::writeDefault(const std::string &s, const std::vector &x) - { - hsize_t firstSize = x[0].size(); - - for (auto &v: x) - { - multiDim_ = (multiDim_ and (v.size() == firstSize)); - } - assert(multiDim_); - dim_.push_back(x.size()); - writeDefault(s, x[0]); - } - - template - typename std::enable_if>::value, void>::type + typename std::enable_if>::is_arithmetic, void>::type Hdf5Writer::writeDefault(const std::string &s, const std::vector &x) { push(s); + writeSingleAttribute(x.size(), HDF5_GRID_GUARD "vector_size", + *Hdf5Type::type); for (hsize_t i = 0; i < x.size(); ++i) { write(s + "_" + std::to_string(i), x[i]); @@ -154,15 +150,97 @@ namespace Grid // Reader template implementation //////////////////////////////////////////// template - void Hdf5Reader::readDefault(const std::string &s, U &output) + void Hdf5Reader::readSingleAttribute(U &x, const std::string &name, + const H5NS::DataType &type) { + H5NS::Attribute attribute; + attribute = group_.openAttribute(name); + attribute.read(type, &x); } template - void Hdf5Reader::readDefault(const std::string &s, std::vector &output) + void Hdf5Reader::readDefault(const std::string &s, U &output) { + readSingleAttribute(output, s, *Hdf5Type::type); + } + + template <> + void Hdf5Reader::readDefault(const std::string &s, std::string &x); + + template + typename std::enable_if>::is_arithmetic, void>::type + Hdf5Reader::readDefault(const std::string &s, std::vector &x) + { + // alias to element type + typedef typename element>::type Element; + // read the dimensions + H5NS::DataSpace dataSpace; + H5E_auto2_t func; + void * client_data; + std::vector hdim; + std::vector dim; + hsize_t size = 1; + + H5NS::Exception::getAutoPrint(func, &client_data); + try + { + H5NS::Exception::dontPrint(); + dataSpace = group_.openDataSet(s).getSpace(); + } + catch (H5NS::Exception &e) + { + H5NS::Exception::setAutoPrint(func, client_data); + dataSpace = group_.openAttribute(s).getSpace(); + } + hdim.resize(dataSpace.getSimpleExtentNdims()); + dataSpace.getSimpleExtentDims(hdim.data()); + for (auto &d: hdim) + { + dim.push_back(d); + size *= d; + } + + // read the flat vector + std::vector buf(size); + + if (size > dataSetThres_) + { + H5NS::DataSet dataSet; + + dataSet = group_.openDataSet(s); + dataSet.read(buf.data(), *Hdf5Type::type); + } + else + { + H5NS::Attribute attribute; + + attribute = group_.openAttribute(s); + attribute.read(*Hdf5Type::type, buf.data()); + } + + // reconstruct the multidimensional vector + Reconstruct> r(buf, dim); + + x = r.getVector(); + } + + template + typename std::enable_if>::is_arithmetic, void>::type + Hdf5Reader::readDefault(const std::string &s, std::vector &x) + { + uint64_t size; + + push(s); + readSingleAttribute(size, HDF5_GRID_GUARD "vector_size", + *Hdf5Type::type); + x.resize(size); + for (hsize_t i = 0; i < x.size(); ++i) + { + read(s + "_" + std::to_string(i), x[i]); + } + pop(); } } diff --git a/tests/IO/Test_serialisation.cc b/tests/IO/Test_serialisation.cc index 7250d618..d3bbabe4 100644 --- a/tests/IO/Test_serialisation.cc +++ b/tests/IO/Test_serialisation.cc @@ -104,8 +104,8 @@ int main(int argc,char **argv) }; // read tests - myclass copy1, copy2, copy3; - std::vector veccopy1, veccopy2, veccopy3; + myclass copy1, copy2, copy3, copy4; + std::vector veccopy1, veccopy2, veccopy3, veccopy4; //// XML { XmlReader RD("bother.xml"); @@ -150,24 +150,41 @@ int main(int argc,char **argv) } { Hdf5Reader TRD("bother.h5"); - read (TRD,"discard",copy3 ); - read (TRD,"discard2",veccopy3 ); + std::cout << "read single" << std::endl; + read (TRD,"discard",copy4 ); + std::cout << "read vec" << std::endl; + read (TRD,"discard2",veccopy4 ); std::cout << "Loaded (h5) -----------------" << std::endl; - std::cout << copy3 << std::endl << veccopy3 << std::endl; + std::cout << copy3 << std::endl << veccopy4 << std::endl; } #endif - std::vector iv = strToVec("1 2 2 4"); - std::vector sv = strToVec("bli bla blu"); + typedef std::vector>> vec3d; - for (auto &e: iv) + vec3d dv, buf; + double d = 0.; + + dv.resize(4); + for (auto &v1: dv) { - std::cout << e << " "; + v1.resize(3); + for (auto &v2: v1) + { + v2.resize(5); + for (auto &x: v2) + { + x = d++; + } + } } - std::cout << std::endl; - for (auto &e: sv) - { - std::cout << e << " "; - } - std::cout << std::endl; + std::cout << dv << std::endl; + + Flatten flatdv(dv); + + std::cout << flatdv.getDim() << std::endl; + std::cout << flatdv.getFlatVector() << std::endl; + + Reconstruct rec(flatdv.getFlatVector(), flatdv.getDim()); + + std::cout << flatdv.getVector() << std::endl; } From 4be08ebccc3caa704dbb7552b353c92ecd43b782 Mon Sep 17 00:00:00 2001 From: Antonin Portelli Date: Wed, 18 Jan 2017 17:39:59 -0800 Subject: [PATCH 09/27] debug code cleaning --- lib/serialisation/Hdf5IO.cc | 8 -------- 1 file changed, 8 deletions(-) diff --git a/lib/serialisation/Hdf5IO.cc b/lib/serialisation/Hdf5IO.cc index 02356220..8b6581ea 100644 --- a/lib/serialisation/Hdf5IO.cc +++ b/lib/serialisation/Hdf5IO.cc @@ -100,12 +100,4 @@ void Hdf5Reader::readDefault(const std::string &s, std::string &x) x.resize(strType.getSize()); attribute.read(strType, &(x[0])); - - std::cout << "length: " << strType.getSize() << std::endl; - std::cout << "string: |"; - for (auto &c: x) - { - std::cout << "'" << c << "'|"; - } - std::cout << std::endl; } From 654e0b0fd0b23ad468c405ae053dd3f44748d28e Mon Sep 17 00:00:00 2001 From: Antonin Portelli Date: Wed, 18 Jan 2017 17:40:32 -0800 Subject: [PATCH 10/27] Serialisable object are now comparable with == --- lib/serialisation/MacroMagic.h | 30 ++++++++++++++---------------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/lib/serialisation/MacroMagic.h b/lib/serialisation/MacroMagic.h index c9137dfe..8b027f30 100644 --- a/lib/serialisation/MacroMagic.h +++ b/lib/serialisation/MacroMagic.h @@ -109,38 +109,36 @@ THE SOFTWARE. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// #define GRID_MACRO_MEMBER(A,B) A B; +#define GRID_MACRO_COMP_MEMBER(A,B) result = (result and (lhs. B == rhs. B)); #define GRID_MACRO_OS_WRITE_MEMBER(A,B) os<< #A <<" "#B <<" = "<< obj. B <<" ; " <\ static inline void write(Writer &WR,const std::string &s, const cname &obj){ \ push(WR,s);\ GRID_MACRO_EVAL(GRID_MACRO_MAP(GRID_MACRO_WRITE_MEMBER,__VA_ARGS__)) \ pop(WR);\ -} \ -\ -\ +}\ template \ static inline void read(Reader &RD,const std::string &s, cname &obj){ \ push(RD,s);\ GRID_MACRO_EVAL(GRID_MACRO_MAP(GRID_MACRO_READ_MEMBER,__VA_ARGS__)) \ pop(RD);\ -} \ -\ -\ +}\ friend inline std::ostream & operator << (std::ostream &os, const cname &obj ) { \ os<<"class "<<#cname<<" {"<::type #define GRID_MACRO_ENUMVAL(A,B) A = B, @@ -149,7 +147,7 @@ friend inline std::ostream & operator << (std::ostream &os, const cname &obj ) { #define GRID_MACRO_ENUMCASEIO(A,B) case GRID_ENUM_TYPE(obj)::A: os << #A; break; #define GRID_SERIALIZABLE_ENUM(name,undefname,...)\ -class name: public Serializable\ +class name: public Grid::Serializable\ {\ public:\ enum EnumType\ @@ -161,7 +159,7 @@ public:\ name(void): value_(undefname) {};\ name(EnumType value): value_(value) {};\ template \ - static inline void write(Writer &WR,const std::string &s, const name &obj)\ + static inline void write(Grid::Writer &WR,const std::string &s, const name &obj)\ {\ switch (obj.value_)\ {\ @@ -171,7 +169,7 @@ public:\ }\ \ template \ - static inline void read(Reader &RD,const std::string &s, name &obj)\ + static inline void read(Grid::Reader &RD,const std::string &s, name &obj)\ {\ std::string buf;\ Grid::read(RD, s, buf);\ From f3f0b6fef99b25cbc6857f4d8b87731a2aa1d2e7 Mon Sep 17 00:00:00 2001 From: Antonin Portelli Date: Wed, 18 Jan 2017 17:41:05 -0800 Subject: [PATCH 11/27] serious rewriting of Test_serialisation, now crashes if IO inconsistent --- tests/IO/Test_serialisation.cc | 217 +++++++++++++++------------------ 1 file changed, 101 insertions(+), 116 deletions(-) diff --git a/tests/IO/Test_serialisation.cc b/tests/IO/Test_serialisation.cc index d3bbabe4..b7158b2b 100644 --- a/tests/IO/Test_serialisation.cc +++ b/tests/IO/Test_serialisation.cc @@ -28,137 +28,119 @@ Author: Peter Boyle /* END LEGAL */ #include -namespace Grid { - - GRID_SERIALIZABLE_ENUM(myenum, undef, red, 1, blue, 2, green, 3); - - class myclass: Serializable { - public: - - GRID_SERIALIZABLE_CLASS_MEMBERS(myclass, - myenum, e, - std::vector, ve, - std::string, name, - int, x, - double, y, - bool , b, - std::vector, array, - std::vector>, twodimarray, - ); - - myclass() {} - myclass(int i) - : array(4,5.1), twodimarray(3,std::vector(2,1.23456)), ve(2, myenum::blue) - { - e=myenum::red; - x=i; - y=2*i; - b=true; - name="bother said pooh"; - } - }; - -} - using namespace Grid; -int16_t i16 = 1; +GRID_SERIALIZABLE_ENUM(myenum, undef, red, 1, blue, 2, green, 3); + +class myclass: Serializable { +public: + GRID_SERIALIZABLE_CLASS_MEMBERS(myclass, + myenum, e, + std::vector, ve, + std::string, name, + int, x, + double, y, + bool , b, + std::vector, array, + std::vector>, twodimarray, + ); + myclass() {} + myclass(int i) + : array(4,5.1), twodimarray(3,std::vector(2,1.23456)), ve(2, myenum::blue) + { + e=myenum::red; + x=i; + y=2*i; + b=true; + name="bother said pooh"; + } +}; + +int16_t i16 = 1; uint16_t u16 = 2; -int32_t i32 = 3; +int32_t i32 = 3; uint32_t u32 = 4; -int64_t i64 = 5; +int64_t i64 = 5; uint64_t u64 = 6; -float f = M_PI; -double d = 2*M_PI; -bool b = false; +float f = M_PI; +double d = 2*M_PI; +bool b = false; + +template +void ioTest(const std::string &filename, const O &object, const std::string &name) +{ + // writer needs to be destroyed so that writing physically happens + { + W writer(filename); + + write(writer, "testobject", object); + } + + R reader(filename); + O buf; + bool good; + + read(reader, "testobject", buf); + good = (object == buf); + std::cout << name << " IO test: " << (good ? "success" : "failure"); + std::cout << std::endl; + if (!good) exit(EXIT_FAILURE); +} int main(int argc,char **argv) { - { - XmlWriter WR("bother.xml"); - - // test basic type writing - push(WR,"BasicTypes"); - write(WR,std::string("i16"),i16); - write(WR,"u16",u16); - write(WR,"i32",i32); - write(WR,"u32",u32); - write(WR,"i64",i64); - write(WR,"u64",u64); - write(WR,"f",f); - write(WR,"d",d); - write(WR,"b",b); - pop(WR); - - // test serializable class writing - myclass obj(1234); // non-trivial constructor - write(WR,"obj",obj); - WR.write("obj2", obj); - std::cout << obj << std::endl; - - std::vector vec; - vec.push_back(myclass(1234)); - vec.push_back(myclass(5678)); - vec.push_back(myclass(3838)); - write(WR, "objvec", vec); - }; + std::cout << "==== basic IO" << std::endl; + XmlWriter WR("bother.xml"); + + // test basic type writing + std::cout << "-- basic writing to 'bother.xml'..." << std::endl; + push(WR,"BasicTypes"); + write(WR,std::string("i16"),i16); + write(WR,"u16",u16); + write(WR,"i32",i32); + write(WR,"u32",u32); + write(WR,"i64",i64); + write(WR,"u64",u64); + write(WR,"f",f); + write(WR,"d",d); + write(WR,"b",b); + pop(WR); + + // test serializable class writing + myclass obj(1234); // non-trivial constructor + std::vector vec; + + std::cout << "-- serialisable class writing to 'bother.xml'..." << std::endl; + write(WR,"obj",obj); + WR.write("obj2", obj); + vec.push_back(myclass(1234)); + vec.push_back(myclass(5678)); + vec.push_back(myclass(3838)); + write(WR, "objvec", vec); + std::cout << "-- serialisable class writing to std::cout:" << std::endl; + std::cout << obj << std::endl; + std::cout << "-- serialisable class comparison:" << std::endl; + std::cout << "vec[0] == obj: " << ((vec[0] == obj) ? "true" : "false") << std::endl; + std::cout << "vec[1] == obj: " << ((vec[1] == obj) ? "true" : "false") << std::endl; // read tests - myclass copy1, copy2, copy3, copy4; - std::vector veccopy1, veccopy2, veccopy3, veccopy4; + std::cout << "\n==== IO self-consistency tests" << std::endl; //// XML - { - XmlReader RD("bother.xml"); - read(RD,"obj",copy1); - read(RD,"objvec", veccopy1); - std::cout << "Loaded (XML) -----------------" << std::endl; - std::cout << copy1 << std::endl << veccopy1 << std::endl; - } + ioTest("iotest.xml", obj, "XML (object) "); + ioTest("iotest.xml", vec, "XML (vector of objects)"); //// binary - { - BinaryWriter BWR("bother.bin"); - write(BWR,"discard",copy1 ); - write(BWR,"discard",veccopy1 ); - } - { - BinaryReader BRD("bother.bin"); - read (BRD,"discard",copy2 ); - read (BRD,"discard",veccopy2 ); - std::cout << "Loaded (bin) -----------------" << std::endl; - std::cout << copy2 << std::endl << veccopy2 << std::endl; - } + ioTest("iotest.bin", obj, "binary (object) "); + ioTest("iotest.bin", vec, "binary (vector of objects)"); //// text - { - TextWriter TWR("bother.txt"); - write(TWR,"discard",copy1 ); - write(TWR,"discard",veccopy1 ); - } - { - TextReader TRD("bother.txt"); - read (TRD,"discard",copy3 ); - read (TRD,"discard",veccopy3 ); - std::cout << "Loaded (txt) -----------------" << std::endl; - std::cout << copy3 << std::endl << veccopy3 << std::endl; - } -#ifdef HAVE_HDF5 + ioTest("iotest.dat", obj, "text (object) "); + ioTest("iotest.dat", vec, "text (vector of objects)"); //// HDF5 - //// HDF5 does not accept elements with the duplicated names, hence "discard2" - { - Hdf5Writer TWR("bother.h5"); - write(TWR,"discard",copy1 ); - write(TWR,"discard2",veccopy1 ); - } - { - Hdf5Reader TRD("bother.h5"); - std::cout << "read single" << std::endl; - read (TRD,"discard",copy4 ); - std::cout << "read vec" << std::endl; - read (TRD,"discard2",veccopy4 ); - std::cout << "Loaded (h5) -----------------" << std::endl; - std::cout << copy3 << std::endl << veccopy4 << std::endl; - } +#ifdef HAVE_HDF5 + ioTest("iotest.h5", obj, "HDF5 (object) "); + ioTest("iotest.h5", vec, "HDF5 (vector of objects)"); #endif + std::cout << "\n==== vector flattening/reconstruction" << std::endl; typedef std::vector>> vec3d; vec3d dv, buf; @@ -177,14 +159,17 @@ int main(int argc,char **argv) } } } + std::cout << "original 3D vector:" << std::endl; std::cout << dv << std::endl; Flatten flatdv(dv); + std::cout << "\ndimensions:" << std::endl; std::cout << flatdv.getDim() << std::endl; + std::cout << "\nflattened vector:" << std::endl; std::cout << flatdv.getFlatVector() << std::endl; Reconstruct rec(flatdv.getFlatVector(), flatdv.getDim()); - + std::cout << "\nreconstructed vector:" << std::endl; std::cout << flatdv.getVector() << std::endl; } From 5405526424a43ef7c78a186c831b1eecc2de985f Mon Sep 17 00:00:00 2001 From: Antonin Portelli Date: Wed, 18 Jan 2017 22:42:19 -0800 Subject: [PATCH 12/27] Code typo --- lib/serialisation/BaseIO.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/serialisation/BaseIO.h b/lib/serialisation/BaseIO.h index 5b5ef427..eca5cff2 100644 --- a/lib/serialisation/BaseIO.h +++ b/lib/serialisation/BaseIO.h @@ -306,7 +306,7 @@ namespace Grid { } template - const V & Reconstruct::Reconstruct::getVector(void) + const V & Reconstruct::getVector(void) { return vector_; } From 24d3d31b01416b5b6e7cc98bcf341023f696982c Mon Sep 17 00:00:00 2001 From: Antonin Portelli Date: Thu, 19 Jan 2017 14:08:22 -0800 Subject: [PATCH 13/27] Genetic scheduler: uses insert instead of emplace for better compiler compatibility --- extras/Hadrons/GeneticScheduler.hpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/extras/Hadrons/GeneticScheduler.hpp b/extras/Hadrons/GeneticScheduler.hpp index c9256d96..d0c52596 100644 --- a/extras/Hadrons/GeneticScheduler.hpp +++ b/extras/Hadrons/GeneticScheduler.hpp @@ -166,7 +166,7 @@ void GeneticScheduler::initPopulation(void) { auto p = graph_.topoSort(gen_); - population_.emplace(func_(p), p); + population_.insert(std::make_pair(func_(p), p)); } } @@ -180,8 +180,8 @@ void GeneticScheduler::doCrossover(void) crossover(c1, c2, p1, p2); PARALLEL_CRITICAL { - population_.emplace(func_(c1), c1); - population_.emplace(func_(c2), c2); + population_.insert(std::make_pair(func_(c1), c1)); + population_.insert(std::make_pair(func_(c2), c2)); } } @@ -200,7 +200,7 @@ void GeneticScheduler::doMutation(void) mutation(m, it->second); PARALLEL_CRITICAL { - population_.emplace(func_(m), m); + population_.insert(std::make_pair(func_(m), m)); } } } From 2c673666dacec2087306309b4f5824073aa13f0e Mon Sep 17 00:00:00 2001 From: Antonin Portelli Date: Thu, 19 Jan 2017 17:19:12 -0800 Subject: [PATCH 14/27] Standardisation of HDF5 types --- lib/serialisation/Hdf5Type.h | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/lib/serialisation/Hdf5Type.h b/lib/serialisation/Hdf5Type.h index beb509c2..52c6ed24 100644 --- a/lib/serialisation/Hdf5Type.h +++ b/lib/serialisation/Hdf5Type.h @@ -17,21 +17,20 @@ static constexpr bool isNative = true;\ }; #define DEFINE_HDF5_NATIVE_TYPES \ -HDF5_NATIVE_TYPE(NATIVE_B8, bool);\ -HDF5_NATIVE_TYPE(NATIVE_CHAR, char);\ -HDF5_NATIVE_TYPE(NATIVE_SCHAR, signed char);\ -HDF5_NATIVE_TYPE(NATIVE_UCHAR, unsigned char);\ -HDF5_NATIVE_TYPE(NATIVE_SHORT, short);\ -HDF5_NATIVE_TYPE(NATIVE_USHORT, unsigned short);\ -HDF5_NATIVE_TYPE(NATIVE_INT, int);\ -HDF5_NATIVE_TYPE(NATIVE_UINT, unsigned int);\ -HDF5_NATIVE_TYPE(NATIVE_LONG, long);\ -HDF5_NATIVE_TYPE(NATIVE_ULONG, unsigned long);\ -HDF5_NATIVE_TYPE(NATIVE_LLONG, long long);\ -HDF5_NATIVE_TYPE(NATIVE_ULLONG, unsigned long long);\ -HDF5_NATIVE_TYPE(NATIVE_FLOAT, float);\ -HDF5_NATIVE_TYPE(NATIVE_DOUBLE, double);\ -HDF5_NATIVE_TYPE(NATIVE_LDOUBLE, long double); +HDF5_NATIVE_TYPE(STD_B8LE, bool);\ +HDF5_NATIVE_TYPE(STD_I8LE, char);\ +HDF5_NATIVE_TYPE(STD_U8LE, unsigned char);\ +HDF5_NATIVE_TYPE(STD_I16LE, short);\ +HDF5_NATIVE_TYPE(STD_U16LE, unsigned short);\ +HDF5_NATIVE_TYPE(STD_I32LE, int);\ +HDF5_NATIVE_TYPE(STD_U32LE, unsigned int);\ +HDF5_NATIVE_TYPE(STD_I64LE, long);\ +HDF5_NATIVE_TYPE(STD_U64LE, unsigned long);\ +HDF5_NATIVE_TYPE(STD_I64LE, long long);\ +HDF5_NATIVE_TYPE(STD_U64LE, unsigned long long);\ +HDF5_NATIVE_TYPE(IEEE_F32LE, float);\ +HDF5_NATIVE_TYPE(IEEE_F64LE, double);\ +HDF5_NATIVE_TYPE(IEEE_F64LE, long double); namespace Grid { From 6eea9e4da71227d205a971adfb968721fac09bc5 Mon Sep 17 00:00:00 2001 From: Antonin Portelli Date: Thu, 19 Jan 2017 18:02:53 -0800 Subject: [PATCH 15/27] HDF5 types static initialisation is mysteriously buggy on BG/Q, changing strategy --- lib/Makefile.am | 1 - lib/serialisation/Hdf5IO.cc | 4 ++-- lib/serialisation/Hdf5IO.h | 20 ++++++++++---------- lib/serialisation/Hdf5Type.cc | 8 -------- lib/serialisation/Hdf5Type.h | 5 ++++- 5 files changed, 16 insertions(+), 22 deletions(-) delete mode 100644 lib/serialisation/Hdf5Type.cc diff --git a/lib/Makefile.am b/lib/Makefile.am index 9aa6af92..fac622ca 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -27,7 +27,6 @@ endif if BUILD_HDF5 extra_sources+=serialisation/Hdf5IO.cc - extra_sources+=serialisation/Hdf5Type.cc extra_headers+=serialisation/Hdf5IO.h extra_headers+=serialisation/Hdf5Type.h endif diff --git a/lib/serialisation/Hdf5IO.cc b/lib/serialisation/Hdf5IO.cc index 8b6581ea..4d5a2df5 100644 --- a/lib/serialisation/Hdf5IO.cc +++ b/lib/serialisation/Hdf5IO.cc @@ -12,7 +12,7 @@ Hdf5Writer::Hdf5Writer(const std::string &fileName) { group_ = file_.openGroup("/"); writeSingleAttribute(dataSetThres_, HDF5_GRID_GUARD "dataset_threshold", - *Hdf5Type::type); + *Hdf5Type::type()); } void Hdf5Writer::push(const std::string &s) @@ -62,7 +62,7 @@ Hdf5Reader::Hdf5Reader(const std::string &fileName) { group_ = file_.openGroup("/"); readSingleAttribute(dataSetThres_, HDF5_GRID_GUARD "dataset_threshold", - *Hdf5Type::type); + *Hdf5Type::type()); } void Hdf5Reader::push(const std::string &s) diff --git a/lib/serialisation/Hdf5IO.h b/lib/serialisation/Hdf5IO.h index b58c86ed..9281e5a0 100644 --- a/lib/serialisation/Hdf5IO.h +++ b/lib/serialisation/Hdf5IO.h @@ -92,7 +92,7 @@ namespace Grid template void Hdf5Writer::writeDefault(const std::string &s, const U &x) { - writeSingleAttribute(x, s, *Hdf5Type::type); + writeSingleAttribute(x, s, *Hdf5Type::type()); } template <> @@ -122,15 +122,15 @@ namespace Grid { H5NS::DataSet dataSet; - dataSet = group_.createDataSet(s, *Hdf5Type::type, dataSpace); - dataSet.write(flatx.data(), *Hdf5Type::type); + dataSet = group_.createDataSet(s, *Hdf5Type::type(), dataSpace); + dataSet.write(flatx.data(), *Hdf5Type::type()); } else { H5NS::Attribute attribute; - attribute = group_.createAttribute(s, *Hdf5Type::type, dataSpace); - attribute.write(*Hdf5Type::type, flatx.data()); + attribute = group_.createAttribute(s, *Hdf5Type::type(), dataSpace); + attribute.write(*Hdf5Type::type(), flatx.data()); } } @@ -140,7 +140,7 @@ namespace Grid { push(s); writeSingleAttribute(x.size(), HDF5_GRID_GUARD "vector_size", - *Hdf5Type::type); + *Hdf5Type::type()); for (hsize_t i = 0; i < x.size(); ++i) { write(s + "_" + std::to_string(i), x[i]); @@ -162,7 +162,7 @@ namespace Grid template void Hdf5Reader::readDefault(const std::string &s, U &output) { - readSingleAttribute(output, s, *Hdf5Type::type); + readSingleAttribute(output, s, *Hdf5Type::type()); } template <> @@ -210,14 +210,14 @@ namespace Grid H5NS::DataSet dataSet; dataSet = group_.openDataSet(s); - dataSet.read(buf.data(), *Hdf5Type::type); + dataSet.read(buf.data(), *Hdf5Type::type()); } else { H5NS::Attribute attribute; attribute = group_.openAttribute(s); - attribute.read(*Hdf5Type::type, buf.data()); + attribute.read(*Hdf5Type::type(), buf.data()); } // reconstruct the multidimensional vector @@ -234,7 +234,7 @@ namespace Grid push(s); readSingleAttribute(size, HDF5_GRID_GUARD "vector_size", - *Hdf5Type::type); + *Hdf5Type::type()); x.resize(size); for (hsize_t i = 0; i < x.size(); ++i) { diff --git a/lib/serialisation/Hdf5Type.cc b/lib/serialisation/Hdf5Type.cc deleted file mode 100644 index 75c7692e..00000000 --- a/lib/serialisation/Hdf5Type.cc +++ /dev/null @@ -1,8 +0,0 @@ -#include "Hdf5Type.h" - -using namespace Grid; - -#define HDF5_NATIVE_TYPE(predType, cType)\ -const H5NS::PredType * Hdf5Type::type = &H5NS::PredType::predType; - -DEFINE_HDF5_NATIVE_TYPES; diff --git a/lib/serialisation/Hdf5Type.h b/lib/serialisation/Hdf5Type.h index 52c6ed24..8b56c406 100644 --- a/lib/serialisation/Hdf5Type.h +++ b/lib/serialisation/Hdf5Type.h @@ -12,7 +12,10 @@ template <>\ struct Hdf5Type\ {\ -static const H5NS::PredType *type;\ +static inline const H5NS::PredType *type(void)\ +{\ + return &H5NS::PredType::predType;\ +}\ static constexpr bool isNative = true;\ }; From ade1058e5f249531217c7f6874f3596ad85479fe Mon Sep 17 00:00:00 2001 From: Antonin Portelli Date: Thu, 19 Jan 2017 18:23:55 -0800 Subject: [PATCH 16/27] Hdf5Type does not need to be a pointer anymore --- lib/serialisation/Hdf5IO.cc | 4 ++-- lib/serialisation/Hdf5IO.h | 14 +++++++------- lib/serialisation/Hdf5Type.h | 4 ++-- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/lib/serialisation/Hdf5IO.cc b/lib/serialisation/Hdf5IO.cc index 4d5a2df5..c5313495 100644 --- a/lib/serialisation/Hdf5IO.cc +++ b/lib/serialisation/Hdf5IO.cc @@ -12,7 +12,7 @@ Hdf5Writer::Hdf5Writer(const std::string &fileName) { group_ = file_.openGroup("/"); writeSingleAttribute(dataSetThres_, HDF5_GRID_GUARD "dataset_threshold", - *Hdf5Type::type()); + Hdf5Type::type()); } void Hdf5Writer::push(const std::string &s) @@ -62,7 +62,7 @@ Hdf5Reader::Hdf5Reader(const std::string &fileName) { group_ = file_.openGroup("/"); readSingleAttribute(dataSetThres_, HDF5_GRID_GUARD "dataset_threshold", - *Hdf5Type::type()); + Hdf5Type::type()); } void Hdf5Reader::push(const std::string &s) diff --git a/lib/serialisation/Hdf5IO.h b/lib/serialisation/Hdf5IO.h index 9281e5a0..1c73bea3 100644 --- a/lib/serialisation/Hdf5IO.h +++ b/lib/serialisation/Hdf5IO.h @@ -92,7 +92,7 @@ namespace Grid template void Hdf5Writer::writeDefault(const std::string &s, const U &x) { - writeSingleAttribute(x, s, *Hdf5Type::type()); + writeSingleAttribute(x, s, Hdf5Type::type()); } template <> @@ -122,7 +122,7 @@ namespace Grid { H5NS::DataSet dataSet; - dataSet = group_.createDataSet(s, *Hdf5Type::type(), dataSpace); + dataSet = group_.createDataSet(s, Hdf5Type::type(), dataSpace); dataSet.write(flatx.data(), *Hdf5Type::type()); } else @@ -140,7 +140,7 @@ namespace Grid { push(s); writeSingleAttribute(x.size(), HDF5_GRID_GUARD "vector_size", - *Hdf5Type::type()); + Hdf5Type::type()); for (hsize_t i = 0; i < x.size(); ++i) { write(s + "_" + std::to_string(i), x[i]); @@ -162,7 +162,7 @@ namespace Grid template void Hdf5Reader::readDefault(const std::string &s, U &output) { - readSingleAttribute(output, s, *Hdf5Type::type()); + readSingleAttribute(output, s, Hdf5Type::type()); } template <> @@ -210,14 +210,14 @@ namespace Grid H5NS::DataSet dataSet; dataSet = group_.openDataSet(s); - dataSet.read(buf.data(), *Hdf5Type::type()); + dataSet.read(buf.data(), Hdf5Type::type()); } else { H5NS::Attribute attribute; attribute = group_.openAttribute(s); - attribute.read(*Hdf5Type::type(), buf.data()); + attribute.read(Hdf5Type::type(), buf.data()); } // reconstruct the multidimensional vector @@ -234,7 +234,7 @@ namespace Grid push(s); readSingleAttribute(size, HDF5_GRID_GUARD "vector_size", - *Hdf5Type::type()); + Hdf5Type::type()); x.resize(size); for (hsize_t i = 0; i < x.size(); ++i) { diff --git a/lib/serialisation/Hdf5Type.h b/lib/serialisation/Hdf5Type.h index 8b56c406..75575bf9 100644 --- a/lib/serialisation/Hdf5Type.h +++ b/lib/serialisation/Hdf5Type.h @@ -12,9 +12,9 @@ template <>\ struct Hdf5Type\ {\ -static inline const H5NS::PredType *type(void)\ +static inline const H5NS::PredType & type(void)\ {\ - return &H5NS::PredType::predType;\ + return H5NS::PredType::predType;\ }\ static constexpr bool isNative = true;\ }; From 81e66d6631ab07ee52522a50478ff3bb304a09d6 Mon Sep 17 00:00:00 2001 From: Antonin Portelli Date: Thu, 19 Jan 2017 18:24:53 -0800 Subject: [PATCH 17/27] HDF5: revert back to native types --- lib/serialisation/Hdf5Type.h | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/lib/serialisation/Hdf5Type.h b/lib/serialisation/Hdf5Type.h index 75575bf9..2e02128e 100644 --- a/lib/serialisation/Hdf5Type.h +++ b/lib/serialisation/Hdf5Type.h @@ -20,20 +20,21 @@ static constexpr bool isNative = true;\ }; #define DEFINE_HDF5_NATIVE_TYPES \ -HDF5_NATIVE_TYPE(STD_B8LE, bool);\ -HDF5_NATIVE_TYPE(STD_I8LE, char);\ -HDF5_NATIVE_TYPE(STD_U8LE, unsigned char);\ -HDF5_NATIVE_TYPE(STD_I16LE, short);\ -HDF5_NATIVE_TYPE(STD_U16LE, unsigned short);\ -HDF5_NATIVE_TYPE(STD_I32LE, int);\ -HDF5_NATIVE_TYPE(STD_U32LE, unsigned int);\ -HDF5_NATIVE_TYPE(STD_I64LE, long);\ -HDF5_NATIVE_TYPE(STD_U64LE, unsigned long);\ -HDF5_NATIVE_TYPE(STD_I64LE, long long);\ -HDF5_NATIVE_TYPE(STD_U64LE, unsigned long long);\ -HDF5_NATIVE_TYPE(IEEE_F32LE, float);\ -HDF5_NATIVE_TYPE(IEEE_F64LE, double);\ -HDF5_NATIVE_TYPE(IEEE_F64LE, long double); +HDF5_NATIVE_TYPE(NATIVE_B8, bool);\ +HDF5_NATIVE_TYPE(NATIVE_CHAR, char);\ +HDF5_NATIVE_TYPE(NATIVE_SCHAR, signed char);\ +HDF5_NATIVE_TYPE(NATIVE_UCHAR, unsigned char);\ +HDF5_NATIVE_TYPE(NATIVE_SHORT, short);\ +HDF5_NATIVE_TYPE(NATIVE_USHORT, unsigned short);\ +HDF5_NATIVE_TYPE(NATIVE_INT, int);\ +HDF5_NATIVE_TYPE(NATIVE_UINT, unsigned int);\ +HDF5_NATIVE_TYPE(NATIVE_LONG, long);\ +HDF5_NATIVE_TYPE(NATIVE_ULONG, unsigned long);\ +HDF5_NATIVE_TYPE(NATIVE_LLONG, long long);\ +HDF5_NATIVE_TYPE(NATIVE_ULLONG, unsigned long long);\ +HDF5_NATIVE_TYPE(NATIVE_FLOAT, float);\ +HDF5_NATIVE_TYPE(NATIVE_DOUBLE, double);\ +HDF5_NATIVE_TYPE(NATIVE_LDOUBLE, long double); namespace Grid { From 7423a352c5b2f97e800667000533c7df9ab06c07 Mon Sep 17 00:00:00 2001 From: Antonin Portelli Date: Thu, 19 Jan 2017 18:33:04 -0800 Subject: [PATCH 18/27] HDF5: typos --- lib/serialisation/Hdf5IO.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/serialisation/Hdf5IO.h b/lib/serialisation/Hdf5IO.h index 1c73bea3..0fb277b0 100644 --- a/lib/serialisation/Hdf5IO.h +++ b/lib/serialisation/Hdf5IO.h @@ -123,14 +123,14 @@ namespace Grid H5NS::DataSet dataSet; dataSet = group_.createDataSet(s, Hdf5Type::type(), dataSpace); - dataSet.write(flatx.data(), *Hdf5Type::type()); + dataSet.write(flatx.data(), Hdf5Type::type()); } else { H5NS::Attribute attribute; - attribute = group_.createAttribute(s, *Hdf5Type::type(), dataSpace); - attribute.write(*Hdf5Type::type(), flatx.data()); + attribute = group_.createAttribute(s, Hdf5Type::type(), dataSpace); + attribute.write(Hdf5Type::type(), flatx.data()); } } From 6b5259cc104d79b714ec93ffbb95e31b039a95b0 Mon Sep 17 00:00:00 2001 From: Antonin Portelli Date: Fri, 20 Jan 2017 11:03:19 -0800 Subject: [PATCH 19/27] HDF5 detects if a name is a dataset or not without using exception catching --- lib/serialisation/Hdf5IO.h | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/lib/serialisation/Hdf5IO.h b/lib/serialisation/Hdf5IO.h index 0fb277b0..3edb7d10 100644 --- a/lib/serialisation/Hdf5IO.h +++ b/lib/serialisation/Hdf5IO.h @@ -177,23 +177,18 @@ namespace Grid // read the dimensions H5NS::DataSpace dataSpace; - H5E_auto2_t func; - void * client_data; std::vector hdim; std::vector dim; hsize_t size = 1; - H5NS::Exception::getAutoPrint(func, &client_data); - try + if (group_.attrExists(s)) { - H5NS::Exception::dontPrint(); - dataSpace = group_.openDataSet(s).getSpace(); - } - catch (H5NS::Exception &e) - { - H5NS::Exception::setAutoPrint(func, client_data); dataSpace = group_.openAttribute(s).getSpace(); } + else + { + dataSpace = group_.openDataSet(s).getSpace(); + } hdim.resize(dataSpace.getSimpleExtentNdims()); dataSpace.getSimpleExtentDims(hdim.data()); for (auto &d: hdim) From afa095d33d1665dbf7648dddef95f78901e7e6cd Mon Sep 17 00:00:00 2001 From: Antonin Portelli Date: Fri, 20 Jan 2017 12:10:41 -0800 Subject: [PATCH 20/27] HDF5: better complex number support --- lib/Grid.h | 2 +- lib/serialisation/BaseIO.h | 9 ++++---- lib/serialisation/Hdf5IO.h | 16 +++++++------- lib/serialisation/Hdf5Type.h | 39 ++++++++++++++++++++++++++++------ tests/IO/Test_serialisation.cc | 6 +++++- 5 files changed, 51 insertions(+), 21 deletions(-) diff --git a/lib/Grid.h b/lib/Grid.h index 0f57c8a6..cb55d0c8 100644 --- a/lib/Grid.h +++ b/lib/Grid.h @@ -60,12 +60,12 @@ Author: paboyle // Grid headers /////////////////// #include "Config.h" -#include #include #include #include #include #include +#include #include #include #include diff --git a/lib/serialisation/BaseIO.h b/lib/serialisation/BaseIO.h index eca5cff2..0357915d 100644 --- a/lib/serialisation/BaseIO.h +++ b/lib/serialisation/BaseIO.h @@ -68,20 +68,21 @@ namespace Grid { return os; } - // Vector element trait ////////////////////////////////////////////////////// + // Vector element trait ////////////////////////////////////////////////////// template struct element { typedef T type; - static constexpr bool is_arithmetic = false; + static constexpr bool is_number = false; }; template struct element> { typedef typename element::type type; - static constexpr bool is_arithmetic = std::is_arithmetic::value - or element::is_arithmetic; + static constexpr bool is_number = std::is_arithmetic::value + or is_complex::value + or element::is_number; }; // Vector flatening utility class //////////////////////////////////////////// diff --git a/lib/serialisation/Hdf5IO.h b/lib/serialisation/Hdf5IO.h index 3edb7d10..2f891cd4 100644 --- a/lib/serialisation/Hdf5IO.h +++ b/lib/serialisation/Hdf5IO.h @@ -32,10 +32,10 @@ namespace Grid template void writeDefault(const std::string &s, const U &x); template - typename std::enable_if>::is_arithmetic, void>::type + typename std::enable_if>::is_number, void>::type writeDefault(const std::string &s, const std::vector &x); template - typename std::enable_if>::is_arithmetic, void>::type + typename std::enable_if>::is_number, void>::type writeDefault(const std::string &s, const std::vector &x); private: template @@ -59,10 +59,10 @@ namespace Grid template void readDefault(const std::string &s, U &output); template - typename std::enable_if>::is_arithmetic, void>::type + typename std::enable_if>::is_number, void>::type readDefault(const std::string &s, std::vector &x); template - typename std::enable_if>::is_arithmetic, void>::type + typename std::enable_if>::is_number, void>::type readDefault(const std::string &s, std::vector &x); private: template @@ -99,7 +99,7 @@ namespace Grid void Hdf5Writer::writeDefault(const std::string &s, const std::string &x); template - typename std::enable_if>::is_arithmetic, void>::type + typename std::enable_if>::is_number, void>::type Hdf5Writer::writeDefault(const std::string &s, const std::vector &x) { // alias to element type @@ -135,7 +135,7 @@ namespace Grid } template - typename std::enable_if>::is_arithmetic, void>::type + typename std::enable_if>::is_number, void>::type Hdf5Writer::writeDefault(const std::string &s, const std::vector &x) { push(s); @@ -169,7 +169,7 @@ namespace Grid void Hdf5Reader::readDefault(const std::string &s, std::string &x); template - typename std::enable_if>::is_arithmetic, void>::type + typename std::enable_if>::is_number, void>::type Hdf5Reader::readDefault(const std::string &s, std::vector &x) { // alias to element type @@ -222,7 +222,7 @@ namespace Grid } template - typename std::enable_if>::is_arithmetic, void>::type + typename std::enable_if>::is_number, void>::type Hdf5Reader::readDefault(const std::string &s, std::vector &x) { uint64_t size; diff --git a/lib/serialisation/Hdf5Type.h b/lib/serialisation/Hdf5Type.h index 2e02128e..cf682138 100644 --- a/lib/serialisation/Hdf5Type.h +++ b/lib/serialisation/Hdf5Type.h @@ -10,13 +10,14 @@ #define HDF5_NATIVE_TYPE(predType, cType)\ template <>\ -struct Hdf5Type\ +class Hdf5Type\ {\ -static inline const H5NS::PredType & type(void)\ -{\ - return H5NS::PredType::predType;\ -}\ -static constexpr bool isNative = true;\ +public:\ + static inline const H5NS::DataType & type(void)\ + {\ + return H5NS::PredType::predType;\ + }\ + static constexpr bool isNative = true;\ }; #define DEFINE_HDF5_NATIVE_TYPES \ @@ -38,12 +39,36 @@ HDF5_NATIVE_TYPE(NATIVE_LDOUBLE, long double); namespace Grid { - template struct Hdf5Type + template class Hdf5Type { + public: static constexpr bool isNative = false; }; DEFINE_HDF5_NATIVE_TYPES; + + template + class Hdf5Type> + { + public: + static inline const H5NS::DataType & type(void) + { + if (typePtr_ == nullptr) + { + typePtr_.reset(new H5NS::CompType(sizeof(std::complex))); + typePtr_->insertMember("re", 0, Hdf5Type::type()); + typePtr_->insertMember("im", sizeof(R), Hdf5Type::type()); + } + + return *typePtr_; + } + static constexpr bool isNative = false; + private: + static std::unique_ptr typePtr_; + }; + + template + std::unique_ptr Hdf5Type>::typePtr_ = nullptr; } #undef HDF5_NATIVE_TYPE diff --git a/tests/IO/Test_serialisation.cc b/tests/IO/Test_serialisation.cc index b7158b2b..8204b05b 100644 --- a/tests/IO/Test_serialisation.cc +++ b/tests/IO/Test_serialisation.cc @@ -43,10 +43,14 @@ public: bool , b, std::vector, array, std::vector>, twodimarray, + std::vector>>, cmplx3darray ); myclass() {} myclass(int i) - : array(4,5.1), twodimarray(3,std::vector(2,1.23456)), ve(2, myenum::blue) + : array(4,5.1) + , twodimarray(3,std::vector(5, 1.23456)) + , cmplx3darray(3,std::vector>(5, std::vector(7, Complex(1.2, 3.4)))) + , ve(2, myenum::blue) { e=myenum::red; x=i; From 4c75095c616c6c246b268c775fee13cbe7ae84da Mon Sep 17 00:00:00 2001 From: Antonin Portelli Date: Fri, 20 Jan 2017 12:14:01 -0800 Subject: [PATCH 21/27] HDF5: header fix --- lib/serialisation/Hdf5Type.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/serialisation/Hdf5Type.h b/lib/serialisation/Hdf5Type.h index cf682138..8634f35b 100644 --- a/lib/serialisation/Hdf5Type.h +++ b/lib/serialisation/Hdf5Type.h @@ -2,7 +2,8 @@ #define GRID_SERIALISATION_HDF5_TYPE_H #include -#include +#include +#include #ifndef H5_NO_NAMESPACE #define H5NS H5 From b7da264b0a64c21bd9f45174c4d831e70243bc63 Mon Sep 17 00:00:00 2001 From: Antonin Portelli Date: Sat, 21 Jan 2017 13:40:23 -0800 Subject: [PATCH 22/27] Hadrons: Application is not storing the environment ref but calling getInstance() each time, solving a very nasty set fault on Linux/KNL --- extras/Hadrons/Application.cc | 43 +++++++++++++++++++--------------- extras/Hadrons/Application.hpp | 8 ++++--- 2 files changed, 29 insertions(+), 22 deletions(-) diff --git a/extras/Hadrons/Application.cc b/extras/Hadrons/Application.cc index 4bb3b383..62674f30 100644 --- a/extras/Hadrons/Application.cc +++ b/extras/Hadrons/Application.cc @@ -42,7 +42,6 @@ using namespace Hadrons; ******************************************************************************/ // constructors //////////////////////////////////////////////////////////////// Application::Application(void) -: env_(Environment::getInstance()) { LOG(Message) << "Modules available:" << std::endl; auto list = ModuleFactory::getInstance().getBuilderList(); @@ -74,11 +73,17 @@ Application::Application(const std::string parameterFileName) parameterFileName_ = parameterFileName; } +// environment shortcut //////////////////////////////////////////////////////// +Environment & Application::env(void) const +{ + return Environment::getInstance(); +} + // access ////////////////////////////////////////////////////////////////////// void Application::setPar(const Application::GlobalPar &par) { par_ = par; - env_.setSeed(strToVec(par_.seed)); + env().setSeed(strToVec(par_.seed)); } const Application::GlobalPar & Application::getPar(void) @@ -89,7 +94,7 @@ const Application::GlobalPar & Application::getPar(void) // execute ///////////////////////////////////////////////////////////////////// void Application::run(void) { - if (!parameterFileName_.empty() and (env_.getNModule() == 0)) + if (!parameterFileName_.empty() and (env().getNModule() == 0)) { parseParameterFile(parameterFileName_); } @@ -124,7 +129,7 @@ void Application::parseParameterFile(const std::string parameterFileName) do { read(reader, "id", id); - env_.createModule(id.name, id.type, reader); + env().createModule(id.name, id.type, reader); } while (reader.nextElement("module")); pop(reader); pop(reader); @@ -134,7 +139,7 @@ void Application::saveParameterFile(const std::string parameterFileName) { XmlWriter writer(parameterFileName); ObjectId id; - const unsigned int nMod = env_.getNModule(); + const unsigned int nMod = env().getNModule(); LOG(Message) << "Saving application to '" << parameterFileName << "'..." << std::endl; write(writer, "parameters", getPar()); @@ -142,10 +147,10 @@ void Application::saveParameterFile(const std::string parameterFileName) for (unsigned int i = 0; i < nMod; ++i) { push(writer, "module"); - id.name = env_.getModuleName(i); - id.type = env_.getModule(i)->getRegisteredName(); + id.name = env().getModuleName(i); + id.type = env().getModule(i)->getRegisteredName(); write(writer, "id", id); - env_.getModule(i)->saveParameters(writer, "options"); + env().getModule(i)->saveParameters(writer, "options"); pop(writer); } pop(writer); @@ -164,10 +169,10 @@ auto memPeak = [this](const std::vector &program)\ \ msg = HadronsLogMessage.isActive();\ HadronsLogMessage.Active(false);\ - env_.dryRun(true);\ - memPeak = env_.executeProgram(program);\ - env_.dryRun(false);\ - env_.freeAll();\ + env().dryRun(true);\ + memPeak = env().executeProgram(program);\ + env().dryRun(false);\ + env().freeAll();\ HadronsLogMessage.Active(true);\ \ return memPeak;\ @@ -179,7 +184,7 @@ void Application::schedule(void) // build module dependency graph LOG(Message) << "Building module graph..." << std::endl; - auto graph = env_.makeModuleGraph(); + auto graph = env().makeModuleGraph(); auto con = graph.getConnectedComponents(); // constrained topological sort using a genetic algorithm @@ -256,7 +261,7 @@ void Application::saveSchedule(const std::string filename) << std::endl; for (auto address: program_) { - program.push_back(env_.getModuleName(address)); + program.push_back(env().getModuleName(address)); } write(writer, "schedule", program); } @@ -274,7 +279,7 @@ void Application::loadSchedule(const std::string filename) program_.clear(); for (auto &name: program) { - program_.push_back(env_.getModuleAddress(name)); + program_.push_back(env().getModuleAddress(name)); } scheduled_ = true; memPeak_ = memPeak(program_); @@ -291,7 +296,7 @@ void Application::printSchedule(void) for (unsigned int i = 0; i < program_.size(); ++i) { LOG(Message) << std::setw(4) << i + 1 << ": " - << env_.getModuleName(program_[i]) << std::endl; + << env().getModuleName(program_[i]) << std::endl; } } @@ -304,9 +309,9 @@ void Application::configLoop(void) { LOG(Message) << BIG_SEP << " Starting measurement for trajectory " << t << " " << BIG_SEP << std::endl; - env_.setTrajectory(t); - env_.executeProgram(program_); + env().setTrajectory(t); + env().executeProgram(program_); } LOG(Message) << BIG_SEP << " End of measurement " << BIG_SEP << std::endl; - env_.freeAll(); + env().freeAll(); } diff --git a/extras/Hadrons/Application.hpp b/extras/Hadrons/Application.hpp index 4ea262df..fce9b6eb 100644 --- a/extras/Hadrons/Application.hpp +++ b/extras/Hadrons/Application.hpp @@ -98,11 +98,13 @@ public: void printSchedule(void); // loop on configurations void configLoop(void); +private: + // environment shortcut + Environment & env(void) const; private: long unsigned int locVol_; std::string parameterFileName_{""}; GlobalPar par_; - Environment &env_; std::vector program_; Environment::Size memPeak_; bool scheduled_{false}; @@ -115,14 +117,14 @@ private: template void Application::createModule(const std::string name) { - env_.createModule(name); + env().createModule(name); } template void Application::createModule(const std::string name, const typename M::Par &par) { - env_.createModule(name, par); + env().createModule(name, par); } END_HADRONS_NAMESPACE From 677757cfebde4861d3701445dee19b9be209304e Mon Sep 17 00:00:00 2001 From: Guido Cossu Date: Wed, 25 Jan 2017 12:47:22 +0000 Subject: [PATCH 23/27] Added and tested SITMO PRNG --- configure.ac | 5 +- lib/lattice/Lattice_rng.h | 7 +- lib/sitmo_rng/sitmo_prng_engine.hpp | 385 ++++++++++++++++++++++++++++ 3 files changed, 395 insertions(+), 2 deletions(-) create mode 100644 lib/sitmo_rng/sitmo_prng_engine.hpp diff --git a/configure.ac b/configure.ac index f848bd23..d3ba9de2 100644 --- a/configure.ac +++ b/configure.ac @@ -319,7 +319,7 @@ AM_CONDITIONAL(BUILD_COMMS_MPI3L, [ test "${comms_type}X" == "mpi3lX" ] ) AM_CONDITIONAL(BUILD_COMMS_NONE, [ test "${comms_type}X" == "noneX" ]) ############### RNG selection -AC_ARG_ENABLE([rng],[AC_HELP_STRING([--enable-rng=ranlux48|mt19937],\ +AC_ARG_ENABLE([rng],[AC_HELP_STRING([--enable-rng=ranlux48|mt19937|sitmo],\ [Select Random Number Generator to be used])],\ [ac_RNG=${enable_rng}],[ac_RNG=ranlux48]) @@ -330,6 +330,9 @@ case ${ac_RNG} in mt19937) AC_DEFINE([RNG_MT19937],[1],[RNG_MT19937] ) ;; + sitmo) + AC_DEFINE([RNG_SITMO],[1],[RNG_SITMO] ) + ;; *) AC_MSG_ERROR([${ac_RNG} unsupported --enable-rng option]); ;; diff --git a/lib/lattice/Lattice_rng.h b/lib/lattice/Lattice_rng.h index 51cc16ec..2caf2de4 100644 --- a/lib/lattice/Lattice_rng.h +++ b/lib/lattice/Lattice_rng.h @@ -30,6 +30,7 @@ Author: paboyle #define GRID_LATTICE_RNG_H #include +#include namespace Grid { @@ -114,10 +115,14 @@ namespace Grid { typedef uint64_t RngStateType; typedef std::ranlux48 RngEngine; static const int RngStateCount = 15; -#else +#elif RNG_MT19937 typedef std::mt19937 RngEngine; typedef uint32_t RngStateType; static const int RngStateCount = std::mt19937::state_size; +#elif RNG_SITMO + typedef sitmo::prng_engine RngEngine; + typedef uint64_t RngStateType; + static const int RngStateCount = 4; #endif std::vector _generators; std::vector> _uniform; diff --git a/lib/sitmo_rng/sitmo_prng_engine.hpp b/lib/sitmo_rng/sitmo_prng_engine.hpp new file mode 100644 index 00000000..baa50390 --- /dev/null +++ b/lib/sitmo_rng/sitmo_prng_engine.hpp @@ -0,0 +1,385 @@ +// Copyright (c) 2012-2013 M.A. (Thijs) van den Berg, http://sitmo.com/ +// +// Use, modification and distribution are subject to the MIT Software License. +// +// The MIT License (MIT) +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + +// version history: +// version 1, 6 Sep 2012 +// version 2, 10 Dec 2013 +// bug fix in the discard() routine, it was discarding to many elements +// added the version() method +// version 3...5, 13 Dec 2013 +// fixed type-conversion earning +// fixed potential issues with constructor template matching + +#ifndef SITMO_PRNG_ENGINE_HPP +#define SITMO_PRNG_ENGINE_HPP +#include + +#ifdef __GNUC__ + #include // respecting the C99 standard. +#endif +#ifdef _MSC_VER + typedef unsigned __int64 uint64_t; // Visual Studio 6.0(VC6) and newer.. + typedef unsigned __int32 uint32_t; +#endif + +// Double mixing function +#define MIX2(x0,x1,rx,z0,z1,rz) \ + x0 += x1; \ + z0 += z1; \ + x1 = (x1 << rx) | (x1 >> (64-rx)); \ + z1 = (z1 << rz) | (z1 >> (64-rz)); \ + x1 ^= x0; \ + z1 ^= z0; + + +// Double mixing function with key adition +#define MIXK(x0,x1,rx,z0,z1,rz,k0,k1,l0,l1) \ + x1 += k1; \ + z1 += l1; \ + x0 += x1+k0; \ + z0 += z1+l0; \ + x1 = (x1 << rx) | (x1 >> (64-rx)); \ + z1 = (z1 << rz) | (z1 >> (64-rz)); \ + x1 ^= x0; \ + z1 ^= z0; \ + + +namespace sitmo { + + // enable_if for C__98 compilers + template + struct sitmo_enable_if { typedef T type; }; + + template + struct sitmo_enable_if { }; + + // SFINAE check for the existence of a "void generate(int*,int*)"member function + template + struct has_generate_template + { + typedef char (&Two)[2];; + template struct helper {}; + template static char test(helper >*); + template static Two test(...); + static bool const value = sizeof(test(0)) == sizeof(char); + }; + + +class prng_engine +{ +public: + // "req" are requirements as stated in the C++ 11 draft n3242=11-0012 + // + // req: 26.5.1.3 Uniform random number generator requirements, p.906, table 116, row 1 + typedef uint32_t result_type; + + // req: 26.5.1.3 Uniform random number generator requirements, p.906, table 116, row 3 + static result_type (min)() { return 0; } + + // req: 26.5.1.3 Uniform random number generator requirements, p.906, table 116, row 4 + static result_type (max)() { return 0xFFFFFFFF; } + + // ------------------------------------------------- + // Constructors + // ------------------------------------------------- + + // req: 26.5.1.4 Random number engine requirements, p.907 table 117, row 1 + // Creates an engine with the same initial state as all other + // default-constructed engines of type E. + prng_engine() + { + seed(); + } + + // req: 26.5.1.4 Random number engine requirements, p.907 table 117, row 2 + // Creates an engine that compares equal to x. + prng_engine(const prng_engine& x) + { + for (unsigned short i=0; i<4; ++i) { + _s[i] = x._s[i]; + _k[i] = x._k[i]; + _o[i] = x._o[i]; + } + _o_counter = x._o_counter; + } + + + // req: 26.5.1.4 Random number engine requirements, p.907 table 117, row 3 + // Creates an engine with initial O(size of state) state determined by s. + prng_engine(uint32_t s) + { + seed(s); + } + + // req: 26.5.1.4 Random number engine requirements, p.908 table 117, row 4 + // Creates an engine with an initial state that depends on a sequence + // produced by one call to q.generate. + template + prng_engine(Seq& q, typename sitmo_enable_if< has_generate_template::value >::type* = 0 ) + { + seed(q); + } + + // ------------------------------------------------- + // Seeding + // ------------------------------------------------- + + // req: 26.5.1.4 Random number engine requirements, p.908 table 117, row 5 + void seed() + { + for (unsigned short i=0; i<4; ++i) { + _k[i] = 0; + _s[i] = 0; + } + _o_counter = 0; + + _o[0] = 0x09218ebde6c85537; + _o[1] = 0x55941f5266d86105; + _o[2] = 0x4bd25e16282434dc; + _o[3] = 0xee29ec846bd2e40b; + } + + // req: 26.5.1.4 Random number engine requirements, p.908 table 117, row 6 + // s needs to be of return_type, which is uint32_t + void seed(uint32_t s) + { + for (unsigned short i=0; i<4; ++i) { + _k[i] = 0; + _s[i] = 0; + } + _k[0] = s; + _o_counter = 0; + + encrypt_counter(); + } + + // req: 26.5.1.4 Random number engine requirements, p.908 table 117, row 7 + template + void seed(Seq& q, typename sitmo_enable_if< has_generate_template::value >::type* = 0 ) + { + typename Seq::result_type w[8]; + q.generate(&w[0], &w[8]); + + for (unsigned short i=0; i<4; ++i) { + _k[i] = ( static_cast(w[2*i]) << 32) | w[2*i+1]; + _s[i] = 0; + } + _o_counter = 0; + + encrypt_counter(); + } + + // req: 26.5.1.4 Random number engine requirements, p.908 table 117, row 8 + // Advances e’s state ei to ei+1 = TA(ei) and returns GA(ei). + uint32_t operator()() + { + // can we return a value from the current block? + if (_o_counter < 8) { + unsigned short _o_index = _o_counter >> 1; + _o_counter++; + if (_o_counter&1) + return _o[_o_index] & 0xFFFFFFFF; + else + return _o[_o_index] >> 32; + } + + // generate a new block and return the first 32 bits + inc_counter(); + encrypt_counter(); + _o_counter = 1; // the next call + return _o[0] & 0xFFFFFFFF; // this call + } + + // ------------------------------------------------- + // misc + // ------------------------------------------------- + + // req: 26.5.1.4 Random number engine requirements, p.908 table 117, row 9 + // Advances e’s state ei to ei+z by any means equivalent to z + // consecutive calls e(). + void discard(uint64_t z) + { + // check if we stay in the current block + if (z < 8 - _o_counter) { + _o_counter += static_cast(z); + return; + } + + // we will have to generate a new block... + z -= (8 - _o_counter); // discard the remainder of the current blok + _o_counter = z % 8; // set the pointer in the correct element in the new block + z -= _o_counter; // update z + z >>= 3; // the number of buffers is elements/8 + ++z; // and one more because we crossed the buffer line + inc_counter(z); + encrypt_counter(); + } + + // ------------------------------------------------- + // IO + // ------------------------------------------------- + template + friend std::basic_ostream& + operator<<(std::basic_ostream& os, const prng_engine& s) { + for (unsigned short i=0; i<4; ++i) + os << s._k[i] << ' ' << s._s[i] << ' ' << s._o[i] << ' '; + os << s._o_counter; + return os; + } + + template + friend std::basic_istream& + operator>>(std::basic_istream& is, prng_engine& s) { + for (unsigned short i=0; i<4; ++i) + is >> s._k[i] >> s._s[i] >> s._o[i]; + is >> s._o_counter; + return is; + } + // req: 26.5.1.4 Random number engine requirements, p.908 table 117, row 10 + // This operator is an equivalence relation. With Sx and Sy as the infinite + // sequences of values that would be generated by repeated future calls to + // x() and y(), respectively, returns true if Sx = Sy; else returns false. + bool operator==(const prng_engine& y) + { + if (_o_counter != y._o_counter) return false; + for (unsigned short i=0; i<4; ++i) { + if (_s[i] != y._s[i]) return false; + if (_k[i] != y._k[i]) return false; + if (_o[i] != y._o[i]) return false; + } + return true; + } + + // req: 26.5.1.4 Random number engine requirements, p.908 table 117, row 11 + bool operator!=(const prng_engine& y) + { + return !(*this == y); + } + + // Extra function to set the key + void set_key(uint64_t k0=0, uint64_t k1=0, uint64_t k2=0, uint64_t k3=0) + { + _k[0] = k0; _k[1] = k1; _k[2] = k2; _k[3] = k3; + encrypt_counter(); + } + + // set the counter + void set_counter(uint64_t s0=0, uint64_t s1=0, uint64_t s2=0, uint64_t s3=0, unsigned short o_counter=0) + { + _s[0] = s0; + _s[1] = s1; + _s[2] = s2; + _s[3] = s3; + _o_counter = o_counter % 8; + encrypt_counter(); + } + + + // versioning + uint32_t version() + { + return 5; + } + +private: + void encrypt_counter() + { + uint64_t b[4]; + uint64_t k[5]; + + for (unsigned short i=0; i<4; ++i) b[i] = _s[i]; + for (unsigned short i=0; i<4; ++i) k[i] = _k[i]; + + k[4] = 0x1BD11BDAA9FC1A22 ^ k[0] ^ k[1] ^ k[2] ^ k[3]; + + MIXK(b[0], b[1], 14, b[2], b[3], 16, k[0], k[1], k[2], k[3]); + MIX2(b[0], b[3], 52, b[2], b[1], 57); + MIX2(b[0], b[1], 23, b[2], b[3], 40); + MIX2(b[0], b[3], 5, b[2], b[1], 37); + MIXK(b[0], b[1], 25, b[2], b[3], 33, k[1], k[2], k[3], k[4]+1); + MIX2(b[0], b[3], 46, b[2], b[1], 12); + MIX2(b[0], b[1], 58, b[2], b[3], 22); + MIX2(b[0], b[3], 32, b[2], b[1], 32); + + MIXK(b[0], b[1], 14, b[2], b[3], 16, k[2], k[3], k[4], k[0]+2); + MIX2(b[0], b[3], 52, b[2], b[1], 57); + MIX2(b[0], b[1], 23, b[2], b[3], 40); + MIX2(b[0], b[3], 5, b[2], b[1], 37); + MIXK(b[0], b[1], 25, b[2], b[3], 33, k[3], k[4], k[0], k[1]+3); + + MIX2(b[0], b[3], 46, b[2], b[1], 12); + MIX2(b[0], b[1], 58, b[2], b[3], 22); + MIX2(b[0], b[3], 32, b[2], b[1], 32); + + MIXK(b[0], b[1], 14, b[2], b[3], 16, k[4], k[0], k[1], k[2]+4); + MIX2(b[0], b[3], 52, b[2], b[1], 57); + MIX2(b[0], b[1], 23, b[2], b[3], 40); + MIX2(b[0], b[3], 5, b[2], b[1], 37); + + for (unsigned int i=0; i<4; ++i) _o[i] = b[i] + k[i]; + _o[3] += 5; + } + + void inc_counter() + { + ++_s[0]; + if (_s[0] != 0) return; + + ++_s[1]; + if (_s[1] != 0) return; + + ++_s[2]; + if (_s[2] != 0) return; + + ++_s[3]; + } + + void inc_counter(uint64_t z) + { + if (z > 0xFFFFFFFFFFFFFFFF - _s[0]) { // check if we will overflow the first 64 bit int + ++_s[1]; + if (_s[1] == 0) { + ++_s[2]; + if (_s[2] == 0) { + ++_s[3]; + } + } + } + _s[0] += z; + } + +private: + uint64_t _k[4]; // key + uint64_t _s[4]; // state (counter) + uint64_t _o[4]; // cipher output 4 * 64 bit = 256 bit output + unsigned short _o_counter; // output chunk counter, the 256 random bits in _o + // are returned in eight 32 bit chunks +}; + + +} // namespace sitmo + +#undef MIXK +#undef MIX2 + +#endif \ No newline at end of file From 70ed9fc40cc71abb598ea41d96f1682680c2fb47 Mon Sep 17 00:00:00 2001 From: Guido Cossu Date: Wed, 25 Jan 2017 18:10:41 +0000 Subject: [PATCH 24/27] Updating the engine to the last version --- lib/sitmo_rng/sitmo_prng_engine.hpp | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/lib/sitmo_rng/sitmo_prng_engine.hpp b/lib/sitmo_rng/sitmo_prng_engine.hpp index baa50390..c76a0080 100644 --- a/lib/sitmo_rng/sitmo_prng_engine.hpp +++ b/lib/sitmo_rng/sitmo_prng_engine.hpp @@ -1,4 +1,4 @@ -// Copyright (c) 2012-2013 M.A. (Thijs) van den Berg, http://sitmo.com/ +// Copyright (c) 2012-2016 M.A. (Thijs) van den Berg, http://sitmo.com/ // // Use, modification and distribution are subject to the MIT Software License. // @@ -29,6 +29,8 @@ // version 3...5, 13 Dec 2013 // fixed type-conversion earning // fixed potential issues with constructor template matching +// version 6, 4 March 2016 +// made min() max() constexpr for C+11 compiler (thanks to James Joseph Balamuta) #ifndef SITMO_PRNG_ENGINE_HPP #define SITMO_PRNG_ENGINE_HPP @@ -92,12 +94,15 @@ public: // // req: 26.5.1.3 Uniform random number generator requirements, p.906, table 116, row 1 typedef uint32_t result_type; - - // req: 26.5.1.3 Uniform random number generator requirements, p.906, table 116, row 3 - static result_type (min)() { return 0; } - // req: 26.5.1.3 Uniform random number generator requirements, p.906, table 116, row 4 + // req: 26.5.1.3 Uniform random number generator requirements, p.906, table 116, row 3 & 4 +#if __cplusplus <= 199711L + static result_type (min)() { return 0; } static result_type (max)() { return 0xFFFFFFFF; } +#else + static constexpr result_type (min)() { return 0; } + static constexpr result_type (max)() { return 0xFFFFFFFF; } +#endif // ------------------------------------------------- // Constructors From ef8d3831eb171e26de039e5d56df91f050301a3c Mon Sep 17 00:00:00 2001 From: Guido Cossu Date: Wed, 25 Jan 2017 18:12:04 +0000 Subject: [PATCH 25/27] Temporary patch the threading error in InsertSlice and ExtractSlice Find source and fix the error --- lib/lattice/Lattice_transfer.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/lattice/Lattice_transfer.h b/lib/lattice/Lattice_transfer.h index a49b1b5f..27b4aa7e 100644 --- a/lib/lattice/Lattice_transfer.h +++ b/lib/lattice/Lattice_transfer.h @@ -386,7 +386,8 @@ void InsertSlice(Lattice &lowDim,Lattice & higherDim,int slice, int } // the above should guarantee that the operations are local - PARALLEL_FOR_LOOP + // Guido: check the threading here + //PARALLEL_FOR_LOOP for(int idx=0;idxlSites();idx++){ std::vector lcoor(nl); std::vector hcoor(nh); @@ -428,7 +429,7 @@ void ExtractSlice(Lattice &lowDim, Lattice & higherDim,int slice, in } } // the above should guarantee that the operations are local - PARALLEL_FOR_LOOP + //PARALLEL_FOR_LOOP for(int idx=0;idxlSites();idx++){ std::vector lcoor(nl); std::vector hcoor(nh); From fad743fbb1504aa05be9e73167362fd2de5a1a5a Mon Sep 17 00:00:00 2001 From: Antonin Portelli Date: Thu, 26 Jan 2017 17:00:41 -0800 Subject: [PATCH 26/27] Build system sanity check: corrected several headers not in the format --- lib/Init.cc | 2 +- lib/Log.cc | 2 +- lib/PerfCount.cc | 4 ++-- lib/Stat.cc | 6 +++--- lib/algorithms/approx/MultiShiftFunction.cc | 2 +- lib/algorithms/approx/Remez.cc | 2 +- lib/algorithms/iterative/Matrix.h | 2 +- lib/communicator/Communicator_base.cc | 2 +- lib/communicator/Communicator_mpi.cc | 2 +- lib/communicator/Communicator_mpi3.cc | 2 +- lib/communicator/Communicator_none.cc | 2 +- lib/communicator/Communicator_shmem.cc | 2 +- lib/pugixml/pugixml.cc | 2 +- lib/qcd/action/fermion/CayleyFermion5D.cc | 2 +- lib/qcd/action/fermion/CayleyFermion5Dcache.cc | 2 +- lib/qcd/action/fermion/CayleyFermion5Ddense.cc | 2 +- lib/qcd/action/fermion/CayleyFermion5Dssp.cc | 2 +- lib/qcd/action/fermion/CayleyFermion5Dvec.cc | 2 +- lib/qcd/action/fermion/ContinuedFractionFermion5D.cc | 2 +- lib/qcd/action/fermion/PartialFractionFermion5D.cc | 2 +- lib/qcd/action/fermion/WilsonFermion.cc | 2 +- lib/qcd/action/fermion/WilsonFermion5D.cc | 4 ++-- lib/qcd/action/fermion/WilsonKernels.cc | 2 +- lib/qcd/action/fermion/WilsonKernelsAsm.cc | 2 +- lib/qcd/action/fermion/WilsonKernelsHand.cc | 2 +- lib/qcd/action/fermion/WilsonTMFermion.cc | 2 +- lib/qcd/hmc/HMC.cc | 2 +- lib/qcd/spin/Dirac.cc | 2 +- lib/qcd/utils/SpaceTimeGrid.cc | 2 +- lib/serialisation/BinaryIO.cc | 2 +- lib/serialisation/Hdf5IO.cc | 2 +- lib/serialisation/TextIO.cc | 2 +- lib/serialisation/XmlIO.cc | 2 +- lib/stencil/Lebesgue.cc | 2 +- lib/stencil/Stencil_common.cc | 2 +- tests/qdpxx/Test_qdpxx_loops_staples.cc | 2 +- tests/qdpxx/Test_qdpxx_munprec.cc | 2 +- 37 files changed, 41 insertions(+), 41 deletions(-) diff --git a/lib/Init.cc b/lib/Init.cc index d6d6b9f8..5abe7a4b 100644 --- a/lib/Init.cc +++ b/lib/Init.cc @@ -41,7 +41,7 @@ Author: paboyle #include #include #include -#include +#include #include #include #include diff --git a/lib/Log.cc b/lib/Log.cc index 7521657b..1a7d8a58 100644 --- a/lib/Log.cc +++ b/lib/Log.cc @@ -29,7 +29,7 @@ See the full license in the file "LICENSE" in the top level distribution directory *************************************************************************************/ /* END LEGAL */ -#include +#include #include diff --git a/lib/PerfCount.cc b/lib/PerfCount.cc index b61851a9..ba0241a2 100644 --- a/lib/PerfCount.cc +++ b/lib/PerfCount.cc @@ -26,8 +26,8 @@ Author: paboyle *************************************************************************************/ /* END LEGAL */ -#include -#include +#include +#include namespace Grid { diff --git a/lib/Stat.cc b/lib/Stat.cc index 7f2e4086..e6fa978e 100644 --- a/lib/Stat.cc +++ b/lib/Stat.cc @@ -1,6 +1,6 @@ -#include -#include -#include +#include +#include +#include namespace Grid { diff --git a/lib/algorithms/approx/MultiShiftFunction.cc b/lib/algorithms/approx/MultiShiftFunction.cc index fc642ad7..24776e96 100644 --- a/lib/algorithms/approx/MultiShiftFunction.cc +++ b/lib/algorithms/approx/MultiShiftFunction.cc @@ -25,7 +25,7 @@ Author: Azusa Yamaguchi See the full license in the file "LICENSE" in the top level distribution directory *************************************************************************************/ /* END LEGAL */ -#include +#include namespace Grid { double MultiShiftFunction::approx(double x) diff --git a/lib/algorithms/approx/Remez.cc b/lib/algorithms/approx/Remez.cc index 38d60088..ca00a330 100644 --- a/lib/algorithms/approx/Remez.cc +++ b/lib/algorithms/approx/Remez.cc @@ -20,7 +20,7 @@ #include #include -#include +#include // Constructor AlgRemez::AlgRemez(double lower, double upper, long precision) diff --git a/lib/algorithms/iterative/Matrix.h b/lib/algorithms/iterative/Matrix.h index afdda2d5..cb78a598 100644 --- a/lib/algorithms/iterative/Matrix.h +++ b/lib/algorithms/iterative/Matrix.h @@ -36,7 +36,7 @@ Author: Peter Boyle #include #include #include -#include +#include /** Sign function **/ diff --git a/lib/communicator/Communicator_base.cc b/lib/communicator/Communicator_base.cc index b003d867..f882d282 100644 --- a/lib/communicator/Communicator_base.cc +++ b/lib/communicator/Communicator_base.cc @@ -25,7 +25,7 @@ Author: Peter Boyle See the full license in the file "LICENSE" in the top level distribution directory *************************************************************************************/ /* END LEGAL */ -#include "Grid.h" +#include namespace Grid { /////////////////////////////////////////////////////////////// diff --git a/lib/communicator/Communicator_mpi.cc b/lib/communicator/Communicator_mpi.cc index 65ced9c7..7f29c239 100644 --- a/lib/communicator/Communicator_mpi.cc +++ b/lib/communicator/Communicator_mpi.cc @@ -25,7 +25,7 @@ Author: Peter Boyle See the full license in the file "LICENSE" in the top level distribution directory *************************************************************************************/ /* END LEGAL */ -#include "Grid.h" +#include #include namespace Grid { diff --git a/lib/communicator/Communicator_mpi3.cc b/lib/communicator/Communicator_mpi3.cc index c707ec1f..2e17e531 100644 --- a/lib/communicator/Communicator_mpi3.cc +++ b/lib/communicator/Communicator_mpi3.cc @@ -25,7 +25,7 @@ Author: Peter Boyle See the full license in the file "LICENSE" in the top level distribution directory *************************************************************************************/ /* END LEGAL */ -#include "Grid.h" +#include #include namespace Grid { diff --git a/lib/communicator/Communicator_none.cc b/lib/communicator/Communicator_none.cc index 5e91b305..af55af46 100644 --- a/lib/communicator/Communicator_none.cc +++ b/lib/communicator/Communicator_none.cc @@ -25,7 +25,7 @@ Author: Peter Boyle See the full license in the file "LICENSE" in the top level distribution directory *************************************************************************************/ /* END LEGAL */ -#include "Grid.h" +#include namespace Grid { /////////////////////////////////////////////////////////////////////////////////////////////////// diff --git a/lib/communicator/Communicator_shmem.cc b/lib/communicator/Communicator_shmem.cc index 56e03224..b7a263a4 100644 --- a/lib/communicator/Communicator_shmem.cc +++ b/lib/communicator/Communicator_shmem.cc @@ -25,7 +25,7 @@ Author: Peter Boyle See the full license in the file "LICENSE" in the top level distribution directory *************************************************************************************/ /* END LEGAL */ -#include "Grid.h" +#include #include namespace Grid { diff --git a/lib/pugixml/pugixml.cc b/lib/pugixml/pugixml.cc index 525d1419..a4f8fde2 100644 --- a/lib/pugixml/pugixml.cc +++ b/lib/pugixml/pugixml.cc @@ -14,7 +14,7 @@ #ifndef SOURCE_PUGIXML_CPP #define SOURCE_PUGIXML_CPP -#include +#include #include #include diff --git a/lib/qcd/action/fermion/CayleyFermion5D.cc b/lib/qcd/action/fermion/CayleyFermion5D.cc index 781380e5..14b4edb6 100644 --- a/lib/qcd/action/fermion/CayleyFermion5D.cc +++ b/lib/qcd/action/fermion/CayleyFermion5D.cc @@ -30,7 +30,7 @@ Author: paboyle /* END LEGAL */ #include -#include +#include namespace Grid { diff --git a/lib/qcd/action/fermion/CayleyFermion5Dcache.cc b/lib/qcd/action/fermion/CayleyFermion5Dcache.cc index 8e7df945..84c8b5bf 100644 --- a/lib/qcd/action/fermion/CayleyFermion5Dcache.cc +++ b/lib/qcd/action/fermion/CayleyFermion5Dcache.cc @@ -29,7 +29,7 @@ Author: paboyle *************************************************************************************/ /* END LEGAL */ -#include +#include namespace Grid { diff --git a/lib/qcd/action/fermion/CayleyFermion5Ddense.cc b/lib/qcd/action/fermion/CayleyFermion5Ddense.cc index 5fa75b50..6c79da4b 100644 --- a/lib/qcd/action/fermion/CayleyFermion5Ddense.cc +++ b/lib/qcd/action/fermion/CayleyFermion5Ddense.cc @@ -30,7 +30,7 @@ Author: paboyle /* END LEGAL */ #include -#include +#include namespace Grid { diff --git a/lib/qcd/action/fermion/CayleyFermion5Dssp.cc b/lib/qcd/action/fermion/CayleyFermion5Dssp.cc index ad7daddb..0224e533 100644 --- a/lib/qcd/action/fermion/CayleyFermion5Dssp.cc +++ b/lib/qcd/action/fermion/CayleyFermion5Dssp.cc @@ -29,7 +29,7 @@ Author: paboyle *************************************************************************************/ /* END LEGAL */ -#include +#include namespace Grid { diff --git a/lib/qcd/action/fermion/CayleyFermion5Dvec.cc b/lib/qcd/action/fermion/CayleyFermion5Dvec.cc index ed742ea3..b99198fa 100644 --- a/lib/qcd/action/fermion/CayleyFermion5Dvec.cc +++ b/lib/qcd/action/fermion/CayleyFermion5Dvec.cc @@ -30,7 +30,7 @@ Author: paboyle /* END LEGAL */ -#include +#include namespace Grid { diff --git a/lib/qcd/action/fermion/ContinuedFractionFermion5D.cc b/lib/qcd/action/fermion/ContinuedFractionFermion5D.cc index e58ab4da..73681a90 100644 --- a/lib/qcd/action/fermion/ContinuedFractionFermion5D.cc +++ b/lib/qcd/action/fermion/ContinuedFractionFermion5D.cc @@ -26,7 +26,7 @@ Author: Peter Boyle See the full license in the file "LICENSE" in the top level distribution directory *************************************************************************************/ /* END LEGAL */ -#include +#include namespace Grid { namespace QCD { diff --git a/lib/qcd/action/fermion/PartialFractionFermion5D.cc b/lib/qcd/action/fermion/PartialFractionFermion5D.cc index 4fcb8784..0c3e9397 100644 --- a/lib/qcd/action/fermion/PartialFractionFermion5D.cc +++ b/lib/qcd/action/fermion/PartialFractionFermion5D.cc @@ -26,7 +26,7 @@ Author: Peter Boyle See the full license in the file "LICENSE" in the top level distribution directory *************************************************************************************/ /* END LEGAL */ -#include +#include namespace Grid { namespace QCD { diff --git a/lib/qcd/action/fermion/WilsonFermion.cc b/lib/qcd/action/fermion/WilsonFermion.cc index 04c3671f..e2b02290 100644 --- a/lib/qcd/action/fermion/WilsonFermion.cc +++ b/lib/qcd/action/fermion/WilsonFermion.cc @@ -29,7 +29,7 @@ See the full license in the file "LICENSE" in the top level distribution directory *************************************************************************************/ /* END LEGAL */ -#include +#include namespace Grid { namespace QCD { diff --git a/lib/qcd/action/fermion/WilsonFermion5D.cc b/lib/qcd/action/fermion/WilsonFermion5D.cc index d70c98c3..252fe368 100644 --- a/lib/qcd/action/fermion/WilsonFermion5D.cc +++ b/lib/qcd/action/fermion/WilsonFermion5D.cc @@ -29,8 +29,8 @@ Author: paboyle See the full license in the file "LICENSE" in the top level distribution directory *************************************************************************************/ /* END LEGAL */ -#include -#include +#include +#include namespace Grid { namespace QCD { diff --git a/lib/qcd/action/fermion/WilsonKernels.cc b/lib/qcd/action/fermion/WilsonKernels.cc index 43776c86..68efd395 100644 --- a/lib/qcd/action/fermion/WilsonKernels.cc +++ b/lib/qcd/action/fermion/WilsonKernels.cc @@ -28,7 +28,7 @@ See the full license in the file "LICENSE" in the top level distribution directory *************************************************************************************/ /* END LEGAL */ -#include +#include namespace Grid { namespace QCD { diff --git a/lib/qcd/action/fermion/WilsonKernelsAsm.cc b/lib/qcd/action/fermion/WilsonKernelsAsm.cc index d7a9edd3..6ab9961f 100644 --- a/lib/qcd/action/fermion/WilsonKernelsAsm.cc +++ b/lib/qcd/action/fermion/WilsonKernelsAsm.cc @@ -30,7 +30,7 @@ Author: Guido Cossu *************************************************************************************/ /* END LEGAL */ -#include +#include namespace Grid { diff --git a/lib/qcd/action/fermion/WilsonKernelsHand.cc b/lib/qcd/action/fermion/WilsonKernelsHand.cc index f5900832..ff1e0d29 100644 --- a/lib/qcd/action/fermion/WilsonKernelsHand.cc +++ b/lib/qcd/action/fermion/WilsonKernelsHand.cc @@ -26,7 +26,7 @@ Author: paboyle See the full license in the file "LICENSE" in the top level distribution directory *************************************************************************************/ /* END LEGAL */ -#include +#include #define REGISTER diff --git a/lib/qcd/action/fermion/WilsonTMFermion.cc b/lib/qcd/action/fermion/WilsonTMFermion.cc index f74f9f00..1d59474e 100644 --- a/lib/qcd/action/fermion/WilsonTMFermion.cc +++ b/lib/qcd/action/fermion/WilsonTMFermion.cc @@ -25,7 +25,7 @@ Author: paboyle See the full license in the file "LICENSE" in the top level distribution directory *************************************************************************************/ /* END LEGAL */ -#include +#include namespace Grid { namespace QCD { diff --git a/lib/qcd/hmc/HMC.cc b/lib/qcd/hmc/HMC.cc index 3cb39111..6386f5bf 100644 --- a/lib/qcd/hmc/HMC.cc +++ b/lib/qcd/hmc/HMC.cc @@ -27,7 +27,7 @@ Author: paboyle See the full license in the file "LICENSE" in the top level distribution directory *************************************************************************************/ /* END LEGAL */ -#include +#include namespace Grid{ namespace QCD{ diff --git a/lib/qcd/spin/Dirac.cc b/lib/qcd/spin/Dirac.cc index 8279a4a7..3e0c4b9b 100644 --- a/lib/qcd/spin/Dirac.cc +++ b/lib/qcd/spin/Dirac.cc @@ -25,7 +25,7 @@ Author: Peter Boyle See the full license in the file "LICENSE" in the top level distribution directory *************************************************************************************/ /* END LEGAL */ -#include +#include namespace Grid { diff --git a/lib/qcd/utils/SpaceTimeGrid.cc b/lib/qcd/utils/SpaceTimeGrid.cc index 695c7f69..81af5f24 100644 --- a/lib/qcd/utils/SpaceTimeGrid.cc +++ b/lib/qcd/utils/SpaceTimeGrid.cc @@ -25,7 +25,7 @@ Author: Peter Boyle See the full license in the file "LICENSE" in the top level distribution directory *************************************************************************************/ /* END LEGAL */ -#include +#include namespace Grid { namespace QCD { diff --git a/lib/serialisation/BinaryIO.cc b/lib/serialisation/BinaryIO.cc index ae0b0744..dbee9d8b 100644 --- a/lib/serialisation/BinaryIO.cc +++ b/lib/serialisation/BinaryIO.cc @@ -26,7 +26,7 @@ Author: paboyle See the full license in the file "LICENSE" in the top level distribution directory *************************************************************************************/ /* END LEGAL */ -#include +#include using namespace Grid; using namespace std; diff --git a/lib/serialisation/Hdf5IO.cc b/lib/serialisation/Hdf5IO.cc index c5313495..b9bb0b87 100644 --- a/lib/serialisation/Hdf5IO.cc +++ b/lib/serialisation/Hdf5IO.cc @@ -1,4 +1,4 @@ -#include +#include using namespace Grid; #ifndef H5_NO_NAMESPACE diff --git a/lib/serialisation/TextIO.cc b/lib/serialisation/TextIO.cc index 39b987d0..ed6f4f5c 100644 --- a/lib/serialisation/TextIO.cc +++ b/lib/serialisation/TextIO.cc @@ -26,7 +26,7 @@ Author: paboyle See the full license in the file "LICENSE" in the top level distribution directory *************************************************************************************/ /* END LEGAL */ -#include +#include using namespace Grid; using namespace std; diff --git a/lib/serialisation/XmlIO.cc b/lib/serialisation/XmlIO.cc index d8953a00..f8469ada 100644 --- a/lib/serialisation/XmlIO.cc +++ b/lib/serialisation/XmlIO.cc @@ -26,7 +26,7 @@ Author: paboyle See the full license in the file "LICENSE" in the top level distribution directory *************************************************************************************/ /* END LEGAL */ -#include +#include using namespace Grid; using namespace std; diff --git a/lib/stencil/Lebesgue.cc b/lib/stencil/Lebesgue.cc index c83975a9..97dd2cf4 100644 --- a/lib/stencil/Lebesgue.cc +++ b/lib/stencil/Lebesgue.cc @@ -26,7 +26,7 @@ Author: paboyle See the full license in the file "LICENSE" in the top level distribution directory *************************************************************************************/ /* END LEGAL */ -#include +#include #include namespace Grid { diff --git a/lib/stencil/Stencil_common.cc b/lib/stencil/Stencil_common.cc index af4e23fd..66fccb4c 100644 --- a/lib/stencil/Stencil_common.cc +++ b/lib/stencil/Stencil_common.cc @@ -26,7 +26,7 @@ Author: Peter Boyle See the full license in the file "LICENSE" in the top level distribution directory *************************************************************************************/ /* END LEGAL */ -#include "Grid.h" +#include namespace Grid { } diff --git a/tests/qdpxx/Test_qdpxx_loops_staples.cc b/tests/qdpxx/Test_qdpxx_loops_staples.cc index c5999065..cf2e0796 100644 --- a/tests/qdpxx/Test_qdpxx_loops_staples.cc +++ b/tests/qdpxx/Test_qdpxx_loops_staples.cc @@ -25,7 +25,7 @@ Author: Azusa Yamaguchi See the full license in the file "LICENSE" in the top level distribution directory *************************************************************************************/ /* END LEGAL */ -#include +#include double calc_grid_p (Grid::QCD::LatticeGaugeField & lat); double calc_chroma_p (Grid::QCD::LatticeGaugeField & lat); diff --git a/tests/qdpxx/Test_qdpxx_munprec.cc b/tests/qdpxx/Test_qdpxx_munprec.cc index 2f847702..fd60566d 100644 --- a/tests/qdpxx/Test_qdpxx_munprec.cc +++ b/tests/qdpxx/Test_qdpxx_munprec.cc @@ -26,7 +26,7 @@ Author: paboyle See the full license in the file "LICENSE" in the top level distribution directory *************************************************************************************/ /* END LEGAL */ -#include +#include int Ls=8; double M5=1.6; From 3bf993d81ad0ae1a0c9491979681163ba1222c1c Mon Sep 17 00:00:00 2001 From: Antonin Portelli Date: Thu, 26 Jan 2017 17:00:59 -0800 Subject: [PATCH 27/27] gitignore update --- .gitignore | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 5838caf7..3f6ea78e 100644 --- a/.gitignore +++ b/.gitignore @@ -104,4 +104,11 @@ lib/fftw/* # libtool macros # ################## m4/lt* -m4/libtool.m4 \ No newline at end of file +m4/libtool.m4 + +# Buck files # +############## +.buck* +buck-out +BUCK +make-bin-BUCK.sh