X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/827f345d26da926941909a521752839e21e9a44e..3f9587e71330e7471ef675d2652cee260a0e3a96:/src/simgrid/host.cpp diff --git a/src/simgrid/host.cpp b/src/simgrid/host.cpp index bcd1e7683e..9808aa6f69 100644 --- a/src/simgrid/host.cpp +++ b/src/simgrid/host.cpp @@ -4,22 +4,40 @@ /* 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 + #include "xbt/dict.h" #include "simgrid/host.h" #include #include +#include "src/kernel/routing/NetPoint.hpp" #include "src/surf/HostImpl.hpp" -#include "surf/surf.h" // routing_get_network_element_type FIXME:killme XBT_LOG_NEW_DEFAULT_SUBCATEGORY(sg_host, sd, "Logging specific to sg_hosts"); -extern std::unordered_map - host_list; // FIXME: don't dupplicate the content of s4u::Host this way +extern std::unordered_map + host_list; // FIXME: don't duplicate the content of s4u::Host this way void sg_host_exit() { - host_list.clear(); + /* copy all names to not modify the map while iterating over it. + * + * Plus, the hosts are destroyed in the lexicographic order to ensure + * that the output is reproducible: we don't want to kill them in the + * pointer order as it could be platform-dependent, which would break + * the tests. + */ + std::vector names = std::vector(); + for (auto kv : host_list) + names.push_back(kv.second->name()); + + std::sort(names.begin(), names.end()); + + for (auto name : names) + 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() @@ -43,7 +61,7 @@ sg_host_t *sg_host_list() { const char *sg_host_get_name(sg_host_t host) { - return host->name().c_str(); + return host->cname(); } void* sg_host_extension_get(sg_host_t host, size_t ext) @@ -63,8 +81,8 @@ sg_host_t sg_host_by_name(const char *name) static int hostcmp_voidp(const void* pa, const void* pb) { - return strcmp((*static_cast(pa))->name().c_str(), - (*static_cast(pb))->name().c_str()); + return strcmp((*static_cast(pa))->cname(), + (*static_cast(pb))->cname()); } xbt_dynar_t sg_hosts_as_dynar() @@ -73,8 +91,8 @@ xbt_dynar_t sg_hosts_as_dynar() for (auto kv : host_list) { simgrid::s4u::Host* host = kv.second; - if (host && host->pimpl_netcard && host->pimpl_netcard->isHost()) - xbt_dynar_push(res, &host); + if (host && host->pimpl_netpoint && host->pimpl_netpoint->isHost()) + xbt_dynar_push(res, &host); } xbt_dynar_sort(res, hostcmp_voidp); return res; @@ -83,7 +101,6 @@ xbt_dynar_t sg_hosts_as_dynar() // ========= Layering madness ==============* #include "src/surf/cpu_interface.hpp" -#include "src/surf/surf_routing.hpp" // ========== User data Layer ========== void *sg_host_user(sg_host_t host) { @@ -180,10 +197,10 @@ void sg_host_dump(sg_host_t host) xbt_dict_cursor_t cursor=nullptr; char *key,*data; - XBT_INFO("Displaying host %s", sg_host_get_name(host)); + XBT_INFO("Displaying host %s", host->cname()); XBT_INFO(" - speed: %.0f", host->speed()); XBT_INFO(" - available speed: %.2f", sg_host_get_available_speed(host)); - props = sg_host_get_properties(host); + props = host->properties(); if (!xbt_dict_is_empty(props)){ XBT_INFO(" - properties:");