Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
new function: Engine::netcardList()
authorMartin Quinson <martin.quinson@loria.fr>
Mon, 19 Dec 2016 09:22:37 +0000 (10:22 +0100)
committerMartin Quinson <martin.quinson@loria.fr>
Mon, 19 Dec 2016 09:22:37 +0000 (10:22 +0100)
include/simgrid/s4u/engine.hpp
src/s4u/s4u_engine.cpp
teshsuite/simdag/flatifier/flatifier.cpp
teshsuite/simdag/is-router/is-router.cpp

index a6ee0bd..62b4164 100644 (file)
@@ -74,6 +74,7 @@ public:
 
   /** @brief Retrieve the netcard of the given name (or nullptr if not found) */
   simgrid::kernel::routing::NetCard* netcardByNameOrNull(const char* name);
 
   /** @brief Retrieve the netcard of the given name (or nullptr if not found) */
   simgrid::kernel::routing::NetCard* netcardByNameOrNull(const char* name);
+  void netcardList(std::vector<simgrid::kernel::routing::NetCard*> * list);
 
   template<class F>
   void registerFunction(const char* name)
 
   template<class F>
   void registerFunction(const char* name)
index 71bf838..6e37df0 100644 (file)
@@ -116,5 +116,14 @@ simgrid::kernel::routing::NetCard* Engine::netcardByNameOrNull(const char* name)
 {
   return static_cast<simgrid::kernel::routing::NetCard*>(xbt_dict_get_or_null(netcards_dict, name));
 }
 {
   return static_cast<simgrid::kernel::routing::NetCard*>(xbt_dict_get_or_null(netcards_dict, name));
 }
+void Engine::netcardList(std::vector<simgrid::kernel::routing::NetCard*>* list)
+{
+  xbt_lib_cursor_t cursor = nullptr;
+  char* key;
+  void* data;
+  xbt_dict_foreach (netcards_dict, cursor, key, data) {
+    list->push_back(static_cast<simgrid::kernel::routing::NetCard*>(data));
+  }
+}
 }
 }
 }
 }
index 291feeb..7d1b499 100644 (file)
@@ -14,7 +14,8 @@
 #include <xbt/sysdep.h>
 #include <xbt/xbt_os_time.h>
 
 #include <xbt/sysdep.h>
 #include <xbt/xbt_os_time.h>
 
-#include <simgrid/s4u/host.hpp>
+#include "simgrid/s4u/engine.hpp"
+#include "simgrid/s4u/host.hpp"
 
 #include <simgrid/simdag.h>
 
 
 #include <simgrid/simdag.h>
 
@@ -72,9 +73,7 @@ int main(int argc, char **argv)
   unsigned int i;
   xbt_dict_t props = nullptr;
   xbt_dict_cursor_t cursor = nullptr;
   unsigned int i;
   xbt_dict_t props = nullptr;
   xbt_dict_cursor_t cursor = nullptr;
-  xbt_lib_cursor_t cursor_src = nullptr;
-  xbt_lib_cursor_t cursor_dst = nullptr;
-  char *src,*dst,*key,*data;
+  char *key, *data;
   sg_netcard_t value1;
   sg_netcard_t value2;
 
   sg_netcard_t value1;
   sg_netcard_t value2;
 
@@ -90,6 +89,9 @@ int main(int argc, char **argv)
 
   create_environment(parse_time, platformFile);
 
 
   create_environment(parse_time, platformFile);
 
+  std::vector<simgrid::kernel::routing::NetCard*> netcardList;
+  simgrid::s4u::Engine::instance()->netcardList(&netcardList);
+
   if (timings) {
     XBT_INFO("Parsing time: %fs (%zu hosts, %d links)", xbt_os_timer_elapsed(parse_time),
              sg_host_count(), sg_link_count());
   if (timings) {
     XBT_INFO("Parsing time: %fs (%zu hosts, %d links)", xbt_os_timer_elapsed(parse_time),
              sg_host_count(), sg_link_count());
@@ -122,11 +124,9 @@ int main(int argc, char **argv)
     }
 
     // Routers
     }
 
     // Routers
-    xbt_dict_foreach (netcards_dict, cursor_src, key, value1) {
-      if(value1->isRouter()) {
-        std::printf("  <router id=\"%s\"/>\n",key);
-      }
-    }
+    for (auto srcCard : netcardList)
+      if (srcCard->isRouter())
+        std::printf("  <router id=\"%s\"/>\n", srcCard->cname());
 
     // Links
     unsigned int totalLinks = sg_link_count();
 
     // Links
     unsigned int totalLinks = sg_link_count();
@@ -146,12 +146,11 @@ int main(int argc, char **argv)
       }
     }
 
       }
     }
 
-    sg_host_t host1, host2;
     for (unsigned int it_src = 0; it_src < totalHosts; it_src++) { // Routes from host
     for (unsigned int it_src = 0; it_src < totalHosts; it_src++) { // Routes from host
-      host1 = hosts[it_src];
+      simgrid::s4u::Host* host1 = hosts[it_src];
       value1 = host1->pimpl_netcard;
       for (unsigned int it_dst = 0; it_dst < totalHosts; it_dst++) { // Routes to host
       value1 = host1->pimpl_netcard;
       for (unsigned int it_dst = 0; it_dst < totalHosts; it_dst++) { // Routes to host
-        host2 = hosts[it_dst];
+        simgrid::s4u::Host* host2 = hosts[it_dst];
         std::vector<Link*> *route = new std::vector<Link*>();
         value2 = host2->pimpl_netcard;
         simgrid::kernel::routing::NetZoneImpl::getGlobalRoute(value1, value2, route, nullptr);
         std::vector<Link*> *route = new std::vector<Link*>();
         value2 = host2->pimpl_netcard;
         simgrid::kernel::routing::NetZoneImpl::getGlobalRoute(value1, value2, route, nullptr);
@@ -163,9 +162,9 @@ int main(int argc, char **argv)
         }
         delete route;
       }
         }
         delete route;
       }
