From 74c678b8644aa28d345490294709922d4c489bf5 Mon Sep 17 00:00:00 2001 From: Fred Suter Date: Tue, 20 Jun 2023 09:24:41 -0400 Subject: [PATCH] Move Tasks from a plugin to s4u --- ChangeLog | 6 +- MANIFEST.in | 8 +-- examples/cpp/task-io/s4u-task-io.cpp | 18 +++--- examples/cpp/task-simple/s4u-task-simple.cpp | 16 ++--- examples/cpp/task-storm/s4u-task-storm.cpp | 51 ++++++++------- .../task-switch-host/s4u-task-switch-host.cpp | 21 +++--- .../s4u-task-variable-load.cpp | 21 +++--- examples/python/task-io/task-io.py | 1 - examples/python/task-simple/task-simple.py | 2 - .../task-switch-host/task-switch-host.py | 1 - .../task-variable-load/task-variable-load.py | 1 - include/simgrid/s4u.hpp | 1 + .../{plugins/task.hpp => s4u/Task.hpp} | 16 ++--- src/bindings/python/simgrid_python.cpp | 19 +++--- src/{plugins/task.cpp => s4u/s4u_Task.cpp} | 64 +++++-------------- tools/cmake/DefinePackages.cmake | 22 +++---- 16 files changed, 110 insertions(+), 158 deletions(-) rename include/simgrid/{plugins/task.hpp => s4u/Task.hpp} (93%) rename src/{plugins/task.cpp => s4u/s4u_Task.cpp} (82%) diff --git a/ChangeLog b/ChangeLog index 78392f19c1..9ae720e54c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -17,13 +17,15 @@ S4U: Comm::set_payload_size() to change the size of the simulated data. - New function: Engine::flatify_platform(), to get a fully detailed vision of the configured platform. + - New Task abstraction: They are designed to represent dataflows, i.e, graphs of repeatable Activities. + See the examples under examples/cpp/task-* and the associated documentation. - Full simDAG integration: Activity::start() actually starts only when all dependencies are fullfiled. If it cannot be started right away, it will start as soon as it becomes possible. - Allow to set a concurrency limit on disks and hosts, as it was already the case for links. - Rename Link::get_usage() to Link::get_load() for consistency with Host:: - Every signal now come with a static version that is invoked for every object of that class, - and an instance version that is invoked for this specific object only. For example, + and an instance version that is invoked for this specific object only. For example, s4u::Actor::on_suspend_cb() adds a callback that is invoked for the suspend of any actor while s4u::Actor::on_this_suspend_cb() adds a callback for this specific actor only. - Activity::on_suspended_cb() is renamed to Activity::on_suspend_cb(), and fired right before the suspend. @@ -34,8 +36,6 @@ S4U: That is, callbacks registered in Exec::on_suspend_cb will not be fired for Comms nor Ios. New S4U plugins: - - Task: They are designed to represent dataflows, i.e, graphs of repeatable Activities. - See the examples under examples/cpp/task-* and the documentation in the Plugins page. - Battery: Enable the management of batteries on hosts. See the examples under examples/cpp/battery-* and the documentation in the Plugins page. - Photovoltaic: Enable the management of photovoltaic panels on hosts. diff --git a/MANIFEST.in b/MANIFEST.in index 13eeb1e84b..76abec2d71 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -399,7 +399,7 @@ include examples/cpp/task-io/s4u-task-io.tesh include examples/cpp/task-simple/s4u-task-simple.cpp include examples/cpp/task-simple/s4u-task-simple.tesh include examples/cpp/task-storm/s4u-task-storm.cpp -include examples/cpp/task-storm/s4u-task-storm.thesh +include examples/cpp/task-storm/s4u-task-storm.tesh include examples/cpp/task-switch-host/s4u-task-switch-host.cpp include examples/cpp/task-switch-host/s4u-task-switch-host.tesh include examples/cpp/task-variable-load/s4u-task-variable-load.cpp @@ -1947,7 +1947,6 @@ include include/simgrid/plugins/live_migration.h include include/simgrid/plugins/load.h include include/simgrid/plugins/ns3.hpp include include/simgrid/plugins/photovoltaic.hpp -include include/simgrid/plugins/task.hpp include include/simgrid/s4u.hpp include include/simgrid/s4u/Activity.hpp include include/simgrid/s4u/Actor.hpp @@ -1964,6 +1963,7 @@ include include/simgrid/s4u/Mailbox.hpp include include/simgrid/s4u/Mutex.hpp include include/simgrid/s4u/NetZone.hpp include include/simgrid/s4u/Semaphore.hpp +include include/simgrid/s4u/Task.hpp include include/simgrid/s4u/VirtualMachine.hpp include include/simgrid/semaphore.h include include/simgrid/simix.h @@ -2230,9 +2230,9 @@ include src/mc/explo/udpor/Configuration_test.cpp include src/mc/explo/udpor/EventSet.cpp include src/mc/explo/udpor/EventSet.hpp include src/mc/explo/udpor/EventSet_test.cpp -include src/mc/explo/udpor/ExtensionSet_test.cpp include src/mc/explo/udpor/ExtensionSetCalculator.cpp include src/mc/explo/udpor/ExtensionSetCalculator.hpp +include src/mc/explo/udpor/ExtensionSet_test.cpp include src/mc/explo/udpor/History.cpp include src/mc/explo/udpor/History.hpp include src/mc/explo/udpor/History_test.cpp @@ -2324,7 +2324,6 @@ include src/plugins/link_energy.cpp include src/plugins/link_energy_wifi.cpp include src/plugins/link_load.cpp include src/plugins/photovoltaic.cpp -include src/plugins/task.cpp include src/plugins/vm/VmLiveMigration.cpp include src/plugins/vm/VmLiveMigration.hpp include src/plugins/vm/dirty_page_tracking.cpp @@ -2343,6 +2342,7 @@ include src/s4u/s4u_Mailbox.cpp include src/s4u/s4u_Mutex.cpp include src/s4u/s4u_Netzone.cpp include src/s4u/s4u_Semaphore.cpp +include src/s4u/s4u_Task.cpp include src/s4u/s4u_VirtualMachine.cpp include src/simgrid/Exception.cpp include src/simgrid/math_utils.h diff --git a/examples/cpp/task-io/s4u-task-io.cpp b/examples/cpp/task-io/s4u-task-io.cpp index 6301657dad..19102f25a5 100644 --- a/examples/cpp/task-io/s4u-task-io.cpp +++ b/examples/cpp/task-io/s4u-task-io.cpp @@ -3,7 +3,7 @@ /* This program is free software; you can redistribute it and/or modify it * under the terms of the license (GNU LGPL) which comes with this package. */ -/* This example demonstrate basic use of the task plugin. +/* This example demonstrate basic use of tasks. * * We model the following graph: * @@ -13,27 +13,27 @@ * comm is a communication task. */ -#include "simgrid/plugins/task.hpp" +#include "simgrid/s4u/Task.hpp" #include "simgrid/s4u.hpp" #include XBT_LOG_NEW_DEFAULT_CATEGORY(task_simple, "Messages specific for this task example"); +namespace sg4 = simgrid::s4u; int main(int argc, char* argv[]) { - simgrid::s4u::Engine e(&argc, argv); + sg4::Engine e(&argc, argv); e.load_platform(argv[1]); - simgrid::plugins::Task::init(); // Retrieve hosts auto* bob = e.host_by_name("bob"); auto* carl = e.host_by_name("carl"); // Create tasks - auto exec1 = simgrid::plugins::ExecTask::init("exec1", 1e9, bob); - auto exec2 = simgrid::plugins::ExecTask::init("exec2", 1e9, carl); - auto write = simgrid::plugins::IoTask::init("write", 1e7, bob->get_disks().front(), simgrid::s4u::Io::OpType::WRITE); - auto read = simgrid::plugins::IoTask::init("read", 1e7, carl->get_disks().front(), simgrid::s4u::Io::OpType::READ); + auto exec1 = sg4::ExecTask::init("exec1", 1e9, bob); + auto exec2 = sg4::ExecTask::init("exec2", 1e9, carl); + auto write = sg4::IoTask::init("write", 1e7, bob->get_disks().front(), sg4::Io::OpType::WRITE); + auto read = sg4::IoTask::init("read", 1e7, carl->get_disks().front(), sg4::Io::OpType::READ); // Create the graph by defining dependencies between tasks exec1->add_successor(write); @@ -41,7 +41,7 @@ int main(int argc, char* argv[]) read->add_successor(exec2); // Add a function to be called when tasks end for log purpose - simgrid::plugins::Task::on_end_cb([](const simgrid::plugins::Task* t) { + sg4::Task::on_end_cb([](const sg4::Task* t) { XBT_INFO("Task %s finished (%d)", t->get_name().c_str(), t->get_count()); }); diff --git a/examples/cpp/task-simple/s4u-task-simple.cpp b/examples/cpp/task-simple/s4u-task-simple.cpp index 3e9d14fa13..dc3df1d04d 100644 --- a/examples/cpp/task-simple/s4u-task-simple.cpp +++ b/examples/cpp/task-simple/s4u-task-simple.cpp @@ -3,7 +3,7 @@ /* This program is free software; you can redistribute it and/or modify it * under the terms of the license (GNU LGPL) which comes with this package. */ -/* This example demonstrate basic use of the task plugin. +/* This example demonstrate basic use of tasks. * * We model the following graph: * @@ -13,32 +13,32 @@ * comm is a communication task. */ -#include "simgrid/plugins/task.hpp" #include "simgrid/s4u.hpp" XBT_LOG_NEW_DEFAULT_CATEGORY(task_simple, "Messages specific for this task example"); +namespace sg4 = simgrid::s4u; + int main(int argc, char* argv[]) { - simgrid::s4u::Engine e(&argc, argv); + sg4::Engine e(&argc, argv); e.load_platform(argv[1]); - simgrid::plugins::Task::init(); // Retrieve hosts auto* tremblay = e.host_by_name("Tremblay"); auto* jupiter = e.host_by_name("Jupiter"); // Create tasks - auto exec1 = simgrid::plugins::ExecTask::init("exec1", 1e9, tremblay); - auto exec2 = simgrid::plugins::ExecTask::init("exec2", 1e9, jupiter); - auto comm = simgrid::plugins::CommTask::init("comm", 1e7, tremblay, jupiter); + auto exec1 = sg4::ExecTask::init("exec1", 1e9, tremblay); + auto exec2 = sg4::ExecTask::init("exec2", 1e9, jupiter); + auto comm = sg4::CommTask::init("comm", 1e7, tremblay, jupiter); // Create the graph by defining dependencies between tasks exec1->add_successor(comm); comm->add_successor(exec2); // Add a function to be called when tasks end for log purpose - simgrid::plugins::Task::on_end_cb([](const simgrid::plugins::Task* t) { + sg4::Task::on_end_cb([](const sg4::Task* t) { XBT_INFO("Task %s finished (%d)", t->get_name().c_str(), t->get_count()); }); diff --git a/examples/cpp/task-storm/s4u-task-storm.cpp b/examples/cpp/task-storm/s4u-task-storm.cpp index 7c02415200..bfd52b740e 100644 --- a/examples/cpp/task-storm/s4u-task-storm.cpp +++ b/examples/cpp/task-storm/s4u-task-storm.cpp @@ -7,12 +7,12 @@ and use them to build a simulation of a stream processing application Spout SA produces data every 100ms. The volume produced is alternatively 1e3, 1e6 and 1e9 bytes. - Spout SB produces 1e6 bytes every 200ms. - + Spout SB produces 1e6 bytes every 200ms. + Bolt B1 and B2 processes data from Spout SA alternatively. The quantity of work to process this data is 10 flops per bytes Bolt B3 processes data from Spout SB. Bolt B4 processes data from Bolt B3. - + Fafard ┌────┐ ┌──►│ B1 │ @@ -29,19 +29,18 @@ ┌────┐ │ │ │ SB ├─────┤ B3 ──► B4│ └────┘ │ │ - └──────────┘ + └──────────┘ */ -#include "simgrid/plugins/task.hpp" #include "simgrid/s4u.hpp" XBT_LOG_NEW_DEFAULT_CATEGORY(task_storm, "Messages specific for this s4u example"); +namespace sg4 = simgrid::s4u; int main(int argc, char* argv[]) { - simgrid::s4u::Engine e(&argc, argv); + sg4::Engine e(&argc, argv); e.load_platform(argv[1]); - simgrid::plugins::Task::init(); // Retrieve hosts auto tremblay = e.host_by_name("Tremblay"); @@ -51,17 +50,17 @@ int main(int argc, char* argv[]) auto bourassa = e.host_by_name("Bourassa"); // Create execution tasks - auto SA = simgrid::plugins::ExecTask::init("SA", tremblay->get_speed() * 0.1, tremblay); - auto SB = simgrid::plugins::ExecTask::init("SB", jupiter->get_speed() * 0.2, jupiter); - auto B1 = simgrid::plugins::ExecTask::init("B1", 1e8, fafard); - auto B2 = simgrid::plugins::ExecTask::init("B2", 1e8, ginette); - auto B3 = simgrid::plugins::ExecTask::init("B3", 1e8, bourassa); - auto B4 = simgrid::plugins::ExecTask::init("B4", 2e8, bourassa); + auto SA = sg4::ExecTask::init("SA", tremblay->get_speed() * 0.1, tremblay); + auto SB = sg4::ExecTask::init("SB", jupiter->get_speed() * 0.2, jupiter); + auto B1 = sg4::ExecTask::init("B1", 1e8, fafard); + auto B2 = sg4::ExecTask::init("B2", 1e8, ginette); + auto B3 = sg4::ExecTask::init("B3", 1e8, bourassa); + auto B4 = sg4::ExecTask::init("B4", 2e8, bourassa); // Create communication tasks - auto SA_to_B1 = simgrid::plugins::CommTask::init("SA_to_B1", 0, tremblay, fafard); - auto SA_to_B2 = simgrid::plugins::CommTask::init("SA_to_B2", 0, tremblay, ginette); - auto SB_to_B3 = simgrid::plugins::CommTask::init("SB_to_B3", 1e6, jupiter, bourassa); + auto SA_to_B1 = sg4::CommTask::init("SA_to_B1", 0, tremblay, fafard); + auto SA_to_B2 = sg4::CommTask::init("SA_to_B2", 0, tremblay, ginette); + auto SB_to_B3 = sg4::CommTask::init("SB_to_B3", 1e6, jupiter, bourassa); // Create the graph by defining dependencies between tasks // Some dependencies are defined dynamically @@ -75,9 +74,9 @@ int main(int argc, char* argv[]) Alternatively we: remove/add the link between SA and SA_to_B2 add/remove the link between SA and SA_to_B1 */ - SA->on_this_start_cb([&](simgrid::plugins::Task* t) { + SA->on_this_start_cb([&](sg4::Task* t) { int count = t->get_count(); - simgrid::plugins::CommTaskPtr comm; + sg4::CommTaskPtr comm; if (count % 2 == 0) { t->remove_successor(SA_to_B2); t->add_successor(SA_to_B1); @@ -90,27 +89,27 @@ int main(int argc, char* argv[]) } std::vector amount = {1e3,1e6,1e9}; comm->set_amount(amount[count % 3]); - auto token = std::make_shared(); + auto token = std::make_shared(); token->set_data(new double(amount[count % 3])); t->set_token(token); }); // The token sent by SA is forwarded by both communication tasks - SA_to_B1->on_this_start_cb([&](simgrid::plugins::Task* t) { + SA_to_B1->on_this_start_cb([&](sg4::Task* t) { t->set_token(t->get_next_token_from(SA)); }); - SA_to_B2->on_this_start_cb([&](simgrid::plugins::Task* t) { + SA_to_B2->on_this_start_cb([&](sg4::Task* t) { t->set_token(t->get_next_token_from(SA)); }); /* B1 and B2 read the value of the token received by their predecessors and use it to adapt their amount of work to do. - */ - B1->on_this_start_cb([&](simgrid::plugins::Task* t) { + */ + B1->on_this_start_cb([&](sg4::Task* t) { auto data = t->get_next_token_from(SA_to_B1)->get_unique_data(); t->set_amount(*data * 10); }); - B2->on_this_start_cb([&](simgrid::plugins::Task* t) { + B2->on_this_start_cb([&](sg4::Task* t) { auto data = t->get_next_token_from(SA_to_B2)->get_unique_data(); t->set_amount(*data * 10); }); @@ -120,8 +119,8 @@ int main(int argc, char* argv[]) SB->enqueue_execs(5); // Add a function to be called when tasks end for log purpose - simgrid::plugins::Task::on_end_cb([] - (const simgrid::plugins::Task* t) { + sg4::Task::on_end_cb([] + (const sg4::Task* t) { XBT_INFO("Task %s finished (%d)", t->get_name().c_str(), t->get_count()); }); diff --git a/examples/cpp/task-switch-host/s4u-task-switch-host.cpp b/examples/cpp/task-switch-host/s4u-task-switch-host.cpp index 6ebca129da..ae19ebc93b 100644 --- a/examples/cpp/task-switch-host/s4u-task-switch-host.cpp +++ b/examples/cpp/task-switch-host/s4u-task-switch-host.cpp @@ -16,16 +16,15 @@ * With exec1 and exec2 on different hosts. */ -#include "simgrid/plugins/task.hpp" #include "simgrid/s4u.hpp" XBT_LOG_NEW_DEFAULT_CATEGORY(task_switch_host, "Messages specific for this task example"); +namespace sg4 = simgrid::s4u; int main(int argc, char* argv[]) { - simgrid::s4u::Engine e(&argc, argv); + sg4::Engine e(&argc, argv); e.load_platform(argv[1]); - simgrid::plugins::Task::init(); // Retrieve hosts auto* tremblay = e.host_by_name("Tremblay"); @@ -33,13 +32,13 @@ int main(int argc, char* argv[]) auto* fafard = e.host_by_name("Fafard"); // Create tasks - auto comm0 = simgrid::plugins::CommTask::init("comm0"); + auto comm0 = sg4::CommTask::init("comm0"); comm0->set_bytes(1e7); comm0->set_source(tremblay); - auto exec1 = simgrid::plugins::ExecTask::init("exec1", 1e9, jupiter); - auto exec2 = simgrid::plugins::ExecTask::init("exec2", 1e9, fafard); - auto comm1 = simgrid::plugins::CommTask::init("comm1", 1e7, jupiter, tremblay); - auto comm2 = simgrid::plugins::CommTask::init("comm2", 1e7, fafard, tremblay); + auto exec1 = sg4::ExecTask::init("exec1", 1e9, jupiter); + auto exec2 = sg4::ExecTask::init("exec2", 1e9, fafard); + auto comm1 = sg4::CommTask::init("comm1", 1e7, jupiter, tremblay); + auto comm2 = sg4::CommTask::init("comm2", 1e7, fafard, tremblay); // Create the initial graph by defining dependencies between tasks comm0->add_successor(exec2); @@ -47,15 +46,15 @@ int main(int argc, char* argv[]) exec2->add_successor(comm2); // Add a function to be called when tasks end for log purpose - simgrid::plugins::Task::on_end_cb([](const simgrid::plugins::Task* t) { + sg4::Task::on_end_cb([](const sg4::Task* t) { XBT_INFO("Task %s finished (%d)", t->get_name().c_str(), t->get_count()); }); // Add a function to be called before each executions of comm0 // This function modifies the graph of tasks by adding or removing // successors to comm0 - comm0->on_this_start_cb([exec1, exec2, jupiter, fafard](simgrid::plugins::Task* t) { - auto* comm0 = dynamic_cast(t); + comm0->on_this_start_cb([exec1, exec2, jupiter, fafard](sg4::Task* t) { + auto* comm0 = dynamic_cast(t); static int count = 0; if (count % 2 == 0) { comm0->set_destination(jupiter); diff --git a/examples/cpp/task-variable-load/s4u-task-variable-load.cpp b/examples/cpp/task-variable-load/s4u-task-variable-load.cpp index 960fb660a6..b0d3efd955 100644 --- a/examples/cpp/task-variable-load/s4u-task-variable-load.cpp +++ b/examples/cpp/task-variable-load/s4u-task-variable-load.cpp @@ -13,50 +13,49 @@ * With a heavy load there is a burst of comm before the exec task can even finish once. */ -#include "simgrid/plugins/task.hpp" #include "simgrid/s4u.hpp" XBT_LOG_NEW_DEFAULT_CATEGORY(task_variable_load, "Messages specific for this s4u example"); +namespace sg4 = simgrid::s4u; -static void variable_load(simgrid::plugins::TaskPtr t) +static void variable_load(sg4::TaskPtr t) { XBT_INFO("--- Small load ---"); for (int i = 0; i < 3; i++) { t->enqueue_execs(1); - simgrid::s4u::this_actor::sleep_for(100); + sg4::this_actor::sleep_for(100); } - simgrid::s4u::this_actor::sleep_until(1000); + sg4::this_actor::sleep_until(1000); XBT_INFO("--- Heavy load ---"); for (int i = 0; i < 3; i++) { t->enqueue_execs(1); - simgrid::s4u::this_actor::sleep_for(1); + sg4::this_actor::sleep_for(1); } } int main(int argc, char* argv[]) { - simgrid::s4u::Engine e(&argc, argv); + sg4::Engine e(&argc, argv); e.load_platform(argv[1]); - simgrid::plugins::Task::init(); // Retreive hosts auto* tremblay = e.host_by_name("Tremblay"); auto* jupiter = e.host_by_name("Jupiter"); // Create tasks - auto comm = simgrid::plugins::CommTask::init("comm", 1e7, tremblay, jupiter); - auto exec = simgrid::plugins::ExecTask::init("exec", 1e9, jupiter); + auto comm = sg4::CommTask::init("comm", 1e7, tremblay, jupiter); + auto exec = sg4::ExecTask::init("exec", 1e9, jupiter); // Create the graph by defining dependencies between tasks comm->add_successor(exec); // Add a function to be called when tasks end for log purpose - simgrid::plugins::Task::on_end_cb([](const simgrid::plugins::Task* t) { + sg4::Task::on_end_cb([](const sg4::Task* t) { XBT_INFO("Task %s finished (%d)", t->get_name().c_str(), t->get_count()); }); // Create the actor that will inject load during the simulation - simgrid::s4u::Actor::create("input", tremblay, variable_load, comm); + sg4::Actor::create("input", tremblay, variable_load, comm); // Start the simulation e.run(); diff --git a/examples/python/task-io/task-io.py b/examples/python/task-io/task-io.py index b74c41169c..431a78990c 100644 --- a/examples/python/task-io/task-io.py +++ b/examples/python/task-io/task-io.py @@ -24,7 +24,6 @@ if __name__ == '__main__': args = parse() e = Engine(sys.argv) e.load_platform(args.platform) - Task.init() # Retrieve hosts bob = e.host_by_name('bob') diff --git a/examples/python/task-simple/task-simple.py b/examples/python/task-simple/task-simple.py index 1219906ce9..4ac876e8f8 100644 --- a/examples/python/task-simple/task-simple.py +++ b/examples/python/task-simple/task-simple.py @@ -34,7 +34,6 @@ if __name__ == '__main__': args = parse() e = Engine(sys.argv) e.load_platform(args.platform) - Task.init() # Retrieve hosts tremblay = e.host_by_name('Tremblay') @@ -57,4 +56,3 @@ if __name__ == '__main__': # runs the simulation e.run() - diff --git a/examples/python/task-switch-host/task-switch-host.py b/examples/python/task-switch-host/task-switch-host.py index a95db1645f..f56bc40883 100644 --- a/examples/python/task-switch-host/task-switch-host.py +++ b/examples/python/task-switch-host/task-switch-host.py @@ -55,7 +55,6 @@ if __name__ == '__main__': args = parse() e = Engine(sys.argv) e.load_platform(args.platform) - Task.init() # Retrieve hosts tremblay = e.host_by_name('Tremblay') diff --git a/examples/python/task-variable-load/task-variable-load.py b/examples/python/task-variable-load/task-variable-load.py index 73105847ce..63925d9b63 100644 --- a/examples/python/task-variable-load/task-variable-load.py +++ b/examples/python/task-variable-load/task-variable-load.py @@ -45,7 +45,6 @@ if __name__ == '__main__': args = parse() e = Engine(sys.argv) e.load_platform(args.platform) - Task.init() # Retrieve hosts tremblay = e.host_by_name('Tremblay') diff --git a/include/simgrid/s4u.hpp b/include/simgrid/s4u.hpp index f694696d23..77a71df2c4 100644 --- a/include/simgrid/s4u.hpp +++ b/include/simgrid/s4u.hpp @@ -22,6 +22,7 @@ #include #include #include +#include #include #include diff --git a/include/simgrid/plugins/task.hpp b/include/simgrid/s4u/Task.hpp similarity index 93% rename from include/simgrid/plugins/task.hpp rename to include/simgrid/s4u/Task.hpp index 87a357be43..ef787347a5 100644 --- a/include/simgrid/plugins/task.hpp +++ b/include/simgrid/s4u/Task.hpp @@ -1,5 +1,5 @@ -#ifndef SIMGRID_PLUGINS_TASK_H_ -#define SIMGRID_PLUGINS_TASK_H_ +#ifndef SIMGRID_S4U_TASK_H_ +#define SIMGRID_S4U_TASK_H_ #include #include @@ -11,7 +11,7 @@ #include #include -namespace simgrid::plugins { +namespace simgrid::s4u { class Task; using TaskPtr = boost::intrusive_ptr; @@ -24,11 +24,6 @@ using CommTaskPtr = boost::intrusive_ptr; class IoTask; using IoTaskPtr = boost::intrusive_ptr; -struct ExtendedAttributeActivity { - static simgrid::xbt::Extension EXTENSION_ID; - Task* task_; -}; - class XBT_PUBLIC Token : public xbt::Extendable {}; class Task { @@ -37,7 +32,6 @@ class Task { bool ready_to_run() const; void receive(Task* source); - void complete(); protected: std::string name_; @@ -54,13 +48,13 @@ protected: explicit Task(const std::string& name); virtual ~Task() = default; virtual void fire() = 0; + void complete(); static xbt::signal on_start; static xbt::signal on_end; std::atomic_int_fast32_t refcount_{0}; public: - static void init(); const std::string& get_name() const { return name_; } const char* get_cname() const { return name_.c_str(); } void enqueue_execs(int n); @@ -145,5 +139,5 @@ public: IoTaskPtr set_op_type(s4u::Io::OpType type); s4u::Io::OpType get_op_type() const { return type_; } }; -} // namespace simgrid::plugins +} // namespace simgrid::s4u #endif diff --git a/src/bindings/python/simgrid_python.cpp b/src/bindings/python/simgrid_python.cpp index 5f0f33599c..52f5ca6adb 100644 --- a/src/bindings/python/simgrid_python.cpp +++ b/src/bindings/python/simgrid_python.cpp @@ -11,7 +11,6 @@ #include "simgrid/kernel/ProfileBuilder.hpp" #include "simgrid/kernel/routing/NetPoint.hpp" #include -#include #include #include #include @@ -25,6 +24,7 @@ #include #include #include +#include #include #include @@ -33,14 +33,14 @@ #include namespace py = pybind11; -using simgrid::plugins::CommTask; -using simgrid::plugins::CommTaskPtr; -using simgrid::plugins::ExecTask; -using simgrid::plugins::ExecTaskPtr; -using simgrid::plugins::IoTask; -using simgrid::plugins::IoTaskPtr; -using simgrid::plugins::Task; -using simgrid::plugins::TaskPtr; +using simgrid::s4u::CommTask; +using simgrid::s4u::CommTaskPtr; +using simgrid::s4u::ExecTask; +using simgrid::s4u::ExecTaskPtr; +using simgrid::s4u::IoTask; +using simgrid::s4u::IoTaskPtr; +using simgrid::s4u::Task; +using simgrid::s4u::TaskPtr; using simgrid::s4u::Actor; using simgrid::s4u::ActorPtr; using simgrid::s4u::Barrier; @@ -921,7 +921,6 @@ PYBIND11_MODULE(simgrid, m) /* Class Task */ py::class_(m, "Task", "Task. See the C++ documentation for details.") - .def_static("init", &Task::init) .def_static( "on_start_cb", [](py::object cb) { diff --git a/src/plugins/task.cpp b/src/s4u/s4u_Task.cpp similarity index 82% rename from src/plugins/task.cpp rename to src/s4u/s4u_Task.cpp index 835b307144..c0a6e38e90 100644 --- a/src/plugins/task.cpp +++ b/src/s4u/s4u_Task.cpp @@ -1,6 +1,6 @@ #include #include -#include +#include #include #include #include @@ -9,16 +9,13 @@ #include "src/simgrid/module.hpp" SIMGRID_REGISTER_PLUGIN(task, "Battery management", nullptr) -/** @defgroup plugin_task plugin_task Plugin Task - +/** @beginrst -This is the task plugin, enabling management of Tasks. -To activate this plugin, first call :cpp:func:`Task::init`. Tasks are designed to represent dataflows, i.e, graphs of Tasks. Tasks can only be instancied using either -:cpp:func:`simgrid::plugins::ExecTask::init` or :cpp:func:`simgrid::plugins::CommTask::init` +:cpp:func:`simgrid::s4u::ExecTask::init` or :cpp:func:`simgrid::s4u::CommTask::init` An ExecTask is an Execution Task. Its underlying Activity is an :ref:`Exec `. A CommTask is a Communication Task. Its underlying Activity is a :ref:`Comm `. @@ -26,9 +23,7 @@ A CommTask is a Communication Task. Its underlying Activity is a :ref:`Comm ExtendedAttributeActivity::EXTENSION_ID; +namespace simgrid::s4u { xbt::signal Task::on_start; xbt::signal Task::on_end; @@ -94,28 +89,7 @@ void Task::complete() fire(); } -/** @ingroup plugin_task - * @brief Init the Task plugin. - * @note Add a completion callback to all Activities to call Task::complete(). - */ -void Task::init() -{ - static bool inited = false; - if (inited) - return; - - inited = true; - ExtendedAttributeActivity::EXTENSION_ID = simgrid::s4u::Activity::extension_create(); - simgrid::s4u::Exec::on_completion_cb( - [](simgrid::s4u::Exec const& exec) { exec.extension()->task_->complete(); }); - simgrid::s4u::Comm::on_completion_cb( - [](simgrid::s4u::Comm const& comm) { comm.extension()->task_->complete(); }); - simgrid::s4u::Io::on_completion_cb( - [](simgrid::s4u::Io const& io) { io.extension()->task_->complete(); }); -} - -/** @ingroup plugin_task - * @param n The number of executions to enqueue. +/** @param n The number of executions to enqueue. * @brief Enqueue executions. * @note Immediatly starts an execution if possible. */ @@ -128,8 +102,7 @@ void Task::enqueue_execs(int n) }); } -/** @ingroup plugin_task - * @param amount The amount to set. +/** @param amount The amount to set. * @brief Set the amout of work to do. * @note Amount in flop for ExecTask and in bytes for CommTask. */ @@ -138,8 +111,7 @@ void Task::set_amount(double amount) simgrid::kernel::actor::simcall_answered([this, amount] { amount_ = amount; }); } -/** @ingroup plugin_task - * @param token The token to set. +/** @param token The token to set. * @brief Set the token to send to successors. * @note The token is passed to each successor after the task end, i.e., after the on_end callback. */ @@ -148,8 +120,7 @@ void Task::set_token(std::shared_ptr token) simgrid::kernel::actor::simcall_answered([this, token] { token_ = token; }); } -/** @ingroup plugin_task - * @return Map of tokens received for the next execution. +/** @return Map of tokens received for the next execution. * @note If there is no queued execution for this task the map might not exist or be partially empty. */ std::shared_ptr Task::get_next_token_from(TaskPtr t) @@ -157,8 +128,7 @@ std::shared_ptr Task::get_next_token_from(TaskPtr t) return tokens_received_.front()[t]; } -/** @ingroup plugin_task - * @param successor The Task to add. +/** @param successor The Task to add. * @brief Add a successor to this Task. * @note It also adds this as a predecessor of successor. */ @@ -170,8 +140,7 @@ void Task::add_successor(TaskPtr successor) }); } -/** @ingroup plugin_task - * @param successor The Task to remove. +/** @param successor The Task to remove. * @brief Remove a successor from this Task. * @note It also remove this from the predecessors of successor. */ @@ -261,8 +230,7 @@ void ExecTask::fire() exec->set_flops_amount(amount_); exec->set_host(host_); exec->start(); - exec->extension_set(new ExtendedAttributeActivity()); - exec->extension()->task_ = this; + exec->on_this_completion_cb([this](Exec const& exec) { this->complete(); }); current_activity_ = exec; } @@ -323,8 +291,7 @@ void CommTask::fire() comm->set_name(name_); comm->set_payload_size(amount_); comm->start(); - comm->extension_set(new ExtendedAttributeActivity()); - comm->extension()->task_ = this; + comm->on_this_completion_cb([this](Comm const& comm) { this->complete(); }); current_activity_ = comm; } @@ -418,9 +385,8 @@ void IoTask::fire() io->set_disk(disk_); io->set_op_type(type_); io->start(); - io->extension_set(new ExtendedAttributeActivity()); - io->extension()->task_ = this; - current_activity_ = io; + io->on_this_completion_cb([this](Io const& io) { this->complete(); }); + current_activity_ = io; } -} // namespace simgrid::plugins +} // namespace simgrid::s4u diff --git a/tools/cmake/DefinePackages.cmake b/tools/cmake/DefinePackages.cmake index 5fa39d64f4..9b9aaa8e06 100644 --- a/tools/cmake/DefinePackages.cmake +++ b/tools/cmake/DefinePackages.cmake @@ -25,7 +25,7 @@ set(EXTRA_DIST src/kernel/resource/models/network_ns3.hpp src/kernel/resource/models/ns3/ns3_simulator.hpp src/kernel/resource/models/ptask_L07.hpp - + src/mc/datatypes.h src/mc/mc.h src/mc/mc_mmu.hpp @@ -56,7 +56,7 @@ set(EXTRA_DIST src/xbt/log_private.hpp src/xbt/mallocator_private.h src/xbt/parmap.hpp - + src/xbt/mmalloc/mmalloc.h src/xbt/mmalloc/mfree.c src/xbt/mmalloc/mm_legacy.c @@ -342,7 +342,7 @@ set(KERNEL_SRC src/kernel/actor/SimcallObserver.hpp src/kernel/actor/SynchroObserver.cpp src/kernel/actor/SynchroObserver.hpp - + src/kernel/context/Context.cpp src/kernel/context/Context.hpp src/kernel/context/ContextRaw.cpp @@ -454,7 +454,6 @@ set(PLUGINS_SRC src/plugins/vm/VmLiveMigration.hpp src/plugins/vm/dirty_page_tracking.cpp src/plugins/battery.cpp - src/plugins/task.cpp src/plugins/photovoltaic.cpp ) @@ -475,6 +474,7 @@ set(S4U_SRC src/s4u/s4u_Mutex.cpp src/s4u/s4u_Netzone.cpp src/s4u/s4u_Semaphore.cpp + src/s4u/s4u_Task.cpp src/s4u/s4u_VirtualMachine.cpp ) @@ -521,7 +521,7 @@ set(MC_SRC_BASE src/mc/mc_replay.hpp src/mc/transition/Transition.cpp ) - + set(MC_SRC_STATELESS src/mc/api/ActorState.hpp src/mc/api/ClockVector.cpp @@ -530,7 +530,7 @@ set(MC_SRC_STATELESS src/mc/api/State.hpp src/mc/api/RemoteApp.cpp src/mc/api/RemoteApp.hpp - + src/mc/explo/DFSExplorer.cpp src/mc/explo/DFSExplorer.hpp src/mc/explo/Exploration.cpp @@ -577,7 +577,7 @@ set(MC_SRC_STATEFUL src/mc/explo/LivenessChecker.hpp src/mc/explo/UdporChecker.cpp src/mc/explo/UdporChecker.hpp - + src/mc/explo/udpor/Comb.hpp src/mc/explo/udpor/Configuration.hpp src/mc/explo/udpor/Configuration.cpp @@ -595,7 +595,7 @@ set(MC_SRC_STATEFUL src/mc/explo/udpor/Unfolding.hpp src/mc/explo/udpor/udpor_forward.hpp src/mc/explo/udpor/udpor_tests_private.hpp - + src/mc/inspect/DwarfExpression.cpp src/mc/inspect/DwarfExpression.hpp src/mc/inspect/Frame.cpp @@ -614,7 +614,7 @@ set(MC_SRC_STATEFUL src/mc/inspect/mc_unw.cpp src/mc/inspect/mc_unw.hpp src/mc/inspect/mc_unw_vmread.cpp - + src/mc/sosp/ChunkedData.cpp src/mc/sosp/ChunkedData.hpp src/mc/sosp/PageStore.cpp @@ -641,7 +641,7 @@ set(MC_SRC_STATEFUL src/mc/api/strategy/MinMatchComm.hpp src/mc/api/strategy/Strategy.hpp src/mc/api/strategy/UniformStrategy.hpp - + src/xbt/mmalloc/mm_interface.c ) @@ -661,7 +661,6 @@ set(headers_to_install include/simgrid/plugins/file_system.h include/simgrid/plugins/live_migration.h include/simgrid/plugins/load.h - include/simgrid/plugins/task.hpp include/simgrid/plugins/photovoltaic.hpp include/simgrid/plugins/ProducerConsumer.hpp include/simgrid/instr.h @@ -695,6 +694,7 @@ set(headers_to_install include/simgrid/s4u/Mutex.hpp include/simgrid/s4u/NetZone.hpp include/simgrid/s4u/Semaphore.hpp + include/simgrid/s4u/Task.hpp include/simgrid/s4u/VirtualMachine.hpp include/simgrid/s4u.hpp -- 2.20.1