// TODO: also test the properties attached to links
+#include <algorithm>
#include <simgrid/s4u.hpp>
#include <string>
static void test_host(std::string hostname)
{
simgrid::s4u::Host* thehost = simgrid::s4u::Host::by_name(hostname);
- std::map<std::string, std::string>* props = thehost->getProperties();
+ std::unordered_map<std::string, std::string>* props = thehost->get_properties();
const char* noexist = "Unknown";
const char* exist = "Hdd";
const char* value;
XBT_INFO("== Print the properties of the host '%s'", hostname.c_str());
- for (const auto& kv : *props)
- XBT_INFO(" Host property: '%s' -> '%s'", kv.first.c_str(), kv.second.c_str());
+ // Sort the properties before displaying them, so that the tests are perfectly reproducible
+ std::vector<std::string> keys;
+ for (auto const& kv : *props)
+ keys.push_back(kv.first);
+ std::sort(keys.begin(), keys.end());
+ for (std::string key : keys)
+ XBT_INFO(" Host property: '%s' -> '%s'", key.c_str(), props->at(key).c_str());
XBT_INFO("== Try to get a host property that does not exist");
value = thehost->get_property(noexist);
XBT_INFO(" Zone property: author -> %s", root->get_property("author"));
/* Get the property list of current bob process */
- std::map<std::string, std::string>* props = simgrid::s4u::Actor::self()->get_properties();
+ std::unordered_map<std::string, std::string>* props = simgrid::s4u::Actor::self()->get_properties();
const char* noexist = "UnknownProcessProp";
XBT_ATTRIB_UNUSED const char* value;
#ifdef __cplusplus
XBT_PUBLIC msg_process_t MSG_process_create_from_stdfunc(const char* name, std::function<void()> code, void* data,
msg_host_t host,
- std::map<std::string, std::string>* properties);
+ std::unordered_map<std::string, std::string>* properties);
#endif
#endif
#define SIMGRID_S4U_ACTOR_HPP
#include <functional>
+#include <map> // deprecated wrappers
#include <simgrid/chrono.hpp>
+#include <unordered_map>
#include <xbt/Extendable.hpp>
#include <xbt/functional.hpp>
#include <xbt/signal.hpp>
kernel::actor::ActorImpl* get_impl();
/** Retrieve the property value (or nullptr if not set) */
- std::map<std::string, std::string>* get_properties(); // FIXME: do not export the map, but only the keys or something
+ std::unordered_map<std::string, std::string>*
+ get_properties(); // FIXME: do not export the map, but only the keys or something
const char* get_property(const char* key);
void set_property(const char* key, const char* value);
}
XBT_ATTRIB_DEPRECATED_v323("Please use Actor::get_properties()") std::map<std::string, std::string>* getProperties()
{
- return get_properties();
+ std::map<std::string, std::string>* res = new std::map<std::string, std::string>();
+ std::unordered_map<std::string, std::string>* props = get_properties();
+ for (auto const& kv : *props)
+ res->insert(kv);
+ return res;
}
XBT_ATTRIB_DEPRECATED_v323("Please use Actor::get_properties()") void setProperty(const char* key, const char* value)
{
const char* get_property(const char* key);
void set_property(std::string key, std::string value);
- std::map<std::string, std::string>* getProperties();
+ std::unordered_map<std::string, std::string>* get_properties();
+ XBT_ATTRIB_DEPRECATED_v323("Please use Host::get_properties()") std::map<std::string, std::string>* getProperties()
+ {
+ std::map<std::string, std::string>* res = new std::map<std::string, std::string>();
+ std::unordered_map<std::string, std::string>* props = get_properties();
+ for (auto const& kv : *props)
+ res->insert(kv);
+ return res;
+ }
double getSpeed();
double get_available_speed();
#include <map>
#include <string>
+#include <unordered_map>
namespace simgrid {
namespace xbt {
Host* get_host() { return attached_to_; };
void set_host(Host* host) { attached_to_ = host; }
- std::map<std::string, std::string>* get_properties();
+ std::unordered_map<std::string, std::string>* get_properties();
const char* get_property(std::string key);
void set_property(std::string, std::string value);
XBT_ATTRIB_DEPRECATED_v323("Please use Storage::get_host()") Host* getHost() { return get_host(); }
XBT_ATTRIB_DEPRECATED_v323("Please use Storage::get_properties()") std::map<std::string, std::string>* getProperties()
{
- return get_properties();
+ std::map<std::string, std::string>* res = new std::map<std::string, std::string>();
+ std::unordered_map<std::string, std::string>* props = get_properties();
+ for (auto const& kv : *props)
+ res->insert(kv);
+ return res;
}
XBT_ATTRIB_DEPRECATED_v323("Please use Storage::get_property()") const char* getProperty(const char* key)
{
#include <xbt/parmap.h>
#ifdef __cplusplus
#include <functional>
-#include <map>
+#include <unordered_map>
#endif
/* ******************************** Host ************************************ */
XBT_PUBLIC void SIMIX_maestro_create(void (*code)(void*), void* data);
#ifdef __cplusplus
XBT_PUBLIC smx_actor_t SIMIX_process_attach(const char* name, void* data, const char* hostname,
- std::map<std::string, std::string>* properties, smx_actor_t parent_process);
+ std::unordered_map<std::string, std::string>* properties,
+ smx_actor_t parent_process);
#endif
XBT_PUBLIC void SIMIX_process_detach();
/* Constructor and Destructor */
#ifdef __cplusplus
XBT_PUBLIC smx_actor_t simcall_process_create(const char* name, xbt_main_func_t code, void* data, sg_host_t host,
- int argc, char** argv, std::map<std::string, std::string>* properties);
+ int argc, char** argv,
+ std::unordered_map<std::string, std::string>* properties);
#endif
XBT_PUBLIC void SIMIX_process_throw(smx_actor_t process, xbt_errcat_t cat, int value, const char* mesg);
#include <xbt/future.hpp>
#include <xbt/signal.hpp>
-#include <map>
#include <string>
+#include <unordered_map>
XBT_PUBLIC void simcall_run_kernel(std::function<void()> const& code);
/* name */ const char*, std::function<void()> code,
/* userdata */ void*,
/* hostname */ sg_host_t,
- /* props */ std::map<std::string, std::string>*,
+ /* props */ std::unordered_map<std::string, std::string>*,
/* parent_process */ smx_actor_t);
XBT_PUBLIC void SIMIX_function_register_process_create(smx_creation_func_t function);
XBT_PUBLIC smx_actor_t simcall_process_create(const char* name, std::function<void()> code, void* data, sg_host_t host,
- std::map<std::string, std::string>* properties);
+ std::unordered_map<std::string, std::string>* properties);
XBT_PUBLIC smx_timer_t SIMIX_timer_set(double date, simgrid::xbt::Task<void()> callback);
/*************************************************************/
XBT_PRIVATE void MSG_process_cleanup_from_SIMIX(smx_actor_t smx_proc);
XBT_PRIVATE smx_actor_t MSG_process_create_from_SIMIX(const char* name, std::function<void()> code, void* data,
- sg_host_t host, std::map<std::string, std::string>* properties,
+ sg_host_t host,
+ std::unordered_map<std::string, std::string>* properties,
smx_actor_t parent_process);
XBT_PRIVATE void MSG_comm_copy_data_from_SIMIX(smx_activity_t comm, void* buff, size_t buff_size);
/* This function creates a MSG process. It has the prototype enforced by SIMIX_function_register_process_create */
smx_actor_t MSG_process_create_from_SIMIX(const char* name, std::function<void()> code, void* data, sg_host_t host,
- std::map<std::string, std::string>* properties,
+ std::unordered_map<std::string, std::string>* properties,
smx_actor_t /*parent_process*/)
{
msg_process_t p = MSG_process_create_from_stdfunc(name, std::move(code), data, host, properties);
if (code)
function = simgrid::xbt::wrapMain(code, argc, static_cast<const char* const*>(argv));
- std::map<std::string, std::string> props;
+ std::unordered_map<std::string, std::string> props;
xbt_dict_cursor_t cursor = nullptr;
char* key;
char* value;
}
msg_process_t MSG_process_create_from_stdfunc(const char* name, std::function<void()> code, void* data, msg_host_t host,
- std::map<std::string, std::string>* properties)
+ std::unordered_map<std::string, std::string>* properties)
{
xbt_assert(code != nullptr && host != nullptr, "Invalid parameters: host and code params must not be nullptr");
simgrid::msg::ActorExt* msgExt = new simgrid::msg::ActorExt(data);
msg_process_t MSG_process_attach(const char *name, void *data, msg_host_t host, xbt_dict_t properties)
{
xbt_assert(host != nullptr, "Invalid parameters: host and code params must not be nullptr");
- std::map<std::string, std::string> props;
+ std::unordered_map<std::string, std::string> props;
xbt_dict_cursor_t cursor = nullptr;
char* key;
char* value;
simgrid::simix::simcall([&self] { SIMIX_process_killall(self); });
}
-std::map<std::string, std::string>* Actor::get_properties()
+std::unordered_map<std::string, std::string>* Actor::get_properties()
{
return simgrid::simix::simcall([this] { return this->pimpl_->get_properties(); });
}
{
xbt_assert(actor != nullptr, "Invalid parameter: First argument must not be nullptr");
xbt_dict_t as_dict = xbt_dict_new_homogeneous(xbt_free_f);
- std::map<std::string, std::string>* props = actor->get_properties();
+ std::unordered_map<std::string, std::string>* props = actor->get_properties();
if (props == nullptr)
return nullptr;
- for (auto const& elm : *props) {
- xbt_dict_set(as_dict, elm.first.c_str(), xbt_strdup(elm.second.c_str()), nullptr);
+ for (auto const& kv : *props) {
+ xbt_dict_set(as_dict, kv.first.c_str(), xbt_strdup(kv.second.c_str()), nullptr);
}
return as_dict;
}
}
/** Get the properties assigned to a host */
-std::map<std::string, std::string>* Host::getProperties()
+std::unordered_map<std::string, std::string>* Host::get_properties()
{
return simgrid::simix::simcall([this] { return this->pimpl_->get_properties(); });
}
xbt_dict_t sg_host_get_properties(sg_host_t host)
{
xbt_dict_t as_dict = xbt_dict_new_homogeneous(xbt_free_f);
- std::map<std::string, std::string>* props = host->getProperties();
+ std::unordered_map<std::string, std::string>* props = host->get_properties();
if (props == nullptr)
return nullptr;
for (auto const& elm : *props) {
XBT_INFO("Displaying host %s", host->get_cname());
XBT_INFO(" - speed: %.0f", host->getSpeed());
XBT_INFO(" - available speed: %.2f", sg_host_get_available_speed(host));
- std::map<std::string, std::string>* props = host->getProperties();
+ std::unordered_map<std::string, std::string>* props = host->get_properties();
if (not props->empty()) {
XBT_INFO(" - properties:");
return pimpl_->typeId_.c_str();
}
-std::map<std::string, std::string>* Storage::get_properties()
+std::unordered_map<std::string, std::string>* Storage::get_properties()
{
return simgrid::simix::simcall([this] { return pimpl_->get_properties(); });
}
{
xbt_assert((storage != nullptr), "Invalid parameters (storage is nullptr)");
xbt_dict_t as_dict = xbt_dict_new_homogeneous(xbt_free_f);
- std::map<std::string, std::string>* props = storage->get_properties();
+ std::unordered_map<std::string, std::string>* props = storage->get_properties();
if (props == nullptr)
return nullptr;
for (auto const& elm : *props) {
* \return the process created
*/
smx_actor_t SIMIX_process_create(const char* name, std::function<void()> code, void* data, simgrid::s4u::Host* host,
- std::map<std::string, std::string>* properties, smx_actor_t parent_process)
+ std::unordered_map<std::string, std::string>* properties, smx_actor_t parent_process)
{
XBT_DEBUG("Start process %s on host '%s'", name, host->get_cname());
}
smx_actor_t SIMIX_process_attach(const char* name, void* data, const char* hostname,
- std::map<std::string, std::string>* properties, smx_actor_t parent_process)
+ std::unordered_map<std::string, std::string>* properties, smx_actor_t parent_process)
{
// This is mostly a copy/paste from SIMIX_process_new(),
// it'd be nice to share some code between those two functions.
* \param properties the properties of the process
*/
smx_actor_t simcall_process_create(const char* name, xbt_main_func_t code, void* data, sg_host_t host, int argc,
- char** argv, std::map<std::string, std::string>* properties)
+ char** argv, std::unordered_map<std::string, std::string>* properties)
{
if (name == nullptr)
name = "";
}
smx_actor_t simcall_process_create(const char* name, std::function<void()> code, void* data, sg_host_t host,
- std::map<std::string, std::string>* properties)
+ std::unordered_map<std::string, std::string>* properties)
{
if (name == nullptr)
name = "";
void* data = nullptr;
s4u::Host* host = nullptr;
double kill_time = 0.0;
- std::shared_ptr<std::map<std::string, std::string>> properties;
+ std::shared_ptr<std::unordered_map<std::string, std::string>> properties;
bool auto_restart = false;
ProcessArg() = default;
explicit ProcessArg(std::string name, std::function<void()> code, void* data, s4u::Host* host, double kill_time,
- std::shared_ptr<std::map<std::string, std::string>> properties, bool auto_restart)
+ std::shared_ptr<std::unordered_map<std::string, std::string>> properties, bool auto_restart)
: name(name)
, code(std::move(code))
, data(data)
typedef simgrid::kernel::actor::ActorImpl* smx_actor_t;
XBT_PRIVATE smx_actor_t SIMIX_process_create(const char* name, std::function<void()> code, void* data, sg_host_t host,
- std::map<std::string, std::string>* properties,
+ std::unordered_map<std::string, std::string>* properties,
smx_actor_t parent_process);
XBT_PRIVATE void SIMIX_process_runall();
* again to restart the process again.
*/
void SIMIX_host_add_auto_restart_process(sg_host_t host, const char* name, std::function<void()> code, void* data,
- double kill_time, std::map<std::string, std::string>* properties,
+ double kill_time, std::unordered_map<std::string, std::string>* properties,
int auto_restart)
{
simgrid::kernel::actor::ProcessArg* arg =
#include <boost/intrusive/list.hpp>
#include <functional>
-#include <map>
+#include <unordered_map>
#include <vector>
#include "src/simix/ActorImpl.hpp"
XBT_PRIVATE void SIMIX_host_add_auto_restart_process(sg_host_t host, const char* name, std::function<void()> code,
void* data, double kill_time,
- std::map<std::string, std::string>* properties, int auto_restart);
+ std::unordered_map<std::string, std::string>* properties,
+ int auto_restart);
XBT_PRIVATE void SIMIX_host_autorestart(sg_host_t host);
void PropertyHolder::set_property(std::string key, std::string value)
{
if (not properties_)
- properties_ = new std::map<std::string, std::string>;
+ properties_ = new std::unordered_map<std::string, std::string>;
(*properties_)[key] = value;
}
/** @brief Return the whole set of properties. Don't mess with it, dude! */
-std::map<std::string, std::string>* PropertyHolder::get_properties()
+std::unordered_map<std::string, std::string>* PropertyHolder::get_properties()
{
if (not properties_)
- properties_ = new std::map<std::string, std::string>;
+ properties_ = new std::unordered_map<std::string, std::string>;
return properties_;
}
#ifndef SRC_SURF_PROPERTYHOLDER_HPP_
#define SRC_SURF_PROPERTYHOLDER_HPP_
-#include <map>
#include <string>
+#include <unordered_map>
namespace simgrid {
namespace surf {
const char* get_property(std::string key);
void set_property(std::string id, std::string value);
- /* FIXME: This should not be exposed, as users may do bad things with the dict they got (it's not a copy).
+ /* FIXME: This should not be exposed, as users may do bad things with the map they got (it's not a copy).
* But some user API expose this call so removing it is not so easy.
*/
- std::map<std::string, std::string>* get_properties();
+ std::unordered_map<std::string, std::string>* get_properties();
private:
- std::map<std::string, std::string>* properties_ = nullptr;
+ std::unordered_map<std::string, std::string>* properties_ = nullptr;
};
} /* namespace surf */
std::string id;
std::string model;
std::string content;
- std::map<std::string, std::string>* properties;
- std::map<std::string, std::string>* model_properties;
+ std::unordered_map<std::string, std::string>* properties;
+ std::unordered_map<std::string, std::string>* model_properties;
sg_size_t size;
- StorageType(std::string id, std::string model, std::string content, std::map<std::string, std::string>* properties,
- std::map<std::string, std::string>* model_properties, sg_size_t size)
+ StorageType(std::string id, std::string model, std::string content,
+ std::unordered_map<std::string, std::string>* properties,
+ std::unordered_map<std::string, std::string>* model_properties, sg_size_t size)
: id(id), model(model), content(content), properties(properties), model_properties(model_properties), size(size)
{
}
#include "src/surf/network_smpi.hpp"
#include "xbt/base.h"
-#include <unordered_map>
+#include <map>
#include <vector>
namespace simgrid {
simgrid::kernel::routing::HostCreationArgs host;
host.id = host_id.c_str();
if ((cluster->properties != nullptr) && (not cluster->properties->empty())) {
- host.properties = new std::map<std::string, std::string>;
+ host.properties = new std::unordered_map<std::string, std::string>;
for (auto const& elm : *cluster->properties)
host.properties->insert({elm.first, elm.second});
std::string actor_name = actor->args[0];
std::function<void()> code = factory(std::move(actor->args));
- std::shared_ptr<std::map<std::string, std::string>> properties(actor->properties);
+ std::shared_ptr<std::unordered_map<std::string, std::string>> properties(actor->properties);
simgrid::kernel::actor::ProcessArg* arg =
new simgrid::kernel::actor::ProcessArg(actor_name, code, nullptr, host, kill_time, properties, auto_restart);
tmgr_trace_t speed_trace = nullptr;
tmgr_trace_t state_trace = nullptr;
const char* coord = nullptr;
- std::map<std::string, std::string>* properties = nullptr;
+ std::unordered_map<std::string, std::string>* properties = nullptr;
};
class HostLinkCreationArgs {
tmgr_trace_t latency_trace = nullptr;
tmgr_trace_t state_trace = nullptr;
simgrid::s4u::Link::SharingPolicy policy = simgrid::s4u::Link::SharingPolicy::FATPIPE;
- std::map<std::string, std::string>* properties = nullptr;
+ std::unordered_map<std::string, std::string>* properties = nullptr;
};
class PeerCreationArgs {
double limiter_link = 0;
ClusterTopology topology;
std::string topo_parameters;
- std::map<std::string, std::string>* properties;
+ std::unordered_map<std::string, std::string>* properties;
std::string router_id;
simgrid::s4u::Link::SharingPolicy sharing_policy;
simgrid::s4u::Link::SharingPolicy bb_sharing_policy;
std::string id;
std::string type_id;
std::string content;
- std::map<std::string, std::string>* properties;
+ std::unordered_map<std::string, std::string>* properties;
std::string attach;
};
std::string id;
std::string model;
std::string content;
- std::map<std::string, std::string>* properties;
- std::map<std::string, std::string>* model_properties;
+ std::unordered_map<std::string, std::string>* properties;
+ std::unordered_map<std::string, std::string>* model_properties;
sg_size_t size;
};
class ActorCreationArgs {
public:
std::vector<std::string> args;
- std::map<std::string, std::string>* properties = nullptr;
+ std::unordered_map<std::string, std::string>* properties = nullptr;
const char* host = nullptr;
const char* function = nullptr;
double start_time = 0.0;
/* make sure these symbols are defined as strong ones in this file so that the linker can resolve them */
/* The default current property receiver. Setup in the corresponding opening callbacks. */
-std::map<std::string, std::string>* current_property_set = nullptr;
-std::map<std::string, std::string>* current_model_property_set = nullptr;
+std::unordered_map<std::string, std::string>* current_property_set = nullptr;
+std::unordered_map<std::string, std::string>* current_model_property_set = nullptr;
int ZONE_TAG = 0; // Whether we just opened a zone tag (to see what to do with the properties)
FILE *surf_file_to_parse = nullptr;
netzone->set_property(A_surfxml_prop_id, A_surfxml_prop_value);
} else {
if (not current_property_set)
- current_property_set = new std::map<std::string, std::string>; // Maybe, it should raise an error
+ current_property_set = new std::unordered_map<std::string, std::string>; // Maybe, it should raise an error
current_property_set->insert({A_surfxml_prop_id, A_surfxml_prop_value});
XBT_DEBUG("add prop %s=%s into current property set %p", A_surfxml_prop_id, A_surfxml_prop_value,
current_property_set);
void ETag_surfxml_config()
{
- for (auto const& elm : *current_property_set) {
- if (simgrid::config::is_default(elm.first.c_str())) {
- std::string cfg = elm.first + ":" + elm.second;
+ // Sort config elements before applying.
+ // That's a little waste of time, but not doing so would break the tests
+ std::vector<std::string> keys;
+ for (auto const& kv : *current_property_set) {
+ keys.push_back(kv.first);
+ }
+ std::sort(keys.begin(), keys.end());
+ for (std::string key : keys) {
+ if (simgrid::config::is_default(key.c_str())) {
+ std::string cfg = key + ":" + current_property_set->at(key);
simgrid::config::set_parse(std::move(cfg));
} else
- XBT_INFO("The custom configuration '%s' is already defined by user!", elm.first.c_str());
+ XBT_INFO("The custom configuration '%s' is already defined by user!", key.c_str());
}
XBT_DEBUG("End configuration name = %s",A_surfxml_config_id);
void STag_surfxml_model___prop(){
if (not current_model_property_set)
- current_model_property_set = new std::map<std::string, std::string>();
+ current_model_property_set = new std::unordered_map<std::string, std::string>();
current_model_property_set->insert({A_surfxml_model___prop_id, A_surfxml_model___prop_value});
}
static void display_storage_properties(simgrid::s4u::Storage* storage)
{
- std::map<std::string, std::string>* props = storage->get_properties();
+ std::unordered_map<std::string, std::string>* props = storage->get_properties();
if (not props->empty()) {
XBT_INFO("\tProperties of mounted storage: %s", storage->get_cname());
static void dump_hosts()
{
- std::map<std::string, std::string>* props = nullptr;
+ std::unordered_map<std::string, std::string>* props = nullptr;
unsigned int totalHosts = sg_host_count();
sg_host_t* hosts = sg_host_list();
std::sort(hosts, hosts + totalHosts,
for (unsigned int i = 0; i < totalHosts; i++) {
std::printf(" <host id=\"%s\" speed=\"%.0f\"", hosts[i]->get_cname(), sg_host_speed(hosts[i]));
- props = hosts[i]->getProperties();
+ props = hosts[i]->get_properties();
if (hosts[i]->get_core_count() > 1) {
std::printf(" core=\"%d\"", hosts[i]->get_core_count());
}
- if (props && not props->empty()) {
+ // Sort the properties before displaying them, so that the tests are perfectly reproducible
+ std::vector<std::string> keys;
+ for (auto const& kv : *props)
+ keys.push_back(kv.first);
+ if (not keys.empty()) {
std::printf(">\n");
- for (auto const& kv : *props) {
- std::printf(" <prop id=\"%s\" value=\"%s\"/>\n", kv.first.c_str(), kv.second.c_str());
- }
+ std::sort(keys.begin(), keys.end());
+ for (std::string key : keys)
+ std::printf(" <prop id=\"%s\" value=\"%s\"/>\n", key.c_str(), props->at(key).c_str());
std::printf(" </host>\n");
} else {
std::printf("/>\n");