Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
hide a global data container
authorMartin Quinson <martin.quinson@loria.fr>
Thu, 15 Sep 2016 16:24:54 +0000 (18:24 +0200)
committerMartin Quinson <martin.quinson@loria.fr>
Thu, 22 Sep 2016 19:23:43 +0000 (21:23 +0200)
include/simgrid/host.h
include/surf/surf_routing.h
src/msg/msg_host.cpp
src/msg/msg_vm.cpp
src/s4u/s4u_host.cpp
src/simgrid/host.cpp
src/surf/sg_platf.cpp
src/surf/surf_interface.cpp
src/surf/surf_routing.cpp
teshsuite/simdag/flatifier/flatifier.cpp
teshsuite/simdag/is-router/is-router.cpp

index 6713ccf..e1d6c26 100644 (file)
@@ -16,6 +16,8 @@
 
 SG_BEGIN_DECL()
 
+XBT_PUBLIC(void) sg_host_exit();
+
 XBT_PUBLIC(size_t) sg_host_count();
 XBT_PUBLIC(sg_host_t *) sg_host_list();
 
index c846b77..075f7c7 100644 (file)
@@ -11,7 +11,6 @@
 
 SG_BEGIN_DECL()
 
-XBT_PUBLIC_DATA(xbt_dict_t) host_list;
 XBT_PUBLIC_DATA(int) SIMIX_STORAGE_LEVEL; //Simix storage level
 XBT_PUBLIC_DATA(int) COORD_HOST_LEVEL;    //Coordinates level
 
