Skip to content

Commit

Permalink
Update workflows
Browse files Browse the repository at this point in the history
  • Loading branch information
lkimuk committed May 9, 2024
1 parent 481c560 commit 4855d1f
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 6 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/cmake-single-platform.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
79 changes: 75 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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**
Expand Down Expand Up @@ -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 <okec/okec.hpp>

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<okec::worst_fit_decision_engine>(&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 <okec/okec.hpp>

Expand All @@ -386,8 +458,7 @@ void generate_task(okec::task& t, int number, std::string const& group)
}
}

okec::awaitable
offloading(std::shared_ptr<okec::client_device> user, okec::task t) {
okec::awaitable offloading(auto user, okec::task t) {
olog::debug("offloading begin");

co_await user->async_send(std::move(t));
Expand Down
3 changes: 1 addition & 2 deletions examples/src/wf_async.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<okec::client_device> user, okec::task t) {
okec::awaitable offloading(auto user, okec::task t) {
log::debug("offloading begin");

co_await user->async_send(std::move(t));
Expand Down

0 comments on commit 4855d1f

Please sign in to comment.