Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
make the getNetzoneByType usable and tested
authorFrederic Suter <frederic.suter@cc.in2p3.fr>
Wed, 28 Feb 2018 16:07:11 +0000 (17:07 +0100)
committerFrederic Suter <frederic.suter@cc.in2p3.fr>
Wed, 28 Feb 2018 16:07:11 +0000 (17:07 +0100)
examples/s4u/CMakeLists.txt
examples/s4u/routing-get-clusters/s4u-routing-get-clusters.cpp [new file with mode: 0644]
examples/s4u/routing-get-clusters/s4u-routing-get-clusters.tesh [new file with mode: 0644]
include/simgrid/s4u/Engine.hpp
src/kernel/routing/ClusterZone.hpp
src/s4u/s4u_engine.cpp

index 29d75ac..8782111 100644 (file)
@@ -9,6 +9,7 @@ foreach (example actor-create actor-daemon actor-join actor-kill actor-kill-pid
                  mutex
                  platform-properties plugin-hostload 
                  replay-comm replay-storage
+                 routing-get-clusters
                  trace-platform)
   add_executable       (s4u-${example}  ${example}/s4u-${example}.cpp)
   target_link_libraries(s4u-${example}  simgrid)
@@ -94,7 +95,9 @@ foreach(example actor-create actor-daemon actor-join actor-kill actor-kill-pid
                 exec-async exec-basic exec-dvfs exec-monitor exec-ptask exec-remote
                 platform-properties plugin-hostload mutex
                 io-file-system io-file-remote io-storage-raw
-                replay-comm replay-storage)
+                replay-comm replay-storage
+                routing-get-clusters
+                )
   ADD_TESH_FACTORIES(s4u-${example} "thread;ucontext;raw;boost" 
                                     --setenv bindir=${CMAKE_CURRENT_BINARY_DIR}/${example} 
                                    --setenv platfdir=${CMAKE_HOME_DIRECTORY}/examples/platforms 
diff --git a/examples/s4u/routing-get-clusters/s4u-routing-get-clusters.cpp b/examples/s4u/routing-get-clusters/s4u-routing-get-clusters.cpp
new file mode 100644 (file)
index 0000000..a796716
--- /dev/null
@@ -0,0 +1,33 @@
+/* Copyright (c) 2009-2017. 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.hpp"
+#include "src/kernel/routing/ClusterZone.hpp"
+
+XBT_LOG_NEW_DEFAULT_CATEGORY(s4u_test, "Messages specific for this s4u example");
+
+int main(int argc, char* argv[])
+{
+  simgrid::s4u::Engine e(&argc, argv);
+  e.loadPlatform(argv[1]);
+
+  std::vector<simgrid::kernel::routing::ClusterZone*>* clusters =
+      new std::vector<simgrid::kernel::routing::ClusterZone*>;
+
+  e.getNetzoneByType<simgrid::kernel::routing::ClusterZone>(clusters);
+
+  for (auto c : *clusters) {
+    XBT_INFO("%s", c->getCname());
+    std::vector<simgrid::s4u::Host*>* hosts = new std::vector<simgrid::s4u::Host*>;
+    c->getHosts(hosts);
+    for (auto h : *hosts)
+      XBT_INFO("   %s", h->getCname());
+    delete hosts;
+  }
+
+  delete clusters;
+
+  return 0;
+}
diff --git a/examples/s4u/routing-get-clusters/s4u-routing-get-clusters.tesh b/examples/s4u/routing-get-clusters/s4u-routing-get-clusters.tesh
new file mode 100644 (file)
index 0000000..6d65ec6
--- /dev/null
@@ -0,0 +1,28 @@
+$ $SG_TEST_EXENV ${bindir:=.}/s4u-routing-get-clusters$EXEEXT ${platfdir}/cluster_backbone.xml "--log=root.fmt:[%10.6r]%e(%P@%h)%e%m%n"
+> [  0.000000] (maestro@) simple
+> [  0.000000] (maestro@)    node-0.1core.org
+> [  0.000000] (maestro@)    node-1.1core.org
+> [  0.000000] (maestro@)    node-2.1core.org
+> [  0.000000] (maestro@)    node-3.1core.org
+> [  0.000000] (maestro@)    node-4.1core.org
+> [  0.000000] (maestro@)    node-5.1core.org
+> [  0.000000] (maestro@)    node-6.1core.org
+> [  0.000000] (maestro@)    node-7.1core.org
+> [  0.000000] (maestro@) backboned
+> [  0.000000] (maestro@)    node-0.2cores.org
+> [  0.000000] (maestro@)    node-1.2cores.org
+> [  0.000000] (maestro@)    node-2.2cores.org
+> [  0.000000] (maestro@)    node-3.2cores.org
+> [  0.000000] (maestro@)    node-4.2cores.org
+> [  0.000000] (maestro@)    node-5.2cores.org
+> [  0.000000] (maestro@)    node-6.2cores.org
+> [  0.000000] (maestro@)    node-7.2cores.org
+> [  0.000000] (maestro@) halfduplex
+> [  0.000000] (maestro@)    node-0.4cores.org
+> [  0.000000] (maestro@)    node-1.4cores.org
+> [  0.000000] (maestro@)    node-2.4cores.org
+> [  0.000000] (maestro@)    node-3.4cores.org
+> [  0.000000] (maestro@)    node-4.4cores.org
+> [  0.000000] (maestro@)    node-5.4cores.org
+> [  0.000000] (maestro@)    node-6.4cores.org
+> [  0.000000] (maestro@)    node-7.4cores.org
index c9d2318..c76d22e 100644 (file)
@@ -15,6 +15,7 @@
 
 #include <simgrid/simix.hpp>
 
+#include <simgrid/s4u/NetZone.hpp>
 #include <simgrid/s4u/forward.hpp>
 
 namespace simgrid {
@@ -85,8 +86,7 @@ public:
   simgrid::s4u::NetZone* getNetzoneByNameOrNull(const char* name);
 
   /** @brief Retrieves all netzones of the same type than the subtype of the whereto vector */
-  template <class T> void getNetzoneByType(std::vector<T*> * whereto);
-
+  template <class T> void getNetzoneByType(std::vector<T*> * whereto) { netzoneByTypeRecursive(getNetRoot(), whereto); }
   /** @brief Retrieve the netcard of the given name (or nullptr if not found) */
   simgrid::kernel::routing::NetPoint* getNetpointByNameOrNull(std::string name);
   void getNetpointList(std::vector<simgrid::kernel::routing::NetPoint*> * list);
@@ -140,6 +140,15 @@ extern XBT_PUBLIC(xbt::signal<void(double)>) onTimeAdvance;
 
 /** Callback fired when the time cannot jump because of inter-actors deadlock */
 extern XBT_PUBLIC(xbt::signal<void(void)>) onDeadlock;
+
+template <class T> XBT_PRIVATE void netzoneByTypeRecursive(s4u::NetZone* current, std::vector<T*>* whereto)
+{
+  for (auto const& elem : *(current->getChildren())) {
+    netzoneByTypeRecursive(elem, whereto);
+    if (elem == dynamic_cast<T*>(elem))
+      whereto->push_back(dynamic_cast<T*>(elem));
+  }
+}
 }
 } // namespace simgrid::s4u
 
