Commit db0d2e4f authored by Matthieu Dorier's avatar Matthieu Dorier

added support for cereal

parent a23f6ad7
......@@ -9,9 +9,6 @@
#include <thallium/margo_exception.hpp>
#include <thallium/buffer.hpp>
#include <thallium/packed_response.hpp>
#include <thallium/serialization/serialize.hpp>
#include <thallium/serialization/stl/vector.hpp>
#include <thallium/serialization/buffer_output_archive.hpp>
namespace thallium {
......
......@@ -12,6 +12,7 @@
#include <margo.h>
#include <thallium/endpoint.hpp>
#include <thallium/margo_exception.hpp>
#include <thallium/serialization/stl/vector.hpp>
namespace thallium {
......@@ -335,10 +336,10 @@ public:
* @brief Function that serializes a bulk object into an archive.
*
* @tparam A Archive type.
* @param ar Input archive.
* @param ar Output archive.
*/
template<typename A>
void save(A& ar) {
void save(A& ar) const {
if(m_bulk == HG_BULK_NULL) {
std::vector<char> buf;
ar & buf;
......@@ -356,7 +357,7 @@ public:
* @brief Deserializes a bulk object from an output archive.
*
* @tparam A Archive type.
* @param ar Output archive.
* @param ar Input archive.
*/
template<typename A>
void load(A& ar);
......
......@@ -11,18 +11,15 @@
#include <utility>
#include <chrono>
#include <margo.h>
#include <thallium/config.hpp>
#include <thallium/buffer.hpp>
#include <thallium/timeout.hpp>
#include <thallium/packed_response.hpp>
#include <thallium/async_response.hpp>
#include <thallium/margo_exception.hpp>
#ifdef USE_CEREAL
#include <thallium/serialization/cereal/archives.hpp>
#else
#include <thallium/serialization/serialize.hpp>
#include <thallium/serialization/stl/vector.hpp>
#include <thallium/serialization/buffer_output_archive.hpp>
#endif
#include <thallium/serialization/serialize.hpp>
#include <thallium/serialization/buffer_output_archive.hpp>
#include <thallium/serialization/stl/vector.hpp>
namespace thallium {
......@@ -202,13 +199,8 @@ public:
template<typename ... T>
packed_response operator()(T&& ... args) const {
buffer b;
#ifdef USE_CEREAL
cereal_output_archive arch(b, *m_engine);
arch(std::forward<T>(args)...);
#else
buffer_output_archive arch(b, *m_engine);
serialize_many(arch, std::forward<T>(args)...);
#endif
arch(std::forward<T>(args)...);
return forward(b);
}
......@@ -229,13 +221,8 @@ public:
template<typename R, typename P, typename ... T>
packed_response timed(const std::chrono::duration<R,P>& t, T&& ... args) const {
buffer b;
#ifdef USE_CEREAL
cereal_output_archive arch(b, *m_engine);
arch(std::forward<T>(args)...);
#else
buffer_output_archive arch(b, *m_engine);
serialize_many(arch, std::forward<T>(args)...);
#endif
arch(std::forward<T>(args)...);
std::chrono::duration<double, std::milli> fp_ms = t;
double timeout_ms = fp_ms.count();
return forward(b, timeout_ms);
......@@ -280,13 +267,8 @@ public:
template<typename ... T>
async_response async(T&& ... t) {
buffer b;
#ifdef USE_CEREAL
cereal_output_archive arch(b, *m_engine);
arch(std::forward<T>(t)...);
#else
buffer_output_archive arch(b, *m_engine);
serialize_many(arch, std::forward<T>(t)...);
#endif
arch(std::forward<T>(t)...);
return iforward(b);
}
......@@ -306,13 +288,8 @@ public:
template<typename R, typename P, typename ... T>
async_response timed_async(const std::chrono::duration<R,P>& t, T&& ... args) {
buffer b;
#ifdef USE_CEREAL
cereal_output_archive arch(b, *m_engine);
arch(std::forward<T>(t)...);
#else
buffer_output_archive arch(b, *m_engine);
serialize_many(arch, std::forward<T>(args)...);
#endif
arch(std::forward<T>(t)...);
std::chrono::duration<double, std::milli> fp_ms = t;
double timeout_ms = fp_ms.count();
return iforward(b, timeout_ms);
......
#undef THALLIUM_USE_CEREAL
#undef ENABLE_CEREAL
#cmakedefine ENABLE_CEREAL
#ifdef ENABLE_CEREAL
#define USE_CEREAL
#define THALLIUM_USE_CEREAL
#undef ENABLE_CEREAL
#endif
......@@ -14,6 +14,7 @@
#include <vector>
#include <atomic>
#include <margo.h>
#include <thallium/config.hpp>
#include <thallium/pool.hpp>
#include <thallium/tuple_util.hpp>
#include <thallium/function_cast.hpp>
......@@ -320,9 +321,13 @@ public:
*
* @return a remote_procedure object.
*/
template<typename ... Args>
template<typename A1, typename ... Args>
remote_procedure define(const std::string& name,
const std::function<void(const request&, Args...)>& fun,
const std::function<void(const request&, A1, Args...)>& fun,
uint16_t provider_id=0, const pool& p = pool());
remote_procedure define(const std::string& name,
const std::function<void(const request&)>& fun,
uint16_t provider_id=0, const pool& p = pool());
/**
......@@ -391,19 +396,15 @@ public:
#include <thallium/remote_procedure.hpp>
#include <thallium/proc_buffer.hpp>
#ifdef USE_CEREAL
#include <thallium/serialization/cereal/archives.hpp>
#else
#include <thallium/serialization/stl/tuple.hpp>
#include <thallium/serialization/buffer_input_archive.hpp>
#include <thallium/serialization/buffer_output_archive.hpp>
#endif
#include <thallium/serialization/buffer_input_archive.hpp>
#include <thallium/serialization/buffer_output_archive.hpp>
#include <thallium/serialization/stl/tuple.hpp>
namespace thallium {
template<typename ... Args>
template<typename A1, typename ... Args>
remote_procedure engine::define(const std::string& name,
const std::function<void(const request&, Args...)>& fun,
const std::function<void(const request&, A1, Args...)>& fun,
uint16_t provider_id, const pool& p) {
hg_id_t id = margo_provider_register_name(m_mid, name.c_str(),
......@@ -414,28 +415,13 @@ remote_procedure engine::define(const std::string& name,
p.native_handle());
m_rpcs[id] = [fun,this](const request& r, const buffer& b) {
#ifdef USE_CEREAL
std::function<void(Args...)> deserialize = [&b, this](Args&&... args) {
cereal_input_archive arch(b, *this);
arch(std::forward<Args>(args)...);
};
std::function<void(Args...)> call_function = [&fun, &r](Args&&... args) {
fun(r, std::forward<Args>(args)...);
std::function<void(A1, Args...)> call_function = [&fun, &r](A1&& a1, Args&&... args) {
fun(r, std::forward<A1>(a1), std::forward<Args>(args)...);
};
std::tuple<typename std::decay<Args>::type...> iargs;
apply_function_to_tuple(deserialize, iargs);
std::tuple<typename std::decay<A1>::type, typename std::decay<Args>::type...> iargs;
buffer_input_archive iarch(b, *this);
iarch(iargs);
apply_function_to_tuple(call_function, iargs);
#else
std::function<void(Args...)> l = [&fun, &r](Args&&... args) {
fun(r, std::forward<Args>(args)...);
};
std::tuple<typename std::decay<Args>::type...> iargs;
if(sizeof...(Args) > 0) {
buffer_input_archive iarch(b, *this);
iarch & iargs;
}
apply_function_to_tuple(l,iargs);
#endif
};
rpc_callback_data* cb_data = new rpc_callback_data;
......
......@@ -7,12 +7,8 @@
#define __THALLIUM_PACKED_RESPONSE_HPP
#include <thallium/buffer.hpp>
#ifdef USE_CEREAL
#include <thallium/serialization/cereal/archives.hpp>
#else
#include <thallium/serialization/serialize.hpp>
#include <thallium/serialization/buffer_input_archive.hpp>
#endif
#include <thallium/serialization/serialize.hpp>
#include <thallium/serialization/buffer_input_archive.hpp>
namespace thallium {
......@@ -56,13 +52,8 @@ public:
template<typename T>
T as() const {
T t;
#ifdef USE_CEREAL
cereal_input_archive iarch(m_buffer, *m_engine);
iarch(t);
#else
buffer_input_archive iarch(m_buffer, *m_engine);
iarch & t;
#endif
iarch(t);
return t;
}
......@@ -86,18 +77,8 @@ public:
std::tuple<typename std::decay<T1>::type,
typename std::decay<T2>::type,
typename std::decay_t<Tn>::type...> t;
#ifdef USE_CEREAL
std::function<void(T1, T2, Tn...)> deserialize = [this](T1&& t1, T2&& t2, Tn&&... tn) {
cereal_input_archive arch(m_buffer, *m_engine);
arch(std::forward<T1>(t1),
std::forward<T2>(t2),
std::forward<Tn>(tn)...);
};
apply_function_to_tuple(deserialize, t);
#else
buffer_input_archive iarch(m_buffer, *m_engine);
iarch & t;
#endif
arch(t);
return t;
}
......
......@@ -8,12 +8,8 @@
#include <margo.h>
#include <thallium/margo_exception.hpp>
#ifdef USE_CEREAL
#include <thallium/serialization/cereal/archives.hpp>
#else
#include <thallium/serialization/serialize.hpp>
#include <thallium/serialization/buffer_output_archive.hpp>
#endif
#include <thallium/serialization/serialize.hpp>
#include <thallium/serialization/buffer_output_archive.hpp>
namespace thallium {
......@@ -117,13 +113,8 @@ public:
if(m_disable_response) return; // XXX throwing an exception?
if(m_handle != HG_HANDLE_NULL) {
buffer b;
#ifdef USE_CEREAL
cereal_output_archive arch(b, *m_engine);
arch(std::forward<T>(t)...);
#else
buffer_output_archive arch(b, *m_engine);
serialize_many(arch, std::forward<T>(t)...);
#endif
arch(std::forward<T>(t)...);
hg_return_t ret = margo_respond(m_handle, &b);
MARGO_ASSERT(ret, margo_respond);
}
......
......@@ -6,6 +6,21 @@
#ifndef __THALLIUM_BUFFER_INPUT_ARCHIVE_HPP
#define __THALLIUM_BUFFER_INPUT_ARCHIVE_HPP
#include <thallium/config.hpp>
#ifdef THALLIUM_USE_CEREAL
#include <thallium/serialization/cereal/archives.hpp>
namespace thallium {
using buffer_input_archive = cereal_input_archive;
}
#else
#include <type_traits>
#include <stdexcept>
#include <cstring>
......@@ -133,3 +148,4 @@ public:
}
#endif
#endif
......@@ -6,6 +6,20 @@
#ifndef __THALLIUM_BUFFER_OUTPUT_ARCHIVE_HPP
#define __THALLIUM_BUFFER_OUTPUT_ARCHIVE_HPP
#include <thallium/config.hpp>
#ifdef THALLIUM_USE_CEREAL
#include <thallium/serialization/cereal/archives.hpp>
namespace thallium {
using buffer_output_archive = cereal_output_archive;
}
#else
#include <type_traits>
#include <thallium/serialization/serialize.hpp>
#include <thallium/buffer.hpp>
......@@ -131,3 +145,4 @@ public:
}
#endif
#endif
......@@ -39,7 +39,7 @@ namespace thallium {
~cereal_output_archive() = default;
inline void write(void* const data, size_t size) {
inline void write(const void* data, size_t size) {
if(m_pos+size > m_buffer.size()) {
if(m_pos+size > m_buffer.capacity()) {
m_buffer.reserve(m_buffer.capacity()*2);
......
......@@ -6,6 +6,10 @@
#ifndef SERIALIZE_H
#define SERIALIZE_H
#include <thallium/config.hpp>
#ifndef THALLIUM_USE_CEREAL
#include <utility>
#include <type_traits>
......@@ -205,3 +209,4 @@ inline void serialize_many(A& ar, T&& t) {
}
#endif
#endif
......@@ -6,6 +6,12 @@
#ifndef __THALLIUM_ARRAY_SERIALIZATION_HPP
#define __THALLIUM_ARRAY_SERIALIZATION_HPP
#include <thallium/config.hpp>
#ifdef THALLIUM_USE_CEREAL
#include <cereal/types/array.hpp>
#else
#include <type_traits>
#include <array>
......@@ -52,3 +58,4 @@ inline void load(A& ar, std::array<T,N>& v) {
} // namespace thallium
#endif
#endif
......@@ -6,6 +6,12 @@
#ifndef __THALLIUM_COMPLEX_SERIALIZATION_HPP
#define __THALLIUM_COMPLEX_SERIALIZATION_HPP
#include <thallium/config.hpp>
#ifdef THALLIUM_USE_CEREAL
#include <cereal/types/complex.hpp>
#else
#include <complex>
namespace thallium {
......@@ -25,3 +31,4 @@ inline void load(A& ar, std::complex<T>& t) {
}
#endif
#endif
......@@ -6,6 +6,12 @@
#ifndef __THALLIUM_DEQUE_SERIALIZATION_HPP
#define __THALLIUM_DEQUE_SERIALIZATION_HPP
#include <thallium/config.hpp>
#ifdef THALLIUM_USE_CEREAL
#include <cereal/types/deque.hpp>
#else
#include <deque>
namespace thallium {
......@@ -33,3 +39,4 @@ inline void load(A& ar, std::deque<T,Alloc>& l) {
}
#endif
#endif
......@@ -6,6 +6,12 @@
#ifndef __THALLIUM_FORWARD_LIST_SERIALIZATION_HPP
#define __THALLIUM_FORWARD_LIST_SERIALIZATION_HPP
#include <thallium/config.hpp>
#ifdef THALLIUM_USE_CEREAL
#include <cereal/types/forward_list.hpp>
#else
#include <forward_list>
namespace thallium {
......@@ -33,3 +39,4 @@ inline void load(A& ar, std::forward_list<T,Alloc>& l) {
}
#endif
#endif
......@@ -6,6 +6,12 @@
#ifndef __THALLIUM_LIST_SERIALIZATION_HPP
#define __THALLIUM_LIST_SERIALIZATION_HPP
#include <thallium/config.hpp>
#ifdef THALLIUM_USE_CEREAL
#include <cereal/types/list.hpp>
#else
#include <list>
namespace thallium {
......@@ -33,3 +39,4 @@ inline void load(A& ar, std::list<T,Alloc>& l) {
}
#endif
#endif
/*
* (C) 2017 The University of Chicago
*
* See COPYRIGHT in top-level directory.
*/
#ifndef __THALLIUM_MAP_SERIALIZATION_HPP
#define __THALLIUM_MAP_SERIALIZATION_HPP
#include <thallium/config.hpp>
#ifdef THALLIUM_USE_CEREAL
#include <cereal/types/map.hpp>
#else
#include <map>
namespace thallium {
......@@ -30,3 +41,4 @@ inline void load(A& ar, std::map<K,V,Compare,Alloc>& m) {
}
#endif
#endif
......@@ -6,6 +6,12 @@
#ifndef __THALLIUM_MULTIMAP_SERIALIZATION_HPP
#define __THALLIUM_MULTIMAP_SERIALIZATION_HPP
#include <thallium/config.hpp>
#ifdef THALLIUM_USE_CEREAL
#include <cereal/types/map.hpp>
#else
#include <map>
namespace thallium {
......@@ -35,3 +41,4 @@ inline void load(A& ar, std::multimap<K,V,Compare,Alloc>& m) {
}
#endif
#endif
......@@ -6,6 +6,12 @@
#ifndef __THALLIUM_MULTISET_SERIALIZATION_HPP
#define __THALLIUM_MULTISET_SERIALIZATION_HPP
#include <thallium/config.hpp>
#ifdef THALLIUM_USE_CEREAL
#include <cereal/types/set.hpp>
#else
#include <utility>
#include <set>
......@@ -35,3 +41,4 @@ inline void load(A& ar, std::multiset<T,Compare,Alloc>& s) {
} // namespace
#endif
#endif
......@@ -6,6 +6,12 @@
#ifndef __THALLIUM_PAIR_SERIALIZE_HPP
#define __THALLIUM_PAIR_SERIALIZE_HPP
#include <thallium/config.hpp>
#ifdef THALLIUM_USE_CEREAL
#include <cereal/types/utility.hpp>
#else
#include <utility>
namespace thallium {
......@@ -19,3 +25,4 @@ inline void serialize(A& a, std::pair<T1,T2>& p) {
}
#endif
#endif
......@@ -6,6 +6,12 @@
#ifndef __THALLIUM_SET_SERIALIZATION_HPP
#define __THALLIUM_SET_SERIALIZATION_HPP
#include <thallium/config.hpp>
#ifdef THALLIUM_USE_CEREAL
#include <cereal/types/set.hpp>
#else
#include <utility>
#include <set>
......@@ -35,3 +41,4 @@ inline void load(A& ar, std::set<T,Compare,Alloc>& s) {
} // namespace
#endif
#endif
#ifndef __THALLIUM_STRING_SERIALIZATION_HPP
#define __THALLIUM_STRING_SERIALIZATION_HPP
#include <thallium/config.hpp>
#ifdef THALLIUM_USE_CEREAL
#include <cereal/types/string.hpp>
#else
#include <string>
#include <iostream>
......@@ -23,5 +29,5 @@ inline void load(A& ar, std::string& s) {
}
}
#endif
#endif
......@@ -6,6 +6,12 @@
#ifndef __THALLIUM_TUPLE_SERIALIZATION_HPP
#define __THALLIUM_TUPLE_SERIALIZATION_HPP
#include <thallium/config.hpp>
#ifdef THALLIUM_USE_CEREAL
#include <cereal/types/tuple.hpp>
#else
#include <tuple>
namespace thallium {
......@@ -44,3 +50,4 @@ inline void load(A& ar, std::tuple<Types...>& t) {
}
#endif
#endif
......@@ -6,6 +6,12 @@
#ifndef __THALLIUM_UNORDERED_MAP_SERIALIZATION_HPP
#define __THALLIUM_UNORDERED_MAP_SERIALIZATION_HPP
#include <thallium/config.hpp>
#ifdef THALLIUM_USE_CEREAL
#include <cereal/types/unordered_map.hpp>
#else
#include <unordered_map>
namespace thallium {
......@@ -36,3 +42,4 @@ inline void load(A& ar, std::unordered_map<K,V,Hash,Pred,Alloc>& m) {
}
#endif
#endif
......@@ -6,6 +6,12 @@
#ifndef __THALLIUM_UNORDERED_MULTIMAP_SERIALIZATION_HPP
#define __THALLIUM_UNORDERED_MULTIMAP_SERIALIZATION_HPP
#include <thallium/config.hpp>
#ifdef THALLIUM_USE_CEREAL
#include <cereal/types/unordered_map.hpp>
#else
#include <unordered_map>
namespace thallium {
......@@ -36,3 +42,4 @@ inline void load(A& ar, std::unordered_multimap<K,V,Hash,Pred,Alloc>& m) {
}
#endif
#endif
......@@ -6,6 +6,12 @@
#ifndef __THALLIUM_UNORDERED_MULTISET_SERIALIZATION_HPP
#define __THALLIUM_UNORDERED_MULTISET_SERIALIZATION_HPP
#include <thallium/config.hpp>
#ifdef USE_CEREAL
#include <cereal/types/unordered_multiset.hpp>
#else
#include <utility>
#include <unordered_set>
......@@ -36,3 +42,4 @@ inline void load(A& ar, std::unordered_multiset<V,Hash,Pred,Alloc>& s) {
}
#endif
#endif
......@@ -6,6 +6,12 @@
#ifndef __THALLIUM_UNORDERED_SET_SERIALIZATION_HPP
#define __THALLIUM_UNORDERED_SET_SERIALIZATION_HPP
#include <thallium/config.hpp>
#ifdef THALLIUM_USE_CEREAL
#include <cereal/types/unordered_set.hpp>
#else
#include <utility>
#include <unordered_set>
......@@ -36,3 +42,4 @@ inline void load(A& ar, std::unordered_set<V,Hash,Pred,Alloc>& s) {
}
#endif
#endif
......@@ -6,6 +6,12 @@
#ifndef __THALLIUM_VECTOR_SERIALIZATION_HPP
#define __THALLIUM_VECTOR_SERIALIZATION_HPP
#include <thallium/config.hpp>
#ifdef THALLIUM_USE_CEREAL
#include <cereal/types/vector.hpp>
#else
#include <type_traits>
#include <vector>
......@@ -64,3 +70,4 @@ inline void load(A& ar, std::vector<T,Alloc>& v) {
} // namespace thallium
#endif
#endif
......@@ -16,8 +16,8 @@ template<size_t N>
struct apply_f_to_t_impl {
template<typename R, typename... ArgsF, typename... ArgsT, typename... Args>
static R apply(const std::function<R(ArgsF...)>& f, std::tuple<ArgsT...> const& t, Args... args) {
return apply_f_to_t_impl<N-1>::apply(f, t, std::get<N-1>(t), args...);
static R apply(const std::function<R(ArgsF...)>& f, std::tuple<ArgsT...>& t, Args&&... args) {
return apply_f_to_t_impl<N-1>::apply(f, t, std::get<N-1>(t), std::forward<Args>(args)...);
}
};
......@@ -25,8 +25,8 @@ template<>
struct apply_f_to_t_impl<0> {
template<typename R, typename... ArgsF, typename... ArgsT, typename... Args>
static R apply(const std::function<R(ArgsF...)>& f, std::tuple<ArgsT...> const& t, Args... args) {
return f(args...);
static R apply(const std::function<R(ArgsF...)>& f, std::tuple<ArgsT...>& t, Args&&... args) {
return f(std::forward<Args>(args)...);
}
};
......@@ -40,7 +40,7 @@ struct apply_f_to_t_impl<0> {
* \return the value returned by f.
*/
template<typename R, typename... ArgsF, typename... ArgsT>
R apply_function_to_tuple(const std::function<R(ArgsF...)>& f, std::tuple<ArgsT...> const& t) {
R apply_function_to_tuple(const std::function<R(ArgsF...)>& f, std::tuple<ArgsT...>& t) {
return detail::apply_f_to_t_impl<sizeof...(ArgsT)>::apply(f,t);
}
......@@ -52,7 +52,7 @@ R apply_function_to_tuple(const std::function<R(ArgsF...)>& f, std::tuple<ArgsT.
* \return the value returned by f.
*/
template<typename R, typename... ArgsF, typename... ArgsT>
R apply_function_to_tuple(R (*f)(ArgsF...), std::tuple<ArgsT...> const& t) {
R apply_function_to_tuple(R (*f)(ArgsF...), std::tuple<ArgsT...>& t) {
std::function<R(ArgsF...)> fun(f);
return apply_function_to_tuple(fun,t);
}
......
......@@ -84,3 +84,5 @@ install (DIRECTORY ../include/thallium
FILES_MATCHING PATTERN "*.hpp")
install (FILES ../include/thallium.hpp
DESTINATION include)
install (FILES ${CMAKE_CURRENT_BINARY_DIR}/../include/thallium/config.hpp
DESTINATION include/thallium)