Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Define PropertyHolder::set_properties.
authorArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Thu, 18 Apr 2019 09:45:34 +0000 (11:45 +0200)
committerArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Thu, 18 Apr 2019 09:55:10 +0000 (11:55 +0200)
It allows to have a single simcall when setting many properties.

include/simgrid/s4u/Host.hpp
src/kernel/actor/ActorImpl.cpp
src/kernel/routing/NetZoneImpl.cpp
src/s4u/s4u_Host.cpp
src/surf/PropertyHolder.cpp
src/surf/PropertyHolder.hpp
src/surf/sg_platf.cpp

index f4d7550..48870a8 100644 (file)
@@ -100,6 +100,7 @@ public:
   const char* get_property(const std::string& key) const;
   void set_property(const std::string& key, const std::string& value);
   const std::unordered_map<std::string, std::string>* get_properties() const;
   const char* get_property(const std::string& key) const;
   void set_property(const std::string& key, const std::string& value);
   const std::unordered_map<std::string, std::string>* get_properties() const;
+  void set_properties(const std::map<std::string, std::string>& properties);
 
   void set_state_profile(kernel::profile::Profile* p);
   void set_speed_profile(kernel::profile::Profile* p);
 
   void set_state_profile(kernel::profile::Profile* p);
   void set_speed_profile(kernel::profile::Profile* p);
index 9a646da..8b3f02d 100644 (file)
@@ -93,8 +93,7 @@ ActorImplPtr ActorImpl::attach(const std::string& name, void* data, s4u::Host* h
 
   /* Add properties */
   if (properties != nullptr)
 
   /* Add properties */
   if (properties != nullptr)
-    for (auto const& kv : *properties)
-      actor->set_property(kv.first, kv.second);
+    actor->set_properties(*properties);
 
   /* Add the process to it's host process list */
   host->pimpl_->process_list_.push_back(*actor);
 
   /* Add the process to it's host process list */
   host->pimpl_->process_list_.push_back(*actor);
@@ -487,8 +486,7 @@ ActorImplPtr ActorImpl::create(const std::string& name, const simix::ActorCode&
 
   /* Add properties */
   if (properties != nullptr)
 
   /* Add properties */
   if (properties != nullptr)
-    for (auto const& kv : *properties)
-      actor->set_property(kv.first, kv.second);
+    actor->set_properties(*properties);
 
   actor->start(code);
 
 
   actor->start(code);
 
index babab5a..670720c 100644 (file)
@@ -105,8 +105,7 @@ simgrid::s4u::Host* NetZoneImpl::create_host(const char* name, const std::vector
   surf_cpu_model_pm->create_cpu(res, speed_per_pstate, coreAmount);
 
   if (props != nullptr)
   surf_cpu_model_pm->create_cpu(res, speed_per_pstate, coreAmount);
 
   if (props != nullptr)
-    for (auto const& kv : *props)
-      res->set_property(kv.first, kv.second);
+    res->set_properties(*props);
 
   simgrid::s4u::Host::on_creation(*res); // notify the signal
 
 
   simgrid::s4u::Host::on_creation(*res); // notify the signal
 
index 2af9129..46d86bb 100644 (file)
@@ -180,6 +180,12 @@ void Host::set_property(const std::string& key, const std::string& value)
 {
   simix::simcall([this, &key, &value] { this->pimpl_->set_property(key, value); });
 }
 {
   simix::simcall([this, &key, &value] { this->pimpl_->set_property(key, value); });
 }
+
+void Host::set_properties(const std::map<std::string, std::string>& properties)
+{
+  simix::simcall([this, &properties] { this->pimpl_->set_properties(properties); });
+}
+
 /** Specify a profile turning the host on and off according to a exhaustive list or a stochastic law.
  * The profile must contain boolean values. */
 void Host::set_state_profile(kernel::profile::Profile* p)
 /** Specify a profile turning the host on and off according to a exhaustive list or a stochastic law.
  * The profile must contain boolean values. */
 void Host::set_state_profile(kernel::profile::Profile* p)
index 8b002a4..bf262b9 100644 (file)
@@ -5,6 +5,8 @@
 
 #include "PropertyHolder.hpp"
 
 
 #include "PropertyHolder.hpp"
 
+#include <map>
+
 namespace simgrid {
 namespace surf {
 
 namespace simgrid {
 namespace surf {
 
@@ -33,5 +35,22 @@ const std::unordered_map<std::string, std::string>* PropertyHolder::get_properti
   return properties_.get();
 }
 
   return properties_.get();
 }
 
+/** @brief Change the value of the given keys in the property set */
+template <class Assoc> void PropertyHolder::set_properties(const Assoc& properties)
+{
+  if (not properties_)
+    properties_.reset(new std::unordered_map<std::string, std::string>);
+  std::unordered_map<std::string, std::string> props(properties.cbegin(), properties.cend());
+#if __cplusplus >= 201703L
+  props.merge(properties_);
+#else
+  props.insert(properties_->cbegin(), properties_->cend());
+#endif
+  properties_->swap(props);
+}
+
+template void PropertyHolder::set_properties(const std::map<std::string, std::string>& properties);
+template void PropertyHolder::set_properties(const std::unordered_map<std::string, std::string>& properties);
+
 } /* namespace surf */
 } /* namespace simgrid */
 } /* namespace surf */
 } /* namespace simgrid */
index 27ae7a6..2c7cdce 100644 (file)
@@ -28,6 +28,7 @@ public:
   void set_property(const std::string& id, const std::string& value);
 
   const std::unordered_map<std::string, std::string>* get_properties();
   void set_property(const std::string& id, const std::string& value);
 
   const std::unordered_map<std::string, std::string>* get_properties();
+  template <class Assoc> void set_properties(const Assoc& properties);
 
 private:
   std::unique_ptr<std::unordered_map<std::string, std::string>> properties_ = nullptr;
 
 private:
   std::unique_ptr<std::unordered_map<std::string, std::string>> properties_ = nullptr;
index e729a52..3b46bc1 100644 (file)
@@ -115,8 +115,7 @@ static void sg_platf_new_link(simgrid::kernel::routing::LinkCreationArgs* link,
       surf_network_model->create_link(link_name, link->bandwidth, link->latency, link->policy);
 
   if (link->properties) {
       surf_network_model->create_link(link_name, link->bandwidth, link->latency, link->policy);
 
   if (link->properties) {
-    for (auto const& elm : *link->properties)
-      l->set_property(elm.first, elm.second);
+    l->set_properties(*link->properties);
   }
 
   if (link->latency_trace)
   }
 
   if (link->latency_trace)
@@ -362,8 +361,7 @@ void sg_platf_new_storage(simgrid::kernel::routing::StorageCreationArgs* storage
   auto s = surf_storage_model->createStorage(storage->id, stype->id, storage->content, storage->attach);
 
   if (storage->properties) {
   auto s = surf_storage_model->createStorage(storage->id, stype->id, storage->content, storage->attach);
 
   if (storage->properties) {
-    for (auto const& elm : *storage->properties)
-      s->set_property(elm.first, elm.second);
+    s->set_properties(*storage->properties);
     delete storage->properties;
   }
 }
     delete storage->properties;
   }
 }