]> AND Public Git Repository - simgrid.git/blobdiff - src/s4u/s4u_Host.cpp
Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Print state_ in symbolic form.
[simgrid.git] / src / s4u / s4u_Host.cpp
index bb56640b9d5075d700ddbce074ef3b92250d86a5..72c27ad7ca5eb270ffd99c7fdadd410e7306048b 100644 (file)
@@ -69,11 +69,20 @@ Host* Host::by_name_or_null(const std::string& name)
 Host* Host::current()
 {
   kernel::actor::ActorImpl* self = kernel::actor::ActorImpl::self();
-  if (self == nullptr)
-    xbt_die("Cannot call Host::current() from the maestro context");
+  xbt_assert(self != nullptr, "Cannot call Host::current() from the maestro context");
   return self->get_host();
 }
 
+xbt::string const& Host::get_name() const
+{
+  return this->pimpl_->get_name();
+}
+
+const char* Host::get_cname() const
+{
+  return this->pimpl_->get_cname();
+}
+
 void Host::turn_on()
 {
   if (not is_on()) {
@@ -262,18 +271,24 @@ Host* Host::set_pstate_speed(const std::vector<double>& speed_per_state)
   return this;
 }
 
-Host* Host::set_pstate_speed(const std::vector<std::string>& speed_per_state)
+std::vector<double> Host::convert_pstate_speed_vector(const std::vector<std::string>& speed_per_state)
 {
-  std::vector<double> speed_list(speed_per_state.size());
+  std::vector<double> speed_list;
+  speed_list.reserve(speed_per_state.size());
   for (const auto& speed_str : speed_per_state) {
     try {
       double speed = xbt_parse_get_speed("", 0, speed_str.c_str(), nullptr, "");
       speed_list.push_back(speed);
-    } catch (const simgrid::ParseError& e) {
-      xbt_die("Host(%s): Impossible to set_pstate_speed, invalid speed %s", get_cname(), speed_str.c_str());
+    } catch (const simgrid::ParseError&) {
+      throw std::invalid_argument(std::string("Invalid speed value: ") + speed_str);
     }
   }
-  set_pstate_speed(speed_list);
+  return speed_list;
+}
+
+Host* Host::set_pstate_speed(const std::vector<std::string>& speed_per_state)
+{
+  set_pstate_speed(Host::convert_pstate_speed_vector(speed_per_state));
   return this;
 }
 
@@ -290,6 +305,12 @@ int Host::get_pstate() const
   return this->pimpl_cpu->get_pstate();
 }
 
+Host* Host::set_coordinates(const std::string& coords)
+{
+  if (not coords.empty())
+    kernel::actor::simcall([this, coords] { this->pimpl_netpoint_->set_coordinates(coords); });
+  return this;
+}
 std::vector<Disk*> Host::get_disks() const
 {
   return this->pimpl_->get_disks();
@@ -297,9 +318,28 @@ std::vector<Disk*> Host::get_disks() const
 
 Disk* Host::create_disk(const std::string& name, double read_bandwidth, double write_bandwidth)
 {
-  auto disk =
-      this->get_netpoint()->get_englobing_zone()->get_disk_model()->create_disk(name, read_bandwidth, write_bandwidth);
-  return disk->set_host(this)->get_iface();
+  return kernel::actor::simcall([this, &name, read_bandwidth, write_bandwidth] {
+    return this->pimpl_->create_disk(name, read_bandwidth, write_bandwidth);
+  });
+}
+
+Disk* Host::create_disk(const std::string& name, const std::string& read_bandwidth, const std::string& write_bandwidth)
+{
+  double d_read;
+  try {
+    d_read = xbt_parse_get_bandwidth("", 0, read_bandwidth.c_str(), nullptr, "");
+  } catch (const simgrid::ParseError&) {
+    throw std::invalid_argument(std::string("Impossible to create disk: ") + name +
+                                std::string(". Invalid read bandwidth: ") + read_bandwidth);
+  }
+  double d_write;
+  try {
+    d_write = xbt_parse_get_bandwidth("", 0, write_bandwidth.c_str(), nullptr, "");
+  } catch (const simgrid::ParseError&) {
+    throw std::invalid_argument(std::string("Impossible to create disk: ") + name +
+                                std::string(". Invalid write bandwidth: ") + write_bandwidth);
+  }
+  return create_disk(name, d_read, d_write);
 }
 
 void Host::add_disk(const Disk* disk)
@@ -332,6 +372,13 @@ void Host::execute(double flops, double priority) const
   this_actor::exec_init(flops)->set_priority(1 / priority)->vetoable_start()->wait();
 }
 
+Host* Host::seal()
+{
+  kernel::actor::simcall([this]() { this->pimpl_->seal(); });
+  simgrid::s4u::Host::on_creation(*this); // notify the signal
+  return this;
+}
+
 } // namespace s4u
 } // namespace simgrid