Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Move all netcards into the dict, and the dict to the engine
authorMartin Quinson <martin.quinson@loria.fr>
Sun, 18 Dec 2016 15:14:36 +0000 (16:14 +0100)
committerMartin Quinson <martin.quinson@loria.fr>
Sun, 18 Dec 2016 22:26:31 +0000 (23:26 +0100)
examples/java/app/masterworker/app_masterworker.tesh
src/kernel/EngineImpl.cpp
src/kernel/routing/NetCard.cpp
src/kernel/routing/NetCard.hpp
src/kernel/routing/NetZoneImpl.cpp
src/s4u/s4u_host.cpp
src/surf/sg_platf.cpp
src/surf/surf_interface.cpp
src/surf/surf_routing.cpp
teshsuite/simdag/is-router/is-router.cpp
teshsuite/simdag/is-router/is-router.tesh

index 8b571e0..e2fcf87 100644 (file)
@@ -1,7 +1,5 @@
 #! tesh
 
-! output sort 19
-
 $ java -classpath ${classpath:=.} app/masterworker/Main ${srcdir:=.}/../platforms/small_platform.xml ${srcdir:=.}/app/masterworker/masterworker.xml "--log=root.fmt:[%10.6r]%e(%i:%P@%h)%e%m%n"
 > [  0.000000] (0:maestro@) Using regular java threads.
 > [  0.000000] (1:app.masterworker.Master@Jacquelin) Hello! Got 7 workers and 5 tasks to process
@@ -9,14 +7,14 @@ $ java -classpath ${classpath:=.} app/masterworker/Main ${srcdir:=.}/../platform
 > [  1.752187] (3:app.masterworker.Worker@Fafard) Received "Task_1". Processing it.
 > [  1.757531] (4:app.masterworker.Worker@Bourassa) Received "Task_2". Processing it.
 > [  2.806417] (5:app.masterworker.Worker@Boivin) Received "Task_3". Processing it.
-> [  2.811761] (1:app.masterworker.Master@Jacquelin) All tasks have been dispatched. Let's tell everybody the computation is over.
 > [  2.811761] (6:app.masterworker.Worker@Ginette) Received "Task_4". Processing it.
+> [  2.811761] (1:app.masterworker.Master@Jacquelin) All tasks have been dispatched. Let's tell everybody the computation is over.
 > [  3.671783] (2:app.masterworker.Worker@Tremblay) Received Finalize. I'm done. See you!
 > [  4.563940] (3:app.masterworker.Worker@Fafard) Received Finalize. I'm done. See you!
 > [  4.569280] (4:app.masterworker.Worker@Bourassa) Received Finalize. I'm done. See you!
 > [  5.618161] (5:app.masterworker.Worker@Boivin) Received Finalize. I'm done. See you!
 > [  5.623501] (6:app.masterworker.Worker@Ginette) Received Finalize. I'm done. See you!
 > [  5.628842] (7:app.masterworker.Worker@Jupiter) Received Finalize. I'm done. See you!
-> [  5.629037] (0:maestro@) MSG_main finished; Cleaning up the simulation...
-> [  5.629037] (1:app.masterworker.Master@Jacquelin) Goodbye now!
 > [  5.629037] (8:app.masterworker.Worker@Jacquelin) Received Finalize. I'm done. See you!
+> [  5.629037] (1:app.masterworker.Master@Jacquelin) Goodbye now!
+> [  5.629037] (0:maestro@) MSG_main finished; Cleaning up the simulation...
index 486b97b..175a18a 100644 (file)
@@ -4,18 +4,25 @@
  * under the terms of the license (GNU LGPL) which comes with this package. */
 
 #include "src/kernel/EngineImpl.hpp"
+#include "src/kernel/routing/NetCard.hpp"
 #include "src/kernel/routing/NetZoneImpl.hpp"
 #include <simgrid/s4u/host.hpp>
 
+xbt_dict_t netcards_dict;
+
 namespace simgrid {
 namespace kernel {
 
 EngineImpl::EngineImpl()
 {
+  netcards_dict = xbt_dict_new_homogeneous([](void* p) {
+    delete static_cast<simgrid::kernel::routing::NetCard*>(p);
+  });
 }
 EngineImpl::~EngineImpl()
 {
   delete netRoot_;
+  xbt_dict_free(&netcards_dict);
 }
 }
 }
