From: Frederic Suter Date: Wed, 28 Feb 2018 16:07:11 +0000 (+0100) Subject: make the getNetzoneByType usable and tested X-Git-Tag: v3.19~176 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/062c59e9c03ee7551aa47606fd34c79cba706856 make the getNetzoneByType usable and tested --- diff --git a/examples/s4u/CMakeLists.txt b/examples/s4u/CMakeLists.txt index 29d75ac84e..8782111271 100644 --- a/examples/s4u/CMakeLists.txt +++ b/examples/s4u/CMakeLists.txt @@ -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 index 0000000000..a796716d71 --- /dev/null +++ b/examples/s4u/routing-get-clusters/s4u-routing-get-clusters.cpp @@ -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* clusters = + new std::vector; + + e.getNetzoneByType(clusters); + + for (auto c : *clusters) { + XBT_INFO("%s", c->getCname()); + std::vector* hosts = new std::vector; + 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 index 0000000000..6d65ec6a08 --- /dev/null +++ b/examples/s4u/routing-get-clusters/s4u-routing-get-clusters.tesh @@ -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 diff --git a/include/simgrid/s4u/Engine.hpp b/include/simgrid/s4u/Engine.hpp index c9d2318b07..c76d22ea27 100644 --- a/include/simgrid/s4u/Engine.hpp +++ b/include/simgrid/s4u/Engine.hpp @@ -15,6 +15,7 @@ #include +#include #include 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 void getNetzoneByType(std::vector * whereto); - + template void getNetzoneByType(std::vector * 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 * list); @@ -140,6 +140,15 @@ extern XBT_PUBLIC(xbt::signal) onTimeAdvance; /** Callback fired when the time cannot jump because of inter-actors deadlock */ extern XBT_PUBLIC(xbt::signal) onDeadlock; + +template XBT_PRIVATE void netzoneByTypeRecursive(s4u::NetZone* current, std::vector* whereto) +{ + for (auto const& elem : *(current->getChildren())) { + netzoneByTypeRecursive(elem, whereto); + if (elem == dynamic_cast(elem)) + whereto->push_back(dynamic_cast(elem)); + } +} } } // namespace simgrid::s4u diff --git a/src/kernel/routing/ClusterZone.hpp b/src/kernel/routing/ClusterZone.hpp index bb1eb033b5..a9a786603d 100644 --- a/src/kernel/routing/ClusterZone.hpp +++ b/src/kernel/routing/ClusterZone.hpp @@ -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); diff --git a/src/s4u/s4u_engine.cpp b/src/s4u/s4u_engine.cpp index 9913599593..0dea4cb784 100644 --- a/src/s4u/s4u_engine.cpp +++ b/src/s4u/s4u_engine.cpp @@ -30,7 +30,6 @@ xbt::signal 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 void netzoneByTypeRecursive(s4u::NetZone* current, std::vector* whereto) -{ - for (auto const& elem : *(current->getChildren())) { - netzoneByTypeRecursive(elem, whereto); - if (elem == dynamic_cast(elem)) - whereto->push_back(elem); - } -} - -/** @brief Retrieve all existing NetZones of the subtype of the whereto vector */ -template void Engine::getNetzoneByType(std::vector* 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) {