Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
stop using sg_host_list() from C++, and improve its implementation
authorMartin Quinson <martin.quinson@loria.fr>
Fri, 9 Mar 2018 14:37:11 +0000 (15:37 +0100)
committerMartin Quinson <martin.quinson@loria.fr>
Fri, 9 Mar 2018 14:37:11 +0000 (15:37 +0100)
examples/s4u/platform-properties/s4u-platform-properties.cpp
src/simdag/sd_dotloader.cpp
src/simgrid/host.cpp
src/surf/plugins/host_energy.cpp
teshsuite/s4u/comm-pt2pt/comm-pt2pt.cpp

index 307a941..dabffc1 100644 (file)
@@ -106,10 +106,10 @@ int main(int argc, char* argv[])
   size_t totalHosts = sg_host_count();
 
   XBT_INFO("There are %zu hosts in the environment", totalHosts);
   size_t totalHosts = sg_host_count();
 
   XBT_INFO("There are %zu hosts in the environment", totalHosts);
-  simgrid::s4u::Host** hosts = sg_host_list();
-  for (unsigned int i = 0; i < totalHosts; i++)
+  std::vector<simgrid::s4u::Host*> hosts;
+  e.getHostList(&hosts);
+  for (unsigned int i = 0; i < hosts.size(); i++)
     XBT_INFO("Host '%s' runs at %.0f flops/s", hosts[i]->getCname(), hosts[i]->getSpeed());
     XBT_INFO("Host '%s' runs at %.0f flops/s", hosts[i]->getCname(), hosts[i]->getSpeed());
-  xbt_free(hosts);
 
   e.loadDeployment(argv[2]);
   e.run();
 
   e.loadDeployment(argv[2]);
   e.run();
index ee34cab..4979a2e 100644 (file)
@@ -5,6 +5,7 @@
  * under the terms of the license (GNU LGPL) which comes with this package. */
 
 #include "simdag_private.hpp"
  * under the terms of the license (GNU LGPL) which comes with this package. */
 
 #include "simdag_private.hpp"
+#include "simgrid/s4u/Engine.hpp"
 #include "simgrid/simdag.h"
 #include "src/internal_config.h"
 #include "xbt/file.hpp"
 #include "simgrid/simdag.h"
 #include "src/internal_config.h"
 #include "xbt/file.hpp"
