Commit db0d2e4f authored by Matthieu Dorier's avatar Matthieu Dorier
Browse files

added support for cereal

parent a23f6ad7
...@@ -6,6 +6,12 @@ ...@@ -6,6 +6,12 @@
#ifndef __THALLIUM_SET_SERIALIZATION_HPP #ifndef __THALLIUM_SET_SERIALIZATION_HPP
#define __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 <utility>
#include <set> #include <set>
...@@ -35,3 +41,4 @@ inline void load(A& ar, std::set<T,Compare,Alloc>& s) { ...@@ -35,3 +41,4 @@ inline void load(A& ar, std::set<T,Compare,Alloc>& s) {
} // namespace } // namespace
#endif #endif
#endif
#ifndef __THALLIUM_STRING_SERIALIZATION_HPP #ifndef __THALLIUM_STRING_SERIALIZATION_HPP
#define __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 <string>
#include <iostream> #include <iostream>
...@@ -23,5 +29,5 @@ inline void load(A& ar, std::string& s) { ...@@ -23,5 +29,5 @@ inline void load(A& ar, std::string& s) {
} }
} }
#endif
#endif #endif
...@@ -6,6 +6,12 @@ ...@@ -6,6 +6,12 @@
#ifndef __THALLIUM_TUPLE_SERIALIZATION_HPP #ifndef __THALLIUM_TUPLE_SERIALIZATION_HPP
#define __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> #include <tuple>
namespace thallium { namespace thallium {
...@@ -44,3 +50,4 @@ inline void load(A& ar, std::tuple<Types...>& t) { ...@@ -44,3 +50,4 @@ inline void load(A& ar, std::tuple<Types...>& t) {
} }
#endif #endif
#endif
...@@ -6,6 +6,12 @@ ...@@ -6,6 +6,12 @@
#ifndef __THALLIUM_UNORDERED_MAP_SERIALIZATION_HPP #ifndef __THALLIUM_UNORDERED_MAP_SERIALIZATION_HPP
#define __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> #include <unordered_map>
namespace thallium { namespace thallium {
...@@ -36,3 +42,4 @@ inline void load(A& ar, std::unordered_map<K,V,Hash,Pred,Alloc>& m) { ...@@ -36,3 +42,4 @@ inline void load(A& ar, std::unordered_map<K,V,Hash,Pred,Alloc>& m) {
} }
#endif #endif
#endif
...@@ -6,6 +6,12 @@ ...@@ -6,6 +6,12 @@
#ifndef __THALLIUM_UNORDERED_MULTIMAP_SERIALIZATION_HPP #ifndef __THALLIUM_UNORDERED_MULTIMAP_SERIALIZATION_HPP
#define __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> #include <unordered_map>
namespace thallium { namespace thallium {
...@@ -36,3 +42,4 @@ inline void load(A& ar, std::unordered_multimap<K,V,Hash,Pred,Alloc>& m) { ...@@ -36,3 +42,4 @@ inline void load(A& ar, std::unordered_multimap<K,V,Hash,Pred,Alloc>& m) {
} }
#endif #endif
#endif
...@@ -6,6 +6,12 @@ ...@@ -6,6 +6,12 @@
#ifndef __THALLIUM_UNORDERED_MULTISET_SERIALIZATION_HPP #ifndef __THALLIUM_UNORDERED_MULTISET_SERIALIZATION_HPP
#define __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 <utility>
#include <unordered_set> #include <unordered_set>
...@@ -36,3 +42,4 @@ inline void load(A& ar, std::unordered_multiset<V,Hash,Pred,Alloc>& s) { ...@@ -36,3 +42,4 @@ inline void load(A& ar, std::unordered_multiset<V,Hash,Pred,Alloc>& s) {
} }
#endif #endif
#endif
...@@ -6,6 +6,12 @@ ...@@ -6,6 +6,12 @@
#ifndef __THALLIUM_UNORDERED_SET_SERIALIZATION_HPP #ifndef __THALLIUM_UNORDERED_SET_SERIALIZATION_HPP
#define __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 <utility>
#include <unordered_set> #include <unordered_set>
...@@ -36,3 +42,4 @@ inline void load(A& ar, std::unordered_set<V,Hash,Pred,Alloc>& s) { ...@@ -36,3 +42,4 @@ inline void load(A& ar, std::unordered_set<V,Hash,Pred,Alloc>& s) {
} }
#endif #endif
#endif
...@@ -6,6 +6,12 @@ ...@@ -6,6 +6,12 @@
#ifndef __THALLIUM_VECTOR_SERIALIZATION_HPP #ifndef __THALLIUM_VECTOR_SERIALIZATION_HPP
#define __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 <type_traits>
#include <vector> #include <vector>
...@@ -64,3 +70,4 @@ inline void load(A& ar, std::vector<T,Alloc>& v) { ...@@ -64,3 +70,4 @@ inline void load(A& ar, std::vector<T,Alloc>& v) {
} // namespace thallium } // namespace thallium
#endif #endif
#endif
...@@ -16,8 +16,8 @@ template<size_t N> ...@@ -16,8 +16,8 @@ template<size_t N>
struct apply_f_to_t_impl { struct apply_f_to_t_impl {
template<typename R, typename... ArgsF, typename... ArgsT, typename... Args> 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) { 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), 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<> ...@@ -25,8 +25,8 @@ template<>
struct apply_f_to_t_impl<0> { struct apply_f_to_t_impl<0> {
template<typename R, typename... ArgsF, typename... ArgsT, typename... Args> 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) { static R apply(const std::function<R(ArgsF...)>& f, std::tuple<ArgsT...>& t, Args&&... args) {
return f(args...); return f(std::forward<Args>(args)...);
} }
}; };
...@@ -40,7 +40,7 @@ struct apply_f_to_t_impl<0> { ...@@ -40,7 +40,7 @@ struct apply_f_to_t_impl<0> {
* \return the value returned by f. * \return the value returned by f.
*/ */
template<typename R, typename... ArgsF, typename... ArgsT> 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); 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. ...@@ -52,7 +52,7 @@ R apply_function_to_tuple(const std::function<R(ArgsF...)>& f, std::tuple<ArgsT.
* \return the value returned by f. * \return the value returned by f.
*/ */
template<typename R, typename... ArgsF, typename... ArgsT> 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); std::function<R(ArgsF...)> fun(f);
return apply_function_to_tuple(fun,t); return apply_function_to_tuple(fun,t);
} }
......
...@@ -84,3 +84,5 @@ install (DIRECTORY ../include/thallium ...@@ -84,3 +84,5 @@ install (DIRECTORY ../include/thallium
FILES_MATCHING PATTERN "*.hpp") FILES_MATCHING PATTERN "*.hpp")
install (FILES ../include/thallium.hpp install (FILES ../include/thallium.hpp
DESTINATION include) DESTINATION include)
install (FILES ${CMAKE_CURRENT_BINARY_DIR}/../include/thallium/config.hpp
DESTINATION include/thallium)
...@@ -63,5 +63,30 @@ void engine::enable_remote_shutdown() { ...@@ -63,5 +63,30 @@ void engine::enable_remote_shutdown() {
margo_enable_remote_shutdown(m_mid); margo_enable_remote_shutdown(m_mid);
} }
remote_procedure engine::define(const std::string& name,
const std::function<void(const request&)>& fun,
uint16_t provider_id, const pool& p) {
hg_id_t id = margo_provider_register_name(m_mid, name.c_str(),
process_buffer,
process_buffer,
rpc_callback<rpc_t, false>,
provider_id,
p.native_handle());
m_rpcs[id] = [fun](const request& r, const buffer& b) {
fun(r);
};
rpc_callback_data* cb_data = new rpc_callback_data;
cb_data->m_engine = this;
cb_data->m_function = void_cast(&m_rpcs[id]);
hg_return_t ret = margo_register_data(m_mid, id, (void*)cb_data, free_rpc_callback_data);
MARGO_ASSERT(ret, margo_register_data);
return remote_procedure(*this, id);
}
} }
...@@ -4,20 +4,24 @@ ...@@ -4,20 +4,24 @@
#include <unistd.h> #include <unistd.h>
#include <iostream> #include <iostream>
#include <thallium.hpp> #include <thallium.hpp>
#include <thallium/serialization/stl/string.hpp> #ifdef USE_CEREAL
#include <cereal/types/string.hpp>
#else
#include <thallium/serialization/stl/string.hpp>
#endif
namespace tl = thallium; namespace tl = thallium;
int client() { int client() {
tl::engine margo("bmi+tcp", MARGO_CLIENT_MODE); tl::engine margo("tcp", MARGO_CLIENT_MODE);
auto remote_send = margo.define("send_bulk").disable_response(); auto remote_send = margo.define("send_bulk").disable_response();
auto remote_stop = margo.define("stop").disable_response(); auto remote_stop = margo.define("stop").disable_response();
std::string server_addr = "bmi+tcp://127.0.0.1:1234"; std::string server_addr = "tcp://127.0.0.1:1234";
sleep(1); sleep(1);
auto server_endpoint = margo.lookup(server_addr); auto server_endpoint = margo.lookup(server_addr);
std::cout << "Lookup done for endpoint " << server_endpoint << std::endl; std::cout << "Lookup done for endpoint " << server_endpoint << std::endl;
std::string buf = "Matthieu"; std::string buf = "Matthieu";
std::vector<std::pair<void*,std::size_t>> seg(1); std::vector<std::pair<void*,std::size_t>> seg(1);
...@@ -27,13 +31,13 @@ int client() { ...@@ -27,13 +31,13 @@ int client() {
tl::bulk b = margo.expose(seg, tl::bulk_mode::read_only); tl::bulk b = margo.expose(seg, tl::bulk_mode::read_only);
remote_send.on(server_endpoint)(b); remote_send.on(server_endpoint)(b);
remote_stop.on(server_endpoint)(); remote_stop.on(server_endpoint)();
return 0; return 0;
} }
int main(int argc, char** argv) { int main(int argc, char** argv) {
client(); client();
return 0; return 0;
} }
...@@ -4,13 +4,17 @@ ...@@ -4,13 +4,17 @@
#include <unistd.h> #include <unistd.h>
#include <iostream> #include <iostream>
#include <thallium.hpp> #include <thallium.hpp>
#ifdef USE_CEREAL
#include <cereal/types/string.hpp>
#else
#include <thallium/serialization/stl/string.hpp> #include <thallium/serialization/stl/string.hpp>
#endif
namespace tl = thallium; namespace tl = thallium;
int server() { int server() {
tl::engine margo("bmi+tcp://127.0.0.1:1234", MARGO_SERVER_MODE); tl::engine margo("tcp://127.0.0.1:1234", MARGO_SERVER_MODE);
std::function<void(const tl::request&, tl::bulk& b)> f = std::function<void(const tl::request&, tl::bulk& b)> f =
[&margo](const tl::request& req, tl::bulk& b) { [&margo](const tl::request& req, tl::bulk& b) {
...@@ -25,7 +29,7 @@ int server() { ...@@ -25,7 +29,7 @@ int server() {
for(auto c : v) std::cout << c; for(auto c : v) std::cout << c;
std::cout << std::endl; std::cout << std::endl;
}; };
margo.define("send_bulk",f).disable_response(); margo.define("send_bulk",f).disable_response();
std::function<void(const tl::request&)> g = std::function<void(const tl::request&)> g =
[&margo](const tl::request& req) { [&margo](const tl::request& req) {
...@@ -34,10 +38,10 @@ int server() { ...@@ -34,10 +38,10 @@ int server() {
}; };
margo.define("stop", g); margo.define("stop", g);
std::string addr = margo.self(); std::string addr = margo.self();
std::cout << "Server running at address " << addr << std::endl; std::cout << "Server running at address " << addr << std::endl;
return 0; return 0;
} }
int main(int argc, char** argv) { int main(int argc, char** argv) {
......
...@@ -4,7 +4,11 @@ ...@@ -4,7 +4,11 @@
#include <unistd.h> #include <unistd.h>
#include <iostream> #include <iostream>
#include <thallium.hpp> #include <thallium.hpp>
#ifdef USE_CEREAL
#include <cereal/types/string.hpp>
#else
#include <thallium/serialization/stl/string.hpp> #include <thallium/serialization/stl/string.hpp>
#endif
namespace tl = thallium; namespace tl = thallium;
......
...@@ -4,17 +4,21 @@ ...@@ -4,17 +4,21 @@
#include <unistd.h> #include <unistd.h>
#include <iostream> #include <iostream>
#include <thallium.hpp> #include <thallium.hpp>
#include <thallium/serialization/stl/string.hpp> #ifdef USE_CEREAL
#include <cereal/types/string.hpp>
#else
#include <thallium/serialization/stl/string.hpp>
#endif
namespace tl = thallium; namespace tl = thallium;
void hello(const tl::request& req, const std::string& name) { void hello(const tl::request& req, const std::string& name) {
std::cout << "Hello " << name << std::endl; std::cout << "Hello " << name << std::endl;
} }
int server() { int server() {
tl::engine margo("tcp", MARGO_SERVER_MODE); tl::engine margo("tcp", MARGO_SERVER_MODE);
margo.define("hello", hello).disable_response(); margo.define("hello", hello).disable_response();
...@@ -33,12 +37,12 @@ int server() { ...@@ -33,12 +37,12 @@ int server() {
margo.define("stop", g); margo.define("stop", g);
std::string addr = margo.self(); std::string addr = margo.self();
std::cout << "Server running at address " << addr << std::endl; std::cout << "Server running at address " << addr << std::endl;
return 0; return 0;
} }
int main(int argc, char** argv) { int main(int argc, char** argv) {
server(); server();
return 0; return 0;
} }
#include <cassert> #include <cassert>
#include <thallium/serialization/serialize.hpp> #include <thallium/config.hpp>
#include <thallium/serialization/buffer_input_archive.hpp> #ifdef USE_CEREAL
#include <thallium/serialization/buffer_output_archive.hpp> #include <thallium/serialization/cereal/archives.hpp>
#include <thallium/serialization/stl/vector.hpp> #else
#include <thallium/serialization/stl/tuple.hpp> #include <thallium/serialization/serialize.hpp>
#include <thallium/serialization/buffer_input_archive.hpp>
#include <thallium/serialization/buffer_output_archive.hpp>
#include <thallium/serialization/stl/vector.hpp>
#include <thallium/serialization/stl/tuple.hpp>
#endif
using namespace thallium; using namespace thallium;
void SerializeValues() { void SerializeValues() {
buffer buf; buffer buf;
double a1 = 1.0; double a1 = 1.0;
int b1 = 42; int b1 = 42;
char c1 = 'c'; char c1 = 'c';
{ {
#ifdef USE_CEREAL
cereal_output_archive arch(buf);
arch(a1,b1,c1);
#else
buffer_output_archive arch(buf); buffer_output_archive arch(buf);
arch & a1 & b1 & c1; arch & a1 & b1 & c1;
#endif
} }
double a2; double a2;
...@@ -24,8 +34,13 @@ void SerializeValues() { ...@@ -24,8 +34,13 @@ void SerializeValues() {
char c2; char c2;
{ {
#ifdef USE_CEREAL
cereal_input_archive arch(buf);
arch(a2,b2,c2);
#else
buffer_input_archive arch(buf); buffer_input_archive arch(buf);
arch & a2 & b2 & c2; arch & a2 & b2 & c2;
#endif
} }
assert(a1 == a2); assert(a1 == a2);
...@@ -35,5 +50,5 @@ void SerializeValues() { ...@@ -35,5 +50,5 @@ void SerializeValues() {
int main(int argc, char** argv) { int main(int argc, char** argv) {
SerializeValues(); SerializeValues();
return 0; return 0;
} }
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment