Loading include/dca/io/hdf5/hdf5_reader.hpp +2 −1 Original line number Diff line number Diff line Loading @@ -50,8 +50,9 @@ public: void open_file(std::string file_name); void close_file(); void open_group(std::string name) { bool open_group(std::string name) { paths_.push_back(name); return true; } void close_group() { paths_.pop_back(); Loading include/dca/io/hdf5/hdf5_writer.hpp +52 −41 Original line number Diff line number Diff line Loading @@ -51,7 +51,7 @@ public: void open_file(std::string file_name_ref, bool overwrite = true); void close_file(); void open_group(std::string new_path); bool open_group(std::string new_path); void close_group(); std::string get_path(); Loading @@ -65,54 +65,56 @@ public: static void to_file(const arbitrary_struct_t& arbitrary_struct, const std::string& file_name); template <typename Scalar> void execute(const std::string& name, Scalar value); bool execute(const std::string& name, Scalar value); template <typename Scalar> void execute(const std::string& name, const std::pair<Scalar, Scalar>& value); bool execute(const std::string& name, const std::pair<Scalar, Scalar>& value); template <typename Scalar> void execute(const std::string& name, const std::vector<Scalar>& value); bool execute(const std::string& name, const std::vector<Scalar>& value, const bool local = false); void execute(const std::string& name, const std::string& value); bool execute(const std::string& name, const std::string& value); void execute(const std::string& name, const std::vector<std::string>& value); bool execute(const std::string& name, const std::vector<std::string>& value); template <typename Scalar, std::size_t n> void execute(const std::string& name, const std::vector<std::array<Scalar, n>>& value); bool execute(const std::string& name, const std::vector<std::array<Scalar, n>>& value); template <typename Scalar> void execute(const std::string& name, const std::vector<std::vector<Scalar>>& value); bool execute(const std::string& name, const std::vector<std::vector<Scalar>>& value); template <typename domain_type> void execute(const std::string& name, const func::dmn_0<domain_type>& dmn); bool execute(const std::string& name, const func::dmn_0<domain_type>& dmn); template <typename Scalar, typename domain_type, DistType DT> void execute(const func::function<Scalar, domain_type, DT>& f); bool execute(const func::function<Scalar, domain_type, DT>& f); template <typename Scalar, typename domain_type, DistType DT> void execute(const std::string& name, const func::function<Scalar, domain_type, DT>& f); bool execute(const std::string& name, const func::function<Scalar, domain_type, DT>& f); template <typename Scalar> void execute(const std::string& name, const dca::linalg::Vector<Scalar, dca::linalg::CPU>& A); bool execute(const std::string& name, const dca::linalg::Vector<Scalar, dca::linalg::CPU>& A); template <typename Scalar> void execute(const std::string& name, const dca::linalg::Matrix<Scalar, dca::linalg::CPU>& A); bool execute(const std::string& name, const dca::linalg::Matrix<Scalar, dca::linalg::CPU>& A); template <typename Scalar> void execute(const dca::linalg::Matrix<Scalar, dca::linalg::CPU>& A) { execute(A.get_name(), A); bool execute(const dca::linalg::Matrix<Scalar, dca::linalg::CPU>& A) { return execute(A.get_name(), A); } template <class T> void execute(const std::string& name, const std::unique_ptr<T>& obj); bool execute(const std::string& name, const std::unique_ptr<T>& obj); template <class T> void execute(const std::unique_ptr<T>& obj); bool execute(const std::unique_ptr<T>& obj); void execute(const std::string& name, const io::Buffer& buffer) { bool execute(const std::string& name, const io::Buffer& buffer) { return execute(name, static_cast<io::Buffer::Container>(buffer)); } void flush() {} operator bool() const noexcept { return static_cast<bool>(file_); } Loading Loading @@ -150,34 +152,37 @@ void HDF5Writer::to_file(const arbitrary_struct_t& arbitrary_struct, const std:: } template <typename Scalar> void HDF5Writer::execute(const std::string& name, Scalar value) { bool HDF5Writer::execute(const std::string& name, Scalar value) { const std::string full_name = get_path() + "/" + name; std::vector<hsize_t> dims{1}; write(full_name, dims, HDF5_TYPE<Scalar>::get_PredType(), &value); return true; } template <typename Scalar> void HDF5Writer::execute(const std::string& name, const std::pair<Scalar, Scalar>& value) { bool HDF5Writer::execute(const std::string& name, const std::pair<Scalar, Scalar>& value) { std::string full_name = get_path() + "/" + name; std::vector<hsize_t> dims{2}; write(full_name, dims, HDF5_TYPE<Scalar>::get_PredType(), &value.first); return true; } template <typename Scalar> void HDF5Writer::execute(const std::string& name, const std::vector<Scalar>& value) //, H5File& file, std::string path) { bool HDF5Writer::execute(const std::string& name, const std::vector<Scalar>& value, [[maybe_unused]] const bool local) { if (value.size() > 0) { std::string full_name = get_path() + "/" + name; std::vector<hsize_t> dims{value.size()}; write(full_name, dims, HDF5_TYPE<Scalar>::get_PredType(), value.data()); return true; } return false; } template <typename Scalar> void HDF5Writer::execute(const std::string& name, const std::vector<std::vector<Scalar>>& value) { bool HDF5Writer::execute(const std::string& name, const std::vector<std::vector<Scalar>>& value) { std::string full_name = get_path() + "/" + name; std::vector<hvl_t> data(value.size()); Loading @@ -189,46 +194,47 @@ void HDF5Writer::execute(const std::string& name, const std::vector<std::vector< const auto type = H5::VarLenType(HDF5_TYPE<Scalar>::get_PredType()); write(full_name, std::vector<hsize_t>{data.size()}, type, data.data()); return true; } template <typename Scalar, std::size_t n> void HDF5Writer::execute(const std::string& name, const std::vector<std::array<Scalar, n>>& value) { bool HDF5Writer::execute(const std::string& name, const std::vector<std::array<Scalar, n>>& value) { if (value.size() == 0) return; return true; std::vector<hsize_t> dims{value.size(), n}; std::string full_name = get_path() + "/" + name; write(full_name, dims, HDF5_TYPE<Scalar>::get_PredType(), value.data()); return true; } template <typename domain_type> void HDF5Writer::execute(const std::string& name, const func::dmn_0<domain_type>& dmn) { bool HDF5Writer::execute(const std::string& name, const func::dmn_0<domain_type>& dmn) { open_group(name); execute("name", dmn.get_name()); execute("elements", dmn.get_elements()); close_group(); return true; } template <typename Scalar, typename domain_type, DistType DT> void HDF5Writer::execute(const func::function<Scalar, domain_type, DT>& f) { bool HDF5Writer::execute(const func::function<Scalar, domain_type, DT>& f) { if (f.size() == 0) return; return true; if (verbose_) std::cout << "\t starts writing function : " << f.get_name() << "\n"; execute(f.get_name(), f); return execute(f.get_name(), f); } template <typename Scalar, typename domain_type, DistType DT> void HDF5Writer::execute(const std::string& name, const func::function<Scalar, domain_type, DT>& f) { bool HDF5Writer::execute(const std::string& name, const func::function<Scalar, domain_type, DT>& f) { if (f.size() == 0) return; return true; const std::string full_name = get_path() + "/" + name; Loading @@ -246,20 +252,22 @@ void HDF5Writer::execute(const std::string& name, const func::function<Scalar, d std::reverse(dims.begin(), dims.end()); auto type = HDF5_TYPE<hsize_t>::get_PredType(); addAttribute(dataset, "domain-sizes", std::vector<hsize_t>{dims.size()}, type, dims.data()); return true; } template <typename Scalar> void HDF5Writer::execute(const std::string& name, bool HDF5Writer::execute(const std::string& name, const dca::linalg::Vector<Scalar, dca::linalg::CPU>& V) { std::string full_name = get_path() + "/" + name; auto dataset = write(full_name, std::vector<hsize_t>{V.size()}, HDF5_TYPE<Scalar>::get_PredType(), V.ptr()); addAttribute(dataset, "name", V.get_name()); return true; } template <typename Scalar> void HDF5Writer::execute(const std::string& name, bool HDF5Writer::execute(const std::string& name, const dca::linalg::Matrix<Scalar, dca::linalg::CPU>& A) { std::vector<hsize_t> dims{hsize_t(A.nrRows()), hsize_t(A.nrCols())}; std::vector<Scalar> linearized(dims[0] * dims[1]); Loading @@ -274,18 +282,21 @@ void HDF5Writer::execute(const std::string& name, auto dataset = write(full_name, dims, HDF5_TYPE<Scalar>::get_PredType(), linearized.data()); addAttribute(dataset, "name", A.get_name()); return true; } template <class T> void HDF5Writer::execute(const std::string& name, const std::unique_ptr<T>& obj) { bool HDF5Writer::execute(const std::string& name, const std::unique_ptr<T>& obj) { if (obj) execute(name, *obj); return true; } template <class T> void HDF5Writer::execute(const std::unique_ptr<T>& obj) { bool HDF5Writer::execute(const std::unique_ptr<T>& obj) { if (obj) execute(*obj); return true; } } // namespace io Loading include/dca/io/json/json_reader.hpp +1 −2 Original line number Diff line number Diff line Loading @@ -35,7 +35,7 @@ public: void close_file() noexcept; // Opens a new group from the currently topmost open group. Returns false if the group does not // exists, but still pushes a null group to the stack of open groups. // exists, does not push a null group to the stack of groups! bool open_group(const std::string& name) noexcept; // Closes the topmost open griup, irreardless of its validity. Returns false if trying to close Loading Loading @@ -73,7 +73,6 @@ bool JSONReader::execute(const std::string& name, T& obj) noexcept { if (!open_groups_.top()) { return false; } return open_groups_.top()->readEntry(name, obj); } Loading include/dca/io/json/json_writer.hpp +19 −13 Original line number Diff line number Diff line Loading @@ -39,7 +39,7 @@ public: // Creates or opens a pre-existing group. // Throws if there is a data entry with the same name in the current group. void open_group(const std::string& name); bool open_group(const std::string& name); // Closes the topmost open group. // Precondition: the current group is not the root. void close_group(); Loading @@ -61,24 +61,26 @@ public: // Commits to the internal data representation the value of "obj". template <class T> void execute(const std::string& name, const T& obj) noexcept; bool execute(const std::string& name, const T& obj, [[maybe_unused]] const bool = false) noexcept; template <class Scalar, class Domain, DistType DT> void execute(const std::string& name, const func::function<Scalar, Domain, DT>& f) noexcept; bool execute(const std::string& name, const func::function<Scalar, Domain, DT>& f) noexcept; template <class Scalar> void execute(const std::string& name, const linalg::Matrix<Scalar, dca::linalg::CPU>& m) noexcept; bool execute(const std::string& name, const linalg::Matrix<Scalar, dca::linalg::CPU>& m) noexcept; template <class T> void execute(const std::string& name, const std::unique_ptr<T>& ptr) noexcept { bool execute(const std::string& name, const std::unique_ptr<T>& ptr) noexcept { if (ptr) execute(name, *ptr); return true; } template <class T> void execute(const T& f) noexcept { execute(f.get_name(), f); bool execute(const T& f) noexcept { return execute(f.get_name(), f); } template <class T> void execute(const std::unique_ptr<T>& f) noexcept { bool execute(const std::unique_ptr<T>& f) noexcept { if (f) execute(f->get_name(), *f); return true; } private: Loading @@ -90,12 +92,14 @@ private: }; template <class T> void JSONWriter::execute(const std::string& name, const T& obj) noexcept { bool JSONWriter::execute(const std::string& name, const T& obj, [[maybe_unused]] const bool local) noexcept { open_groups_.top()->addEntry(name, obj); return true; } template <class Scalar, class Domain, DistType DT> void JSONWriter::execute(const std::string& name, const func::function<Scalar, Domain, DT>& f) noexcept { bool JSONWriter::execute(const std::string& name, const func::function<Scalar, Domain, DT>& f) noexcept { if (verbose_) std::cout << "\t starts writing function : " << f.get_name() << "\n"; Loading @@ -106,10 +110,11 @@ void JSONWriter::execute(const std::string& name, const func::function<Scalar, D execute("data", f.getValues()); close_group(); return true; } template <class Scalar> void JSONWriter::execute(const std::string& name, bool JSONWriter::execute(const std::string& name, const linalg::Matrix<Scalar, dca::linalg::CPU>& m) noexcept { open_group(name); Loading @@ -126,6 +131,7 @@ void JSONWriter::execute(const std::string& name, execute("data", data); close_group(); return true; } } // namespace dca::io Loading include/dca/io/reader.hpp +11 −6 Original line number Diff line number Diff line Loading @@ -20,7 +20,6 @@ #include "dca/io/hdf5/hdf5_reader.hpp" #include "dca/io/json/json_reader.hpp" #ifdef DCA_HAVE_ADIOS2 #include "dca/io/adios2/adios2_reader.hpp" #endif Loading @@ -32,7 +31,8 @@ class Reader { public: // In: format. output format, HDF5 or JSON. // In: verbose. If true, the reader outputs a short log whenever it is executed. Reader(const Concurrency& concurrency, const std::string& format, bool verbose = true) { Reader(const Concurrency& concurrency, const std::string& format, bool verbose = true) : concurrency_(concurrency) { if (format == "HDF5") { reader_.template emplace<io::HDF5Reader>(verbose); } Loading Loading @@ -60,8 +60,11 @@ public: std::visit([&](auto& var) { var.close_file(); }, reader_); } void open_group(const std::string& new_path) { std::visit([&](auto& var) { var.open_group(new_path); }, reader_); /** For reading input there is great utility in knowing if a group is present. * It isn't an exceptional circumstance if a group is not present. */ bool open_group(const std::string& new_path) { return std::visit([&](auto& var) -> bool { return var.open_group(new_path); }, reader_); } void close_group() { std::visit([&](auto& var) { var.close_group(); }, reader_); Loading @@ -78,7 +81,9 @@ private: #ifdef DCA_HAVE_ADIOS2 ,io::ADIOS2Reader<Concurrency> #endif > reader_; > reader_; const Concurrency& concurrency_; }; extern template class Reader<dca::parallel::NoConcurrency>; Loading Loading
include/dca/io/hdf5/hdf5_reader.hpp +2 −1 Original line number Diff line number Diff line Loading @@ -50,8 +50,9 @@ public: void open_file(std::string file_name); void close_file(); void open_group(std::string name) { bool open_group(std::string name) { paths_.push_back(name); return true; } void close_group() { paths_.pop_back(); Loading
include/dca/io/hdf5/hdf5_writer.hpp +52 −41 Original line number Diff line number Diff line Loading @@ -51,7 +51,7 @@ public: void open_file(std::string file_name_ref, bool overwrite = true); void close_file(); void open_group(std::string new_path); bool open_group(std::string new_path); void close_group(); std::string get_path(); Loading @@ -65,54 +65,56 @@ public: static void to_file(const arbitrary_struct_t& arbitrary_struct, const std::string& file_name); template <typename Scalar> void execute(const std::string& name, Scalar value); bool execute(const std::string& name, Scalar value); template <typename Scalar> void execute(const std::string& name, const std::pair<Scalar, Scalar>& value); bool execute(const std::string& name, const std::pair<Scalar, Scalar>& value); template <typename Scalar> void execute(const std::string& name, const std::vector<Scalar>& value); bool execute(const std::string& name, const std::vector<Scalar>& value, const bool local = false); void execute(const std::string& name, const std::string& value); bool execute(const std::string& name, const std::string& value); void execute(const std::string& name, const std::vector<std::string>& value); bool execute(const std::string& name, const std::vector<std::string>& value); template <typename Scalar, std::size_t n> void execute(const std::string& name, const std::vector<std::array<Scalar, n>>& value); bool execute(const std::string& name, const std::vector<std::array<Scalar, n>>& value); template <typename Scalar> void execute(const std::string& name, const std::vector<std::vector<Scalar>>& value); bool execute(const std::string& name, const std::vector<std::vector<Scalar>>& value); template <typename domain_type> void execute(const std::string& name, const func::dmn_0<domain_type>& dmn); bool execute(const std::string& name, const func::dmn_0<domain_type>& dmn); template <typename Scalar, typename domain_type, DistType DT> void execute(const func::function<Scalar, domain_type, DT>& f); bool execute(const func::function<Scalar, domain_type, DT>& f); template <typename Scalar, typename domain_type, DistType DT> void execute(const std::string& name, const func::function<Scalar, domain_type, DT>& f); bool execute(const std::string& name, const func::function<Scalar, domain_type, DT>& f); template <typename Scalar> void execute(const std::string& name, const dca::linalg::Vector<Scalar, dca::linalg::CPU>& A); bool execute(const std::string& name, const dca::linalg::Vector<Scalar, dca::linalg::CPU>& A); template <typename Scalar> void execute(const std::string& name, const dca::linalg::Matrix<Scalar, dca::linalg::CPU>& A); bool execute(const std::string& name, const dca::linalg::Matrix<Scalar, dca::linalg::CPU>& A); template <typename Scalar> void execute(const dca::linalg::Matrix<Scalar, dca::linalg::CPU>& A) { execute(A.get_name(), A); bool execute(const dca::linalg::Matrix<Scalar, dca::linalg::CPU>& A) { return execute(A.get_name(), A); } template <class T> void execute(const std::string& name, const std::unique_ptr<T>& obj); bool execute(const std::string& name, const std::unique_ptr<T>& obj); template <class T> void execute(const std::unique_ptr<T>& obj); bool execute(const std::unique_ptr<T>& obj); void execute(const std::string& name, const io::Buffer& buffer) { bool execute(const std::string& name, const io::Buffer& buffer) { return execute(name, static_cast<io::Buffer::Container>(buffer)); } void flush() {} operator bool() const noexcept { return static_cast<bool>(file_); } Loading Loading @@ -150,34 +152,37 @@ void HDF5Writer::to_file(const arbitrary_struct_t& arbitrary_struct, const std:: } template <typename Scalar> void HDF5Writer::execute(const std::string& name, Scalar value) { bool HDF5Writer::execute(const std::string& name, Scalar value) { const std::string full_name = get_path() + "/" + name; std::vector<hsize_t> dims{1}; write(full_name, dims, HDF5_TYPE<Scalar>::get_PredType(), &value); return true; } template <typename Scalar> void HDF5Writer::execute(const std::string& name, const std::pair<Scalar, Scalar>& value) { bool HDF5Writer::execute(const std::string& name, const std::pair<Scalar, Scalar>& value) { std::string full_name = get_path() + "/" + name; std::vector<hsize_t> dims{2}; write(full_name, dims, HDF5_TYPE<Scalar>::get_PredType(), &value.first); return true; } template <typename Scalar> void HDF5Writer::execute(const std::string& name, const std::vector<Scalar>& value) //, H5File& file, std::string path) { bool HDF5Writer::execute(const std::string& name, const std::vector<Scalar>& value, [[maybe_unused]] const bool local) { if (value.size() > 0) { std::string full_name = get_path() + "/" + name; std::vector<hsize_t> dims{value.size()}; write(full_name, dims, HDF5_TYPE<Scalar>::get_PredType(), value.data()); return true; } return false; } template <typename Scalar> void HDF5Writer::execute(const std::string& name, const std::vector<std::vector<Scalar>>& value) { bool HDF5Writer::execute(const std::string& name, const std::vector<std::vector<Scalar>>& value) { std::string full_name = get_path() + "/" + name; std::vector<hvl_t> data(value.size()); Loading @@ -189,46 +194,47 @@ void HDF5Writer::execute(const std::string& name, const std::vector<std::vector< const auto type = H5::VarLenType(HDF5_TYPE<Scalar>::get_PredType()); write(full_name, std::vector<hsize_t>{data.size()}, type, data.data()); return true; } template <typename Scalar, std::size_t n> void HDF5Writer::execute(const std::string& name, const std::vector<std::array<Scalar, n>>& value) { bool HDF5Writer::execute(const std::string& name, const std::vector<std::array<Scalar, n>>& value) { if (value.size() == 0) return; return true; std::vector<hsize_t> dims{value.size(), n}; std::string full_name = get_path() + "/" + name; write(full_name, dims, HDF5_TYPE<Scalar>::get_PredType(), value.data()); return true; } template <typename domain_type> void HDF5Writer::execute(const std::string& name, const func::dmn_0<domain_type>& dmn) { bool HDF5Writer::execute(const std::string& name, const func::dmn_0<domain_type>& dmn) { open_group(name); execute("name", dmn.get_name()); execute("elements", dmn.get_elements()); close_group(); return true; } template <typename Scalar, typename domain_type, DistType DT> void HDF5Writer::execute(const func::function<Scalar, domain_type, DT>& f) { bool HDF5Writer::execute(const func::function<Scalar, domain_type, DT>& f) { if (f.size() == 0) return; return true; if (verbose_) std::cout << "\t starts writing function : " << f.get_name() << "\n"; execute(f.get_name(), f); return execute(f.get_name(), f); } template <typename Scalar, typename domain_type, DistType DT> void HDF5Writer::execute(const std::string& name, const func::function<Scalar, domain_type, DT>& f) { bool HDF5Writer::execute(const std::string& name, const func::function<Scalar, domain_type, DT>& f) { if (f.size() == 0) return; return true; const std::string full_name = get_path() + "/" + name; Loading @@ -246,20 +252,22 @@ void HDF5Writer::execute(const std::string& name, const func::function<Scalar, d std::reverse(dims.begin(), dims.end()); auto type = HDF5_TYPE<hsize_t>::get_PredType(); addAttribute(dataset, "domain-sizes", std::vector<hsize_t>{dims.size()}, type, dims.data()); return true; } template <typename Scalar> void HDF5Writer::execute(const std::string& name, bool HDF5Writer::execute(const std::string& name, const dca::linalg::Vector<Scalar, dca::linalg::CPU>& V) { std::string full_name = get_path() + "/" + name; auto dataset = write(full_name, std::vector<hsize_t>{V.size()}, HDF5_TYPE<Scalar>::get_PredType(), V.ptr()); addAttribute(dataset, "name", V.get_name()); return true; } template <typename Scalar> void HDF5Writer::execute(const std::string& name, bool HDF5Writer::execute(const std::string& name, const dca::linalg::Matrix<Scalar, dca::linalg::CPU>& A) { std::vector<hsize_t> dims{hsize_t(A.nrRows()), hsize_t(A.nrCols())}; std::vector<Scalar> linearized(dims[0] * dims[1]); Loading @@ -274,18 +282,21 @@ void HDF5Writer::execute(const std::string& name, auto dataset = write(full_name, dims, HDF5_TYPE<Scalar>::get_PredType(), linearized.data()); addAttribute(dataset, "name", A.get_name()); return true; } template <class T> void HDF5Writer::execute(const std::string& name, const std::unique_ptr<T>& obj) { bool HDF5Writer::execute(const std::string& name, const std::unique_ptr<T>& obj) { if (obj) execute(name, *obj); return true; } template <class T> void HDF5Writer::execute(const std::unique_ptr<T>& obj) { bool HDF5Writer::execute(const std::unique_ptr<T>& obj) { if (obj) execute(*obj); return true; } } // namespace io Loading
include/dca/io/json/json_reader.hpp +1 −2 Original line number Diff line number Diff line Loading @@ -35,7 +35,7 @@ public: void close_file() noexcept; // Opens a new group from the currently topmost open group. Returns false if the group does not // exists, but still pushes a null group to the stack of open groups. // exists, does not push a null group to the stack of groups! bool open_group(const std::string& name) noexcept; // Closes the topmost open griup, irreardless of its validity. Returns false if trying to close Loading Loading @@ -73,7 +73,6 @@ bool JSONReader::execute(const std::string& name, T& obj) noexcept { if (!open_groups_.top()) { return false; } return open_groups_.top()->readEntry(name, obj); } Loading
include/dca/io/json/json_writer.hpp +19 −13 Original line number Diff line number Diff line Loading @@ -39,7 +39,7 @@ public: // Creates or opens a pre-existing group. // Throws if there is a data entry with the same name in the current group. void open_group(const std::string& name); bool open_group(const std::string& name); // Closes the topmost open group. // Precondition: the current group is not the root. void close_group(); Loading @@ -61,24 +61,26 @@ public: // Commits to the internal data representation the value of "obj". template <class T> void execute(const std::string& name, const T& obj) noexcept; bool execute(const std::string& name, const T& obj, [[maybe_unused]] const bool = false) noexcept; template <class Scalar, class Domain, DistType DT> void execute(const std::string& name, const func::function<Scalar, Domain, DT>& f) noexcept; bool execute(const std::string& name, const func::function<Scalar, Domain, DT>& f) noexcept; template <class Scalar> void execute(const std::string& name, const linalg::Matrix<Scalar, dca::linalg::CPU>& m) noexcept; bool execute(const std::string& name, const linalg::Matrix<Scalar, dca::linalg::CPU>& m) noexcept; template <class T> void execute(const std::string& name, const std::unique_ptr<T>& ptr) noexcept { bool execute(const std::string& name, const std::unique_ptr<T>& ptr) noexcept { if (ptr) execute(name, *ptr); return true; } template <class T> void execute(const T& f) noexcept { execute(f.get_name(), f); bool execute(const T& f) noexcept { return execute(f.get_name(), f); } template <class T> void execute(const std::unique_ptr<T>& f) noexcept { bool execute(const std::unique_ptr<T>& f) noexcept { if (f) execute(f->get_name(), *f); return true; } private: Loading @@ -90,12 +92,14 @@ private: }; template <class T> void JSONWriter::execute(const std::string& name, const T& obj) noexcept { bool JSONWriter::execute(const std::string& name, const T& obj, [[maybe_unused]] const bool local) noexcept { open_groups_.top()->addEntry(name, obj); return true; } template <class Scalar, class Domain, DistType DT> void JSONWriter::execute(const std::string& name, const func::function<Scalar, Domain, DT>& f) noexcept { bool JSONWriter::execute(const std::string& name, const func::function<Scalar, Domain, DT>& f) noexcept { if (verbose_) std::cout << "\t starts writing function : " << f.get_name() << "\n"; Loading @@ -106,10 +110,11 @@ void JSONWriter::execute(const std::string& name, const func::function<Scalar, D execute("data", f.getValues()); close_group(); return true; } template <class Scalar> void JSONWriter::execute(const std::string& name, bool JSONWriter::execute(const std::string& name, const linalg::Matrix<Scalar, dca::linalg::CPU>& m) noexcept { open_group(name); Loading @@ -126,6 +131,7 @@ void JSONWriter::execute(const std::string& name, execute("data", data); close_group(); return true; } } // namespace dca::io Loading
include/dca/io/reader.hpp +11 −6 Original line number Diff line number Diff line Loading @@ -20,7 +20,6 @@ #include "dca/io/hdf5/hdf5_reader.hpp" #include "dca/io/json/json_reader.hpp" #ifdef DCA_HAVE_ADIOS2 #include "dca/io/adios2/adios2_reader.hpp" #endif Loading @@ -32,7 +31,8 @@ class Reader { public: // In: format. output format, HDF5 or JSON. // In: verbose. If true, the reader outputs a short log whenever it is executed. Reader(const Concurrency& concurrency, const std::string& format, bool verbose = true) { Reader(const Concurrency& concurrency, const std::string& format, bool verbose = true) : concurrency_(concurrency) { if (format == "HDF5") { reader_.template emplace<io::HDF5Reader>(verbose); } Loading Loading @@ -60,8 +60,11 @@ public: std::visit([&](auto& var) { var.close_file(); }, reader_); } void open_group(const std::string& new_path) { std::visit([&](auto& var) { var.open_group(new_path); }, reader_); /** For reading input there is great utility in knowing if a group is present. * It isn't an exceptional circumstance if a group is not present. */ bool open_group(const std::string& new_path) { return std::visit([&](auto& var) -> bool { return var.open_group(new_path); }, reader_); } void close_group() { std::visit([&](auto& var) { var.close_group(); }, reader_); Loading @@ -78,7 +81,9 @@ private: #ifdef DCA_HAVE_ADIOS2 ,io::ADIOS2Reader<Concurrency> #endif > reader_; > reader_; const Concurrency& concurrency_; }; extern template class Reader<dca::parallel::NoConcurrency>; Loading