@@ -212,7 +213,9 @@ xbt_dynar_t SD_dotload_generic(const char* filename, bool sequential, bool sched
 
   if(schedule){
     if (schedule_success) {
 
   if(schedule){
     if (schedule_success) {
-      sg_host_t* workstations = sg_host_list();
+      std::vector<simgrid::s4u::Host*> hosts;
+      simgrid::s4u::Engine::getInstance()->getHostList(&hosts);
+
       for (auto const& elm : computers) {
         SD_task_t previous_task = nullptr;
         for (auto const& task : *elm.second) {
       for (auto const& elm : computers) {
         SD_task_t previous_task = nullptr;
         for (auto const& task : *elm.second) {
@@ -221,13 +224,12 @@ xbt_dynar_t SD_dotload_generic(const char* filename, bool sequential, bool sched
             if (previous_task && not SD_task_dependency_exists(previous_task, task))
               SD_task_dependency_add(previous_task, task);
 
             if (previous_task && not SD_task_dependency_exists(previous_task, task))
               SD_task_dependency_add(previous_task, task);
 
-            SD_task_schedulel(task, 1, workstations[atoi(elm.first.c_str())]);
+            SD_task_schedulel(task, 1, hosts[atoi(elm.first.c_str())]);
             previous_task = task;
           }
         }
         delete elm.second;
       }
             previous_task = task;
           }
         }
         delete elm.second;
       }
-      xbt_free(workstations);
     } else {
       XBT_WARN("The scheduling is ignored");
       for (auto const& elm : computers)
     } else {
       XBT_WARN("The scheduling is ignored");
       for (auto const& elm : computers)
index 3c9fe63..e49a988 100644 (file)
@@ -37,8 +37,13 @@ size_t sg_host_count()
  */
 sg_host_t *sg_host_list() {
   xbt_assert(sg_host_count() > 0, "There is no host!");
  */
 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::getInstance()->getHostList(&hosts);
 
 
-  return (sg_host_t*)xbt_dynar_to_array(sg_hosts_as_dynar());
+  sg_host_t* res = (sg_host_t*)malloc(sizeof(sg_host_t) * hosts.size());
+  memcpy(res, hosts.data(), sizeof(sg_host_t) * hosts.size());
+
+  return res;
 }
 
 const char *sg_host_get_name(sg_host_t host)
 }
 
 const char *sg_host_get_name(sg_host_t host)
index 171f6b7..8826efc 100644 (file)
@@ -432,15 +432,16 @@ static void onHostDestruction(simgrid::s4u::Host& host)
 
 static void onSimulationEnd()
 {
 
 static void onSimulationEnd()
 {
-  sg_host_t* host_list     = sg_host_list();
-  int host_count           = sg_host_count();
+  std::vector<simgrid::s4u::Host*> hosts;
+  simgrid::s4u::Engine::getInstance()->getHostList(&hosts);
+
   double total_energy      = 0.0; // Total energy consumption (whole platform)
   double used_hosts_energy = 0.0; // Energy consumed by hosts that computed something
   double total_energy      = 0.0; // Total energy consumption (whole platform)
   double used_hosts_energy = 0.0; // Energy consumed by hosts that computed something
-  for (int i = 0; i < host_count; i++) {
-    if (dynamic_cast<simgrid::s4u::VirtualMachine*>(host_list[i]) == nullptr) { // Ignore virtual machines
+  for (size_t i = 0; i < hosts.size(); i++) {
+    if (dynamic_cast<simgrid::s4u::VirtualMachine*>(hosts[i]) == nullptr) { // Ignore virtual machines
 
 
-      bool host_was_used = (sg_host_get_computed_flops(host_list[i]) != 0);
-      double energy      = host_list[i]->extension<HostEnergy>()->getConsumedEnergy();
+      bool host_was_used = (sg_host_get_computed_flops(hosts[i]) != 0);
+      double energy      = hosts[i]->extension<HostEnergy>()->getConsumedEnergy();
       total_energy      += energy;
       if (host_was_used)
         used_hosts_energy += energy;
       total_energy      += energy;
       if (host_was_used)
         used_hosts_energy += energy;
@@ -448,7 +449,6 @@ static void onSimulationEnd()
   }
   XBT_INFO("Total energy consumption: %f Joules (used hosts: %f Joules; unused/idle hosts: %f)",
            total_energy, used_hosts_energy, total_energy - used_hosts_energy);
   }
   XBT_INFO("Total energy consumption: %f Joules (used hosts: %f Joules; unused/idle hosts: %f)",
            total_energy, used_hosts_energy, total_energy - used_hosts_energy);
-  xbt_free(host_list);
 }
 
 /* **************************** Public interface *************************** */
 }
 
 /* **************************** Public interface *************************** */
index 41be1f3..c82af7b 100644 (file)
@@ -182,10 +182,11 @@ int main(int argc, char* argv[])
   }
   xbt_assert(argSend.front().size() == argRecv.front().size(), "Sender and receiver spec must be of the same size");
 
   }
   xbt_assert(argSend.front().size() == argRecv.front().size(), "Sender and receiver spec must be of the same size");
 
-  simgrid::s4u::Host** hosts = sg_host_list();
+  std::vector<simgrid::s4u::Host*> hosts;
+  e.getHostList(&hosts);
+
   simgrid::s4u::Actor::createActor("sender", hosts[0], sender, argSend);
   simgrid::s4u::Actor::createActor("recver", hosts[1], receiver, argRecv);
   simgrid::s4u::Actor::createActor("sender", hosts[0], sender, argSend);
   simgrid::s4u::Actor::createActor("recver", hosts[1], receiver, argRecv);
-  xbt_free(hosts);
 
   e.run();
   XBT_INFO("Simulation time %g", e.getClock());
 
   e.run();
   XBT_INFO("Simulation time %g", e.getClock());