mirror of
https://github.com/triqs/dft_tools
synced 2024-12-25 13:53:40 +01:00
parameters : small details
- an include missing on OS X - change serialization in the general case where hdf5 can be used, (version of hdf5 high enough) to use only one buffer, not a buffer per field. - put back the mpi_param example.
This commit is contained in:
parent
27af80c04e
commit
4789dccda6
@ -26,12 +26,9 @@ int main(int argc, char* argv[]) {
|
|||||||
P["d"] = 2.7;
|
P["d"] = 2.7;
|
||||||
P["s"] = std::string("-14.3");
|
P["s"] = std::string("-14.3");
|
||||||
}
|
}
|
||||||
/*
|
|
||||||
* WITH SERIALIZATION
|
|
||||||
std::cout << "Before bcast rank " << world.rank() << " : " << P << std::endl ;
|
std::cout << "Before bcast rank " << world.rank() << " : " << P << std::endl ;
|
||||||
boost::mpi::broadcast(world,P,0);
|
boost::mpi::broadcast(world,P,0);
|
||||||
std::cout << "After bcast rank " << world.rank() << " : " << P << std::endl ;
|
std::cout << "After bcast rank " << world.rank() << " : " << P << std::endl ;
|
||||||
*/
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -125,8 +125,8 @@ namespace params {
|
|||||||
template <typename T> bool has_type() const { return index == typeid(T); }
|
template <typename T> bool has_type() const { return index == typeid(T); }
|
||||||
|
|
||||||
public:
|
public:
|
||||||
#ifdef TRIQS_SERIALIZATION_WITH_BOOST
|
#ifdef TRIQS_SERIALIZATION_WITH_HDF5_IMPOSSIBLE
|
||||||
_field() : index(typeid(void)) {} // BREAKS invariant : only used for BOOST serialization.
|
_field() : index(typeid(void)) {} // BREAKS invariant : only used for BOOST serialization failsafe mode.
|
||||||
#endif
|
#endif
|
||||||
_field(_field &&c) = default;
|
_field(_field &&c) = default;
|
||||||
_field(_field const &x) : index(x.index), p(x.p ? x.p->clone() : nullptr), name_(x.name_), modified(x.modified), no_default_value(x.no_default_value) {} // regular type
|
_field(_field const &x) : index(x.index), p(x.p ? x.p->clone() : nullptr), name_(x.name_), modified(x.modified), no_default_value(x.no_default_value) {} // regular type
|
||||||
@ -182,6 +182,7 @@ namespace params {
|
|||||||
BOOST_PP_SEQ_FOR_EACH(CAST_OPERATOR, nil, TRIQS_UTIL_OPAQUE_OBJECT_PREDEFINED_CAST);
|
BOOST_PP_SEQ_FOR_EACH(CAST_OPERATOR, nil, TRIQS_UTIL_OPAQUE_OBJECT_PREDEFINED_CAST);
|
||||||
#undef CAST_OPERATOR
|
#undef CAST_OPERATOR
|
||||||
|
|
||||||
|
#ifdef TRIQS_SERIALIZATION_WITH_HDF5_IMPOSSIBLE
|
||||||
// ----- Boost serialisation
|
// ----- Boost serialisation
|
||||||
|
|
||||||
template <class Archive> void save(Archive &ar, const unsigned int version) const {
|
template <class Archive> void save(Archive &ar, const unsigned int version) const {
|
||||||
@ -194,6 +195,7 @@ namespace params {
|
|||||||
p->deserialize(s);
|
p->deserialize(s);
|
||||||
}
|
}
|
||||||
BOOST_SERIALIZATION_SPLIT_MEMBER();
|
BOOST_SERIALIZATION_SPLIT_MEMBER();
|
||||||
|
#endif
|
||||||
|
|
||||||
friend std::ostream &operator<<(std::ostream &out, _field const &ob) { return ob.p->print(out); }
|
friend std::ostream &operator<<(std::ostream &out, _field const &ob) { return ob.p->print(out); }
|
||||||
|
|
||||||
|
@ -4,6 +4,7 @@
|
|||||||
#include <triqs/utility/serialization.hpp>
|
#include <triqs/utility/serialization.hpp>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <boost/algorithm/string.hpp>
|
#include <boost/algorithm/string.hpp>
|
||||||
|
#include <iomanip>
|
||||||
|
|
||||||
namespace triqs {
|
namespace triqs {
|
||||||
namespace params {
|
namespace params {
|
||||||
|
@ -48,9 +48,11 @@ namespace params {
|
|||||||
std::string key;
|
std::string key;
|
||||||
_field f;
|
_field f;
|
||||||
std::string doc;
|
std::string doc;
|
||||||
|
#ifdef TRIQS_SERIALIZATION_WITH_HDF5_IMPOSSIBLE
|
||||||
template <class Archive> void serialize(Archive& ar, const unsigned int version) {
|
template <class Archive> void serialize(Archive& ar, const unsigned int version) {
|
||||||
ar& TRIQS_MAKE_NVP("key", key) & TRIQS_MAKE_NVP("f", f) & TRIQS_MAKE_NVP("doc", doc);
|
ar& TRIQS_MAKE_NVP("key", key) & TRIQS_MAKE_NVP("f", f) & TRIQS_MAKE_NVP("doc", doc);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
};
|
};
|
||||||
using _data_t = std::vector<_data_elem>;
|
using _data_t = std::vector<_data_elem>;
|
||||||
_data_t _data;
|
_data_t _data;
|
||||||
@ -59,7 +61,23 @@ namespace params {
|
|||||||
_data_t::const_iterator find(std::string const& key) const;
|
_data_t::const_iterator find(std::string const& key) const;
|
||||||
|
|
||||||
friend class boost::serialization::access;
|
friend class boost::serialization::access;
|
||||||
template <class Archive> void serialize(Archive& ar, const unsigned int version) { ar& TRIQS_MAKE_NVP("_data", _data); }
|
#ifdef TRIQS_SERIALIZATION_WITH_HDF5_IMPOSSIBLE
|
||||||
|
template <class Archive> void serialize(Archive& ar, const unsigned int version) {
|
||||||
|
ar& TRIQS_MAKE_NVP("_data", _data);
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
// do it at once, with one buffer only.
|
||||||
|
template <class Archive> void save(Archive &ar, const unsigned int version) const {
|
||||||
|
std::string s = h5::serialize(*this);
|
||||||
|
ar << TRIQS_MAKE_NVP("seria_str", s);
|
||||||
|
}
|
||||||
|
template <class Archive> void load(Archive &ar, const unsigned int version) {
|
||||||
|
std::string s;
|
||||||
|
ar >> TRIQS_MAKE_NVP("seria_str", s);
|
||||||
|
*this = h5::deserialize<parameters>(s);
|
||||||
|
}
|
||||||
|
BOOST_SERIALIZATION_SPLIT_MEMBER();
|
||||||
|
#endif
|
||||||
|
|
||||||
public:
|
public:
|
||||||
parameters();
|
parameters();
|
||||||
|
@ -20,14 +20,14 @@
|
|||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#if defined(TRIQS_SERIALIZATION_USE_BOOST) or not H5_VERSION_GE(1,8,9)
|
#if defined(TRIQS_SERIALIZATION_DO_NOT_USE_HDF5) or not H5_VERSION_GE(1,8,9)
|
||||||
|
|
||||||
|
#define TRIQS_SERIALIZATION_WITH_HDF5_IMPOSSIBLE
|
||||||
#include "./boost_serialization.hpp"
|
#include "./boost_serialization.hpp"
|
||||||
|
|
||||||
#define TRIQS_SERIALIZATION_WITH_BOOST
|
|
||||||
#else
|
#else
|
||||||
#include "../h5/serialization.hpp"
|
|
||||||
#define TRIQS_SERIALIZATION_WITH_HDF5
|
|
||||||
|
|
||||||
|
#include "../h5/serialization.hpp"
|
||||||
namespace triqs {
|
namespace triqs {
|
||||||
using h5::serialize;
|
using h5::serialize;
|
||||||
using h5::deserialize;
|
using h5::deserialize;
|
||||||
|
Loading…
Reference in New Issue
Block a user