Skip to content

Commit 857f50a

Browse files
committed
added functions to access pointer to Mercury buffer
1 parent b0a0bc8 commit 857f50a

File tree

10 files changed

+123
-1
lines changed

10 files changed

+123
-1
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
add_executable (21_encoding_server server.cpp)
2+
target_link_libraries (21_encoding_server thallium)
3+
add_executable (21_encoding_client client.cpp)
4+
target_link_libraries (21_encoding_client thallium)

examples/21_encoding/client.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#include <iostream>
2+
#include <thallium.hpp>
3+
#include "encoder.hpp"
4+
5+
namespace tl = thallium;
6+
7+
int main(int argc, char** argv) {
8+
if(argc != 2) {
9+
std::cerr << "Usage: " << argv[0] << " <address>" << std::endl;
10+
exit(0);
11+
}
12+
tl::engine myEngine("tcp", THALLIUM_CLIENT_MODE);
13+
tl::remote_procedure stream = myEngine.define("stream");
14+
tl::endpoint server = myEngine.lookup(argv[1]);
15+
encoder e;
16+
stream.on(server)(e);
17+
18+
return 0;
19+
}
20+

examples/21_encoding/encoder.hpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#include <iostream>
2+
3+
class encoder {
4+
5+
public:
6+
7+
template<typename A>
8+
void save(A& ar) const {
9+
auto buffer = static_cast<char*>(ar.save_ptr(26));
10+
for(int i = 0; i < 26; ++i) {
11+
buffer[i] = 'A' + i;
12+
}
13+
ar.restore_ptr(buffer, 26);
14+
}
15+
16+
template<typename A>
17+
void load(A& ar) {
18+
auto buffer = static_cast<char*>(ar.save_ptr(26));
19+
for(int i = 0; i < 26; ++i) {
20+
std::cout << buffer[i];
21+
}
22+
std::cout << std::endl;
23+
ar.restore_ptr(buffer, 26);
24+
}
25+
};

examples/21_encoding/server.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#include <iostream>
2+
#include <thallium.hpp>
3+
#include "encoder.hpp"
4+
5+
namespace tl = thallium;
6+
7+
int main() {
8+
9+
tl::engine myEngine("tcp", THALLIUM_SERVER_MODE);
10+
std::cout << "Server running at address " << myEngine.self() << std::endl;
11+
12+
std::function<void(const tl::request&, const encoder&)> stream =
13+
[&myEngine](const tl::request& req, const encoder&) {
14+
req.respond();
15+
};
16+
17+
myEngine.define("stream", stream);
18+
myEngine.wait_for_finalize();
19+
20+
return 0;
21+
}
22+

examples/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,4 @@ add_subdirectory(17_partial)
1919
add_subdirectory(18_config)
2020
add_subdirectory(19_logging)
2121
add_subdirectory(20_timed_cb)
22+
add_subdirectory(21_encoding)

include/thallium/serialization/cereal/archives.hpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,14 @@ namespace thallium {
6767
return m_context;
6868
}
6969

70+
void* save_ptr(size_t size) {
71+
return hg_proc_save_ptr(m_proc, size);
72+
}
73+
74+
void restore_ptr(void* buf, size_t size) {
75+
hg_proc_restore_ptr(m_proc, buf, size);
76+
}
77+
7078
private:
7179

7280
hg_proc_t m_proc;
@@ -122,6 +130,14 @@ namespace thallium {
122130
return m_context;
123131
}
124132

133+
void* save_ptr(size_t size) {
134+
return hg_proc_save_ptr(m_proc, size);
135+
}
136+
137+
void restore_ptr(void* buf, size_t size) {
138+
hg_proc_restore_ptr(m_proc, buf, size);
139+
}
140+
125141
private:
126142

127143
hg_proc_t m_proc;

include/thallium/serialization/proc_input_archive.hpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,20 @@ class proc_input_archive : public input_archive {
161161
auto& get_context() {
162162
return m_context;
163163
}
164+
165+
/**
166+
* @brief Calls hg_proc_save_ptr for manual encoding into the Mercury buffer.
167+
*/
168+
void* save_ptr(size_t size) {
169+
return hg_proc_save_ptr(m_proc, size);
170+
}
171+
172+
/**
173+
* @brief Restore pointer after manual encoding.
174+
*/
175+
void restore_ptr(void* buf, size_t size) {
176+
hg_proc_restore_ptr(m_proc, buf, size);
177+
}
164178
};
165179

166180
}

include/thallium/serialization/proc_output_archive.hpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,20 @@ class proc_output_archive : public output_archive {
153153
auto& get_context() {
154154
return m_context;
155155
}
156+
157+
/**
158+
* @brief Calls hg_proc_save_ptr for manual encoding into the Mercury buffer.
159+
*/
160+
void* save_ptr(size_t size) {
161+
return hg_proc_save_ptr(m_proc, size);
162+
}
163+
164+
/**
165+
* @brief Restore pointer after manual encoding.
166+
*/
167+
void restore_ptr(void* buf, size_t size) {
168+
hg_proc_restore_ptr(m_proc, buf, size);
169+
}
156170
};
157171

158172
}

spack.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
11
spack:
22
specs:
33
- mochi-margo ^mercury~boostsys~checksum ^libfabric fabrics=tcp,rxm
4+
- pkg-config
45
- cmake
56
- cereal
67
concretizer:
78
unify: true
9+
reuse: true
10+
modules:
11+
prefix_inspections:
12+
lib: [LD_LIBRARY_PATH]
13+
lib64: [LD_LIBRARY_PATH]

src/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ set (thallium-pkg "share/cmake/thallium")
1313
# library version set here (e.g. for shared libs).
1414
#
1515
set (THALLIUM_VERSION_MAJOR 0)
16-
set (THALLIUM_VERSION_MINOR 12)
16+
set (THALLIUM_VERSION_MINOR 13)
1717
set (THALLIUM_VERSION_PATCH 0)
1818
set (thallium-vers "${THALLIUM_VERSION_MAJOR}.${THALLIUM_VERSION_MINOR}")
1919
set (THALLIUM_VERSION "${thallium-vers}.${THALLIUM_VERSION_PATCH}")

0 commit comments

Comments
 (0)