Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
some dict related cleanups
authorFrederic Suter <frederic.suter@cc.in2p3.fr>
Thu, 3 Aug 2017 08:03:35 +0000 (10:03 +0200)
committerFrederic Suter <frederic.suter@cc.in2p3.fr>
Thu, 3 Aug 2017 08:03:35 +0000 (10:03 +0200)
src/bindings/java/jmsg_host.cpp
src/bindings/lua/lua_platf.cpp
src/surf/StorageImpl.hpp
src/surf/network_smpi.cpp
src/surf/xml/surfxml_sax_cb.cpp
teshsuite/simdag/flatifier/flatifier.cpp

index e2208b3..db414b9 100644 (file)
@@ -7,6 +7,7 @@
 
 #include "simgrid/plugins/energy.h"
 #include "simgrid/s4u/Host.hpp"
+#include "simgrid/s4u/Storage.hpp"
 
 #include "jmsg.h"
 #include "jmsg_host.h"
@@ -237,8 +238,8 @@ JNIEXPORT jobjectArray JNICALL Java_org_simgrid_msg_Host_getMountedStorage(JNIEn
 
   int index = 0;
   jobjectArray jtable;
-  xbt_dict_t dict =  MSG_host_get_mounted_storage_list(host);
-  int count = xbt_dict_length(dict);
+  std::unordered_map<std::string, msg_storage_t> mounted_storages = host->getMountedStorages();
+  int count  = mounted_storages.size();
   jclass cls = env->FindClass("org/simgrid/msg/Storage");
 
   jtable = env->NewObjectArray((jsize) count, cls, nullptr);
@@ -248,17 +249,12 @@ JNIEXPORT jobjectArray JNICALL Java_org_simgrid_msg_Host_getMountedStorage(JNIEn
     return nullptr;
   }
 
-  xbt_dict_cursor_t cursor=nullptr;
-  const char* mount_name;
-  const char* storage_name;
-
-  xbt_dict_foreach(dict,cursor,mount_name,storage_name) {
-    jname = env->NewStringUTF(storage_name);
+  for (auto elm : mounted_storages) {
+    jname    = env->NewStringUTF(elm.second->getName());
     jstorage = Java_org_simgrid_msg_Storage_getByName(env,cls,jname);
     env->SetObjectArrayElement(jtable, index, jstorage);
     index++;
   }
-  xbt_dict_free(&dict);
   return jtable;
 }
 
index c0b812c..c2219f7 100644 (file)
@@ -452,23 +452,19 @@ int console_add_ASroute(lua_State *L) {
 }
 
 int console_AS_open(lua_State *L) {
- const char *id;
- const char *mode;
- int type;
-
  XBT_DEBUG("Opening AS");
 
  lua_ensure(lua_istable(L, 1), "Bad Arguments to AS_open, Should be a table with named arguments");
 
  lua_pushstring(L, "id");
- type = lua_gettable(L, -2);
int type = lua_gettable(L, -2);
  lua_ensure(type == LUA_TSTRING, "Attribute 'id' must be specified for any AS and must be a string.");
- id = lua_tostring(L, -1);
const char* id = lua_tostring(L, -1);
  lua_pop(L, 1);
 
  lua_pushstring(L, "mode");
  lua_gettable(L, -2);
- mode = lua_tostring(L, -1);
const char* mode = lua_tostring(L, -1);
  lua_pop(L, 1);
 
  int mode_int = A_surfxml_AS_routing_None;
@@ -535,8 +531,7 @@ int console_host_set_property(lua_State *L) {
 
   sg_host_t host = sg_host_by_name(name);
   lua_ensure(host, "no host '%s' found",name);
-  xbt_dict_t props = sg_host_get_properties(host);
-  xbt_dict_set(props,prop_id,xbt_strdup(prop_value),nullptr);
+  host->setProperty(prop_id, prop_value);
 
   return 0;
 }
index 18835f3..da1f082 100644 (file)
@@ -120,7 +120,7 @@ public:
   /**
    * @brief Get the content of the current Storage
    *
-   * @return A xbt_dict_t with path as keys and size in bytes as values
+   * @return A map with path as keys and size in bytes as values
    */
   virtual std::map<std::string, sg_size_t>* getContent();
 
index 411a467..8452508 100644 (file)
@@ -18,8 +18,6 @@ XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(surf_network);
 std::vector<s_smpi_factor_t> smpi_bw_factor;
 std::vector<s_smpi_factor_t> smpi_lat_factor;
 
-xbt_dict_t gap_lookup = nullptr;
-
 /*********
  * Model *
  *********/
@@ -47,68 +45,62 @@ void surf_network_model_init_SMPI()
 }
 
 namespace simgrid {
-  namespace surf {
-
-  NetworkSmpiModel::NetworkSmpiModel() : NetworkCm02Model()
-  {
-    haveGap_ = true;
-    }
-
-    NetworkSmpiModel::~NetworkSmpiModel()
-    {
-      xbt_dict_free(&gap_lookup);
-    }
-
-    double NetworkSmpiModel::bandwidthFactor(double size)
-    {
-      if (smpi_bw_factor.empty())
-        smpi_bw_factor = parse_factor(xbt_cfg_get_string("smpi/bw-factor"));
-
-      double current = 1.0;
-      for (const auto& fact : smpi_bw_factor) {
-        if (size <= fact.factor) {
-          XBT_DEBUG("%f <= %zu return %f", size, fact.factor, current);
-          return current;
-        } else
-          current = fact.values.front();
-      }
-      XBT_DEBUG("%f > %zu return %f", size, smpi_bw_factor.back().factor, current);
+namespace surf {
 
-      return current;
-    }
-
-    double NetworkSmpiModel::latencyFactor(double size)
-    {
-      if (smpi_lat_factor.empty())
-        smpi_lat_factor = parse_factor(xbt_cfg_get_string("smpi/lat-factor"));
-
-      double current=1.0;
-      for (const auto& fact : smpi_lat_factor) {
-        if (size <= fact.factor) {
-          XBT_DEBUG("%f <= %zu return %f", size, fact.factor, current);
-          return current;
-        }else
-          current=fact.values.front();
-      }
-      XBT_DEBUG("%f > %zu return %f", size, smpi_lat_factor.back().factor, current);
+NetworkSmpiModel::NetworkSmpiModel() : NetworkCm02Model()
+{
+  haveGap_ = true;
+}
+
+NetworkSmpiModel::~NetworkSmpiModel() = default;
 
+double NetworkSmpiModel::bandwidthFactor(double size)
+{
+  if (smpi_bw_factor.empty())
+    smpi_bw_factor = parse_factor(xbt_cfg_get_string("smpi/bw-factor"));
+
+  double current = 1.0;
+  for (const auto& fact : smpi_bw_factor) {
+    if (size <= fact.factor) {
+      XBT_DEBUG("%f <= %zu return %f", size, fact.factor, current);
       return current;
-    }
+    } else
+      current = fact.values.front();
+  }
+  XBT_DEBUG("%f > %zu return %f", size, smpi_bw_factor.back().factor, current);
+
+  return current;
+}
 
-    double NetworkSmpiModel::bandwidthConstraint(double rate, double bound, double size)
-    {
-      return rate < 0 ? bound : std::min(bound, rate * bandwidthFactor(size));
-    }
+double NetworkSmpiModel::latencyFactor(double size)
+{
+  if (smpi_lat_factor.empty())
+    smpi_lat_factor = parse_factor(xbt_cfg_get_string("smpi/lat-factor"));
 
-    /************
-     * Resource *
-     ************/
+  double current = 1.0;
+  for (const auto& fact : smpi_lat_factor) {
+    if (size <= fact.factor) {
+      XBT_DEBUG("%f <= %zu return %f", size, fact.factor, current);
+      return current;
+    } else
+      current = fact.values.front();
+  }
+  XBT_DEBUG("%f > %zu return %f", size, smpi_lat_factor.back().factor, current);
 
+  return current;
+}
 
+double NetworkSmpiModel::bandwidthConstraint(double rate, double bound, double size)
+{
+  return rate < 0 ? bound : std::min(bound, rate * bandwidthFactor(size));
+}
 
-    /**********
    * Action *
    **********/
+/************
* Resource *
************/
 
-  }
+/**********
+ * Action *
+ **********/
+}
 }
index 8d77fca..829e026 100644 (file)
@@ -323,9 +323,6 @@ std::map<std::string, std::string>* current_property_set       = nullptr;
 std::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)
 
