Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
use unordered_maps to store properties
authorMartin Quinson <martin.quinson@loria.fr>
Sun, 10 Jun 2018 14:55:37 +0000 (16:55 +0200)
committerMartin Quinson <martin.quinson@loria.fr>
Sun, 10 Jun 2018 14:55:37 +0000 (16:55 +0200)
25 files changed:
examples/s4u/platform-properties/s4u-platform-properties.cpp
include/simgrid/msg.h
include/simgrid/s4u/Actor.hpp
include/simgrid/s4u/Host.hpp
include/simgrid/s4u/Storage.hpp
include/simgrid/simix.h
include/simgrid/simix.hpp
src/msg/msg_private.hpp
src/msg/msg_process.cpp
src/s4u/s4u_Actor.cpp
src/s4u/s4u_Host.cpp
src/s4u/s4u_Storage.cpp
src/simix/ActorImpl.cpp
src/simix/ActorImpl.hpp
src/simix/smx_host.cpp
src/simix/smx_host_private.hpp
src/surf/PropertyHolder.cpp
src/surf/PropertyHolder.hpp
src/surf/StorageImpl.hpp
src/surf/network_ib.hpp
src/surf/sg_platf.cpp
src/surf/xml/platf_private.hpp
src/surf/xml/surfxml_sax_cb.cpp
teshsuite/s4u/storage_client_server/storage_client_server.cpp
teshsuite/simdag/flatifier/flatifier.cpp

index 62e2b84..f125e9d 100644 (file)
@@ -5,6 +5,7 @@
 
 // TODO: also test the properties attached to links
 
+#include <algorithm>
 #include <simgrid/s4u.hpp>
 #include <string>
 
@@ -13,14 +14,19 @@ XBT_LOG_NEW_DEFAULT_CATEGORY(s4u_test, "Property test");
 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);
@@ -78,7 +84,7 @@ static int bob(int argc, char* argv[])
   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;
 
index 3ff8e91..c22f433 100644 (file)
@@ -375,7 +375,7 @@ SG_END_DECL()
 #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
index b8e4288..bbe2e73 100644 (file)
@@ -7,7 +7,9 @@
 #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>
@@ -276,7 +278,8 @@ public:
   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);
 