index 799983e..e45e174 100644 (file)
@@ -16,6 +16,15 @@ namespace kernel {
 namespace routing {
 
 simgrid::xbt::signal<void(NetCard*)> NetCard::onCreation;
+
+NetCard::NetCard(std::string name, NetCard::Type componentType, NetZoneImpl* netzone_p)
+    : name_(name), componentType_(componentType), netzone_(netzone_p)
+{
+  if (netzone_p != nullptr)
+    id_ = netzone_p->addComponent(this);
+  xbt_dict_set(netcards_dict, name.c_str(), static_cast<void*>(this), nullptr);
+  simgrid::kernel::routing::NetCard::onCreation(this);
+}
 }
 }
 } // namespace simgrid::kernel::routing
@@ -26,6 +35,5 @@ simgrid::xbt::signal<void(NetCard*)> NetCard::onCreation;
  */
 simgrid::kernel::routing::NetCard* sg_netcard_by_name_or_null(const char* name)
 {
-  sg_host_t host = sg_host_by_name(name);
-  return (host != nullptr) ? host->pimpl_netcard : simgrid::s4u::Engine::instance()->netcardByNameOrNull(name);
+  return simgrid::s4u::Engine::instance()->netcardByNameOrNull(name);
 }
index 3f03189..b899b68 100644 (file)
@@ -29,13 +29,7 @@ class NetCard : public simgrid::xbt::Extendable<NetCard> {
 public:
   enum class Type { Host, Router, NetZone };
 
-  NetCard(std::string name, NetCard::Type componentType, NetZoneImpl* netzone_p)
-      : name_(name), componentType_(componentType), netzone_(netzone_p)
-  {
-    if (netzone_p != nullptr)
-      id_ = netzone_p->addComponent(this);
-    simgrid::kernel::routing::NetCard::onCreation(this);
-  }
+  NetCard(std::string name, NetCard::Type componentType, NetZoneImpl* netzone_p);
   ~NetCard() = default;
 
   // Our rank in the vertices_ array of our containing AS.
index 57619a8..7a8ecff 100644 (file)
@@ -32,13 +32,14 @@ NetZoneImpl::NetZoneImpl(NetZone* father, const char* name) : NetZone(father, na
              "Refusing to create a second NetZone called '%s'.", name);
 
   netcard_ = new NetCard(name, NetCard::Type::NetZone, static_cast<NetZoneImpl*>(father));
-  xbt_dict_set(netcards_dict, name, static_cast<void*>(netcard_), nullptr);
   XBT_DEBUG("NetZone '%s' created with the id '%d'", name, netcard_->id());
 }
 NetZoneImpl::~NetZoneImpl()
 {
   for (auto& kv : bypassRoutes_)
     delete kv.second;
+
+  xbt_dict_remove(netcards_dict, name_);
 }
 
 simgrid::s4u::Host* NetZoneImpl::createHost(const char* name, std::vector<double>* speedPerPstate, int coreAmount)
index 77057f2..1499c26 100644 (file)
@@ -52,8 +52,9 @@ Host::~Host()
   xbt_assert(currentlyDestroying_, "Please call h->destroy() instead of manually deleting it.");
 
   delete pimpl_;
+  if (pimpl_netcard != nullptr) // not removed yet by a children class
+    xbt_dict_remove(netcards_dict, name_.c_str());
   delete pimpl_cpu;
-  delete pimpl_netcard;
   delete mounts;
 }
 
index 9c95b66..4e7b0e7 100644 (file)
@@ -120,7 +120,6 @@ void sg_platf_new_router(sg_platf_router_cbarg_t router)
 
   simgrid::kernel::routing::NetCard* netcard =
     new simgrid::kernel::routing::NetCard(router->id, simgrid::kernel::routing::NetCard::Type::Router, current_routing);
-  xbt_dict_set(netcards_dict, router->id, netcard, nullptr);
   XBT_DEBUG("Router '%s' has the id %d", router->id, netcard->id());
 
   if (router->coord && strcmp(router->coord, ""))
