diff --git a/examples/21_encoding/CMakeLists.txt b/examples/21_encoding/CMakeLists.txt new file mode 100644 index 0000000..2a39767 --- /dev/null +++ b/examples/21_encoding/CMakeLists.txt @@ -0,0 +1,4 @@ +add_executable (21_encoding_server server.cpp) +target_link_libraries (21_encoding_server thallium) +add_executable (21_encoding_client client.cpp) +target_link_libraries (21_encoding_client thallium) diff --git a/examples/21_encoding/client.cpp b/examples/21_encoding/client.cpp new file mode 100644 index 0000000..df9ea3f --- /dev/null +++ b/examples/21_encoding/client.cpp @@ -0,0 +1,20 @@ +#include +#include +#include "encoder.hpp" + +namespace tl = thallium; + +int main(int argc, char** argv) { + if(argc != 2) { + std::cerr << "Usage: " << argv[0] << "
" << std::endl; + exit(0); + } + tl::engine myEngine("tcp", THALLIUM_CLIENT_MODE); + tl::remote_procedure stream = myEngine.define("stream"); + tl::endpoint server = myEngine.lookup(argv[1]); + encoder e; + stream.on(server)(e); + + return 0; +} + diff --git a/examples/21_encoding/encoder.hpp b/examples/21_encoding/encoder.hpp new file mode 100644 index 0000000..d974656 --- /dev/null +++ b/examples/21_encoding/encoder.hpp @@ -0,0 +1,25 @@ +#include + +class encoder { + + public: + + template + void save(A& ar) const { + auto buffer = static_cast(ar.save_ptr(26)); + for(int i = 0; i < 26; ++i) { + buffer[i] = 'A' + i; + } + ar.restore_ptr(buffer, 26); + } + + template + void load(A& ar) { + auto buffer = static_cast(ar.save_ptr(26)); + for(int i = 0; i < 26; ++i) { + std::cout << buffer[i]; + } + std::cout << std::endl; + ar.restore_ptr(buffer, 26); + } +}; diff --git a/examples/21_encoding/server.cpp b/examples/21_encoding/server.cpp new file mode 100644 index 0000000..37d5546 --- /dev/null +++ b/examples/21_encoding/server.cpp @@ -0,0 +1,22 @@ +#include +#include +#include "encoder.hpp" + +namespace tl = thallium; + +int main() { + + tl::engine myEngine("tcp", THALLIUM_SERVER_MODE); + std::cout << "Server running at address " << myEngine.self() << std::endl; + + std::function stream = + [&myEngine](const tl::request& req, const encoder&) { + req.respond(); + }; + + myEngine.define("stream", stream); + myEngine.wait_for_finalize(); + + return 0; +} + diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index ba31fb3..4bd1542 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -19,3 +19,4 @@ add_subdirectory(17_partial) add_subdirectory(18_config) add_subdirectory(19_logging) add_subdirectory(20_timed_cb) +add_subdirectory(21_encoding) diff --git a/include/thallium/serialization/cereal/archives.hpp b/include/thallium/serialization/cereal/archives.hpp index af19038..d9ca3c2 100644 --- a/include/thallium/serialization/cereal/archives.hpp +++ b/include/thallium/serialization/cereal/archives.hpp @@ -67,6 +67,14 @@ namespace thallium { return m_context; } + void* save_ptr(size_t size) { + return hg_proc_save_ptr(m_proc, size); + } + + void restore_ptr(void* buf, size_t size) { + hg_proc_restore_ptr(m_proc, buf, size); + } + private: hg_proc_t m_proc; @@ -122,6 +130,14 @@ namespace thallium { return m_context; } + void* save_ptr(size_t size) { + return hg_proc_save_ptr(m_proc, size); + } + + void restore_ptr(void* buf, size_t size) { + hg_proc_restore_ptr(m_proc, buf, size); + } + private: hg_proc_t m_proc; diff --git a/include/thallium/serialization/proc_input_archive.hpp b/include/thallium/serialization/proc_input_archive.hpp index a656b9d..d2c03c1 100644 --- a/include/thallium/serialization/proc_input_archive.hpp +++ b/include/thallium/serialization/proc_input_archive.hpp @@ -161,6 +161,20 @@ class proc_input_archive : public input_archive { auto& get_context() { return m_context; } + + /** + * @brief Calls hg_proc_save_ptr for manual encoding into the Mercury buffer. + */ + void* save_ptr(size_t size) { + return hg_proc_save_ptr(m_proc, size); + } + + /** + * @brief Restore pointer after manual encoding. + */ + void restore_ptr(void* buf, size_t size) { + hg_proc_restore_ptr(m_proc, buf, size); + } }; } diff --git a/include/thallium/serialization/proc_output_archive.hpp b/include/thallium/serialization/proc_output_archive.hpp index 76b390f..3000484 100644 --- a/include/thallium/serialization/proc_output_archive.hpp +++ b/include/thallium/serialization/proc_output_archive.hpp @@ -153,6 +153,20 @@ class proc_output_archive : public output_archive { auto& get_context() { return m_context; } + + /** + * @brief Calls hg_proc_save_ptr for manual encoding into the Mercury buffer. + */ + void* save_ptr(size_t size) { + return hg_proc_save_ptr(m_proc, size); + } + + /** + * @brief Restore pointer after manual encoding. + */ + void restore_ptr(void* buf, size_t size) { + hg_proc_restore_ptr(m_proc, buf, size); + } }; } diff --git a/spack.yaml b/spack.yaml index 583f591..fc9a87f 100644 --- a/spack.yaml +++ b/spack.yaml @@ -1,7 +1,13 @@ spack: specs: - mochi-margo ^mercury~boostsys~checksum ^libfabric fabrics=tcp,rxm + - pkg-config - cmake - cereal concretizer: unify: true + reuse: true + modules: + prefix_inspections: + lib: [LD_LIBRARY_PATH] + lib64: [LD_LIBRARY_PATH] diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index a74f962..68316cd 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -13,7 +13,7 @@ set (thallium-pkg "share/cmake/thallium") # library version set here (e.g. for shared libs). # set (THALLIUM_VERSION_MAJOR 0) -set (THALLIUM_VERSION_MINOR 12) +set (THALLIUM_VERSION_MINOR 13) set (THALLIUM_VERSION_PATCH 0) set (thallium-vers "${THALLIUM_VERSION_MAJOR}.${THALLIUM_VERSION_MINOR}") set (THALLIUM_VERSION "${thallium-vers}.${THALLIUM_VERSION_PATCH}")