Skip to content

Serialization #17

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions code/api/include/allscale/api/user/data/grid.h
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,7 @@ namespace data {
}

bool operator==(const GridRegion& other) const {
return difference(*this,other).empty() && other.difference(other,*this).empty();
return difference(*this,other, false).empty() && other.difference(other,*this, false).empty();
}

bool operator!=(const GridRegion& other) const {
Expand All @@ -504,6 +504,7 @@ namespace data {

// build result
GridRegion res = a;
res.regions.reserve(a.regions.size() + b.regions.size());

// combine regions
for(const auto& cur : difference(b,a).regions) {
Expand Down Expand Up @@ -531,6 +532,8 @@ namespace data {
// build result
GridRegion res;

res.regions.reserve(a.regions.size() + b.regions.size());

// combine regions
for(const auto& curA : a.regions) {
for(const auto& curB : b.regions) {
Expand All @@ -548,7 +551,7 @@ namespace data {
return res;
}

static GridRegion difference(const GridRegion& a, const GridRegion& b) {
static GridRegion difference(const GridRegion& a, const GridRegion& b, bool do_compress = true) {

// handle empty sets
if(a.empty() || b.empty()) return a;
Expand All @@ -569,8 +572,11 @@ namespace data {
res.regions.swap(next);
}

// compress result
res.compress();
if (do_compress)
{
// compress result
res.compress();
}

// done
return res;
Expand Down
3 changes: 2 additions & 1 deletion code/utils/include/allscale/utils/serializer/arrays.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

#ifdef ALLSCALE_WITH_HPX
#include <hpx/runtime/serialization/array.hpp>
#endif
#else

#include "allscale/utils/serializer.h"

Expand Down Expand Up @@ -63,3 +63,4 @@ namespace utils {
} // end namespace utils
} // end namespace allscale

#endif
4 changes: 3 additions & 1 deletion code/utils/include/allscale/utils/serializer/strings.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

#ifdef ALLSCALE_WITH_HPX
#include <hpx/runtime/serialization/string.hpp>
#endif
#else

#include "allscale/utils/serializer.h"

Expand Down Expand Up @@ -32,3 +32,5 @@ namespace utils {

} // end namespace utils
} // end namespace allscale

#endif
4 changes: 3 additions & 1 deletion code/utils/include/allscale/utils/serializer/vectors.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

#ifdef ALLSCALE_WITH_HPX
#include "allscale/utils/serializer.h"
#endif
#include <hpx/runtime/serialization/vector.hpp>
#else

#include <vector>

Expand Down Expand Up @@ -80,3 +81,4 @@ namespace utils {

} // end namespace utils
} // end namespace allscale
#endif
41 changes: 41 additions & 0 deletions code/utils/include/allscale/utils/vector.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,26 @@ namespace utils {
return out << vec.data;
}

#ifdef ALLSCALE_WITH_HPX
template <typename Archive>
void serialize(Archive& ar, unsigned)
{
ar & data;
}
#endif

private:

template<typename R, std::size_t ... Index>
void init_internal(const std::initializer_list<R>& list, const std::integer_sequence<std::size_t,Index...>&) {
__allscale_unused auto bla = { data[Index] = *(list.begin() + Index) ... };
}

template<typename R>
void init(const std::initializer_list<R>& list) {
init_internal(list,std::make_index_sequence<Dims>());
}

};

template<typename T, std::size_t Dims, typename S>
Expand Down Expand Up @@ -309,6 +329,16 @@ namespace utils {
return out << "[" << vec.x << "," << vec.y << "," << vec.z << "]";
}

#ifdef ALLSCALE_WITH_HPX
template <typename Archive>
void serialize(Archive& ar, unsigned)
{
ar & x;
ar & y;
ar & z;
}
#endif

};

template<typename T>
Expand Down Expand Up @@ -398,8 +428,18 @@ namespace utils {
return out << "[" << vec.x << "," << vec.y << "]";
}

#ifdef ALLSCALE_WITH_HPX
template <typename Archive>
void serialize(Archive& ar, unsigned)
{
ar & x;
ar & y;
}
#endif

};

#ifndef ALLSCALE_WITH_HPX
/**
* Add support for trivially serializing / de-serializing Vector instances.
*/
Expand All @@ -412,6 +452,7 @@ namespace utils {
*/
template<typename T, std::size_t Dims>
struct serializer<Vector<T,Dims>,typename std::enable_if<!is_trivially_serializable<T>::value && is_serializable<T>::value,void>::type> : public serializer<std::array<T,Dims>> {};
#endif

} // end namespace utils
} // end namespace allscale
Expand Down