@@ -128,7 +127,7 @@ void sg_platf_new_router(sg_platf_router_cbarg_t router)
 
   auto cluster = dynamic_cast<simgrid::kernel::routing::ClusterZone*>(current_routing);
   if(cluster != nullptr)
-    cluster->router_ = static_cast<simgrid::kernel::routing::NetCard*>(xbt_dict_get_or_null(netcards_dict, router->id));
+    cluster->router_ = simgrid::s4u::Engine::instance()->netcardByNameOrNull(router->id);
 
   if (TRACE_is_enabled() && TRACE_needs_platform())
     sg_instr_new_router(router);
index 1171e7a..3f44e4f 100644 (file)
@@ -289,9 +289,6 @@ void surf_init(int *argc, char **argv)
   XBT_DEBUG("Create all Libs");
   USER_HOST_LEVEL = simgrid::s4u::Host::extension_create(nullptr);
 
-  netcards_dict = xbt_dict_new_homogeneous([](void* p) {
-    delete static_cast<simgrid::kernel::routing::NetCard*>(p);
-  });
   storage_lib = xbt_lib_new();
   storage_type_lib = xbt_lib_new();
   file_lib = xbt_lib_new();
@@ -324,7 +321,6 @@ void surf_exit()
   xbt_dynar_free(&surf_path);
 
   sg_host_exit();
-  xbt_dict_free(&netcards_dict);
   xbt_lib_free(&storage_lib);
   sg_link_exit();
   xbt_lib_free(&storage_type_lib);
index ef30cf2..1bf0d25 100644 (file)
@@ -5,4 +5,3 @@
 
 #include "xbt/dict.h"
 
-xbt_dict_t netcards_dict;
index ffef43b..b201d70 100644 (file)
@@ -15,9 +15,7 @@ int main(int argc, char **argv)
   SD_create_environment(argv[1]);
 
   xbt_dynar_t hosts = sg_hosts_as_dynar();
-  int size          = sg_host_count() + xbt_dict_length(netcards_dict);
-
-  printf("Host number: %zu, link number: %d, elmts number: %d\n", sg_host_count(), sg_link_count(), size);
+  printf("Host count: %zu, link number: %d\n", sg_host_count(), sg_link_count());
 
   int it;
   sg_host_t host;
@@ -28,6 +26,7 @@ int main(int argc, char **argv)
   }
   xbt_dynar_free(&hosts);
 
+  printf("NetCards count: %d\n", xbt_dict_length(netcards_dict));
   xbt_lib_cursor_t cursor = nullptr;
   char* key;
   void *ignored;
index 646da91..2fabad2 100644 (file)
@@ -1,8 +1,8 @@
 #! ./tesh
-! output sort
+
 $ ${bindir:=.}/is-router ../platforms/test_of_is_router.xml "--log=root.fmt:[%10.6r]%e[%i:%P@%h]%e%m%n"
 > [  0.000000] [0:maestro@] Switching to the L07 model to handle parallel tasks.
-> Host number: 10, link number: 1, elmts number: 21
+> Host count: 10, link number: 1
 >    - Seen: "host01". Type: host
 >    - Seen: "host02". Type: host
 >    - Seen: "host03". Type: host
@@ -13,11 +13,22 @@ $ ${bindir:=.}/is-router ../platforms/test_of_is_router.xml "--log=root.fmt:[%10
 >    - Seen: "host08". Type: host
 >    - Seen: "host09". Type: host
 >    - Seen: "host10". Type: host
+> NetCards count: 21
+>    - Seen: "host01". Type: host
+>    - Seen: "host02". Type: host
+>    - Seen: "host03". Type: host
+>    - Seen: "host04". Type: host
+>    - Seen: "host05". Type: host
+>    - Seen: "host06". Type: host
+>    - Seen: "host07". Type: host
+>    - Seen: "host08". Type: host
+>    - Seen: "host09". Type: host
 >    - Seen: "router1". Type: router
 >    - Seen: "router2". Type: router
 >    - Seen: "router3". Type: router
 >    - Seen: "router4". Type: router
 >    - Seen: "router5". Type: router
+>    - Seen: "host10". Type: host
 >    - Seen: "AS0". Type: netzone
 >    - Seen: "AS1". Type: netzone
 >    - Seen: "AS2". Type: netzone