1 /* Copyright (c) 2017-2023. The SimGrid Team. All rights reserved. */
3 /* This program is free software; you can redistribute it and/or modify it
4 * under the terms of the license (GNU LGPL) which comes with this package. */
6 /* This example tests increasing and decreasing parallelism degree of Tasks.
7 * First we increase and decrease parallelism degree while the Task is idle,
8 * then we increase and decrease parallelism degree while the Task has queued firings.
11 #include "simgrid/s4u.hpp"
13 XBT_LOG_NEW_DEFAULT_CATEGORY(task_parallelism, "Messages specific for this s4u example");
14 namespace sg4 = simgrid::s4u;
16 static void manager(sg4::ExecTaskPtr t)
18 t->set_parallelism_degree(1);
19 t->enqueue_firings(2);
20 sg4::this_actor::sleep_for(300);
22 t->set_parallelism_degree(2);
23 t->enqueue_firings(4);
24 sg4::this_actor::sleep_for(300);
26 t->set_parallelism_degree(1);
27 t->enqueue_firings(2);
28 sg4::this_actor::sleep_for(300);
30 t->enqueue_firings(11);
31 t->set_parallelism_degree(2);
32 sg4::this_actor::sleep_for(150);
33 t->set_parallelism_degree(1);
34 sg4::this_actor::sleep_for(200);
35 t->set_parallelism_degree(3);
38 int main(int argc, char* argv[])
40 sg4::Engine e(&argc, argv);
41 e.load_platform(argv[1]);
42 auto pm0 = e.host_by_name("PM0");
43 auto t = sg4::ExecTask::init("exec_A", 100 * pm0->get_speed(), pm0);
44 sg4::Task::on_completion_cb(
45 [](const sg4::Task* t) { XBT_INFO("Task %s finished (%d)", t->get_cname(), t->get_count()); });
46 sg4::Task::on_start_cb([](const sg4::Task* t) { XBT_INFO("Task %s start", t->get_cname()); });
47 sg4::Actor::create("sender", pm0, manager, t);