index 4d09dff..1d369c0 100644 (file)
@@ -128,7 +128,7 @@ void __MSG_host_priv_free(msg_host_priv_t priv)
  */
 int MSG_get_host_number()
 {
-  return xbt_dict_length(host_list);
+  return sg_host_count();
 }
 
 /** \ingroup m_host_management
index 2198f6d..46dae39 100644 (file)
@@ -196,7 +196,7 @@ msg_vm_t MSG_vm_create_core(msg_host_t ind_pm, const char *name)
 {
   /* make sure the VM of the same name does not exit */
   {
-    simgrid::s4u::Host* ind_host_tmp = (simgrid::s4u::Host*) xbt_dict_get_or_null(host_list, name);
+    simgrid::s4u::Host* ind_host_tmp = sg_host_by_name(name);
     if (ind_host_tmp != nullptr && sg_host_simix(ind_host_tmp) != nullptr) {
       XBT_ERROR("host %s already exits", name);
       return nullptr;
index 7d13e33..5db68c5 100644 (file)
@@ -20,6 +20,8 @@
 #include "simgrid/s4u/host.hpp"
 #include "simgrid/s4u/storage.hpp"
 
+xbt_dict_t host_list = nullptr; // FIXME: make it a static field of Host
+
 int MSG_HOST_LEVEL = -1;
 int USER_HOST_LEVEL = -1;
 
@@ -55,6 +57,12 @@ Host *Host::by_name(std::string name) {
 }
 Host* Host::by_name_or_null(const char* name)
 {
+  if (host_list == nullptr)
+    host_list = xbt_dict_new_homogeneous([](void*p) {
+      simgrid::s4u::Host* host = static_cast<simgrid::s4u::Host*>(p);
+      simgrid::s4u::Host::onDestruction(*host);
+      delete host;
+    });
   return (Host*) xbt_dict_get_or_null(host_list, name);
 }
 Host* Host::by_name_or_create(const char* name)
index 77aa8ef..f3701a7 100644 (file)
 
 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(sg_host, sd, "Logging specific to sg_hosts");
 
+extern xbt_dict_t host_list; // FIXME:killme don't dupplicate the content of s4u::Host this way
+
+void sg_host_exit()
+{
+  xbt_dict_free(&host_list);
+}
+
 size_t sg_host_count()
 {
   return xbt_dict_length(host_list);
index e1971f0..a1ff3b1 100644 (file)
@@ -570,6 +570,7 @@ void sg_platf_new_process(sg_platf_process_cbarg_t process)
         msg->used -= 3;
 
         xbt_strbuff_append(msg," ...(list truncated)......");// That will be shortened by 3 chars when existing the loop
+        break;
       }
     }
     msg->data[msg->used-3]='\0';
index 1829975..194b467 100644 (file)
@@ -289,15 +289,10 @@ void sg_version(int *ver_major,int *ver_minor,int *ver_patch) {
 
 void surf_init(int *argc, char **argv)
 {
-  if (host_list != nullptr) // Already initialized
+  if (USER_HOST_LEVEL != -1) // Already initialized
     return;
 
   XBT_DEBUG("Create all Libs");
-  host_list = xbt_dict_new_homogeneous([](void*p) {
-    simgrid::s4u::Host* host = static_cast<simgrid::s4u::Host*>(p);
-    simgrid::s4u::Host::onDestruction(*host);
-    delete host;
-  });
   USER_HOST_LEVEL = simgrid::s4u::Host::extension_create(nullptr);
 
   as_router_lib = xbt_lib_new();
@@ -338,7 +333,7 @@ void surf_exit()
 
   xbt_dynar_free(&surf_path);
 
-  xbt_dict_free(&host_list);
+  sg_host_exit();
   xbt_lib_free(&as_router_lib);
   xbt_lib_free(&storage_lib);
   sg_link_exit();
index e12af64..b6c6e65 100644 (file)
@@ -34,7 +34,6 @@ namespace routing {
  * @ingroup SURF_build_api
  * @brief A library containing all known hosts
  */
-xbt_dict_t host_list = nullptr;
 
 int COORD_HOST_LEVEL = -1;         //Coordinates level
 
index 6e9499a..db4dede 100644 (file)
@@ -147,14 +147,16 @@ int main(int argc, char **argv)
     }
 
     sg_host_t host1, host2;
-    xbt_dict_foreach(host_list, cursor_src, src, host1){ // Routes from host
-      value1 = sg_host_by_name(src)->pimpl_netcard;
-      xbt_dict_foreach(host_list, cursor_dst, dst, host2){ //to host
+    for (unsigned int it_src = 0; it_src < totalHosts; it_src++) { // Routes from host
+      host1 = hosts[it_src];
+      value1 = sg_host_by_name(host1->name().c_str())->pimpl_netcard;
+      for (unsigned int it_dst = 0; it_dst < totalHosts; it_dst++) { // Routes to host
+        host2 = hosts[it_dst];
         std::vector<Link*> *route = new std::vector<Link*>();
-        value2 = sg_host_by_name(dst)->pimpl_netcard;
+        value2 = host2->pimpl_netcard;
         routing_platf->getRouteAndLatency(value1, value2, route,nullptr);
         if (! route->empty()){
-          std::printf("  <route src=\"%s\" dst=\"%s\">\n  ", src, dst);
+          std::printf("  <route src=\"%s\" dst=\"%s\">\n  ", host1->name().c_str(), host2->name().c_str());
           for (auto link: *route)
             std::printf("<link_ctn id=\"%s\"/>",link->getName());
           std::printf("\n  </route>\n");
@@ -164,7 +166,7 @@ int main(int argc, char **argv)
       xbt_lib_foreach(as_router_lib, cursor_dst, dst, value2){ //to router
         value2 = (sg_netcard_t)xbt_lib_get_or_null(as_router_lib,dst,ROUTING_ASR_LEVEL);
         if(value2->isRouter()){
-          std::printf("  <route src=\"%s\" dst=\"%s\">\n  ", src, dst);
+          std::printf("  <route src=\"%s\" dst=\"%s\">\n  ", host1->name().c_str(), dst);
           std::vector<Link*> *route = new std::vector<Link*>();
           routing_platf->getRouteAndLatency((sg_netcard_t)value1,(sg_netcard_t)value2,route,nullptr);
           for (auto link : *route)
@@ -190,10 +192,11 @@ int main(int argc, char **argv)
             std::printf("\n  </route>\n");
           }
         }
-        xbt_dict_foreach(host_list, cursor_dst, dst, value2){ //to host
-          std::printf("  <route src=\"%s\" dst=\"%s\">\n  ",src, dst);
+        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->name().c_str());
           std::vector<Link*> *route = new std::vector<Link*>();
-          value2 = sg_host_by_name(dst)->pimpl_netcard;
+          value2 = host2->pimpl_netcard;
           routing_platf->getRouteAndLatency((sg_netcard_t)value1,(sg_netcard_t)value2,route, nullptr);
           for(auto link : *route)
             std::printf("<link_ctn id=\"%s\"/>",link->getName());
index 680fce3..9039cdc 100644 (file)
@@ -6,28 +6,31 @@
 #include <stdio.h>
 #include "simgrid/simdag.h"
 #include "src/surf/surf_routing.hpp"
+#include "simgrid/s4u/host.hpp"
+
 
 int main(int argc, char **argv)
 {
   /* SD initialization */
-  int size;
-  xbt_lib_cursor_t cursor = nullptr;
   char *key, *data;
 
   SD_init(&argc, argv);
-
-  /* creation of the environment */
   SD_create_environment(argv[1]);
 
-  size = xbt_dict_length(host_list) + xbt_lib_length(as_router_lib);
+  xbt_dynar_t hosts = sg_hosts_as_dynar();
+  int size = sg_host_count() + xbt_lib_length(as_router_lib);
 
   printf("Host number: %zu, link number: %d, elmts number: %d\n", sg_host_count(), sg_link_count(), size);
 
-  xbt_dict_foreach(host_list, cursor, key, data) {
-    simgrid::kernel::routing::NetCard * nc = sg_netcard_by_name_or_null(key);
-    printf("   - Seen: \"%s\". Type: %s\n", key, nc->isRouter() ? "router" : (nc->isAS()?"AS":"host"));
+  int it;
+  xbt_dynar_foreach(hosts, it, data) {
+    sg_host_t host = (sg_host_t)data;
+    simgrid::kernel::routing::NetCard * nc = host->pimpl_netcard;
+    printf("   - Seen: \"%s\". Type: %s\n", host->name().c_str(), nc->isRouter() ? "router" : (nc->isAS()?"AS":"host"));
   }
+  xbt_dynar_free(&hosts);
 
+  xbt_lib_cursor_t cursor = nullptr;
   xbt_lib_foreach(as_router_lib, cursor, key, data) {
     simgrid::kernel::routing::NetCard * nc = sg_netcard_by_name_or_null(key);
     printf("   - Seen: \"%s\". Type: %s\n", key, nc->isRouter() ? "router" : (nc->isAS()?"AS":"host"));