X-Git-Url: http://bilbo.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/7ec4bfe63855f02819ad397d3b29babf4421ea00..417ed3b671abe3a71fa4106d23d0a432084cc207:/examples/cpp/dag-simple/s4u-dag-simple.cpp?ds=sidebyside diff --git a/examples/cpp/dag-simple/s4u-dag-simple.cpp b/examples/cpp/dag-simple/s4u-dag-simple.cpp index f377550aa0..aae95e7101 100644 --- a/examples/cpp/dag-simple/s4u-dag-simple.cpp +++ b/examples/cpp/dag-simple/s4u-dag-simple.cpp @@ -1,4 +1,4 @@ -/* Copyright (c) 2007-2021. The SimGrid Team. All rights reserved. */ +/* Copyright (c) 2007-2023. The SimGrid Team. All rights reserved. */ /* 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. */ @@ -7,27 +7,28 @@ #include XBT_LOG_NEW_DEFAULT_CATEGORY(s4u_test, "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]); - std::set vetoed; + std::set vetoed; e.track_vetoed_activities(&vetoed); auto fafard = e.host_by_name("Fafard"); // Display the details on vetoed activities - simgrid::s4u::Activity::on_veto.connect([](const simgrid::s4u::Activity& a) { - const auto& exec = static_cast(a); // all activities are execs in this example + sg4::Activity::on_veto_cb([](const sg4::Activity& a) { + const auto& exec = static_cast(a); // all activities are execs in this example XBT_INFO("Activity '%s' vetoed. Dependencies: %s; Ressources: %s", exec.get_cname(), (exec.dependencies_solved() ? "solved" : "NOT solved"), (exec.is_assigned() ? "assigned" : "NOT assigned")); }); - simgrid::s4u::Activity::on_completion.connect([](simgrid::s4u::Activity& activity) { - const auto* exec = dynamic_cast(&activity); + sg4::Activity::on_completion_cb([](sg4::Activity const& activity) { + const auto* exec = dynamic_cast(&activity); if (exec == nullptr) // Only Execs are concerned here return; XBT_INFO("Activity '%s' is complete (start time: %f, finish time: %f)", exec->get_cname(), exec->get_start_time(), @@ -38,9 +39,9 @@ int main(int argc, char* argv[]) double computation_amount = fafard->get_speed(); // Create a small DAG: Two parents and a child - simgrid::s4u::ExecPtr first_parent = simgrid::s4u::Exec::init(); - simgrid::s4u::ExecPtr second_parent = simgrid::s4u::Exec::init(); - simgrid::s4u::ExecPtr child = simgrid::s4u::Exec::init(); + sg4::ExecPtr first_parent = sg4::Exec::init(); + sg4::ExecPtr second_parent = sg4::Exec::init(); + sg4::ExecPtr child = sg4::Exec::init(); first_parent->add_successor(child); second_parent->add_successor(child); @@ -55,14 +56,14 @@ int main(int argc, char* argv[]) second_parent->set_host(fafard); // Start all activities that can actually start. - first_parent->vetoable_start(); - second_parent->vetoable_start(); - child->vetoable_start(); + first_parent->start(); + second_parent->start(); + child->start(); - while (child->get_state() != simgrid::s4u::Activity::State::FINISHED) { + while (child->get_state() != sg4::Activity::State::FINISHED) { e.run(); for (auto* a : vetoed) { - auto* exec = static_cast(a); + auto* exec = static_cast(a); // In this simple case, we just assign the child task to a resource when its dependencies are solved if (exec->dependencies_solved() && not exec->is_assigned()) { @@ -75,7 +76,7 @@ int main(int argc, char* argv[]) vetoed.clear(); // DON'T FORGET TO CLEAR this set between two calls to run } - XBT_INFO("Simulation time %g", simgrid::s4u::Engine::get_clock()); + XBT_INFO("Simulation time %g", sg4::Engine::get_clock()); return 0; }