index bb1eb03..a9a7866 100644 (file)
@@ -65,7 +65,7 @@ namespace routing {
  *  (because the private router is directly connected to the cluster core).
  */
 
-class XBT_PRIVATE ClusterZone : public NetZoneImpl {
+class ClusterZone : public NetZoneImpl {
 public:
   explicit ClusterZone(NetZone* father, std::string name);
 
index 9913599..0dea4cb 100644 (file)
@@ -30,7 +30,6 @@ xbt::signal<void(void)> onDeadlock;
 
 Engine *Engine::instance_ = nullptr; /* That singleton is awful, but I don't see no other solution right now. */
 
-
 Engine::Engine(int *argc, char **argv) {
   xbt_assert(s4u::Engine::instance_ == nullptr, "It is currently forbidden to create more than one instance of s4u::Engine");
   TRACE_global_init();
@@ -154,21 +153,6 @@ NetZone* Engine::getNetzoneByNameOrNull(const char* name)
   return netzoneByNameRecursive(getNetRoot(), name);
 }
 
-template <class T> void netzoneByTypeRecursive(s4u::NetZone* current, std::vector<T*>* whereto)
-{
-  for (auto const& elem : *(current->getChildren())) {
-    netzoneByTypeRecursive(elem, whereto);
-    if (elem == dynamic_cast<T*>(elem))
-      whereto->push_back(elem);
-  }
-}
-
-/** @brief Retrieve all existing NetZones of the subtype of the whereto vector */
-template <class T> void Engine::getNetzoneByType(std::vector<T*>* whereto)
-{
-  netzoneByTypeRecursive(getNetRoot(), whereto);
-}
-
 /** @brief Retrieve the netpoint of the given name (or nullptr if not found) */
 simgrid::kernel::routing::NetPoint* Engine::getNetpointByNameOrNull(std::string name)
 {