Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
merge dag parsers into a single file
authorSUTER Frederic <frederic.suter@cc.in2p3.fr>
Sun, 2 Jan 2022 15:43:58 +0000 (16:43 +0100)
committerSUTER Frederic <frederic.suter@cc.in2p3.fr>
Sun, 2 Jan 2022 15:43:58 +0000 (16:43 +0100)
MANIFEST.in
examples/cpp/dag-from-dax/s4u-dag-from-dax.tesh
examples/cpp/dag-from-dot/s4u-dag-from-dot.tesh
examples/cpp/dag-scheduling/s4u-dag-scheduling.tesh
src/simdag/sd_daxloader.cpp
src/simdag/sd_dotloader.cpp [deleted file]
src/simdag/simdag_private.hpp [deleted file]
tools/cmake/DefinePackages.cmake

index 9141a50..576b495 100644 (file)
@@ -2445,8 +2445,6 @@ include src/simdag/dax.dtd
 include src/simdag/dax_dtd.c
 include src/simdag/dax_dtd.h
 include src/simdag/sd_daxloader.cpp
-include src/simdag/sd_dotloader.cpp
-include src/simdag/simdag_private.hpp
 include src/simgrid/Exception.cpp
 include src/simgrid/sg_config.cpp
 include src/simgrid/sg_version.cpp
index ad0b9cb..6728d9a 100644 (file)
@@ -2,8 +2,8 @@
 p Test the DAX loader on a small DAX instance
 
 $ ${bindir:=.}/s4u-dag-from-dax --log=no_loc ${platfdir}/cluster_backbone.xml ${srcdir:=.}/smalldax.xml
-> [0.000000] [daxparse/WARNING] Ignore file o1 size redefinition from 1000000 to 304
-> [0.000000] [daxparse/WARNING] Ignore file o2 size redefinition from 1000000 to 304
+> [0.000000] [dag_parsing/WARNING] Ignore file o1 size redefinition from 1000000 to 304
+> [0.000000] [dag_parsing/WARNING] Ignore file o2 size redefinition from 1000000 to 304
 > [0.000000] [dag_from_dax/INFO] --------- Display all activities of the loaded DAG -----------
 > [0.000000] [dag_from_dax/INFO] 'root' is an Exec: 0 flops to execute. Dependencies: solved; Ressources: NOT assigned
 > [0.000000] [dag_from_dax/INFO] '1@task1' is an Exec: 42000000000 flops to execute. Dependencies: NOT solved; Ressources: NOT assigned
@@ -33,5 +33,5 @@ p Test the DAX loader with a DAX comprising a cycle.
 
 ! expect return 2
 $ ${bindir:=.}/s4u-dag-from-dax --log=no_loc ${platfdir}/cluster_backbone.xml ${srcdir:=.}/simple_dax_with_cycle.xml
-> [0.000000] [daxparse/ERROR] The DAX described in simple_dax_with_cycle.xml is not a DAG. It contains a cycle.
+> [0.000000] [dag_parsing/ERROR] The DAX described in simple_dax_with_cycle.xml is not a DAG. It contains a cycle.
 > [0.000000] [dag_from_dax/ERROR] A problem occurred during DAX parsing (cycle or syntax). Do not continue this test
