Commit 142f87ed authored by Matthieu Dorier's avatar Matthieu Dorier

added many example

parent 32e87f50
......@@ -56,3 +56,4 @@ xpkg_import_module (margo REQUIRED margo)
add_subdirectory (src)
add_subdirectory (test)
add_subdirectory (examples)
add_executable(00_init_server server.cpp)
target_link_libraries(00_init_server thallium)
add_executable(00_init_client client.cpp)
target_link_libraries(00_init_client thallium)
#include <thallium.hpp>
namespace tl = thallium;
int main(int argc, char** argv) {
tl::engine myEngine("bmi+tcp", THALLIUM_CLIENT_MODE);
return 0;
}
#include <iostream>
#include <thallium.hpp>
namespace tl = thallium;
int main(int argc, char** argv) {
tl::engine myEngine("bmi+tcp://127.0.0.1:1234", THALLIUM_SERVER_MODE);
std::cout << "Server running at address " << myEngine.self() << std::endl;
return 0;
}
add_executable(01_hello_server server.cpp)
target_link_libraries(01_hello_server thallium)
add_executable(01_hello_client client.cpp)
target_link_libraries(01_hello_client thallium)
#include <thallium.hpp>
namespace tl = thallium;
int main(int argc, char** argv) {
tl::engine myEngine("bmi+tcp", THALLIUM_CLIENT_MODE);
tl::remote_procedure hello = myEngine.define("hello").ignore_response();
tl::endpoint server = myEngine.lookup("bmi+tcp://127.0.0.1:1234");
hello.on(server)();
return 0;
}
#include <iostream>
#include <thallium.hpp>
namespace tl = thallium;
void hello(const tl::request& req) {
std::cout << "Hello World!" << std::endl;
}
int main(int argc, char** argv) {
tl::engine myEngine("bmi+tcp://127.0.0.1:1234", THALLIUM_SERVER_MODE);
myEngine.define("hello", hello).ignore_response();
return 0;
}
add_executable(02_sum_server server.cpp)
target_link_libraries(02_sum_server thallium)
add_executable(02_sum_client client.cpp)
target_link_libraries(02_sum_client thallium)
#include <iostream>
#include <thallium.hpp>
namespace tl = thallium;
int main(int argc, char** argv) {
tl::engine myEngine("bmi+tcp", THALLIUM_CLIENT_MODE);
tl::remote_procedure sum = myEngine.define("sum");
tl::endpoint server = myEngine.lookup("bmi+tcp://127.0.0.1:1234");
int ret = sum.on(server)(42,63);
std::cout << "Server answered " << ret << std::endl;
return 0;
}
#include <iostream>
#include <thallium.hpp>
namespace tl = thallium;
void sum(const tl::request& req, int x, int y) {
std::cout << "Computing " << x << "+" << y << std::endl;
req.respond(x+y);
}
int main(int argc, char** argv) {
tl::engine myEngine("bmi+tcp://127.0.0.1:1234", THALLIUM_SERVER_MODE);
myEngine.define("sum", sum);
return 0;
}
add_executable(03_lambda_server server.cpp)
target_link_libraries(03_lambda_server thallium)
add_executable(03_lambda_client client.cpp)
target_link_libraries(03_lambda_client thallium)
#include <iostream>
#include <thallium.hpp>
namespace tl = thallium;
int main(int argc, char** argv) {
tl::engine myEngine("bmi+tcp", THALLIUM_CLIENT_MODE);
tl::remote_procedure sum = myEngine.define("sum");
tl::endpoint server = myEngine.lookup("bmi+tcp://127.0.0.1:1234");
int ret = sum.on(server)(42,63);
std::cout << "Server answered " << ret << std::endl;
return 0;
}
#include <iostream>
#include <thallium.hpp>
namespace tl = thallium;
int main(int argc, char** argv) {
tl::engine myEngine("bmi+tcp://127.0.0.1:1234", THALLIUM_SERVER_MODE);
std::function<void(const tl::request&, int, int)> sum =
[](const tl::request& req, int x, int y) {
std::cout << "Computing " << x << "+" << y << std::endl;
req.respond(x+y);
};
myEngine.define("sum", sum);
return 0;
}
add_executable(04_stop_server server.cpp)
target_link_libraries(04_stop_server thallium)
add_executable(04_stop_client client.cpp)
target_link_libraries(04_stop_client thallium)
#include <iostream>
#include <thallium.hpp>
namespace tl = thallium;
int main(int argc, char** argv) {
tl::engine myEngine("bmi+tcp", THALLIUM_CLIENT_MODE);
tl::remote_procedure sum = myEngine.define("sum");
tl::endpoint server = myEngine.lookup("bmi+tcp://127.0.0.1:1234");
int ret = sum.on(server)(42,63);
std::cout << "Server answered " << ret << std::endl;
return 0;
}
#include <iostream>
#include <thallium.hpp>
namespace tl = thallium;
int main(int argc, char** argv) {
tl::engine myEngine("bmi+tcp://127.0.0.1:1234", THALLIUM_SERVER_MODE);
std::function<void(const tl::request&, int, int)> sum =
[&myEngine](const tl::request& req, int x, int y) {
std::cout << "Computing " << x << "+" << y << std::endl;
req.respond(x+y);
myEngine.finalize();
};
myEngine.define("sum", sum);
return 0;
}
add_executable(05_stl_server server.cpp)
target_link_libraries(05_stl_server thallium)
add_executable(05_stl_client client.cpp)
target_link_libraries(05_stl_client thallium)
#include <string>
#include <thallium.hpp>
#include <thallium/serialization/stl/string.hpp>
namespace tl = thallium;
int main(int argc, char** argv) {
tl::engine myEngine("bmi+tcp", THALLIUM_CLIENT_MODE);
tl::remote_procedure hello = myEngine.define("hello").ignore_response();
tl::endpoint server = myEngine.lookup("bmi+tcp://127.0.0.1:1234");
std::string name = "Matthieu";
hello.on(server)(name);
return 0;
}
#include <string>
#include <iostream>
#include <thallium.hpp>
#include <thallium/serialization/stl/string.hpp>
namespace tl = thallium;
void hello(const tl::request& req, const std::string& name) {
std::cout << "Hello " << name << std::endl;
}
int main(int argc, char** argv) {
tl::engine myEngine("bmi+tcp://127.0.0.1:1234", THALLIUM_SERVER_MODE);
myEngine.define("hello", hello).ignore_response();
return 0;
}
add_executable(06_custom_server server.cpp)
target_link_libraries(06_custom_server thallium)
add_executable(06_custom_client client.cpp)
target_link_libraries(06_custom_client thallium)
#include <iostream>
#include <thallium.hpp>
#include "point.hpp"
namespace tl = thallium;
int main(int argc, char** argv) {
tl::engine myEngine("bmi+tcp", THALLIUM_CLIENT_MODE);
tl::remote_procedure dot_product = myEngine.define("dot_product");
tl::endpoint server = myEngine.lookup("bmi+tcp://127.0.0.1:1234");
point p(1,2,3);
point q(5,2,4);
double ret = dot_product.on(server)(p,q);
std::cout << "Dot product : " << ret << std::endl;
return 0;
}
class point {
private:
double x;
double y;
double z;
public:
point(double a=0.0, double b=0.0, double c=0.0)
: x(a), y(b), z(c) {}
template<typename A>
void serialize(A& ar) {
ar & x;
ar & y;
ar & z;
}
double operator*(const point& p) const {
return p.x * x + p.y * y + p.z * z;
}
};
#include <iostream>
#include <thallium.hpp>
#include "point.hpp"
namespace tl = thallium;
int main(int argc, char** argv) {
tl::engine myEngine("bmi+tcp://127.0.0.1:1234", THALLIUM_SERVER_MODE);
std::function<void(const tl::request&, const point&, const point&)> dot_product =
[&myEngine](const tl::request& req, const point& p, const point& q) {
req.respond(p*q);
myEngine.finalize();
};
myEngine.define("dot_product", dot_product);
return 0;
}
add_executable(07_rdma_server server.cpp)
target_link_libraries(07_rdma_server thallium)
add_executable(07_rdma_client client.cpp)
target_link_libraries(07_rdma_client thallium)
#include <iostream>
#include <thallium.hpp>
namespace tl = thallium;
int main(int argc, char** argv) {
tl::engine myEngine("bmi+tcp", MARGO_CLIENT_MODE);
tl::remote_procedure remote_do_rdma = myEngine.define("do_rdma").ignore_response();
tl::endpoint server_endpoint = myEngine.lookup("bmi+tcp://127.0.0.1:1234");
std::string buffer = "Matthieu";
std::vector<std::pair<void*,std::size_t>> segments(1);
segments[0].first = (void*)(&buffer[0]);
segments[0].second = buffer.size()+1;
tl::bulk myBulk = myEngine.expose(segments, tl::bulk_mode::read_only);
remote_do_rdma.on(server_endpoint)(myBulk);
return 0;
}
#include <iostream>
#include <thallium.hpp>
#include <thallium/serialization/stl/string.hpp>
namespace tl = thallium;
int main(int argc, char** argv) {
tl::engine myEngine("bmi+tcp://127.0.0.1:1234", THALLIUM_SERVER_MODE);
std::function<void(const tl::request&, tl::bulk&)> f =
[&myEngine](const tl::request& req, tl::bulk& b) {
tl::endpoint ep = req.get_endpoint();
std::vector<char> v(6);
std::vector<std::pair<void*,std::size_t>> segments(1);
segments[0].first = (void*)(&v[0]);
segments[0].second = v.size();
tl::bulk local = myEngine.expose(segments, tl::bulk_mode::write_only);
b.on(ep) >> local;
std::cout << "Server received bulk: ";
for(auto c : v) std::cout << c;
std::cout << std::endl;
};
myEngine.define("do_rdma",f).ignore_response();
}
add_subdirectory(00_init)
add_subdirectory(01_hello)
add_subdirectory(02_sum)
add_subdirectory(03_lambda)
add_subdirectory(04_stop)
add_subdirectory(05_stl)
add_subdirectory(06_custom)
add_subdirectory(07_rdma)
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