1#ifndef VISTLE_ARCHIVES_CONFIG_H
2#define VISTLE_ARCHIVES_CONFIG_H
6#define USE_BOOST_ARCHIVE_MPI
9#ifdef USE_INTROSPECTION_ARCHIVE
10#ifndef USE_BOOST_ARCHIVE
11#define USE_BOOST_ARCHIVE
15#ifdef USE_BOOST_ARCHIVE
16#ifndef USE_BOOST_ARCHIVE_MPI
17#define USE_BOOST_ARCHIVE_MPI
42template<
class Archive>
46struct archive_helper {
49 template<
class Base,
class Derived>
50 static BaseClass<Base> serialize_base(Derived &d);
52 template<
class Object>
54 template<
class Object>
55 static NameValuePair<Object> make_nvp(
const char *name,
Object &d);
59 template<
class T,
class S>
60 static ArrayWrapper<T> wrap_array(T *t,
bool exact, S nx, S ny = 1, S nz = 1);
62 template<
class Archive>
66template<
class Base,
class Derived,
class Archive>
67typename archive_helper<typename archive_tag<Archive>::type>::template BaseClass<Base> serialize_base(
const Archive &,
70 return archive_helper<typename archive_tag<Archive>::type>::template serialize_base<Base>(d);
73template<
class Archive,
class Object>
74typename archive_helper<typename archive_tag<Archive>::type>::template NameValuePair<Object> make_nvp(
const char *name,
77 return archive_helper<typename archive_tag<Archive>::type>::make_nvp(name, d);
80template<
class Archive,
class T,
class S>
81typename archive_helper<typename archive_tag<Archive>::type>::template ArrayWrapper<T>
82wrap_array(T *t,
bool exact, S nx, S ny = 1, S nz = 1)
84 return archive_helper<typename archive_tag<Archive>::type>::wrap_array(t, exact, nx, ny, nz);
90#ifdef USE_BOOST_ARCHIVE
91#include <boost/serialization/nvp.hpp>
92#include <boost/serialization/array.hpp>
93#if BOOST_VERSION >= 106400
94#include <boost/serialization/array_wrapper.hpp>
95#include <boost/serialization/array_optimization.hpp>
106struct archive_tag<boost_oarchive> {
107 typedef boost_tag type;
110struct archive_tag<boost_iarchive> {
111 typedef boost_tag type;
115struct archive_helper<boost_tag> {
117 using BaseClass = Base &;
118 template<
class Base,
class Derived>
119 static BaseClass<Base> serialize_base(Derived &d)
121 return boost::serialization::base_object<Base>(d);
124 template<
class Object>
125 using NameValuePair =
const boost::serialization::nvp<Object>;
126 template<
class Object>
127 static NameValuePair<Object> make_nvp(
const char *name, Object &obj)
129 return boost::serialization::make_nvp(name, obj);
132#if BOOST_VERSION > 105500
134 using ArrayWrapper =
const boost::serialization::array_wrapper<T>;
137 using ArrayWrapper =
const boost::serialization::array<T>;
139 template<
class T,
class S>
140 static ArrayWrapper<T> wrap_array(T *t,
bool exact, S nx, S ny, S nz)
142 return boost::serialization::make_array(t, nx * ny * nz);
149#include <yas/binary_iarchive.hpp>
150#include <yas/binary_oarchive.hpp>
151#include <yas/serialize.hpp>
152#include <yas/boost_types.hpp>
153#include <yas/types/concepts/array.hpp>
173template<
class Archive>
186struct ZfpParameters {
187 FieldCompressionMode mode = Uncompressed;
190 double accuracy = 1e-20;
195 static const zfp_type value = zfp_type_none;
199struct zfp_type_map<int32_t> {
200 static const zfp_type value = zfp_type_int32;
203struct zfp_type_map<int64_t> {
204 static const zfp_type value = zfp_type_int64;
207struct zfp_type_map<float> {
208 static const zfp_type value = zfp_type_float;
211struct zfp_type_map<double> {
212 static const zfp_type value = zfp_type_double;
215template<zfp_type type>
216bool compressZfp(
buffer &compressed,
const void *src,
const Index dim[3],
const ZfpParameters ¶m);
217template<zfp_type type>
218bool decompressZfp(
void *dest,
const buffer &compressed,
const Index dim[3]);
225 template<
class Base,
class Derived>
228 return yas::base_object<Base>(d);
231 template<
class Object>
233 template<
class Object>
241 struct ArrayWrapper {
250 const T *
begin()
const {
return m_begin; }
251 T *
end() {
return m_end; }
252 const T *
end()
const {
return m_end; }
253 bool empty()
const {
return m_end == m_begin; }
256 const T &
operator[](
size_t idx)
const {
return *(m_begin + idx); }
257 void push_back(
const T &) { assert(
"not supported" == 0); }
261 std::cerr <<
"requesting resize from " << size() <<
" to " << sz << std::endl;
262 assert(
"not supported" == 0);
267 m_dim[0] = (
Index)sx;
268 m_dim[1] = (
Index)sy;
269 m_dim[2] = (
Index)sz;
273 template<
class Archive>
278 template<
class Archive>
283 template<
class Archive>
286 bool compress =
false;
289 ar &m_dim[0] & m_dim[1] & m_dim[2];
294 for (
int c = 0; c < 3; ++c)
295 dim[c] = m_dim[c] == 1 ? 0 : m_dim[c];
296 decompressZfp<zfp_type_map<T>::value>(
static_cast<void *
>(m_begin), compressed, dim);
299 yas::detail::concepts::array::load<yas_flags>(ar, *
this);
302 template<
class Archive>
305 bool compress = ar.compressionMode() != Uncompressed && !m_exact;
310 param.mode = ar.compressionMode();
311 param.rate = ar.zfpRate();
312 param.precision = ar.zfpPrecision();
313 param.accuracy = ar.zfpAccuracy();
317 for (
int c = 0; c < 3; ++c)
318 dim[c] = m_dim[c] == 1 ? 0 : m_dim[c];
319 if (compressZfp<zfp_type_map<T>::value>(compressed,
static_cast<const void *
>(m_begin), dim, param)) {
321 ar &m_dim[0] & m_dim[1] & m_dim[2];
324 std::cerr <<
"compression failed" << std::endl;
333 yas::detail::concepts::array::save<yas_flags>(ar, *
this);
338 template<
class T,
class S>
339 static ArrayWrapper<T>
wrap_array(T *t,
bool exact, S nx, S ny, S nz)
341 ArrayWrapper<T> wrap(t, t + nx * ny * nz);
342 wrap.setExact(exact);
343 wrap.setDimensions(nx, ny, nz);
347 template<
class Archive>
354extern template bool V_COREEXPORT decompressZfp<zfp_type_int32>(
void *dest,
const buffer &compressed,
356extern template bool V_COREEXPORT decompressZfp<zfp_type_int64>(
void *dest,
const buffer &compressed,
358extern template bool V_COREEXPORT decompressZfp<zfp_type_float>(
void *dest,
const buffer &compressed,
360extern template bool V_COREEXPORT decompressZfp<zfp_type_double>(
void *dest,
const buffer &compressed,
365 const ZfpParameters ¶m);
366extern template bool V_COREEXPORT compressZfp<zfp_type_int32>(
buffer &compressed,
const void *src,
const Index dim[3],
367 const ZfpParameters ¶m);
368extern template bool V_COREEXPORT compressZfp<zfp_type_int64>(
buffer &compressed,
const void *src,
const Index dim[3],
369 const ZfpParameters ¶m);
370extern template bool V_COREEXPORT compressZfp<zfp_type_float>(
buffer &compressed,
const void *src,
const Index dim[3],
371 const ZfpParameters ¶m);
372extern template bool V_COREEXPORT compressZfp<zfp_type_double>(
buffer &compressed,
const void *src,
const Index dim[3],
373 const ZfpParameters ¶m);
377using detail::ZfpParameters;
378using detail::compressZfp;
379using detail::decompressZfp;
385#ifdef USE_INTROSPECTION_ARCHIVE
386class FindObjectReferenceOArchive;
392#elif defined(USE_BOOST_ARCHIVE)
397using detail::serialize_base;
400#ifdef USE_BOOST_ARCHIVE_MPI
401#include <boost/serialization/access.hpp>
402#include <boost/serialization/split_member.hpp>
404#ifdef USE_BOOST_ARCHIVE
405#include <boost/serialization/assume_abstract.hpp>
406#include <boost/archive/archive_exception.hpp>
408#define ARCHIVE_ASSUME_ABSTRACT_BOOST(obj) BOOST_SERIALIZATION_ASSUME_ABSTRACT(obj)
410#define ARCHIVE_ASSUME_ABSTRACT_BOOST(obj)
413#define ARCHIVE_ASSUME_ABSTRACT_YAS(obj)
415#include <yas/serialize.hpp>
416#include <yas/object.hpp>
417#include <yas/std_types.hpp>
418#include <yas/std_traits.hpp>
419#include <yas/std_streams.hpp>
420#include <yas/boost_types.hpp>
425#ifdef DEBUG_SERIALIZATION
427inline const boost::serialization::nvp<T> vistle_make_nvp(
const char *name, T &t)
429 std::cerr <<
"<" << name <<
">" << std::endl;
430 return boost::serialization::make_nvp<T>(name, t);
433#define V_NAME(name, obj) \
434 vistle_make_nvp(name, (obj)); \
435 std::cerr << "</" << name << ">" << std::endl;
438#define V_NAME(name, obj) boost::serialization::make_nvp(name, (obj))
441#define V_NAME(ar, name, obj) (obj)
445#ifdef USE_BOOST_ARCHIVE_MPI
446#define ARCHIVE_ACCESS_BOOST friend class boost::serialization::access;
448#define ARCHIVE_ACCESS_BOOST
450#if defined(USE_BOOST_ARCHIVE_MPI)
451#define ARCHIVE_FORWARD_SERIALIZE \
452 template<class Archive> \
453 void serialize(Archive &ar, const unsigned int ) \
458#define ARCHIVE_FORWARD_SERIALIZE
461#define ARCHIVE_ACCESS_YAS public:
463#define ARCHIVE_ACCESS_YAS
465#define ARCHIVE_ACCESS ARCHIVE_ACCESS_BOOST ARCHIVE_ACCESS_YAS ARCHIVE_FORWARD_SERIALIZE
466#define ARCHIVE_ASSUME_ABSTRACT(obj) ARCHIVE_ASSUME_ABSTRACT_BOOST(obj) ARCHIVE_ASSUME_ABSTRACT_YAS(obj)
468#ifdef USE_BOOST_ARCHIVE_MPI
469#define BOOST_ARCHIVE_ACCESS_SPLIT \
470 friend class boost::serialization::access; \
471 template<class Archive> \
472 void serialize(Archive &ar, const unsigned int version) \
474 boost::serialization::split_member(ar, *this, version); \
476 template<class Archive> \
477 void save(Archive &ar, const unsigned int version) const \
481 template<class Archive> \
482 void load(Archive &ar, const unsigned int version) \
487#define BOOST_ARCHIVE_ACCESS_SPLIT
489#define YAS_ARCHIVE_ACCESS_SPLIT \
491 template<class Archive> \
492 void serialize(Archive &ar) const \
496 template<class Archive> \
497 void serialize(Archive &ar) \
502#define ARCHIVE_ACCESS_SPLIT \
504 BOOST_ARCHIVE_ACCESS_SPLIT YAS_ARCHIVE_ACCESS_SPLIT
506#ifdef USE_BOOST_ARCHIVE
507#define ARCHIVE_REGISTRATION_BOOST(override) \
508 virtual void saveToArchive(boost_oarchive &ar) const override; \
509 virtual void loadFromArchive(boost_iarchive &ar) override;
510#define ARCHIVE_REGISTRATION_BOOST_INLINE \
511 void saveToArchive(boost_oarchive &ar) const override { this->serialize(ar); } \
512 void loadFromArchive(boost_iarchive &ar) override { this->serialize(ar); }
513#define ARCHIVE_REGISTRATION_BOOST_IMPL(ObjType, prefix) \
514 prefix void ObjType::saveToArchive(boost_oarchive &ar) const { this->serialize(ar); } \
515 prefix void ObjType::loadFromArchive(boost_iarchive &ar) { this->serialize(ar); }
517#define ARCHIVE_REGISTRATION_BOOST(override)
518#define ARCHIVE_REGISTRATION_BOOST_INLINE
519#define ARCHIVE_REGISTRATION_BOOST_IMPL(ObjType, prefix)
523#define ARCHIVE_REGISTRATION_YAS(override) \
524 virtual void saveToArchive(yas_oarchive &ar) const override; \
525 virtual void loadFromArchive(yas_iarchive &ar) override;
526#define ARCHIVE_REGISTRATION_YAS_INLINE \
527 void saveToArchive(yas_oarchive &ar) const override { this->serialize(ar); } \
528 void loadFromArchive(yas_iarchive &ar) override { this->serialize(ar); }
529#define ARCHIVE_REGISTRATION_YAS_IMPL(ObjType, prefix) \
530 prefix void ObjType::saveToArchive(yas_oarchive &ar) const { this->serialize(ar); } \
531 prefix void ObjType::loadFromArchive(yas_iarchive &ar) { this->serialize(ar); }
533#define ARCHIVE_REGISTRATION_YAS(override)
534#define ARCHIVE_REGISTRATION_YAS_INLINE
535#define ARCHIVE_REGISTRATION_YAS_IMPL(ObjType, prefix)
537#ifdef USE_INTROSPECTION_ARCHIVE
538#define ARCHIVE_REGISTRATION_INTROSPECT \
539 void save(FindObjectReferenceOArchive &ar) const override { const_cast<ObjType *>(this)->serialize(ar, 0); }
541#define ARCHIVE_REGISTRATION_INTROSPECT
543#define ARCHIVE_REGISTRATION(override) \
544 ARCHIVE_REGISTRATION_BOOST(override) ARCHIVE_REGISTRATION_YAS(override) ARCHIVE_REGISTRATION_INTROSPECT
545#define ARCHIVE_REGISTRATION_INLINE \
546 ARCHIVE_REGISTRATION_BOOST_INLINE ARCHIVE_REGISTRATION_YAS_INLINE ARCHIVE_REGISTRATION_INTROSPECT
547#define ARCHIVE_REGISTRATION_IMPL(ObjType, prefix) \
548 ARCHIVE_REGISTRATION_BOOST_IMPL(ObjType, prefix) ARCHIVE_REGISTRATION_YAS_IMPL(ObjType, prefix)
Definition: archives.h:342
Definition: archives.h:197
#define V_COREEXPORT
Definition: export.h:9
yas::mem_ostream type
Definition: archives_config.h:182
const std::size_t yas_flags
Definition: archives_config.h:161
yas_tag type
Definition: archives_config.h:166
yas::mem_istream type
Definition: archives_config.h:178
yas_tag type
Definition: archives_config.h:170
Definition: archives_config.h:174
Definition: archives_config.h:163
Definition: allobjects.cpp:30
std::vector< char, allocator< char > > buffer
Definition: buffer.h:9
yas_iarchive iarchive
Definition: archives_config.h:391
yas_oarchive oarchive
Definition: archives_config.h:390
DEFINE_ENUM_WITH_STRING_CONVERSIONS(FieldCompressionMode,(Uncompressed)(ZfpFixedRate)(ZfpAccuracy)(ZfpPrecision)) namespace detail
Definition: archives_config.h:38
uint32_t Index
Definition: index.h:13
const T & operator[](size_t idx) const
Definition: archives_config.h:256
void load(Archive &ar)
Definition: archives_config.h:284
T * m_begin
Definition: archives_config.h:244
void setExact(bool exact)
Definition: archives_config.h:271
void push_back(const T &)
Definition: archives_config.h:257
const T * begin() const
Definition: archives_config.h:250
void resize(std::size_t sz)
Definition: archives_config.h:258
bool empty() const
Definition: archives_config.h:253
T * end()
Definition: archives_config.h:251
T & operator[](size_t idx)
Definition: archives_config.h:255
Index size() const
Definition: archives_config.h:254
void serialize(Archive &ar) const
Definition: archives_config.h:274
T * begin()
Definition: archives_config.h:249
T value_type
Definition: archives_config.h:242
void setDimensions(size_t sx, size_t sy, size_t sz)
Definition: archives_config.h:265
const T * end() const
Definition: archives_config.h:252
void serialize(Archive &ar)
Definition: archives_config.h:279
T & reference
Definition: archives_config.h:243
ArrayWrapper(T *begin, T *end)
Definition: archives_config.h:248
void save(Archive &ar) const
Definition: archives_config.h:303
static BaseClass< Base > serialize_base(Derived &d)
Definition: archives_config.h:226
static NameValuePair< Object > make_nvp(const char *name, Object &obj)
Definition: archives_config.h:234
Base & BaseClass
Definition: archives_config.h:224
typename ArchiveStreamType< Archive >::type StreamType
Definition: archives_config.h:348
static ArrayWrapper< T > wrap_array(T *t, bool exact, S nx, S ny, S nz)
Definition: archives_config.h:339