From: Martin Quinson Date: Sun, 18 Dec 2016 15:14:36 +0000 (+0100) Subject: Move all netcards into the dict, and the dict to the engine X-Git-Tag: v3_14~40 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/0db7c964785a7e463746904785e2c9b7c7fd7963 Move all netcards into the dict, and the dict to the engine --- diff --git a/examples/java/app/masterworker/app_masterworker.tesh b/examples/java/app/masterworker/app_masterworker.tesh index 8b571e05e2..e2fcf87955 100644 --- a/examples/java/app/masterworker/app_masterworker.tesh +++ b/examples/java/app/masterworker/app_masterworker.tesh @@ -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... diff --git a/src/kernel/EngineImpl.cpp b/src/kernel/EngineImpl.cpp index 486b97b1a0..175a18aa7a 100644 --- a/src/kernel/EngineImpl.cpp +++ b/src/kernel/EngineImpl.cpp @@ -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 +xbt_dict_t netcards_dict; + namespace simgrid { namespace kernel { EngineImpl::EngineImpl() { + netcards_dict = xbt_dict_new_homogeneous([](void* p) { + delete static_cast(p); + }); } EngineImpl::~EngineImpl() { delete netRoot_; + xbt_dict_free(&netcards_dict); } } } diff --git a/src/kernel/routing/NetCard.cpp b/src/kernel/routing/NetCard.cpp index 799983e564..e45e174b41 100644 --- a/src/kernel/routing/NetCard.cpp +++ b/src/kernel/routing/NetCard.cpp @@ -16,6 +16,15 @@ namespace kernel { namespace routing { simgrid::xbt::signal 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(this), nullptr); + simgrid::kernel::routing::NetCard::onCreation(this); +} } } } // namespace simgrid::kernel::routing @@ -26,6 +35,5 @@ simgrid::xbt::signal 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); } diff --git a/src/kernel/routing/NetCard.hpp b/src/kernel/routing/NetCard.hpp index 3f0318961f..b899b6821a 100644 --- a/src/kernel/routing/NetCard.hpp +++ b/src/kernel/routing/NetCard.hpp @@ -29,13 +29,7 @@ class NetCard : public simgrid::xbt::Extendable { 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. diff --git a/src/kernel/routing/NetZoneImpl.cpp b/src/kernel/routing/NetZoneImpl.cpp index 57619a8094..7a8ecff949 100644 --- a/src/kernel/routing/NetZoneImpl.cpp +++ b/src/kernel/routing/NetZoneImpl.cpp @@ -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(father)); - xbt_dict_set(netcards_dict, name, static_cast(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* speedPerPstate, int coreAmount) diff --git a/src/s4u/s4u_host.cpp b/src/s4u/s4u_host.cpp index 77057f2a85..1499c26d5f 100644 --- a/src/s4u/s4u_host.cpp +++ b/src/s4u/s4u_host.cpp @@ -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; } diff --git a/src/surf/sg_platf.cpp b/src/surf/sg_platf.cpp index 9c95b66c10..4e7b0e74bc 100644 --- a/src/surf/sg_platf.cpp +++ b/src/surf/sg_platf.cpp @@ -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(current_routing); if(cluster != nullptr) - cluster->router_ = static_cast(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); diff --git a/src/surf/surf_interface.cpp b/src/surf/surf_interface.cpp index 1171e7aa72..3f44e4fe9e 100644 --- a/src/surf/surf_interface.cpp +++ b/src/surf/surf_interface.cpp @@ -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(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); diff --git a/src/surf/surf_routing.cpp b/src/surf/surf_routing.cpp index ef30cf2d60..1bf0d25ee7 100644 --- a/src/surf/surf_routing.cpp +++ b/src/surf/surf_routing.cpp @@ -5,4 +5,3 @@ #include "xbt/dict.h" -xbt_dict_t netcards_dict; diff --git a/teshsuite/simdag/is-router/is-router.cpp b/teshsuite/simdag/is-router/is-router.cpp index ffef43b7de..b201d7050c 100644 --- a/teshsuite/simdag/is-router/is-router.cpp +++ b/teshsuite/simdag/is-router/is-router.cpp @@ -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; diff --git a/teshsuite/simdag/is-router/is-router.tesh b/teshsuite/simdag/is-router/is-router.tesh index 646da91e02..2fabad2417 100644 --- a/teshsuite/simdag/is-router/is-router.tesh +++ b/teshsuite/simdag/is-router/is-router.tesh @@ -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