]> AND Public Git Repository - simgrid.git/blobdiff - examples/cpp/dag-scheduling/s4u-dag-scheduling.cpp
Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Revalidate the tesh of some working MC tests
[simgrid.git] / examples / cpp / dag-scheduling / s4u-dag-scheduling.cpp
index 8dc40601945b42ccd930236db307930153a10759..f2d1549e36c1b4615e7b0f89634230130814ee33 100644 (file)
@@ -20,24 +20,22 @@ struct HostAttribute {
 
 static double sg_host_get_available_at(const simgrid::s4u::Host* host)
 {
-  return static_cast<HostAttribute*>(host->get_data())->available_at;
+  return host->get_data<HostAttribute>()->available_at;
 }
 
-static void sg_host_set_available_at(simgrid::s4u::Host* host, double time)
+static void sg_host_set_available_at(const simgrid::s4u::Host* host, double time)
 {
-  auto* attr         = static_cast<HostAttribute*>(host->get_data());
-  attr->available_at = time;
+  host->get_data<HostAttribute>()->available_at = time;
 }
 
 static simgrid::s4u::Exec* sg_host_get_last_scheduled_task(const simgrid::s4u::Host* host)
 {
-  return static_cast<HostAttribute*>(host->get_data())->last_scheduled_task;
+  return host->get_data<HostAttribute>()->last_scheduled_task;
 }
 
-static void sg_host_set_last_scheduled_task(simgrid::s4u::Host* host, simgrid::s4u::ExecPtr task)
+static void sg_host_set_last_scheduled_task(const simgrid::s4u::Host* host, simgrid::s4u::ExecPtr task)
 {
-  auto* attr                = static_cast<HostAttribute*>(host->get_data());
-  attr->last_scheduled_task = task.get();
+  host->get_data<HostAttribute>()->last_scheduled_task = task.get();
 }
 
 static bool dependency_exists(const simgrid::s4u::Exec* src, simgrid::s4u::Exec* dst)
@@ -102,7 +100,7 @@ static double finish_on_at(const simgrid::s4u::ExecPtr task, const simgrid::s4u:
         }
         // We use the user data field to store the finish time of the predecessor of the comm, i.e., its potential start
         // time
-        data_available = *(static_cast<double*>(comm->get_data())) + redist_time;
+        data_available = *comm->get_data<double>() + redist_time;
       }
 
       const auto* exec = dynamic_cast<simgrid::s4u::Exec*>(parent.get());
@@ -148,7 +146,7 @@ static void schedule_on(simgrid::s4u::ExecPtr exec, simgrid::s4u::Host* host)
     auto* comm = dynamic_cast<simgrid::s4u::Comm*>(pred.get());
     if (comm != nullptr) {
       comm->set_destination(host);
-      delete static_cast<double*>(comm->get_data());
+      delete comm->get_data<double>();
     }
   }
   // we can also set the source of all the output comms of this exec
@@ -165,9 +163,9 @@ int main(int argc, char** argv)
   std::set<simgrid::s4u::Activity*> vetoed;
   e.track_vetoed_activities(&vetoed);
 
-  simgrid::s4u::Activity::on_completion_cb([](simgrid::s4u::Activity& activity) {
+  simgrid::s4u::Activity::on_completion_cb([](simgrid::s4u::Activity const& activity) {
     // when an Exec completes, we need to set the potential start time of all its ouput comms
-    const auto* exec = dynamic_cast<simgrid::s4u::Exec*>(&activity);
+    const auto* exec = dynamic_cast<simgrid::s4u::Exec const*>(&activity);
     if (exec == nullptr) // Only Execs are concerned here
       return;
     for (const auto& succ : exec->get_successors()) {