Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Update copyright lines for 2022.
[simgrid.git] / examples / cpp / dag-simple / s4u-dag-simple.cpp
index 0743dfd..b829beb 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (c) 2007-2021. The SimGrid Team. All rights reserved.          */
+/* Copyright (c) 2007-2022. 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. */
@@ -18,14 +18,22 @@ int main(int argc, char* argv[])
   auto fafard = e.host_by_name("Fafard");
 
   // Display the details on vetoed activities
-  simgrid::s4u::Activity::on_veto.connect([](simgrid::s4u::Activity& a) {
-    auto& exec = static_cast<simgrid::s4u::Exec&>(a); // all activities are execs in this example
+  simgrid::s4u::Activity::on_veto_cb([](const simgrid::s4u::Activity& a) {
+    const auto& exec = static_cast<const simgrid::s4u::Exec&>(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_cb([](simgrid::s4u::Activity& activity) {
+    const auto* exec = dynamic_cast<simgrid::s4u::Exec*>(&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(),
+             exec->get_finish_time());
+  });
+
   // Define an amount of work that should take 1 second to execute.
   double computation_amount = fafard->get_speed();
 
@@ -36,13 +44,6 @@ int main(int argc, char* argv[])
   first_parent->add_successor(child);
   second_parent->add_successor(child);
 
-  /*
-    std::vector<simgrid::s4u::ExecPtr> pending_execs;
-    pending_execs.push_back(first_parent);
-    pending_execs.push_back(second_parent);
-    pending_execs.push_back(child);
-  */
-
   // Set the parameters (the name is for logging purposes only)
   // + First parent ends after 1 second and the Second parent after 2 seconds.
   first_parent->set_name("parent 1")->set_flops_amount(computation_amount);