@@ -337,7 +340,11 @@ public:
   }
   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)
   {
index 87f6cbb..4d9f607 100644 (file)
@@ -98,7 +98,15 @@ public:
 
   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();
index ffb98ce..bd86099 100644 (file)
@@ -12,6 +12,7 @@
 
 #include <map>
 #include <string>
+#include <unordered_map>
 
 namespace simgrid {
 namespace xbt {
@@ -54,7 +55,7 @@ public:
   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);
 
@@ -76,7 +77,11 @@ public:
   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)
   {
index 982468f..370f11b 100644 (file)
@@ -12,7 +12,7 @@
 #include <xbt/parmap.h>
 #ifdef __cplusplus
 #include <functional>
-#include <map>
+#include <unordered_map>
 #endif
 
 /* ******************************** Host ************************************ */
@@ -135,7 +135,8 @@ XBT_PUBLIC void SIMIX_process_set_function(const char* process_host, const char*
 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();
 
@@ -186,7 +187,8 @@ SG_BEGIN_DECL()
 /* 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);
index eee08fc..9943239 100644 (file)
@@ -12,8 +12,8 @@
 #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);
 
@@ -100,13 +100,13 @@ typedef smx_actor_t (*smx_creation_func_t)(
     /* 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);
 
index 25cead3..e9f8cfe 100644 (file)
@@ -86,7 +86,8 @@ XBT_PUBLIC_DATA MSG_Global_t msg_global;
 /*************************************************************/
 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);
 
index cf699a6..51ea774 100644 (file)
@@ -58,7 +58,7 @@ void MSG_process_cleanup_from_SIMIX(smx_actor_t smx_actor)
 
 /* 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);
@@ -131,7 +131,7 @@ msg_process_t MSG_process_create_with_environment(const char *name, xbt_main_fun
   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;
@@ -147,7 +147,7 @@ msg_process_t MSG_process_create_with_environment(const char *name, xbt_main_fun
 }
 
 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);
@@ -172,7 +172,7 @@ msg_process_t MSG_process_create_from_stdfunc(const char* name, std::function<vo
 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;
index 940243c..105cd93 100644 (file)
@@ -217,7 +217,7 @@ void Actor::kill_all()
   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(); });
 }
@@ -500,11 +500,11 @@ xbt_dict_t sg_actor_get_properties(sg_actor_t actor)
 {
   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;
 }
index ba215f5..af81dcb 100644 (file)
@@ -204,7 +204,7 @@ void Host::route_to(Host* dest, std::vector<kernel::resource::LinkImpl*>& links,
 }
 
 /** 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(); });
 }
@@ -526,7 +526,7 @@ int sg_host_is_off(sg_host_t host)
 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) {
@@ -605,7 +605,7 @@ void sg_host_dump(sg_host_t host)
   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:");
index 1e86878..3c54d86 100644 (file)
@@ -40,7 +40,7 @@ const char* Storage::get_type()
   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(); });
 }
@@ -108,7 +108,7 @@ xbt_dict_t sg_storage_get_properties(sg_storage_t storage)
 {
   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) {
index b83645a..b2603b8 100644 (file)
@@ -288,7 +288,7 @@ void SIMIX_maestro_create(void (*code)(void*), void* data)
  * \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());
@@ -345,7 +345,7 @@ smx_actor_t SIMIX_process_create(const char* name, std::function<void()> code, v
 }
 
 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.
@@ -798,7 +798,7 @@ void SIMIX_process_auto_restart_set(smx_actor_t process, int auto_restart) {
  * \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 = "";
@@ -811,7 +811,7 @@ smx_actor_t simcall_process_create(const char* name, xbt_main_func_t code, void*
 }
 
 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 = "";
index af2a7f3..81c6326 100644 (file)
@@ -30,11 +30,11 @@ public:
   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)
@@ -137,7 +137,7 @@ XBT_PUBLIC void create_maestro(std::function<void()> code);
 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();
index 3a22697..6590640 100644 (file)
@@ -79,7 +79,7 @@ const char* sg_host_self_get_name()
  * 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 =
index 17a0a39..1fd1796 100644 (file)
@@ -8,7 +8,7 @@
 
 #include <boost/intrusive/list.hpp>
 #include <functional>
-#include <map>
+#include <unordered_map>
 #include <vector>
 
 #include "src/simix/ActorImpl.hpp"
@@ -40,7 +40,8 @@ public:
 
 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);
 
index eed6a29..853bcb5 100644 (file)
@@ -25,15 +25,15 @@ const char* PropertyHolder::get_property(std::string key)
 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_;
 }
 
index 02eb5b9..37a30ef 100644 (file)
@@ -5,8 +5,8 @@
 
 #ifndef SRC_SURF_PROPERTYHOLDER_HPP_
 #define SRC_SURF_PROPERTYHOLDER_HPP_
-#include <map>
 #include <string>
+#include <unordered_map>
 
 namespace simgrid {
 namespace surf {
@@ -24,13 +24,13 @@ public:
   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 */
index 530c728..204791f 100644 (file)
@@ -171,11 +171,12 @@ public:
   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)
   {
   }
index 5bd37c9..2aac5e3 100644 (file)
@@ -10,7 +10,7 @@
 #include "src/surf/network_smpi.hpp"
 #include "xbt/base.h"
 
-#include <unordered_map>
+#include <map>
 #include <vector>
 
 namespace simgrid {
index 6498e13..bf7afcc 100644 (file)
@@ -188,7 +188,7 @@ void sg_platf_new_cluster(simgrid::kernel::routing::ClusterCreationArgs* cluster
     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});
@@ -438,7 +438,7 @@ void sg_platf_new_actor(simgrid::kernel::routing::ActorCreationArgs* actor)
 
   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);
index 793941d..8ae587d 100644 (file)
@@ -40,7 +40,7 @@ struct HostCreationArgs {
   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 {
@@ -59,7 +59,7 @@ public:
   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 {
@@ -102,7 +102,7 @@ public:
   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;
@@ -124,7 +124,7 @@ public:
   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;
 };
 
@@ -133,8 +133,8 @@ public:
   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;
 };
 
@@ -166,7 +166,7 @@ enum class ActorOnFailure { DIE, RESTART }; // FIXME: move to a better namespace
 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;
index fcab8b4..ebc12b7 100644 (file)
@@ -266,8 +266,8 @@ static std::vector<double> surf_parse_get_all_speeds(char* speeds, const char* e
 /* 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;
@@ -409,7 +409,7 @@ void STag_surfxml_prop()
     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);
@@ -858,12 +858,19 @@ void STag_surfxml_config()
 
 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);
 
@@ -931,7 +938,7 @@ void STag_surfxml_argument(){
 
 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});
 }
index 6510ae1..d2ed8fe 100644 (file)
@@ -13,7 +13,7 @@ XBT_LOG_NEW_DEFAULT_CATEGORY(storage, "Messages specific for this simulation");
 
 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());
 
index 7ed0610..31f1dc8 100644 (file)
@@ -47,7 +47,7 @@ static void create_environment(xbt_os_timer_t parse_time, const char *platformFi
 
 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,
@@ -55,15 +55,19 @@ static void dump_hosts()
 
   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");