-/* dictionary of random generator data */
-xbt_dict_t random_data_list = nullptr;
-
 YY_BUFFER_STATE surf_input_buffer;
 FILE *surf_file_to_parse = nullptr;
 
index bb2aa74..60bd850 100644 (file)
@@ -50,10 +50,7 @@ static void create_environment(xbt_os_timer_t parse_time, const char *platformFi
 static void dump_platform()
 {
   int version = 4;
-  xbt_dict_t props = nullptr;
-  xbt_dict_cursor_t cursor = nullptr;
-  char* key;
-  char* data;
+  std::map<std::string, std::string>* props = nullptr;
 
   std::printf("<?xml version='1.0'?>\n");
   std::printf("<!DOCTYPE platform SYSTEM \"http://simgrid.gforge.inria.fr/simgrid/simgrid.dtd\">\n");
@@ -68,20 +65,19 @@ static void dump_platform()
 
   for (unsigned int i = 0; i < totalHosts; i++) {
     std::printf("  <host id=\"%s\" speed=\"%.0f\"", hosts[i]->getCname(), sg_host_speed(hosts[i]));
-    props = sg_host_get_properties(hosts[i]);
+    props = hosts[i]->getProperties();
     if (hosts[i]->getCoreCount() > 1) {
       std::printf(" core=\"%d\"", hosts[i]->getCoreCount());
     }
-    if (props && not xbt_dict_is_empty(props)) {
+    if (props && not props->empty()) {
       std::printf(">\n");
-      xbt_dict_foreach (props, cursor, key, data) {
-        std::printf("    <prop id=\"%s\" value=\"%s\"/>\n", key, data);
+      for (auto kv : *props) {
+        std::printf("    <prop id=\"%s\" value=\"%s\"/>\n", kv.first.c_str(), kv.second.c_str());
       }
       std::printf("  </host>\n");
     } else {
       std::printf("/>\n");
     }
-    xbt_dict_free(&props);
   }
 
   // Routers