index fb4af3b..b8216cf 100644 (file)
@@ -48,5 +48,5 @@ $ ${bindir:=.}/s4u-dag-from-dot --log=no_loc ${platfdir}/cluster_backbone.xml ${
 
 ! expect return 2
 $ ${bindir:=.}/s4u-dag-from-dot --log=no_loc ${platfdir}/cluster_backbone.xml ${srcdir:=.}/dag_with_cycle.dot
-> [0.000000] [dotparse/ERROR] The DOT described in dag_with_cycle.dot is not a DAG. It contains a cycle.
+> [0.000000] [dag_parsing/ERROR] The DOT described in dag_with_cycle.dot is not a DAG. It contains a cycle.
 > [0.000000] [dag_from_dot/CRITICAL] No dot loaded. Do you have a cycle in your graph?
index a469608..6abc5c7 100644 (file)
@@ -1,6 +1,6 @@
 #!/usr/bin/env tesh
 
-$ ${bindir:=.}/s4u-dag-scheduling --log=daxparse.thresh:critical --log=no_loc ${platfdir}/simulacrum_7_hosts.xml ${srcdir:=.}/Montage_25.xml
+$ ${bindir:=.}/s4u-dag-scheduling --log=dag_parsing.thresh:critical --log=no_loc ${platfdir}/simulacrum_7_hosts.xml ${srcdir:=.}/Montage_25.xml
 > [0.000000] [dag_scheduling/INFO] Schedule ID00002@mProjectPP on Host 27
 > [0.001301] [dag_scheduling/INFO] Schedule ID00000@mProjectPP on Host 26
 > [0.001301] [dag_scheduling/INFO] Schedule ID00003@mProjectPP on Host 30
index 877bfc8..d471fe2 100644 (file)
@@ -4,21 +4,26 @@
 /* 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. */
 
-#include "simdag_private.hpp"
-#include "simgrid/s4u/Comm.hpp"
-#include "simgrid/s4u/Engine.hpp"
-#include "simgrid/s4u/Exec.hpp"
-#include "xbt/file.hpp"
-#include "xbt/log.h"
-#include "xbt/misc.h"
+#include "src/internal_config.h"
 #include <algorithm>
 #include <map>
+#include <simgrid/s4u/Comm.hpp>
+#include <simgrid/s4u/Engine.hpp>
+#include <simgrid/s4u/Exec.hpp>
 #include <stdexcept>
+#include <xbt/asserts.h>
+#include <xbt/file.hpp>
+#include <xbt/log.h>
+#include <xbt/misc.h>
 
 #include "dax_dtd.h"
 #include "dax_dtd.c"
 
-XBT_LOG_NEW_DEFAULT_CATEGORY(daxparse, "Parsing DAX files");
+XBT_LOG_NEW_DEFAULT_CATEGORY(dag_parsing, "Generation DAGs from files");
+
+#if HAVE_GRAPHVIZ
+#include <graphviz/cgraph.h>
+#endif
 
 /* Ensure that transfer tasks have unique names even though a file is used several times */
 static void uniq_transfer_task_name(simgrid::s4u::Comm* comm)
@@ -31,7 +36,7 @@ static void uniq_transfer_task_name(simgrid::s4u::Comm* comm)
   comm->set_name(new_name)->vetoable_start();
 }
 
-bool check_for_cycle(const std::vector<simgrid::s4u::ActivityPtr>& dag)
+static bool check_for_cycle(const std::vector<simgrid::s4u::ActivityPtr>& dag)
 {
   std::vector<simgrid::s4u::ActivityPtr> current;
 
@@ -174,6 +179,118 @@ std::vector<ActivityPtr> create_DAG_from_DAX(const std::string& filename)
   return result;
 }
 
