Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
New: Engine::hostList() and Engine::hostCount(). Still clumsy.
authorMartin Quinson <martin.quinson@loria.fr>
Tue, 14 Mar 2017 08:59:57 +0000 (09:59 +0100)
committerMartin Quinson <martin.quinson@loria.fr>
Wed, 15 Mar 2017 15:09:54 +0000 (16:09 +0100)
- the underlaying data is not part of Engine
- ranged for loops are still difficult to write

ChangeLog
examples/s4u/app-token-ring/s4u_app-token-ring.cpp
include/simgrid/s4u/engine.hpp
src/s4u/s4u_engine.cpp
src/s4u/s4u_host.cpp
src/simgrid/host.cpp

index d7bfa97..5deb010 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -32,6 +32,7 @@ SimGrid (3.15) UNRELEASED; urgency=low
    - s4u::Host::onSpeedChange: when the pstate is changed, or when an
      event from the availability_file changes the avail speed.
  - Links are now usable from s4u
+ - New: Engine::hostList() and Engine::hostCount(). Still clumsy.
  - Drop Host::getPstateSpeedCurrent() which dupplicates Host::speed()
 
  SimDag
index 303529b..266b60c 100644 (file)
@@ -11,8 +11,6 @@
 #include <vector>
 
 XBT_LOG_NEW_DEFAULT_CATEGORY(s4u_app_token_ring, "Messages specific for this s4u example");
-// FIXME: The following duplicates the content of s4u::Host
-extern std::map<std::string, simgrid::s4u::Host*> host_list;
 
 class RelayRunner {
   size_t task_comm_size = 1000000; /* The token is 1MB long*/
@@ -28,7 +26,7 @@ public:
     rank = xbt_str_parse_int(simgrid::s4u::this_actor::name().c_str(),
                              "Any process of this example must have a numerical name, not %s");
     my_mailbox = simgrid::s4u::Mailbox::byName(std::to_string(rank));
-    if (rank + 1 == host_list.size())
+    if (rank + 1 == simgrid::s4u::Engine::instance()->hostCount())
       /* The last process, which sends the token back to rank 0 */
       neighbor_mailbox = simgrid::s4u::Mailbox::byName("0");
     else
@@ -57,10 +55,11 @@ int main(int argc, char** argv)
   xbt_assert(argc > 1, "Usage: %s platform.xml\n", argv[0]);
   e->loadPlatform(argv[1]);
 
-  XBT_INFO("Number of hosts '%zu'", host_list.size());
+  XBT_INFO("Number of hosts '%zu'", e->hostCount());
   int id = 0;
-  for (auto h : host_list) {
-    simgrid::s4u::Host* host = h.second;
+  std::vector<simgrid::s4u::Host*> list;
+  e->hostList(&list);
+  for (auto host : list) {
     /* - Give a unique rank to each host and create a @ref relay_runner process on each */
     simgrid::s4u::Actor::createActor((std::to_string(id)).c_str(), host, RelayRunner());
     id++;
index 413f7ef..9a1a5d9 100644 (file)
@@ -57,6 +57,9 @@ public:
   /** @brief Load a deployment file and launch the actors that it contains */
   void loadDeployment(const char *deploy);
 
+  unsigned int hostCount();
+  void hostList(std::vector<Host*>*);
+
   /** @brief Run the simulation */
   void run();
 
index bcb1820..0434602 100644 (file)
@@ -78,6 +78,19 @@ void Engine::loadDeployment(const char *deploy)
 {
   SIMIX_launch_application(deploy);
 }
+// FIXME: The following duplicates the content of s4u::Host
+extern std::map<std::string, simgrid::s4u::Host*> host_list;
+/** @brief Returns the amount of hosts in the platform */
+unsigned int Engine::hostCount()
+{
+  return host_list.size();
+}
+/** @brief Fills the passed list with all hosts found in the platform */
+void Engine::hostList(std::vector<Host*>* list)
+{
+  for (auto kv : host_list)
+    list->push_back(kv.second);
+}
 
 void Engine::run() {
   if (MC_is_active()) {
index e3c3635..4d74e35 100644 (file)
@@ -23,8 +23,6 @@
 
 XBT_LOG_EXTERNAL_CATEGORY(surf_route);
 
-std::map<std::string, simgrid::s4u::Host*> host_list; // FIXME: move it to Engine
-
 int USER_HOST_LEVEL = -1;
 
 namespace simgrid {
@@ -35,6 +33,8 @@ template class Extendable<simgrid::s4u::Host>;
 
 namespace s4u {
 
+std::map<std::string, simgrid::s4u::Host*> host_list; // FIXME: move it to Engine
+
 simgrid::xbt::signal<void(Host&)> Host::onCreation;
 simgrid::xbt::signal<void(Host&)> Host::onDestruction;
 simgrid::xbt::signal<void(Host&)> Host::onStateChange;
index 21f311f..5bf6743 100644 (file)
 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(sg_host, sd, "Logging specific to sg_hosts");
 
 // FIXME: The following duplicates the content of s4u::Host
+namespace simgrid {
+namespace s4u {
 extern std::map<std::string, simgrid::s4u::Host*> host_list;
+}
+}
 
 extern "C" {
 
@@ -33,20 +37,20 @@ void sg_host_exit()
    * the tests.
    */
   std::vector<std::string> names = std::vector<std::string>();
-  for (auto kv : host_list)
+  for (auto kv : simgrid::s4u::host_list)
     names.push_back(kv.second->name());
 
   std::sort(names.begin(), names.end());
 
   for (auto name : names)
-    host_list.at(name)->destroy();
+    simgrid::s4u::host_list.at(name)->destroy();
 
   // host_list.clear(); This would be sufficient if the dict would contain smart_ptr. It's now useless
 }
 
 size_t sg_host_count()
 {
-  return host_list.size();
+  return simgrid::s4u::host_list.size();
 }
 /** @brief Returns the host list
  *
@@ -93,7 +97,7 @@ xbt_dynar_t sg_hosts_as_dynar()
 {
   xbt_dynar_t res = xbt_dynar_new(sizeof(sg_host_t),nullptr);
 
-  for (auto kv : host_list) {
+  for (auto kv : simgrid::s4u::host_list) {
     simgrid::s4u::Host* host = kv.second;
     if (host && host->pimpl_netpoint && host->pimpl_netpoint->isHost())
       xbt_dynar_push(res, &host);