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

added support for cereal

parent a23f6ad7
......@@ -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)
......@@ -63,5 +63,30 @@ void engine::enable_remote_shutdown() {
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 @@
#include <unistd.h>
#include <iostream>
#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;
int client() {
tl::engine margo("bmi+tcp", MARGO_CLIENT_MODE);
auto remote_send = margo.define("send_bulk").disable_response();
tl::engine margo("tcp", MARGO_CLIENT_MODE);
auto remote_send = margo.define("send_bulk").disable_response();
auto remote_stop = margo.define("stop").disable_response();
std::string server_addr = "bmi+tcp://127.0.0.1:1234";
sleep(1);
std::string server_addr = "tcp://127.0.0.1:1234";
sleep(1);
auto server_endpoint = margo.lookup(server_addr);
std::cout << "Lookup done for endpoint " << server_endpoint << std::endl;
auto server_endpoint = margo.lookup(server_addr);
std::cout << "Lookup done for endpoint " << server_endpoint << std::endl;
std::string buf = "Matthieu";
std::vector<std::pair<void*,std::size_t>> seg(1);
......@@ -27,13 +31,13 @@ int client() {
tl::bulk b = margo.expose(seg, tl::bulk_mode::read_only);
remote_send.on(server_endpoint)(b);
remote_stop.on(server_endpoint)();
return 0;
return 0;
}
int main(int argc, char** argv) {
client();
return 0;
client();
return 0;
}
......@@ -4,13 +4,17 @@
#include <unistd.h>
#include <iostream>
#include <thallium.hpp>
#ifdef USE_CEREAL
#include <cereal/types/string.hpp>
#else
#include <thallium/serialization/stl/string.hpp>
#endif
namespace tl = thallium;
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 =
[&margo](const tl::request& req, tl::bulk& b) {
......@@ -25,7 +29,7 @@ int server() {
for(auto c : v) std::cout << c;
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 =
[&margo](const tl::request& req) {
......@@ -34,10 +38,10 @@ int server() {
};
margo.define("stop", g);
std::string addr = margo.self();
std::cout << "Server running at address " << addr << std::endl;
std::string addr = margo.self();
std::cout << "Server running at address " << addr << std::endl;
return 0;
return 0;
}
int main(int argc, char** argv) {
......
......@@ -4,7 +4,11 @@
#include <unistd.h>
#include <iostream>
#include <thallium.hpp>
#ifdef USE_CEREAL
#include <cereal/types/string.hpp>
#else
#include <thallium/serialization/stl/string.hpp>
#endif
namespace tl = thallium;
......
......@@ -4,17 +4,21 @@
#include <unistd.h>
#include <iostream>
#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;
void hello(const tl::request& req, const std::string& name) {
std::cout << "Hello " << name << std::endl;
std::cout << "Hello " << name << std::endl;
}
int server() {
tl::engine margo("tcp", MARGO_SERVER_MODE);
tl::engine margo("tcp", MARGO_SERVER_MODE);
margo.define("hello", hello).disable_response();
......@@ -33,12 +37,12 @@ int server() {
margo.define("stop", g);
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) {
server();
return 0;
server();
return 0;
}
#include <cassert>
#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>
#include <thallium/config.hpp>
#ifdef USE_CEREAL
#include <thallium/serialization/cereal/archives.hpp>
#else
#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;
void SerializeValues() {
buffer buf;
double a1 = 1.0;
int b1 = 42;
char c1 = 'c';
double a1 = 1.0;
int b1 = 42;
char c1 = 'c';
{
#ifdef USE_CEREAL
cereal_output_archive arch(buf);
arch(a1,b1,c1);
#else
buffer_output_archive arch(buf);
arch & a1 & b1 & c1;
#endif
}
double a2;
......@@ -24,8 +34,13 @@ void SerializeValues() {
char c2;
{
#ifdef USE_CEREAL
cereal_input_archive arch(buf);
arch(a2,b2,c2);
#else
buffer_input_archive arch(buf);
arch & a2 & b2 & c2;
#endif
}
assert(a1 == a2);
......@@ -35,5 +50,5 @@ void SerializeValues() {
int main(int argc, char** argv) {
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