Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Fix build with graphviz >= 3.
[simgrid.git] / src / dag / loaders.cpp
index 2b9eaa2..72ca8aa 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (c) 2009-2021. The SimGrid Team.
+/* Copyright (c) 2009-2022. The SimGrid Team.
  * All rights reserved.                                                     */
 
 /* This program is free software; you can redistribute it and/or modify it
@@ -41,7 +41,7 @@ static bool check_for_cycle(const std::vector<simgrid::s4u::ActivityPtr>& dag)
   std::vector<simgrid::s4u::ActivityPtr> current;
 
   for (const auto& a : dag)
-    if (dynamic_cast<simgrid::s4u::Exec*>(a.get()) != nullptr && a->is_waited_by() == 0)
+    if (dynamic_cast<simgrid::s4u::Exec*>(a.get()) != nullptr && a->has_no_successor())
       current.push_back(a);
 
   while (not current.empty()) {
@@ -72,8 +72,7 @@ static bool check_for_cycle(const std::vector<simgrid::s4u::ActivityPtr>& dag)
 
 static YY_BUFFER_STATE input_buffer;
 
-namespace simgrid {
-namespace s4u {
+namespace simgrid::s4u {
 
 static std::vector<ActivityPtr> result;
 static std::map<std::string, ExecPtr, std::less<>> jobs;
@@ -110,10 +109,8 @@ std::vector<ActivityPtr> create_DAG_from_DAX(const std::string& filename)
    * Files not produced in the system are said to be produced by root task (top of DAG).
    * Files not consumed in the system are said to be consumed by end task (bottom of DAG).
    */
-  CommPtr file;
-
-  for (auto const& elm : files) {
-    file = elm.second;
+  for (auto const& [_, elm] : files) {
+    CommPtr file = elm;
     CommPtr newfile;
     if (file->dependencies_solved()) {
       for (auto const& it : file->get_successors()) {
@@ -123,7 +120,7 @@ std::vector<ActivityPtr> create_DAG_from_DAX(const std::string& filename)
         result.push_back(newfile);
       }
     }
-    if (file->is_waited_by() == 0) {
+    if (file->has_no_successor()) {
       for (auto const& it : file->get_dependencies()) {
         newfile = Comm::sendto_init()->set_name(file->get_name())->set_payload_size(file->get_remaining());
         it->add_successor(newfile);
@@ -162,7 +159,7 @@ std::vector<ActivityPtr> create_DAG_from_DAX(const std::string& filename)
       if ((a != root_task) && (a != end_task)) {
         if (a->dependencies_solved())
           root_task->add_successor(a);
-        if (a->is_waited_by() == 0)
+        if (a->has_no_successor())
           a->add_successor(end_task);
       }
     }
@@ -185,7 +182,7 @@ std::vector<ActivityPtr> create_DAG_from_dot(const std::string& filename)
   FILE* in_file = fopen(filename.c_str(), "r");
   xbt_assert(in_file != nullptr, "Failed to open file: %s", filename.c_str());
 
-  Agraph_t* dag_dot = agread(in_file, NIL(Agdisc_t*));
+  Agraph_t* dag_dot = agread(in_file, NULL);
 
   std::unordered_map<std::string, ActivityPtr> activities;
   std::vector<ActivityPtr> dag;
@@ -196,17 +193,17 @@ std::vector<ActivityPtr> create_DAG_from_dot(const std::string& filename)
   /* Create all the nodes */
   Agnode_t* node = nullptr;
   for (node = agfstnode(dag_dot); node; node = agnxtnode(dag_dot, node)) {
-    char* name    = agnameof(node);
+    const std::string name = agnameof(node);
     double amount = atof(agget(node, (char*)"size"));
 
     if (activities.find(name) == activities.end()) {
-      XBT_DEBUG("See <Exec id = %s amount = %.0f>", name, amount);
+      XBT_DEBUG("See <Exec id = %s amount = %.0f>", name.c_str(), amount);
       act = Exec::init()->set_name(name)->set_flops_amount(amount)->vetoable_start();
-      activities.insert({std::string(name), act});
-      if (strcmp(name, "root") && strcmp(name, "end"))
+      activities.try_emplace(name, act);
+      if (name != "root" && name != "end")
         dag.push_back(act);
     } else {
-      XBT_WARN("Exec '%s' is defined more than once", name);
+      XBT_WARN("Exec '%s' is defined more than once", name.c_str());
     }
   }
   /*Check if 'root' and 'end' nodes have been explicitly declared.  If not, create them. */
@@ -244,7 +241,7 @@ std::vector<ActivityPtr> create_DAG_from_dot(const std::string& filename)
           act = Comm::sendto_init()->set_name(name)->set_payload_size(size)->vetoable_start();
           src->add_successor(act);
           act->add_successor(dst);
-          activities.insert({name, act});
+          activities.try_emplace(name, act);
           dag.push_back(act);
         } else {
           XBT_WARN("Comm '%s' is defined more than once", name.c_str());
@@ -267,7 +264,7 @@ std::vector<ActivityPtr> create_DAG_from_dot(const std::string& filename)
       root->add_successor(a);
     }
 
-    if (a->is_waited_by() == 0 && a != end) {
+    if (a->has_no_successor() && a != end) {
       XBT_DEBUG("Activity '%s' has no successors. Add dependency to 'end'", a->get_cname());
       a->add_successor(end);
     }
@@ -281,6 +278,7 @@ std::vector<ActivityPtr> create_DAG_from_dot(const std::string& filename)
     for (const auto& a : dag)
       a->destroy();
     dag.clear();
+    dag.shrink_to_fit();
   }
 
   return dag;
@@ -292,8 +290,7 @@ std::vector<ActivityPtr> create_DAG_from_dot(const std::string& filename)
           "Please install graphviz, graphviz-dev, and libgraphviz-dev (and erase CMakeCache.txt) before recompiling.");
 }
 #endif
-} // namespace s4u
-} // namespace simgrid
+} // namespace simgrid::s4u
 
 void STag_dax__adag()
 {
@@ -314,7 +311,7 @@ void STag_dax__job()
     runtime *= 4200000000.; /* Assume that timings were done on a 4.2GFlops machine. I mean, why not? */
     XBT_DEBUG("See <job id=%s runtime=%s %.0f>", A_dax__job_id, A_dax__job_runtime, runtime);
     simgrid::s4u::current_job = simgrid::s4u::Exec::init()->set_name(name)->set_flops_amount(runtime)->vetoable_start();
-    simgrid::s4u::jobs.insert({A_dax__job_id, simgrid::s4u::current_job});
+    simgrid::s4u::jobs.try_emplace(A_dax__job_id, simgrid::s4u::current_job);
     simgrid::s4u::result.push_back(simgrid::s4u::current_job);
   } catch (const std::invalid_argument&) {
     throw std::invalid_argument(std::string("Parse error: ") + A_dax__job_runtime + " is not a double");