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_free(hosts);
e.loadDeployment(argv[2]);
e.run();
* 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"
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) {
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;
}
- xbt_free(workstations);
} else {
XBT_WARN("The scheduling is ignored");
for (auto const& elm : computers)
*/
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)
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
- 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;
}
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 *************************** */
}
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);
- xbt_free(hosts);
e.run();
XBT_INFO("Simulation time %g", e.getClock());