+#if HAVE_GRAPHVIZ
+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*));
+
+  std::unordered_map<std::string, ActivityPtr> activities;
+  std::vector<ActivityPtr> dag;
+
+  ActivityPtr root;
+  ActivityPtr end;
+  ActivityPtr act;
+  /* Create all the nodes */
+  Agnode_t* node = nullptr;
+  for (node = agfstnode(dag_dot); node; node = agnxtnode(dag_dot, node)) {
+    char* 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);
+      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"))
+        dag.push_back(act);
+    } else {
+      XBT_WARN("Exec '%s' is defined more than once", name);
+    }
+  }
+  /*Check if 'root' and 'end' nodes have been explicitly declared.  If not, create them. */
+  if (activities.find("root") == activities.end())
+    root = Exec::init()->set_name("root")->set_flops_amount(0)->vetoable_start();
+  else
+    root = activities.at("root");
+
+  if (activities.find("end") == activities.end())
+    end = Exec::init()->set_name("end")->set_flops_amount(0)->vetoable_start();
+  else
+    end = activities.at("end");
+
+  /* Create edges */
+  std::vector<Agedge_t*> edges;
+  for (node = agfstnode(dag_dot); node; node = agnxtnode(dag_dot, node)) {
+    edges.clear();
+    for (Agedge_t* edge = agfstout(dag_dot, node); edge; edge = agnxtout(dag_dot, edge))
+      edges.push_back(edge);
+
+    /* Be sure edges are sorted */
+    std::sort(edges.begin(), edges.end(), [](const Agedge_t* a, const Agedge_t* b) { return AGSEQ(a) < AGSEQ(b); });
+
+    for (Agedge_t* edge : edges) {
+      const char* src_name = agnameof(agtail(edge));
+      const char* dst_name = agnameof(aghead(edge));
+      double size          = atof(agget(edge, (char*)"size"));
+
+      ActivityPtr src = activities.at(src_name);
+      ActivityPtr dst = activities.at(dst_name);
+      if (size > 0) {
+        std::string name = std::string(src_name) + "->" + dst_name;
+        XBT_DEBUG("See <Comm id=%s amount = %.0f>", name.c_str(), size);
+        if (activities.find(name) == activities.end()) {
+          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});
+          dag.push_back(act);
+        } else {
+          XBT_WARN("Comm '%s' is defined more than once", name.c_str());
+        }
+      } else {
+        src->add_successor(dst);
+      }
+    }
+  }
+
+  XBT_DEBUG("All activities have been created, put %s at the beginning and %s at the end", root->get_cname(),
+            end->get_cname());
+  dag.insert(dag.begin(), root);
+  dag.push_back(end);
+
+  /* Connect entry tasks to 'root', and exit tasks to 'end'*/
+  for (const auto& a : dag) {
+    if (a->dependencies_solved() && a != root) {
+      XBT_DEBUG("Activity '%s' has no dependencies. Add dependency from 'root'", a->get_cname());
+      root->add_successor(a);
+    }
+
+    if (a->is_waited_by() == 0 && a != end) {
+      XBT_DEBUG("Activity '%s' has no successors. Add dependency to 'end'", a->get_cname());
+      a->add_successor(end);
+    }
+  }
+  agclose(dag_dot);
+  fclose(in_file);
+
+  if (not check_for_cycle(dag)) {
+    std::string base = simgrid::xbt::Path(filename).get_base_name();
+    XBT_ERROR("The DOT described in %s is not a DAG. It contains a cycle.", base.c_str());
+    for (const auto& a : dag)
+      a->destroy();
+    dag.clear();
+  }
+
+  return dag;
+}
+#else
+std::vector<ActivityPtr> create_DAG_from_dot(const std::string& filename) xbt_die(
+    "create_DAG_from_dot() is not usable because graphviz was not found.\n"
+    "Please install graphviz, graphviz-dev, and libgraphviz-dev (and erase CMakeCache.txt) before recompiling.");
+}
+#endif
 } // namespace s4u
 } // namespace simgrid
 