-      xbt_dict_foreach (netcards_dict, cursor_dst, dst, value2) { // to router
+      for (auto value2 : netcardList) { // to router
         if(value2->isRouter()){
         if(value2->isRouter()){
-          std::printf("  <route src=\"%s\" dst=\"%s\">\n  ", host1->cname(), dst);
+          std::printf("  <route src=\"%s\" dst=\"%s\">\n  ", host1->cname(), value2->cname());
           std::vector<Link*> *route = new std::vector<Link*>();
           simgrid::kernel::routing::NetZoneImpl::getGlobalRoute(value1, value2, route, nullptr);
           for (auto link : *route)
           std::vector<Link*> *route = new std::vector<Link*>();
           simgrid::kernel::routing::NetZoneImpl::getGlobalRoute(value1, value2, route, nullptr);
           for (auto link : *route)
@@ -176,12 +175,12 @@ int main(int argc, char **argv)
       }
     }
 
       }
     }
 
-    xbt_dict_foreach (netcards_dict, cursor_src, src, value1) { // Routes from router
+    for (auto value1 : netcardList) { // Routes from router
       if (value1->isRouter()){
       if (value1->isRouter()){
-        xbt_dict_foreach (netcards_dict, cursor_dst, dst, value2) { // to router
-          if(value2->isRouter()){
-            std::printf("  <route src=\"%s\" dst=\"%s\">\n  ", src, dst);
-            std::vector<Link*> *route = new std::vector<Link*>();
+        for (auto value2 : netcardList) { // to router
+          if (value2->isRouter()) {
+            std::printf("  <route src=\"%s\" dst=\"%s\">\n  ", value1->cname(), value2->cname());
+            std::vector<Link*>route = new std::vector<Link*>();
             simgrid::kernel::routing::NetZoneImpl::getGlobalRoute(value1, value2, route, nullptr);
             for(auto link :*route)
               std::printf("<link_ctn id=\"%s\"/>",link->getName());
             simgrid::kernel::routing::NetZoneImpl::getGlobalRoute(value1, value2, route, nullptr);
             for(auto link :*route)
               std::printf("<link_ctn id=\"%s\"/>",link->getName());
@@ -190,8 +189,8 @@ int main(int argc, char **argv)
           }
         }
         for (unsigned int it_dst = 0; it_dst < totalHosts; it_dst++) { // Routes to host
           }
         }
         for (unsigned int it_dst = 0; it_dst < totalHosts; it_dst++) { // Routes to host
-          host2 = hosts[it_dst];
-          std::printf("  <route src=\"%s\" dst=\"%s\">\n  ", src, host2->cname());
+          simgrid::s4u::Host* host2 = hosts[it_dst];
+          std::printf("  <route src=\"%s\" dst=\"%s\">\n  ", value1->cname(), host2->cname());
           std::vector<Link*> *route = new std::vector<Link*>();
           value2 = host2->pimpl_netcard;
           simgrid::kernel::routing::NetZoneImpl::getGlobalRoute(value1, value2, route, nullptr);
           std::vector<Link*> *route = new std::vector<Link*>();
           value2 = host2->pimpl_netcard;
           simgrid::kernel::routing::NetZoneImpl::getGlobalRoute(value1, value2, route, nullptr);
index b201d70..585b8ce 100644 (file)
@@ -3,6 +3,7 @@
 /* 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. */
 
 /* 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 "simgrid/simdag.h"
 #include "src/kernel/routing/NetCard.hpp"
 #include "simgrid/s4u/host.hpp"
 #include "simgrid/simdag.h"
 #include "src/kernel/routing/NetCard.hpp"
@@ -17,6 +18,9 @@ int main(int argc, char **argv)
   xbt_dynar_t hosts = sg_hosts_as_dynar();
   printf("Host count: %zu, link number: %d\n", sg_host_count(), sg_link_count());
 
   xbt_dynar_t hosts = sg_hosts_as_dynar();
   printf("Host count: %zu, link number: %d\n", sg_host_count(), sg_link_count());
 
+  std::vector<simgrid::kernel::routing::NetCard*> netcardList;
+  simgrid::s4u::Engine::instance()->netcardList(&netcardList);
+
   int it;
   sg_host_t host;
   xbt_dynar_foreach(hosts, it, host) {
   int it;
   sg_host_t host;
   xbt_dynar_foreach(hosts, it, host) {
@@ -27,13 +31,9 @@ int main(int argc, char **argv)
   xbt_dynar_free(&hosts);
 
   printf("NetCards count: %d\n", xbt_dict_length(netcards_dict));
   xbt_dynar_free(&hosts);
 
   printf("NetCards count: %d\n", xbt_dict_length(netcards_dict));
-  xbt_lib_cursor_t cursor = nullptr;
-  char* key;
-  void *ignored;
-  xbt_dict_foreach (netcards_dict, cursor, key, ignored) {
-    simgrid::kernel::routing::NetCard * nc = sg_netcard_by_name_or_null(key);
-    printf("   - Seen: \"%s\". Type: %s\n", key, nc->isRouter() ? "router" : (nc->isNetZone() ? "netzone" : "host"));
-  }
+  for (auto nc : netcardList)
+    printf("   - Seen: \"%s\". Type: %s\n", nc->cname(),
+           nc->isRouter() ? "router" : (nc->isNetZone() ? "netzone" : "host"));
 
   SD_exit();
   return 0;
 
   SD_exit();
   return 0;