Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Clang-tidy: readability-qualified-auto.
[simgrid.git] / examples / cpp / dag-scheduling / s4u-dag-scheduling.cpp
index 59814cdcf0c3531beb02c991cf3db99262cba8ee..51dde09ae9972370dae9eac661ed8b16cb65f01d 100644 (file)
@@ -17,7 +17,7 @@ static std::vector<sg4::Exec*> get_ready_tasks(const std::vector<sg4::ActivityPt
   std::vector<sg4::Exec*> ready_tasks;
   std::map<sg4::Exec*, unsigned int> candidate_execs;
 
-  for (auto& a : dax) {
+  for (const auto& a : dax) {
     // Only look at activity that have their dependencies solved but are not assigned
     if (a->dependencies_solved() && not a->is_assigned()) {
       // if it is an exec, it's ready
@@ -49,7 +49,7 @@ static sg4::Host* get_best_host(const sg4::ExecPtr exec, double* min_finish_time
     for (const auto& parent : exec->get_dependencies()) {
       /* normal case */
       if (const auto* comm = dynamic_cast<sg4::Comm*>(parent.get())) {
-        auto source = comm->get_source();
+        const auto* source = comm->get_source();
         XBT_DEBUG("transfer from %s to %s", source->get_cname(), host->get_cname());
         /* Estimate the redistribution time from this parent */
         double redist_time;
@@ -66,11 +66,11 @@ static sg4::Host* get_best_host(const sg4::ExecPtr exec, double* min_finish_time
         // 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 = *comm->get_data<double>() + redist_time;
-     }
+      }
 
       /* no transfer, control dependency */
-      if (const auto* exec = dynamic_cast<sg4::Exec*>(parent.get()))
-        data_available = exec->get_finish_time();
+      if (const auto* parent_exec = dynamic_cast<sg4::Exec*>(parent.get()))
+        data_available = parent_exec->get_finish_time();
 
       if (last_data_available < data_available)
         last_data_available = data_available;
@@ -118,15 +118,12 @@ int main(int argc, char** argv)
   std::set<sg4::Activity*> vetoed;
   e.track_vetoed_activities(&vetoed);
 
-  sg4::Activity::on_completion_cb([](sg4::Activity const& activity) {
+  sg4::Exec::on_completion_cb([](sg4::Exec const& exec) {
     // when an Exec completes, we need to set the potential start time of all its ouput comms
-    const auto* exec = dynamic_cast<sg4::Exec const*>(&activity);
-    if (exec == nullptr) // Only Execs are concerned here
-      return;
-    for (const auto& succ : exec->get_successors()) {
+    for (const auto& succ : exec.get_successors()) {
       auto* comm = dynamic_cast<sg4::Comm*>(succ.get());
       if (comm != nullptr) {
-        auto* finish_time = new double(exec->get_finish_time());
+        auto* finish_time = new double(exec.get_finish_time());
         // We use the user data field to store the finish time of the predecessor of the comm, i.e., its potential start
         // time
         comm->set_data(finish_time);
@@ -148,9 +145,9 @@ int main(int argc, char** argv)
   auto dax = sg4::create_DAG_from_DAX(argv[2]);
 
   /* Schedule the root first */
-  double finish_time;
+  double root_finish_time;
   auto* root = static_cast<sg4::Exec*>(dax.front().get());
-  auto host  = get_best_host(root, &finish_time);
+  auto* host = get_best_host(root, &root_finish_time);
   schedule_on(root, host);
 
   e.run();
@@ -174,7 +171,7 @@ int main(int argc, char** argv)
     sg4::Exec* selected_task = nullptr;
     sg4::Host* selected_host = nullptr;
 
-    for (auto exec : ready_tasks) {
+    for (auto* exec : ready_tasks) {
       XBT_DEBUG("%s is ready", exec->get_cname());
       double finish_time;
       host = get_best_host(exec, &finish_time);