Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
simgrid_get_all_hosts was redundant with existing sg_host_list
authorFrederic Suter <frederic.suter@cc.in2p3.fr>
Sun, 9 Feb 2020 14:07:52 +0000 (15:07 +0100)
committerFrederic Suter <frederic.suter@cc.in2p3.fr>
Sun, 9 Feb 2020 14:07:52 +0000 (15:07 +0100)
examples/c/app-token-ring/app-token-ring.c
examples/c/io-disk-raw/io-disk-raw.c
include/simgrid/engine.h
src/s4u/s4u_Engine.cpp
src/s4u/s4u_Host.cpp

index 2c5d41e..275b4dc 100644 (file)
@@ -57,9 +57,8 @@ int main(int argc, char* argv[])
   xbt_assert(argc > 1, "Usage: %s platform.xml\n", argv[0]);
   simgrid_load_platform(argv[1]); /* - Load the platform description */
 
-  size_t host_count;
-  sg_host_t* hosts;
-  simgrid_get_all_hosts(&host_count, &hosts);
+  size_t host_count = sg_host_count();
+  sg_host_t* hosts  = sg_host_list();
 
   XBT_INFO("Number of hosts '%zu'", host_count);
   for (size_t i = 0; i < host_count; i++) {
index 4349974..0c3c48b 100644 (file)
@@ -63,9 +63,8 @@ int main(int argc, char* argv[])
 
   simgrid_register_function("host", host);
 
-  size_t host_count;
-  sg_host_t* hosts;
-  simgrid_get_all_hosts(&host_count, &hosts);
+  size_t host_count = sg_host_count();
+  sg_host_t* hosts  = sg_host_list();
 
   for (long i = 0; i < host_count; i++) {
     XBT_INFO("*** %s properties ****", sg_host_get_name(hosts[i]));
index 87d337a..30be8af 100644 (file)
@@ -51,8 +51,6 @@ XBT_PUBLIC int simgrid_get_actor_count();
  */
 XBT_PUBLIC void sg_config_continue_after_help();
 
-XBT_PUBLIC void simgrid_get_all_hosts(size_t* host_count, sg_host_t** hosts);
-
 SG_END_DECL
 
 #endif /* INCLUDE_SIMGRID_ENGINE_H_ */
index 65ef3a1..3d52d6a 100644 (file)
@@ -439,20 +439,3 @@ int simgrid_get_actor_count()
 {
   return simgrid::s4u::Engine::get_instance()->get_actor_count();
 }
-
-void simgrid_get_all_hosts(size_t* host_count, sg_host_t** hosts)
-{
-  simgrid::s4u::Engine* e               = simgrid::s4u::Engine::get_instance();
-  *host_count                           = e->get_host_count();
-  std::vector<simgrid::s4u::Host*> list = e->get_all_hosts();
-
-  auto last = std::remove_if(begin(list), end(list), [](const simgrid::s4u::Host* host) {
-    return not host || not host->get_netpoint() || not host->get_netpoint()->is_host();
-  });
-  std::sort(begin(list), last,
-            [](const simgrid::s4u::Host* a, const simgrid::s4u::Host* b) { return a->get_name() < b->get_name(); });
-
-  *hosts = static_cast<sg_host_t*>(xbt_malloc(sizeof(sg_host_t) * (*host_count)));
-  for (size_t i = 0; i < *host_count; i++)
-    (*hosts)[i] = list[i];
-}
index 2e250b9..b52da40 100644 (file)
@@ -313,8 +313,16 @@ size_t sg_host_count()
 }
 sg_host_t* sg_host_list()
 {
-  xbt_assert(sg_host_count() > 0, "There is no host!");
-  std::vector<simgrid::s4u::Host*> hosts = simgrid::s4u::Engine::get_instance()->get_all_hosts();
+  simgrid::s4u::Engine* e = simgrid::s4u::Engine::get_instance();
+  size_t host_count       = e->get_host_count();
+  xbt_assert(host_count > 0, "There is no host!");
+  std::vector<simgrid::s4u::Host*> hosts = e->get_all_hosts();
+
+  auto last = std::remove_if(begin(hosts), end(hosts), [](const simgrid::s4u::Host* host) {
+    return not host || not host->get_netpoint() || not host->get_netpoint()->is_host();
+  });
+  std::sort(begin(hosts), last,
+            [](const simgrid::s4u::Host* a, const simgrid::s4u::Host* b) { return a->get_name() < b->get_name(); });
 
   sg_host_t* res = xbt_new(sg_host_t, hosts.size());
   memcpy(res, hosts.data(), sizeof(sg_host_t) * hosts.size());