Skip to content

Commit

Permalink
added functions to access pointer to Mercury buffer
Browse files Browse the repository at this point in the history
  • Loading branch information
mdorier committed Aug 7, 2024
1 parent b0a0bc8 commit 857f50a
Show file tree
Hide file tree
Showing 10 changed files with 123 additions and 1 deletion.
4 changes: 4 additions & 0 deletions examples/21_encoding/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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)
20 changes: 20 additions & 0 deletions examples/21_encoding/client.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#include <iostream>
#include <thallium.hpp>
#include "encoder.hpp"

namespace tl = thallium;

int main(int argc, char** argv) {
if(argc != 2) {
std::cerr << "Usage: " << argv[0] << " <address>" << 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;
}

25 changes: 25 additions & 0 deletions examples/21_encoding/encoder.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#include <iostream>

class encoder {

public:

template<typename A>
void save(A& ar) const {
auto buffer = static_cast<char*>(ar.save_ptr(26));
for(int i = 0; i < 26; ++i) {
buffer[i] = 'A' + i;
}
ar.restore_ptr(buffer, 26);
}

template<typename A>
void load(A& ar) {
auto buffer = static_cast<char*>(ar.save_ptr(26));
for(int i = 0; i < 26; ++i) {
std::cout << buffer[i];
}
std::cout << std::endl;
ar.restore_ptr(buffer, 26);
}
};
22 changes: 22 additions & 0 deletions examples/21_encoding/server.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#include <iostream>
#include <thallium.hpp>
#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<void(const tl::request&, const encoder&)> stream =
[&myEngine](const tl::request& req, const encoder&) {
req.respond();
};

myEngine.define("stream", stream);
myEngine.wait_for_finalize();

return 0;
}

1 change: 1 addition & 0 deletions examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
16 changes: 16 additions & 0 deletions include/thallium/serialization/cereal/archives.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
14 changes: 14 additions & 0 deletions include/thallium/serialization/proc_input_archive.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
};

}
Expand Down
14 changes: 14 additions & 0 deletions include/thallium/serialization/proc_output_archive.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
};

}
Expand Down
6 changes: 6 additions & 0 deletions spack.yaml
Original file line number Diff line number Diff line change
@@ -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]
2 changes: 1 addition & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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}")
Expand Down

0 comments on commit 857f50a

Please sign in to comment.