diff --git a/src/simdag/sd_dotloader.cpp b/src/simdag/sd_dotloader.cpp
deleted file mode 100644 (file)
index a59bf74..0000000
+++ /dev/null
@@ -1,147 +0,0 @@
-/* Copyright (c) 2009-2021. 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. */
-
-#include "simdag_private.hpp"
-#include "simgrid/s4u/Activity.hpp"
-#include "simgrid/s4u/Comm.hpp"
-#include "simgrid/s4u/Engine.hpp"
-#include "simgrid/s4u/Exec.hpp"
-#include "src/internal_config.h"
-#include "xbt/file.hpp"
-#include <algorithm>
-#include <cstring>
-#include <unordered_map>
-#include <vector>
-
-#if HAVE_GRAPHVIZ
-#include <graphviz/cgraph.h>
-
-XBT_LOG_NEW_DEFAULT_CATEGORY(dotparse, "Parsing DOT files");
-
-namespace simgrid {
-namespace s4u {
-
-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*));
-
-  std::unordered_map<std::string, ActivityPtr> activities;
-  std::vector<ActivityPtr> dag;
-
-  ActivityPtr root;
-  ActivityPtr end;
-  ActivityPtr act;
-  /* Create all the nodes */
-  Agnode_t* node = nullptr;
-  for (node = agfstnode(dag_dot); node; node = agnxtnode(dag_dot, node)) {
-    char* 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);
-      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"))
-        dag.push_back(act);
-    } else {
-      XBT_WARN("Exec '%s' is defined more than once", name);
-    }
-  }
-  /*Check if 'root' and 'end' nodes have been explicitly declared.  If not, create them. */
-  if (activities.find("root") == activities.end())
-    root = Exec::init()->set_name("root")->set_flops_amount(0)->vetoable_start();
-  else
-    root = activities.at("root");
-
-  if (activities.find("end") == activities.end())
-    end = Exec::init()->set_name("end")->set_flops_amount(0)->vetoable_start();
-  else
-    end = activities.at("end");
-
-  /* Create edges */
-  std::vector<Agedge_t*> edges;
-  for (node = agfstnode(dag_dot); node; node = agnxtnode(dag_dot, node)) {
-    edges.clear();
-    for (Agedge_t* edge = agfstout(dag_dot, node); edge; edge = agnxtout(dag_dot, edge))
-      edges.push_back(edge);
-
-    /* Be sure edges are sorted */
-    std::sort(edges.begin(), edges.end(), [](const Agedge_t* a, const Agedge_t* b) { return AGSEQ(a) < AGSEQ(b); });
-
-    for (Agedge_t* edge : edges) {
-      const char* src_name = agnameof(agtail(edge));
-      const char* dst_name = agnameof(aghead(edge));
-      double size          = atof(agget(edge, (char*)"size"));
-
-      ActivityPtr src = activities.at(src_name);
-      ActivityPtr dst = activities.at(dst_name);
-      if (size > 0) {
-        std::string name = std::string(src_name) + "->" + dst_name;
-        XBT_DEBUG("See <Comm id=%s amount = %.0f>", name.c_str(), size);
-        if (activities.find(name) == activities.end()) {
-          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});
-          dag.push_back(act);
-        } else {
-          XBT_WARN("Comm '%s' is defined more than once", name.c_str());
-        }
-      } else {
-        src->add_successor(dst);
-      }
-    }
-  }
-
-  XBT_DEBUG("All activities have been created, put %s at the beginning and %s at the end", root->get_cname(),
-            end->get_cname());
-  dag.insert(dag.begin(), root);
-  dag.push_back(end);
-
-  /* Connect entry tasks to 'root', and exit tasks to 'end'*/
-  for (const auto& a : dag) {
-    if (a->dependencies_solved() && a != root) {
-      XBT_DEBUG("Activity '%s' has no dependencies. Add dependency from 'root'", a->get_cname());
-      root->add_successor(a);
-    }
-
-    if (a->is_waited_by() == 0 && a != end) {
-      XBT_DEBUG("Activity '%s' has no successors. Add dependency to 'end'", a->get_cname());
-      a->add_successor(end);
-    }
-  }
-  agclose(dag_dot);
-  fclose(in_file);
-
-  if (not check_for_cycle(dag)) {
-    std::string base = simgrid::xbt::Path(filename).get_base_name();
-    XBT_ERROR("The DOT described in %s is not a DAG. It contains a cycle.", base.c_str());
-    for (const auto& a : dag)
-      a->destroy();
-    dag.clear();
-  }
-
-  return dag;
-}
-
-} // namespace s4u
-} // namespace simgrid
-
-#else
-namespace simgrid {
-namespace s4u {
-std::vector<ActivityPtr> create_DAG_from_dot(const std::string& filename)
-{
-  xbt_die("create_DAG_from_dot() is not usable because graphviz was not found.\n"
-          "Please install graphviz, graphviz-dev, and libgraphviz-dev (and erase CMakeCache.txt) before recompiling.");
-}
-} // namespace s4u
-} // namespace simgrid
-
-#endif
diff --git a/src/simdag/simdag_private.hpp b/src/simdag/simdag_private.hpp
deleted file mode 100644 (file)
index 5208fe3..0000000
+++ /dev/null
@@ -1,17 +0,0 @@
-/* Copyright (c) 2006-2021. 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. */
-
-#include <simgrid/s4u/Engine.hpp>
-#include <simgrid/s4u/Host.hpp>
-#include <xbt/Extendable.hpp>
-
-#include <set>
-#include <string>
-#include <vector>
-
-#ifndef SIMDAG_PRIVATE_HPP
-#define SIMDAG_PRIVATE_HPP
-XBT_PRIVATE bool check_for_cycle(const std::vector<simgrid::s4u::ActivityPtr>& dag);
-#endif
index 1924341..c4d8f3d 100644 (file)
@@ -18,7 +18,6 @@ set(EXTRA_DIST
   src/simdag/dax.dtd
   src/simdag/dax_dtd.c
   src/simdag/dax_dtd.h
-  src/simdag/simdag_private.hpp
   src/simix/simcalls.in
   src/simix/simcalls.py
   src/simix/popping_private.hpp
@@ -472,7 +471,6 @@ set(MSG_SRC
 
 set(SIMDAG_SRC
   src/simdag/sd_daxloader.cpp
-  src/simdag/sd_dotloader.cpp
   )
 
 set(BINDINGS_SRC