From: mlaurent Date: Thu, 29 Jun 2023 11:14:05 +0000 (+0200) Subject: Merge branch 'master' of https://framagit.org/simgrid/simgrid X-Git-Tag: v3.35~164^2 X-Git-Url: http://bilbo.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/d9c1e4df4ecfc39d84e55527fa05e9bd19f70c6c?hp=-c Merge branch 'master' of https://framagit.org/simgrid/simgrid --- d9c1e4df4ecfc39d84e55527fa05e9bd19f70c6c diff --combined examples/cpp/task-storm/s4u-task-storm.cpp index d290ca01e9,5c7ae70c68..58d08c379c --- a/examples/cpp/task-storm/s4u-task-storm.cpp +++ b/examples/cpp/task-storm/s4u-task-storm.cpp @@@ -3,15 -3,15 +3,15 @@@ /* 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 takes the main concepts of Apache Storm presented here https://storm.apache.org/releases/2.4.0/Concepts.html - and use them to build a simulation of a stream processing application +/* This example takes the main concepts of Apache Storm presented here + https://storm.apache.org/releases/2.4.0/Concepts.html 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. - 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. + 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 ┌────┐ @@@ -45,7 -45,7 +45,7 @@@ int main(int argc, char* argv[] // Retrieve hosts auto tremblay = e.host_by_name("Tremblay"); auto jupiter = e.host_by_name("Jupiter"); - auto fafard = e.host_by_name("Fafard"); + auto fafard = e.host_by_name("Fafard"); auto ginette = e.host_by_name("Ginette"); auto bourassa = e.host_by_name("Bourassa"); @@@ -74,19 -74,20 +74,19 @@@ 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([SA_to_B1,SA_to_B2](sg4::Task* t) { + SA->on_this_start_cb([SA_to_B1, SA_to_B2](sg4::Task* t) { int count = t->get_count(); sg4::CommTaskPtr comm; if (count % 2 == 0) { t->remove_successor(SA_to_B2); t->add_successor(SA_to_B1); comm = SA_to_B1; - } - else { + } else { t->remove_successor(SA_to_B1); t->add_successor(SA_to_B2); comm = SA_to_B2; } - std::vector amount = {1e3,1e6,1e9}; + std::vector amount = {1e3, 1e6, 1e9}; comm->set_amount(amount[count % 3]); auto token = std::make_shared(); token->set_data(new double(amount[count % 3])); @@@ -94,8 -95,8 +94,8 @@@ }); // The token sent by SA is forwarded by both communication tasks - SA_to_B1->on_this_start_cb([SA](sg4::Task* t) { t->set_token(t->get_next_token_from(SA)); }); - SA_to_B2->on_this_start_cb([SA](sg4::Task* t) { t->set_token(t->get_next_token_from(SA)); }); + SA_to_B1->on_this_start_cb([&SA](sg4::Task* t) { t->set_token(t->get_next_token_from(SA)); }); + SA_to_B2->on_this_start_cb([&SA](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. @@@ -114,8 -115,10 +114,8 @@@ SB->enqueue_firings(5); // Add a function to be called when tasks end for log purpose - sg4::Task::on_completion_cb([] - (const sg4::Task* t) { - XBT_INFO("Task %s finished (%d)", t->get_name().c_str(), t->get_count()); - }); + sg4::Task::on_completion_cb( + [](const sg4::Task* t) { XBT_INFO("Task %s finished (%d)", t->get_name().c_str(), t->get_count()); }); // Start the simulation e.run(); diff --combined examples/cpp/task-switch-host/s4u-task-switch-host.cpp index 252f3382e3,4a93265d30..b007523f73 --- a/examples/cpp/task-switch-host/s4u-task-switch-host.cpp +++ b/examples/cpp/task-switch-host/s4u-task-switch-host.cpp @@@ -46,13 -46,14 +46,13 @@@ int main(int argc, char* argv[] exec2->add_successor(comm2); // Add a function to be called when tasks end for log purpose - sg4::Task::on_completion_cb([](const sg4::Task* t) { - XBT_INFO("Task %s finished (%d)", t->get_name().c_str(), t->get_count()); - }); + sg4::Task::on_completion_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 firing of comm0 // This function modifies the graph of tasks by adding or removing // successors to comm0 - comm0->on_this_start_cb([comm0, exec1, exec2, jupiter, fafard](sg4::Task*) { + comm0->on_this_start_cb([&comm0, exec1, exec2, jupiter, fafard](const sg4::Task*) { static int count = 0; if (count % 2 == 0) { comm0->set_destination(jupiter); diff --combined include/simgrid/s4u/Activity.hpp index 46ab38b77e,4f766d4485..b66268ef3b --- a/include/simgrid/s4u/Activity.hpp +++ b/include/simgrid/s4u/Activity.hpp @@@ -104,14 -104,16 +104,16 @@@ protected * It is forbidden to change the amount of work once the Activity is started */ Activity* set_remaining(double remains); - virtual void fire_on_completion() const = 0; + virtual void fire_on_start() const = 0; + virtual void fire_on_this_start() const = 0; + virtual void fire_on_completion() const = 0; virtual void fire_on_this_completion() const = 0; - virtual void fire_on_suspend() const = 0; - virtual void fire_on_this_suspend() const = 0; - virtual void fire_on_resume() const = 0; - virtual void fire_on_this_resume() const = 0; - virtual void fire_on_veto() const = 0; - virtual void fire_on_this_veto() const = 0; + virtual void fire_on_suspend() const = 0; + virtual void fire_on_this_suspend() const = 0; + virtual void fire_on_resume() const = 0; + virtual void fire_on_this_resume() const = 0; + virtual void fire_on_veto() = 0; + virtual void fire_on_this_veto() = 0; public: void start() @@@ -233,7 -235,8 +235,8 @@@ template class Acti std::string name_ = "unnamed"; std::string tracing_category_ = ""; - protected: + inline static xbt::signal on_start; + xbt::signal on_this_start; inline static xbt::signal on_completion; xbt::signal on_this_completion; inline static xbt::signal on_suspend; @@@ -243,7 -246,23 +246,23 @@@ inline static xbt::signal on_veto; xbt::signal on_this_veto; + protected: + void fire_on_start() const override { on_start(static_cast(*this)); } + void fire_on_this_start() const override { on_this_start(static_cast(*this)); } + void fire_on_completion() const override { on_completion(static_cast(*this)); } + void fire_on_this_completion() const override { on_this_completion(static_cast(*this)); } + void fire_on_suspend() const override { on_suspend(static_cast(*this)); } + void fire_on_this_suspend() const override { on_this_suspend(static_cast(*this)); } + void fire_on_resume() const override { on_resume(static_cast(*this)); } + void fire_on_this_resume() const override { on_this_resume(static_cast(*this)); } + void fire_on_veto() override { on_veto(static_cast(*this)); } + void fire_on_this_veto() override { on_this_veto(static_cast(*this)); } + public: + /*! \static Add a callback fired when any activity starts (no veto) */ + static void on_start_cb(const std::function& cb) { on_start.connect(cb); } + /*! Add a callback fired when this specific activity starts (no veto) */ + void on_this_start_cb(const std::function& cb) { on_this_start.connect(cb); } /*! \static Add a callback fired when any activity completes (either normally, cancelled or failed) */ static void on_completion_cb(const std::function& cb) { on_completion.connect(cb); } /*! Add a callback fired when this specific activity completes (either normally, cancelled or failed) */ @@@ -264,15 -283,9 +283,15 @@@ void on_this_veto_cb(const std::function& cb) { on_this_veto.connect(cb); } XBT_ATTRIB_DEPRECATED_v338("Please use on_suspend_cb() instead") static void on_suspended_cb( - const std::function& cb) { on_suspend.connect(cb); } + const std::function& cb) + { + on_suspend.connect(cb); + } XBT_ATTRIB_DEPRECATED_v338("Please use on_resume_cb() instead") static void on_resumed_cb( - const std::function& cb) { on_resume.connect(cb); } + const std::function& cb) + { + on_resume.connect(cb); + } AnyActivity* add_successor(ActivityPtr a) { diff --combined include/simgrid/s4u/Task.hpp index 5c8050b86f,c776b898c3..f854adb86d --- a/include/simgrid/s4u/Task.hpp +++ b/include/simgrid/s4u/Task.hpp @@@ -30,8 -30,8 +30,8 @@@ class Task std::string name_; double amount_; int queued_firings_ = 0; - int count_ = 0; - bool working_ = false; + int count_ = 0; + bool working_ = false; std::set successors_ = {}; std::map predecessors_ = {}; @@@ -45,20 -45,20 +45,20 @@@ ActivityPtr previous_activity_; ActivityPtr current_activity_; + inline static xbt::signal on_start; + xbt::signal on_this_start; + inline static xbt::signal on_completion; + xbt::signal on_this_completion; + protected: explicit Task(const std::string& name); - virtual ~Task() = default; + virtual ~Task() = default; virtual void fire(); void complete(); - void set_current_activity (ActivityPtr a) { current_activity_ = a; } + void set_current_activity(ActivityPtr a) { current_activity_ = a; } - inline static xbt::signal on_start; - xbt::signal on_this_start; - inline static xbt::signal on_completion; - xbt::signal on_this_completion; - public: const std::string& get_name() const { return name_; } const char* get_cname() const { return name_.c_str(); } @@@ -77,7 -77,7 +77,7 @@@ void enqueue_firings(int n); /** Add a callback fired before this task activity starts */ - void on_this_start_cb(const std::function& func){ on_this_start.connect(func); } + void on_this_start_cb(const std::function& func) { on_this_start.connect(func); } /** Add a callback fired before a task activity starts. * Triggered after the on_this_start function**/ static void on_start_cb(const std::function& cb) { on_start.connect(cb); } diff --combined src/bindings/python/simgrid_python.cpp index 268750fb19,f5e9bff9f0..07517ed349 --- a/src/bindings/python/simgrid_python.cpp +++ b/src/bindings/python/simgrid_python.cpp @@@ -10,6 -10,7 +10,7 @@@ #include "simgrid/kernel/ProfileBuilder.hpp" #include "simgrid/kernel/routing/NetPoint.hpp" + #include "simgrid/plugins/load.h" #include #include #include @@@ -33,30 -34,30 +34,30 @@@ #include namespace py = pybind11; -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; using simgrid::s4u::BarrierPtr; using simgrid::s4u::Comm; using simgrid::s4u::CommPtr; +using simgrid::s4u::CommTask; +using simgrid::s4u::CommTaskPtr; using simgrid::s4u::Disk; using simgrid::s4u::Engine; +using simgrid::s4u::ExecTask; +using simgrid::s4u::ExecTaskPtr; using simgrid::s4u::Host; using simgrid::s4u::Io; +using simgrid::s4u::IoTask; +using simgrid::s4u::IoTaskPtr; using simgrid::s4u::Link; using simgrid::s4u::Mailbox; using simgrid::s4u::Mutex; using simgrid::s4u::MutexPtr; using simgrid::s4u::Semaphore; using simgrid::s4u::SemaphorePtr; +using simgrid::s4u::Task; +using simgrid::s4u::TaskPtr; XBT_LOG_NEW_DEFAULT_CATEGORY(python, "python"); @@@ -365,6 -366,8 +366,8 @@@ PYBIND11_MODULE(simgrid, m py::overload_cast(&Host::create_disk), py::call_guard(), "Create a disk") .def("seal", &Host::seal, py::call_guard(), "Seal this host") + .def("turn_off", &Host::turn_off, py::call_guard(), "Turn off this host") + .def("turn_on", &Host::turn_on, py::call_guard(), "Turn on this host") .def_property("pstate", &Host::get_pstate, py::cpp_function(&Host::set_pstate, py::call_guard()), "The current pstate (read/write property).") @@@ -400,7 -403,28 +403,28 @@@ "") .def( "__repr__", [](const Host* h) { return "Host(" + h->get_name() + ")"; }, - "Textual representation of the Host"); + "Textual representation of the Host."); + + m.def("sg_host_load_plugin_init", [host]() { + sg_host_load_plugin_init(); + + static_cast>>(host) + .def( + "reset_load", [](const Host* h) { sg_host_load_reset(h); }, py::call_guard(), + "Reset counters of the host load plugin for this host.") + .def_property_readonly( + "current_load", [](const Host* h) { return sg_host_get_current_load(h); }, "Current load of the host.") + .def_property_readonly( + "avg_load", [](const Host* h) { return sg_host_get_avg_load(h); }, "Average load of the host.") + .def_property_readonly( + "idle_time", [](const Host* h) { return sg_host_get_idle_time(h); }, "Idle time of the host") + .def_property_readonly( + "total_idle_time", [](const Host* h) { return sg_host_get_total_idle_time(h); }, + "Total idle time of the host.") + .def_property_readonly( + "computed_flops", [](const Host* h) { return sg_host_get_computed_flops(h); }, + "Computed flops of the host."); + }); py::enum_(host, "SharingPolicy") .value("NONLINEAR", simgrid::s4u::Host::SharingPolicy::NONLINEAR) diff --combined src/mc/api/strategy/MaxMatchComm.hpp index 0bc3dade6a,ec279d0245..77dadd154c --- a/src/mc/api/strategy/MaxMatchComm.hpp +++ b/src/mc/api/strategy/MaxMatchComm.hpp @@@ -25,7 -25,7 +25,7 @@@ class MaxMatchComm : public Strategy public: void copy_from(const Strategy* strategy) override { - const MaxMatchComm* cast_strategy = dynamic_cast(strategy); + const auto* cast_strategy = dynamic_cast(strategy); xbt_assert(cast_strategy != nullptr); for (auto& [id, val] : cast_strategy->mailbox_) mailbox_[id] = val; @@@ -42,52 -42,45 +42,45 @@@ std::pair best_transition(bool must_be_todo) const override { - std::pair min_found = std::make_pair(-1, value_of_state_+2); + std::pair min_found = std::make_pair(-1, value_of_state_ + 2); for (auto const& [aid, actor] : actors_to_run_) { if ((not actor.is_todo() && must_be_todo) || not actor.is_enabled() || actor.is_done()) continue; int aid_value = value_of_state_; const Transition* transition = actor.get_transition(actor.get_times_considered()).get(); - - const CommRecvTransition* cast_recv = dynamic_cast(transition); - if (cast_recv != nullptr) { - if (mailbox_.count(cast_recv->get_mailbox()) > 0 and - mailbox_.at(cast_recv->get_mailbox()) > 0) { - aid_value--; // This means we have waiting recv corresponding to this recv - } else { + + if (auto const* cast_recv = dynamic_cast(transition)) { - if (mailbox_.count(cast_recv->get_mailbox()) > 0 && mailbox_.at(cast_recv->get_mailbox()) > 0) { - aid_value--; // This means we have waiting recv corresponding to this recv - } else { - aid_value++; - } ++ if (mailbox_.count(cast_recv->get_mailbox()) > 0 && mailbox_.at(cast_recv->get_mailbox()) > 0) { ++ aid_value--; // This means we have waiting recv corresponding to this recv ++ } else { + aid_value++; - } ++ } } - - const CommSendTransition* cast_send = dynamic_cast(transition); - if (cast_send != nullptr) { - if (mailbox_.count(cast_send->get_mailbox()) > 0 and - mailbox_.at(cast_send->get_mailbox()) < 0) { - aid_value--; // This means we have waiting recv corresponding to this send - }else { - aid_value++; - } + + if (auto const* cast_send = dynamic_cast(transition)) { - if (mailbox_.count(cast_send->get_mailbox()) > 0 && mailbox_.at(cast_send->get_mailbox()) < 0) { - aid_value--; // This means we have waiting recv corresponding to this send - } else { - aid_value++; - } ++ if (mailbox_.count(cast_send->get_mailbox()) > 0 && mailbox_.at(cast_send->get_mailbox()) < 0) { ++ aid_value--; // This means we have waiting recv corresponding to this send ++ } else { ++ aid_value++; ++ } } - + if (aid_value < min_found.second) min_found = std::make_pair(aid, aid_value); } return min_found; } - void execute_next(aid_t aid, RemoteApp& app) override { const Transition* transition = actors_to_run_.at(aid).get_transition(actors_to_run_.at(aid).get_times_considered()).get(); last_transition_ = transition->type_; - const CommRecvTransition* cast_recv = dynamic_cast(transition); - if (cast_recv != nullptr) + if (auto const* cast_recv = dynamic_cast(transition)) last_mailbox_ = cast_recv->get_mailbox(); - const CommSendTransition* cast_send = dynamic_cast(transition); - if (cast_send != nullptr) + if (auto const* cast_send = dynamic_cast(transition)) last_mailbox_ = cast_send->get_mailbox(); } }; diff --combined src/mc/api/strategy/MinMatchComm.hpp index 607a0a04a3,7393f4a71f..7d06c9dcf0 --- a/src/mc/api/strategy/MinMatchComm.hpp +++ b/src/mc/api/strategy/MinMatchComm.hpp @@@ -28,25 -28,25 +28,25 @@@ class MinMatchComm : public Strategy public: void copy_from(const Strategy* strategy) override { - const MinMatchComm* cast_strategy = dynamic_cast(strategy); - xbt_assert(cast_strategy != nullptr); - for (auto& [id, val] : cast_strategy->mailbox_) - mailbox_[id] = val; - if (cast_strategy->last_transition_ == Transition::Type::COMM_ASYNC_RECV) - mailbox_[cast_strategy->last_mailbox_]--; - if (cast_strategy->last_transition_ == Transition::Type::COMM_ASYNC_SEND) - mailbox_[cast_strategy->last_mailbox_]++; - - for (auto const& [_, val] : mailbox_) - value_of_state_ -= std::abs(val); - xbt_assert(value_of_state_ > 0, "MinMatchComm value shouldn't reach 0"); + const auto* cast_strategy = dynamic_cast(strategy); + xbt_assert(cast_strategy != nullptr); + for (auto& [id, val] : cast_strategy->mailbox_) + mailbox_[id] = val; + if (cast_strategy->last_transition_ == Transition::Type::COMM_ASYNC_RECV) + mailbox_[cast_strategy->last_mailbox_]--; + if (cast_strategy->last_transition_ == Transition::Type::COMM_ASYNC_SEND) + mailbox_[cast_strategy->last_mailbox_]++; + + for (auto const& [_, val] : mailbox_) + value_of_state_ -= std::abs(val); + xbt_assert(value_of_state_ > 0, "MinMatchComm value shouldn't reach 0"); } MinMatchComm() = default; ~MinMatchComm() override = default; std::pair best_transition(bool must_be_todo) const override { - std::pair min_found = std::make_pair(-1, value_of_state_+2); + std::pair min_found = std::make_pair(-1, value_of_state_ + 2); for (auto const& [aid, actor] : actors_to_run_) { if ((not actor.is_todo() && must_be_todo) || not actor.is_enabled() || actor.is_done()) continue; @@@ -54,23 -54,21 +54,21 @@@ int aid_value = value_of_state_; const Transition* transition = actor.get_transition(actor.get_times_considered()).get(); - const CommRecvTransition* cast_recv = dynamic_cast(transition); - if (cast_recv != nullptr) { - if ((mailbox_.count(cast_recv->get_mailbox()) > 0 and - mailbox_.at(cast_recv->get_mailbox()) <= 0) or mailbox_.count(cast_recv->get_mailbox()) == 0) - aid_value--; // This means we don't have waiting recv corresponding to this recv - else - aid_value++; + if (auto const* cast_recv = dynamic_cast(transition)) { - if ((mailbox_.count(cast_recv->get_mailbox()) > 0 && mailbox_.at(cast_recv->get_mailbox()) <= 0) || - mailbox_.count(cast_recv->get_mailbox()) == 0) - aid_value--; // This means we don't have waiting recv corresponding to this recv - else - aid_value++; ++ if ((mailbox_.count(cast_recv->get_mailbox()) > 0 && mailbox_.at(cast_recv->get_mailbox()) <= 0) || ++ mailbox_.count(cast_recv->get_mailbox()) == 0) ++ aid_value--; // This means we don't have waiting recv corresponding to this recv ++ else ++ aid_value++; } - const CommSendTransition* cast_send = dynamic_cast(transition); - if (cast_send != nullptr) { - if ((mailbox_.count(cast_send->get_mailbox()) > 0 and - mailbox_.at(cast_send->get_mailbox()) >= 0) or mailbox_.count(cast_send->get_mailbox()) == 0) - aid_value--; - else - aid_value++; + if (auto const* cast_send = dynamic_cast(transition)) { - if ((mailbox_.count(cast_send->get_mailbox()) > 0 && mailbox_.at(cast_send->get_mailbox()) >= 0) || - mailbox_.count(cast_send->get_mailbox()) == 0) - aid_value--; - else - aid_value++; ++ if ((mailbox_.count(cast_send->get_mailbox()) > 0 && mailbox_.at(cast_send->get_mailbox()) >= 0) || ++ mailbox_.count(cast_send->get_mailbox()) == 0) ++ aid_value--; ++ else ++ aid_value++; } - + if (aid_value < min_found.second) min_found = std::make_pair(aid, aid_value); } @@@ -83,12 -81,10 +81,10 @@@ const Transition* transition = actors_to_run_.at(aid).get_transition(actors_to_run_.at(aid).get_times_considered()).get(); last_transition_ = transition->type_; - const CommRecvTransition* cast_recv = dynamic_cast(transition); - if (cast_recv != nullptr) + if (auto const* cast_recv = dynamic_cast(transition)) last_mailbox_ = cast_recv->get_mailbox(); - const CommSendTransition* cast_send = dynamic_cast(transition); - if (cast_send != nullptr) + if (auto const* cast_send = dynamic_cast(transition)) last_mailbox_ = cast_send->get_mailbox(); } }; diff --combined src/mc/api/strategy/Strategy.hpp index 96eb753e02,f496ef5b7d..60e21f53fa --- a/src/mc/api/strategy/Strategy.hpp +++ b/src/mc/api/strategy/Strategy.hpp @@@ -35,7 -35,7 +35,7 @@@ public virtual std::pair best_transition(bool must_be_todo) const = 0; /** Returns the best transition among those that should be interleaved. */ - std::pair next_transition() { return best_transition(true); } + std::pair next_transition() const { return best_transition(true); } /** Allows for the strategy to update its fields knowing that the actor aid will * be executed and a children strategy will then be created. */ @@@ -44,9 -44,9 +44,9 @@@ /** Ensure at least one transition is marked as todo among the enabled ones not done. * If required, it marks as todo the best transition according to the strategy. */ void consider_best() { - for (auto& [_, actor] :actors_to_run_) - if (actor.is_todo()) - return; + if (std::any_of(begin(actors_to_run_), end(actors_to_run_), + [](const auto& actor) { return actor.second.is_todo(); })) + return; aid_t best_aid = best_transition(false).first; if (best_aid != -1) actors_to_run_.at(best_aid).mark_todo(); @@@ -56,7 -56,7 +56,7 @@@ // else raise an error void consider_one(aid_t aid) { - xbt_assert(actors_to_run_.at(aid).is_enabled() and not actors_to_run_.at(aid).is_done(), + xbt_assert(actors_to_run_.at(aid).is_enabled() && not actors_to_run_.at(aid).is_done(), "Tried to mark as TODO actor %ld but it is either not enabled or already done", aid); actors_to_run_.at(aid).mark_todo(); } @@@ -66,10 -66,10 +66,10 @@@ { unsigned long count = 0; for (auto& [_, actor] : actors_to_run_) - if (actor.is_enabled() and not actor.is_done()) { - if (actor.is_enabled() && not actor.is_done()) { -- actor.mark_todo(); -- count++; -- } ++ if (actor.is_enabled() && not actor.is_done()) { ++ actor.mark_todo(); ++ count++; ++ } return count; } diff --combined src/mc/api/strategy/UniformStrategy.hpp index cc5bd85773,472c571d3a..0b665a807b --- a/src/mc/api/strategy/UniformStrategy.hpp +++ b/src/mc/api/strategy/UniformStrategy.hpp @@@ -9,12 -9,12 +9,12 @@@ #include "src/mc/transition/Transition.hpp" #include "xbt/random.hpp" - #define MAX_RAND 100000 - namespace simgrid::mc { /** Guiding strategy that valuate states randomly */ class UniformStrategy : public Strategy { + static constexpr int MAX_RAND = 100000; + std::map valuation; public: @@@ -25,7 -25,7 +25,7 @@@ } void copy_from(const Strategy* strategy) override { - for (auto& [aid, _] : actors_to_run_) + for (auto const& [aid, _] : actors_to_run_) valuation[aid] = xbt::random::uniform_int(0, MAX_RAND); } @@@ -35,7 -35,7 +35,7 @@@ // Consider only valid actors for (auto const& [aid, actor] : actors_to_run_) { - if ((actor.is_todo() or not must_be_todo) and (not actor.is_done()) and actor.is_enabled()) + if ((actor.is_todo() || not must_be_todo) && (not actor.is_done()) && actor.is_enabled()) possibilities++; } @@@ -48,7 -48,7 +48,7 @@@ chosen = xbt::random::uniform_int(0, possibilities-1); for (auto const& [aid, actor] : actors_to_run_) { - if (((not actor.is_todo()) and must_be_todo) or actor.is_done() or (not actor.is_enabled())) - if (((not actor.is_todo()) && must_be_todo) || actor.is_done() || (not actor.is_enabled())) ++ if (((not actor.is_todo()) && must_be_todo) || actor.is_done() || (not actor.is_enabled())) continue; if (chosen == 0) { return std::make_pair(aid, valuation.at(aid)); diff --combined src/mc/mc_config.cpp index bde1a6b886,8460a9154f..9253c04f0e --- a/src/mc/mc_config.cpp +++ b/src/mc/mc_config.cpp @@@ -66,11 -66,11 +66,11 @@@ simgrid::config::Flag _sg_ "model-check/strategy", "Specify the the kind of heuristic to use for guided model-checking", "none", - {{"none", "No specific strategy: simply pick the first available transistion and act as a DFS."}, + {{"none", "No specific strategy: simply pick the first available transition and act as a DFS."}, {"max_match_comm", "Try to minimize the number of in-fly communication by appairing matching send and receive."}, -- {"min_match_comm", "Try to maximize the number of in-fly communication by not appairing matching send and receive."}, -- {"uniform", "No specific strategy: choices are made randomly based on a uniform sampling."} -- }}; ++ {"min_match_comm", ++ "Try to maximize the number of in-fly communication by not appairing matching send and receive."}, ++ {"uniform", "No specific strategy: choices are made randomly based on a uniform sampling."}}}; simgrid::config::Flag _sg_mc_random_seed{"model-check/rand-seed", "give a specific random seed to initialize the uniform distribution", 0, diff --combined src/s4u/s4u_Comm.cpp index a36df4e27e,0ef8afbafd..fe134094d3 --- a/src/s4u/s4u_Comm.cpp +++ b/src/s4u/s4u_Comm.cpp @@@ -78,13 -78,12 +78,13 @@@ void Comm::send(kernel::actor::ActorImp simgrid::kernel::activity::ActivityImplPtr comm = nullptr; simgrid::kernel::actor::CommIsendSimcall send_observer{ - sender, mbox->get_impl(), task_size, rate, static_cast(src_buff), src_buff_size, match_fun, - nullptr, copy_data_fun, data, false}; + sender, mbox->get_impl(), task_size, rate, static_cast(src_buff), + src_buff_size, match_fun, nullptr, copy_data_fun, data, + false, "Isend"}; comm = simgrid::kernel::actor::simcall_answered( [&send_observer] { return simgrid::kernel::activity::CommImpl::isend(&send_observer); }, &send_observer); - if (simgrid::kernel::actor::ActivityWaitSimcall wait_observer{sender, comm.get(), timeout}; + if (simgrid::kernel::actor::ActivityWaitSimcall wait_observer{sender, comm.get(), timeout, "Wait"}; simgrid::kernel::actor::simcall_blocking( [&wait_observer] { wait_observer.get_activity()->wait_for(wait_observer.get_issuer(), wait_observer.get_timeout()); @@@ -96,7 -95,7 +96,7 @@@ } else { simgrid::kernel::actor::CommIsendSimcall observer(sender, mbox->get_impl(), task_size, rate, static_cast(src_buff), src_buff_size, match_fun, - nullptr, copy_data_fun, data, false); + nullptr, copy_data_fun, data, false, "Isend"); simgrid::kernel::actor::simcall_blocking([&observer, timeout] { simgrid::kernel::activity::ActivityImplPtr comm = simgrid::kernel::activity::CommImpl::isend(&observer); comm->wait_for(observer.get_issuer(), timeout); @@@ -123,12 -122,11 +123,12 @@@ void Comm::recv(kernel::actor::ActorImp match_fun, copy_data_fun, data, - rate}; + rate, + "Irecv"}; comm = simgrid::kernel::actor::simcall_answered( [&observer] { return simgrid::kernel::activity::CommImpl::irecv(&observer); }, &observer); - if (simgrid::kernel::actor::ActivityWaitSimcall wait_observer{receiver, comm.get(), timeout}; + if (simgrid::kernel::actor::ActivityWaitSimcall wait_observer{receiver, comm.get(), timeout, "wait"}; simgrid::kernel::actor::simcall_blocking( [&wait_observer] { wait_observer.get_activity()->wait_for(wait_observer.get_issuer(), wait_observer.get_timeout()); @@@ -139,7 -137,7 +139,7 @@@ comm = nullptr; } else { simgrid::kernel::actor::CommIrecvSimcall observer(receiver, mbox->get_impl(), static_cast(dst_buff), - dst_buff_size, match_fun, copy_data_fun, data, rate); + dst_buff_size, match_fun, copy_data_fun, data, rate, "Irecv"); simgrid::kernel::actor::simcall_blocking([&observer, timeout] { simgrid::kernel::activity::ActivityImplPtr comm = simgrid::kernel::activity::CommImpl::irecv(&observer); comm->wait_for(observer.get_issuer(), timeout); @@@ -314,8 -312,8 +314,8 @@@ Comm* Comm::do_start( xbt_assert(src_buff_ == nullptr && dst_buff_ == nullptr, "Direct host-to-host communications cannot carry any data."); XBT_DEBUG("host-to-host Comm. Pimpl already created and set, just start it."); - on_start(*this); - on_this_start(*this); + fire_on_start(); + fire_on_this_start(); kernel::actor::simcall_answered([this] { pimpl_->set_state(kernel::activity::State::READY); boost::static_pointer_cast(pimpl_)->start(); @@@ -333,8 -331,7 +333,8 @@@ clean_fun_, copy_data_function_, get_data(), - detached_}; + detached_, + "Isend"}; pimpl_ = kernel::actor::simcall_answered([&observer] { return kernel::activity::CommImpl::isend(&observer); }, &observer); } else if (dst_buff_ != nullptr) { // Receiver side @@@ -348,8 -345,7 +348,8 @@@ match_fun_, copy_data_function_, get_data(), - rate_}; + rate_, + "Irecv"}; pimpl_ = kernel::actor::simcall_answered([&observer] { return kernel::activity::CommImpl::irecv(&observer); }, &observer); } else { @@@ -364,8 -360,8 +364,8 @@@ pimpl_->set_actor(sender_); // Only throw the signal when both sides are here and the status is READY if (pimpl_->get_state() != kernel::activity::State::WAITING) { - on_start(*this); - on_this_start(*this); + fire_on_start(); + fire_on_this_start(); } } @@@ -426,7 -422,7 +426,7 @@@ Comm* Comm::wait_for(double timeout case State::STARTED: try { issuer = kernel::actor::ActorImpl::self(); - kernel::actor::ActivityWaitSimcall observer{issuer, pimpl_.get(), timeout}; + kernel::actor::ActivityWaitSimcall observer{issuer, pimpl_.get(), timeout, "Wait"}; if (kernel::actor::simcall_blocking( [&observer] { observer.get_activity()->wait_for(observer.get_issuer(), observer.get_timeout()); }, &observer)) { diff --combined src/s4u/s4u_Task.cpp index b6d8ccd7ff,9419363f1d..ee75342eae --- a/src/s4u/s4u_Task.cpp +++ b/src/s4u/s4u_Task.cpp @@@ -1,9 -1,9 +1,9 @@@ #include #include -#include #include #include #include +#include #include #include "src/simgrid/module.hpp" @@@ -45,11 -45,12 +45,12 @@@ bool Task::ready_to_run() cons void Task::receive(Task* source) { XBT_DEBUG("Task %s received a token from %s", name_.c_str(), source->name_.c_str()); - auto source_count = predecessors_[source]++; + auto source_count = predecessors_[source]; + predecessors_[source]++; if (tokens_received_.size() <= queued_firings_ + source_count) - tokens_received_.push_back({}); + tokens_received_.emplace_back(); tokens_received_[queued_firings_ + source_count][source] = source->token_; - bool enough_tokens = true; + bool enough_tokens = true; for (auto const& [key, val] : predecessors_) if (val < 1) { enough_tokens = false; @@@ -125,13 -126,12 +126,13 @@@ std::shared_ptr Task::get_next_t return tokens_received_.front()[t]; } -void Task::fire() { +void Task::fire() +{ on_this_start(this); on_start(this); - working_ = true; + working_ = true; queued_firings_ = std::max(queued_firings_ - 1, 0); - if (tokens_received_.size() > 0) + if (not tokens_received_.empty()) tokens_received_.pop_front(); }