From 4855d1ffb2120df9fc159fdebed24391d816818f Mon Sep 17 00:00:00 2001 From: lkimuk Date: Thu, 9 May 2024 22:09:48 +0800 Subject: [PATCH] Update workflows --- .github/workflows/cmake-single-platform.yml | 2 + README.md | 79 +++++++++++++++++++-- examples/src/wf_async.cc | 3 +- 3 files changed, 78 insertions(+), 6 deletions(-) diff --git a/.github/workflows/cmake-single-platform.yml b/.github/workflows/cmake-single-platform.yml index d3144c1..93afeb4 100644 --- a/.github/workflows/cmake-single-platform.yml +++ b/.github/workflows/cmake-single-platform.yml @@ -11,6 +11,8 @@ on: env: # Customize the CMake build type here (Release, Debug, RelWithDebInfo, etc.) BUILD_TYPE: Release + CC: gcc-13 + CXX: g++-13 jobs: build: diff --git a/README.md b/README.md index d81a014..3e656b7 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,8 @@ - [Iterate through tasks](#iterate-through-tasks) - [Append attributes to tasks and modify the task attribute values](#append-attributes-to-tasks-and-modify-the-task-attribute-values) - [Specify the default offloading strategy](#specify-the-default-offloading-strategy) - - [Offloading your first set of tasks using the worst-fit decision engine](#offloading-your-first-set-of-tasks-using-the-worst-fit-decision-engine) + - [Asynchronously offload your first set of tasks using the worst-fit decision engine with callbacks](#asynchronously-offload-your-first-set-of-tasks-using-the-worst-fit-decision-engine-with-callbacks) + - [Asynchronously offload your first set of tasks using the worst-fit decision engine with coroutines](#asynchronously-offload-your-first-set-of-tasks-using-the-worst-fit-decision-engine-with-coroutines) ## Prerequisites **Libraries** @@ -367,7 +368,78 @@ When your program runs, the decision engine will automatically gather resource i [+0.00000000s] █ The decision engine received resource information from edge server(10.1.2.5). ``` -### Offloading your first set of tasks using the worst-fit decision engine +### Asynchronously offload your first set of tasks using the worst-fit decision engine with callbacks +```cpp +#include + +namespace olog = okec::log; + + +void generate_task(okec::task& t, int number, std::string const& group) +{ + for (auto i = number; i-- > 0;) + { + t.emplace_back({ + { "task_id", okec::task::get_unique_id() }, + { "group", group }, + { "cpu", okec::rand_range(0.2, 1.2).to_string() }, + { "deadline", okec::rand_range(1, 5).to_string() }, + }); + } +} + + +int main() +{ + olog::set_level(olog::level::all); + okec::simulator sim; + + // Create 1 base station + okec::base_station_container base_stations(sim, 1); + // Create 5 edge servers + okec::edge_device_container edge_servers(sim, 5); + // Create 2 user devices + okec::client_device_container user_devices(sim, 2); + + // Connect the base stations and edge servers + base_stations.connect_device(edge_servers); + + // Set the network model for every device + okec::multiple_and_single_LAN_WLAN_network_model model; + okec::network_initializer(model, user_devices, base_stations.get(0)); + + // Initialize the resources for each edge server. + okec::resource_container resources(edge_servers.size()); + resources.initialize([](auto res) { + res->attribute("cpu", okec::rand_range(2.1, 2.2).to_string()); + }); + + // Install each resource on each edge server. + edge_servers.install_resources(resources); + + // Specify the default offloading strategy + auto decision_engine = std::make_shared(&user_devices, &base_stations); + decision_engine->initialize(); + + + // Offload tasks + okec::task t; + generate_task(t, 5, "1st"); + auto user1 = user_devices.get_device(0); + user1->async_send(std::move(t)); + user1->async_read([](auto resp) { + olog::success("received response."); + + okec::print("{:r}", resp); + }); + + + // Run the simulator + sim.run(); +} +``` + +### Asynchronously offload your first set of tasks using the worst-fit decision engine with coroutines ```cpp #include @@ -386,8 +458,7 @@ void generate_task(okec::task& t, int number, std::string const& group) } } -okec::awaitable -offloading(std::shared_ptr user, okec::task t) { +okec::awaitable offloading(auto user, okec::task t) { olog::debug("offloading begin"); co_await user->async_send(std::move(t)); diff --git a/examples/src/wf_async.cc b/examples/src/wf_async.cc index cf73de8..cba40ad 100644 --- a/examples/src/wf_async.cc +++ b/examples/src/wf_async.cc @@ -25,8 +25,7 @@ void my_monitor(std::string_view address, std::string_view attr, std::string_vie file << okec::format("At time {:.2f}s,{},{},{}\n", okec::now::seconds(), address, old_val, new_val); } -okec::awaitable -offloading(std::shared_ptr user, okec::task t) { +okec::awaitable offloading(auto user, okec::task t) { log::debug("offloading begin"); co_await user->async_send(std::move(t));