SG_BEGIN_DECL()
-XBT_PUBLIC(void) sg_host_exit();
-
XBT_PUBLIC(size_t) sg_host_count();
XBT_PUBLIC(sg_host_t *) sg_host_list();
/** @brief Load a deployment file and launch the actors that it contains */
void loadDeployment(const char* deploy);
+protected:
+ friend s4u::Host;
+ void addHost(std::string name, simgrid::s4u::Host * host);
+ void delHost(std::string name);
+
+public:
+ simgrid::s4u::Host* hostByName(std::string name);
+ simgrid::s4u::Host* hostByNameOrNull(std::string name);
size_t getHostCount();
void getHostList(std::vector<Host*> * whereTo);
size_t getLinkCount();
#include "src/kernel/routing/NetPoint.hpp"
#include "src/kernel/routing/NetZoneImpl.hpp"
+#include <algorithm>
+
namespace simgrid {
namespace kernel {
EngineImpl::EngineImpl() = default;
EngineImpl::~EngineImpl()
{
- sg_host_exit(); // Hosts should be part of the engine, at some point
+ /* 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<std::string> names;
+ for (auto const& kv : hosts_)
+ names.push_back(kv.second->getName());
+
+ std::sort(names.begin(), names.end());
+
+ for (auto const& name : names)
+ hosts_.at(name)->destroy();
+
+ /* Also delete the other data */
delete netRoot_;
for (auto const& kv : netpoints_)
delete kv.second;
/* 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 <map>
#include <simgrid/s4u/NetZone.hpp>
#include <simgrid/s4u/forward.hpp>
#include <string>
kernel::routing::NetZoneImpl* netRoot_ = nullptr;
private:
+ std::map<std::string, simgrid::s4u::Host*> hosts_;
std::unordered_map<std::string, simgrid::kernel::routing::NetPoint*> netpoints_;
friend simgrid::s4u::Engine;
};
{
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 */
size_t Engine::getHostCount()
{
- return host_list.size();
+ return pimpl->hosts_.size();
}
/** @brief Fills the passed list with all hosts found in the platform */
void Engine::getHostList(std::vector<Host*>* list)
{
- for (auto const& kv : host_list)
+ for (auto const& kv : pimpl->hosts_)
list->push_back(kv.second);
}
+void Engine::addHost(std::string name, simgrid::s4u::Host* host)
+{
+ pimpl->hosts_[name] = host;
+}
+void Engine::delHost(std::string name)
+{
+ pimpl->hosts_.erase(name);
+}
+simgrid::s4u::Host* Engine::hostByName(std::string name)
+{
+ return pimpl->hosts_.at(name); // Will raise a std::out_of_range if the host does not exist
+}
+simgrid::s4u::Host* Engine::hostByNameOrNull(std::string name)
+{
+ auto host = pimpl->hosts_.find(name);
+ return host == pimpl->hosts_.end() ? nullptr : host->second;
+}
+
/** @brief Returns the amount of links in the platform */
size_t Engine::getLinkCount()
{
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;
: name_(name)
{
xbt_assert(Host::by_name_or_null(name) == nullptr, "Refusing to create a second host named '%s'.", name);
- host_list[name_] = this;
+ Engine::getInstance()->addHost(std::string(name_), this);
new simgrid::surf::HostImpl(this);
}
if (not currentlyDestroying_) {
currentlyDestroying_ = true;
onDestruction(*this);
- host_list.erase(name_);
+ Engine::getInstance()->delHost(std::string(name_));
delete this;
}
}
Host* Host::by_name(std::string name)
{
- return host_list.at(name); // Will raise a std::out_of_range if the host does not exist
+ return Engine::getInstance()->hostByName(name);
}
Host* Host::by_name(const char* name)
{
- return host_list.at(std::string(name)); // Will raise a std::out_of_range if the host does not exist
+ return Engine::getInstance()->hostByName(std::string(name));
}
Host* Host::by_name_or_null(const char* name)
{
- return by_name_or_null(std::string(name));
+ return Engine::getInstance()->hostByNameOrNull(std::string(name));
}
Host* Host::by_name_or_null(std::string name)
{
- auto host = host_list.find(name);
- return host == host_list.end() ? nullptr : host->second;
+ return Engine::getInstance()->hostByNameOrNull(name);
}
Host *Host::current(){
#include <vector>
#include "simgrid/host.h"
+#include "simgrid/s4u/Engine.hpp"
#include "simgrid/s4u/Host.hpp"
#include "xbt/Extendable.hpp"
#include "xbt/dict.h"
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" {
-void sg_host_exit()
-{
- /* 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<std::string> names = std::vector<std::string>();
- for (auto const& kv : simgrid::s4u::host_list)
- names.push_back(kv.second->getName());
-
- std::sort(names.begin(), names.end());
-
- for (auto const& name : names)
- 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 simgrid::s4u::host_list.size();
+ return simgrid::s4u::Engine::getInstance()->getHostCount();
}
/** @brief Returns the host list
*
*/
sg_host_t *sg_host_list() {
xbt_assert(sg_host_count() > 0, "There is no host!");
+
return (sg_host_t*)xbt_dynar_to_array(sg_hosts_as_dynar());
}
{
xbt_dynar_t res = xbt_dynar_new(sizeof(sg_host_t),nullptr);
- for (auto const& kv : simgrid::s4u::host_list) {
- simgrid::s4u::Host* host = kv.second;
+ std::vector<simgrid::s4u::Host*> list;
+ simgrid::s4u::Engine::getInstance()->getHostList(&list);
+
+ for (auto const& host : list) {
if (host && host->pimpl_netpoint && host->pimpl_netpoint->isHost())
xbt_dynar_push(res, &host);
}
#include "SmpiHost.hpp"
#include "private.hpp"
#include "simgrid/msg.h" /* barrier */
+#include "simgrid/s4u/Engine.hpp"
#include "smpi_comm.hpp"
#include <map>
};
}
}
-namespace s4u {
-extern std::map<std::string, simgrid::s4u::Host*> host_list;
-}
}
using simgrid::smpi::app::Instance;
static int already_called = 0;
if (not already_called) {
already_called = 1;
- for (auto const& item : simgrid::s4u::host_list) {
- simgrid::s4u::Host* host = item.second;
+ std::vector<simgrid::s4u::Host*> list;
+ simgrid::s4u::Engine::getInstance()->getHostList(&list);
+ for (auto const& host : list) {
host->extension_set(new simgrid::smpi::SmpiHost(host));
}
}
}
}
-// FIXME: The following duplicates the content of s4u::Host
-namespace simgrid {
-namespace s4u {
-extern std::map<std::string, simgrid::s4u::Host*> host_list;
-}
-}
-
static int surf_parse_models_setup_already_called = 0;
std::map<std::string, simgrid::surf::StorageType*> storage_types;
// The requested host does not exist. Do a nice message to the user
std::string msg = std::string("Cannot create process '") + process->function + "': host '" + process->host +
"' does not exist\nExisting hosts: '";
- for (auto const& kv : simgrid::s4u::host_list) {
- simgrid::s4u::Host* host = kv.second;
+
+ std::vector<simgrid::s4u::Host*> list;
+ simgrid::s4u::Engine::getInstance()->getHostList(&list);
+
+ for (auto const& host : list) {
msg += host->getName();
msg += "', '";
if (msg.length() > 1024) {
{
TRACE_end(); /* Just in case it was not called by the upper layer (or there is no upper layer) */
- sg_host_exit();
sg_link_exit();
for (auto const& e : storage_types) {
simgrid::surf::StorageType* stype = e.second;