Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
make all Activity starts vetoable
[simgrid.git] / examples / cpp / dag-io / s4u-dag-io.cpp
index 12077c7..ee00eb0 100644 (file)
@@ -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. */
@@ -8,10 +8,11 @@
 #include <vector>
 
 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);
   sg_storage_file_system_init();
   e.load_platform(argv[1]);
 
@@ -19,13 +20,13 @@ int main(int argc, char* argv[])
   auto carl = e.host_by_name("carl");
 
   // Display the details on vetoed activities
-  simgrid::s4u::Activity::on_veto.connect([](simgrid::s4u::Activity& a) {
+  sg4::Activity::on_veto_cb([](const sg4::Activity& a) {
     XBT_INFO("Activity '%s' vetoed. Dependencies: %s; Ressources: %s", a.get_cname(),
              (a.dependencies_solved() ? "solved" : "NOT solved"), (a.is_assigned() ? "assigned" : "NOT assigned"));
   });
 
-  simgrid::s4u::Activity::on_completion.connect([](simgrid::s4u::Activity& activity) {
-    auto* exec = dynamic_cast<simgrid::s4u::Exec*>(&activity);
+  sg4::Activity::on_completion_cb([](sg4::Activity const& activity) {
+    const auto* exec = dynamic_cast<sg4::Exec const*>(&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(),
@@ -33,10 +34,10 @@ int main(int argc, char* argv[])
   });
 
   // Create a small DAG: parent->write_output->read_input->child
-  simgrid::s4u::ExecPtr parent     = simgrid::s4u::Exec::init();
-  simgrid::s4u::IoPtr write_output = simgrid::s4u::Io::init();
-  simgrid::s4u::IoPtr read_input   = simgrid::s4u::Io::init();
-  simgrid::s4u::ExecPtr child      = simgrid::s4u::Exec::init();
+  sg4::ExecPtr parent     = sg4::Exec::init();
+  sg4::IoPtr write_output = sg4::Io::init();
+  sg4::IoPtr read_input   = sg4::Io::init();
+  sg4::ExecPtr child      = sg4::Exec::init();
   parent->add_successor(write_output);
   write_output->add_successor(read_input);
   read_input->add_successor(child);
@@ -44,19 +45,19 @@ int main(int argc, char* argv[])
   // Set the parameters (the name is for logging purposes only)
   // + parent and chile end after 1 second
   parent->set_name("parent")->set_flops_amount(bob->get_speed());
-  write_output->set_name("write")->set_size(1e9)->set_op_type(simgrid::s4u::Io::OpType::WRITE);
-  read_input->set_name("read")->set_size(1e9)->set_op_type(simgrid::s4u::Io::OpType::READ);
+  write_output->set_name("write")->set_size(1e9)->set_op_type(sg4::Io::OpType::WRITE);
+  read_input->set_name("read")->set_size(1e9)->set_op_type(sg4::Io::OpType::READ);
   child->set_name("child")->set_flops_amount(carl->get_speed());
 
   // Schedule and try to start the different activities
-  parent->set_host(bob)->vetoable_start();
-  write_output->set_disk(bob->get_disks().front())->vetoable_start();
-  read_input->set_disk(carl->get_disks().front())->vetoable_start();
-  child->set_host(carl)->vetoable_start();
+  parent->set_host(bob)->start();
+  write_output->set_disk(bob->get_disks().front())->start();
+  read_input->set_disk(carl->get_disks().front())->start();
+  child->set_host(carl)->start();
 
   e.run();
 
-  XBT_INFO("Simulation time %g", simgrid::s4u::Engine::get_clock());
+  XBT_INFO("Simulation time %g", sg4::Engine::get_clock());
 
   return 0;
 }