Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Seal objects at Engine::run
authorBruno Donassolo <bruno.donassolo@inria.fr>
Tue, 11 May 2021 14:34:16 +0000 (16:34 +0200)
committerBruno Donassolo <bruno.donassolo@inria.fr>
Tue, 11 May 2021 14:34:16 +0000 (16:34 +0200)
Seal, recursively, netzones, hosts, links and disks.
Some extra checks when creating and sealing resources.
Add test for this case.

MANIFEST.in
src/kernel/resource/DiskImpl.cpp
src/kernel/routing/NetZoneImpl.cpp
src/s4u/s4u_Engine.cpp
src/surf/HostImpl.cpp
src/surf/network_interface.cpp
teshsuite/s4u/CMakeLists.txt
teshsuite/s4u/seal-platform/seal-platform.cpp [new file with mode: 0644]
teshsuite/s4u/seal-platform/seal-platform.tesh [new file with mode: 0644]

index d2a0459..79afec6 100644 (file)
@@ -733,6 +733,8 @@ include teshsuite/s4u/ns3-simultaneous-send-rcv/ns3-simultaneous-send-rcv.cpp
 include teshsuite/s4u/ns3-simultaneous-send-rcv/ns3-simultaneous-send-rcv.tesh
 include teshsuite/s4u/pid/pid.cpp
 include teshsuite/s4u/pid/pid.tesh
+include teshsuite/s4u/seal-platform/seal-platform.cpp
+include teshsuite/s4u/seal-platform/seal-platform.tesh
 include teshsuite/s4u/storage_client_server/storage_client_server.cpp
 include teshsuite/s4u/storage_client_server/storage_client_server.tesh
 include teshsuite/s4u/trace-integration/test-hbp1-c0s0-c0s1.xml
index cbc75c2..fda3775 100644 (file)
@@ -108,6 +108,9 @@ DiskImpl* DiskImpl::set_write_bandwidth_profile(profile::Profile* profile)
 
 void DiskImpl::seal()
 {
+  if (is_sealed())
+    return;
+
   xbt_assert(this->get_model(), "Cannot seal Disk (%s) without setting the model first", get_cname());
   lmm::System* maxmin_system = get_model()->get_maxmin_system();
   this->set_read_constraint(maxmin_system->constraint_new(this, read_bw_.peak * read_bw_.scale))
index 76bf13a..c56eb1b 100644 (file)
@@ -141,6 +141,9 @@ int NetZoneImpl::get_host_count() const
 
 s4u::Host* NetZoneImpl::create_host(const std::string& name, const std::vector<double>& speed_per_pstate)
 {
+  xbt_assert(cpu_model_pm_,
+             "Impossible to create host: %s. Invalid CPU model: nullptr. Have you set the parent of this NetZone: %s?",
+             name.c_str(), get_cname());
   auto* res = (new surf::HostImpl(name))->get_iface();
   res->set_netpoint((new NetPoint(name, NetPoint::Type::Host))->set_englobing_zone(this));
 
@@ -151,11 +154,18 @@ s4u::Host* NetZoneImpl::create_host(const std::string& name, const std::vector<d
 
 s4u::Link* NetZoneImpl::create_link(const std::string& name, const std::vector<double>& bandwidths)
 {
+  xbt_assert(
+      network_model_,
+      "Impossible to create link: %s. Invalid network model: nullptr. Have you set the parent of this NetZone: %s?",
+      name.c_str(), get_cname());
   return network_model_->create_link(name, bandwidths)->get_iface();
 }
 
 s4u::Disk* NetZoneImpl::create_disk(const std::string& name, double read_bandwidth, double write_bandwidth)
 {
+  xbt_assert(disk_model_,
+             "Impossible to create disk: %s. Invalid disk model: nullptr. Have you set the parent of this NetZone: %s?",
+             name.c_str(), get_cname());
   auto* l = disk_model_->create_disk(name, read_bandwidth, write_bandwidth);
 
   return l->get_iface();
index 2d980c9..6f68977 100644 (file)
@@ -305,6 +305,12 @@ std::vector<ActorPtr> Engine::get_filtered_actors(const std::function<bool(Actor
 
 void Engine::run() const
 {
+  /* sealing resources before run: links */
+  for (auto* link : get_all_links())
+    link->seal();
+  /* seal netzone root, recursively seal children netzones, hosts and disks */
+  get_netzone_root()->seal();
+
   /* Clean IO before the run */
   fflush(stdout);
   fflush(stderr);
index adfa033..fcb6b4d 100644 (file)
@@ -161,6 +161,10 @@ void HostImpl::seal()
   // seals host's CPU
   get_iface()->pimpl_cpu->seal();
   sealed_ = true;
+
+  /* seal its disks */
+  for (auto* disk : disks_)
+    disk->seal();
 }
 } // namespace surf
 } // namespace simgrid
index f1403fa..98e6ad9 100644 (file)
@@ -132,6 +132,9 @@ void LinkImpl::turn_off()
 
 void LinkImpl::seal()
 {
+  if (is_sealed())
+    return;
+
   xbt_assert(this->get_model(), "Cannot seal Link(%s) without setting the Network model first", this->get_cname());
   Resource::seal();
   s4u::Link::on_creation(piface_);
index 53b2f55..86416f7 100644 (file)
@@ -7,6 +7,7 @@ foreach(x actor actor-autorestart actor-suspend
         basic-link-test basic-parsing-test evaluate-get-route-time evaluate-parse-time is-router
         storage_client_server listen_async pid
         trace-integration
+        seal-platform
        vm-live-migration vm-suicide)
   add_executable       (${x}  EXCLUDE_FROM_ALL ${x}/${x}.cpp)
   target_link_libraries(${x}  simgrid)
@@ -34,7 +35,7 @@ foreach(x actor actor-autorestart actor-suspend
 endforeach()
 
 foreach(x basic-link-test basic-parsing-test host-on-off host-on-off-actors host-on-off-recv is-router listen_async 
-               pid storage_client_server trace-integration)
+               pid storage_client_server trace-integration seal-platform)
   set(tesh_files    ${tesh_files}    ${CMAKE_CURRENT_SOURCE_DIR}/${x}/${x}.tesh)
   ADD_TESH(tesh-s4u-${x} --setenv srcdir=${CMAKE_HOME_DIRECTORY}/teshsuite/s4u/${x} --setenv platfdir=${CMAKE_HOME_DIRECTORY}/examples/platforms --cd ${CMAKE_BINARY_DIR}/teshsuite/s4u/${x} ${CMAKE_HOME_DIRECTORY}/teshsuite/s4u/${x}/${x}.tesh)
 endforeach()
diff --git a/teshsuite/s4u/seal-platform/seal-platform.cpp b/teshsuite/s4u/seal-platform/seal-platform.cpp
new file mode 100644 (file)
index 0000000..a91e452
--- /dev/null
@@ -0,0 +1,104 @@
+/* Copyright (c) 2010-2021. The SimGrid Team. All rights reserved.          */
+
+/* This program is free software; you can redistribute it and/or modify it
+ * under the terms of the license (GNU LGPL) which comes with this package. */
+
+#include "simgrid/s4u.hpp"
+namespace sg4 = simgrid::s4u;
+
+XBT_LOG_NEW_DEFAULT_CATEGORY(s4u_torus_multicpu, "Messages specific for this s4u example");
+
+class Sender {
+  long msg_size = 1e6; /* message size in bytes */
+  std::vector<sg4::Host*> hosts_;
+
+public:
+  explicit Sender(const std::vector<sg4::Host*>& hosts) : hosts_{hosts} {}
+  void operator()() const
+  {
+    /* Vector in which we store all ongoing communications */
+    std::vector<sg4::CommPtr> pending_comms;
+    /* Make a vector of the mailboxes to use */
+    std::vector<sg4::Mailbox*> mboxes;
+
+    std::string msg_content =
+        std::string("Hello, I'm alive and running on ") + std::string(sg4::this_actor::get_host()->get_name());
+    for (const auto* host : hosts_) {
+      auto* payload = new std::string(msg_content);
+      /* Create a communication representing the ongoing communication, and store it in pending_comms */
+      auto mbox = sg4::Mailbox::by_name(host->get_name());
+      mboxes.push_back(mbox);
+      sg4::CommPtr comm = mbox->put_async(payload, msg_size);
+      pending_comms.push_back(comm);
+    }
+
+    XBT_INFO("Done dispatching all messages");
+
+    /* Now that all message exchanges were initiated, wait for their completion in one single call */
+    sg4::Comm::wait_all(&pending_comms);
+
+    XBT_INFO("Goodbye now!");
+  }
+};
+
+/* Receiver actor: wait for 1 message on the mailbox identified by the hostname */
+class Receiver {
+public:
+  void operator()() const
+  {
+    auto mbox     = sg4::Mailbox::by_name(sg4::this_actor::get_host()->get_name());
+    auto comm     = mbox->get_init();
+    auto received = mbox->get_unique<std::string>();
+    XBT_INFO("I got a '%s'.", received->c_str());
+
+    sg4::Disk* disk      = sg4::Host::current()->get_disks().front();
+    sg_size_t write_size = disk->write(4e6);
+    XBT_INFO("Wrote %llu bytes on '%s'", write_size, disk->get_cname());
+  }
+};
+
+/*************************************************************************************************/
+static sg4::NetZone* create_zone(sg4::NetZone* root, const std::string& id)
+{
+  auto* zone = sg4::create_floyd_zone(id);
+  zone->set_parent(root);
+  constexpr int n_host = 2;
+
+  auto* router = zone->create_router("router" + id);
+  for (int i = 0; i < n_host; i++) {
+    std::string hostname = id + "-cpu-" + std::to_string(i);
+    auto* host           = zone->create_host(hostname, 1e9);
+    host->create_disk("disk-" + hostname, 1e9, 1e6);
+    auto* link = zone->create_link("link-" + hostname, 1e9);
+    zone->add_route(host->get_netpoint(), router, nullptr, nullptr, std::vector<sg4::Link*>{link});
+  }
+  return zone;
+}
+
+/*************************************************************************************************/
+
+int main(int argc, char* argv[])
+{
+  sg4::Engine e(&argc, argv);
+
+  /* create platform: intentionally do not do the seal of objects */
+  auto* root  = sg4::create_full_zone("root");
+  auto* zoneA = create_zone(root, "A");
+  auto* zoneB = create_zone(root, "B");
+  auto* link  = root->create_link("root-link", 1e10);
+  root->add_route(zoneA->get_netpoint(), zoneB->get_netpoint(), e.netpoint_by_name("routerA"),
+                  e.netpoint_by_name("routerB"), std::vector<sg4::Link*>{link});
+
+  std::vector<sg4::Host*> host_list = e.get_all_hosts();
+  /* create the sender actor running on first host */
+  sg4::Actor::create("sender", host_list[0], Sender(host_list));
+  /* create receiver in every host */
+  for (auto* host : host_list) {
+    sg4::Actor::create(std::string("receiver-") + std::string(host->get_name()), host, Receiver());
+  }
+
+  /* runs the simulation */
+  e.run();
+
+  return 0;
+}
diff --git a/teshsuite/s4u/seal-platform/seal-platform.tesh b/teshsuite/s4u/seal-platform/seal-platform.tesh
new file mode 100644 (file)
index 0000000..11ea6df
--- /dev/null
@@ -0,0 +1,11 @@
+$ ./seal-platform
+> [A-cpu-0:sender:(1) 0.000000] [s4u_torus_multicpu/INFO] Done dispatching all messages
+> [A-cpu-0:receiver-A-cpu-0:(2) 0.000103] [s4u_torus_multicpu/INFO] I got a 'Hello, I'm alive and running on A-cpu-0'.
+> [B-cpu-1:receiver-B-cpu-1:(5) 0.003247] [s4u_torus_multicpu/INFO] I got a 'Hello, I'm alive and running on A-cpu-0'.
+> [B-cpu-0:receiver-B-cpu-0:(4) 0.003247] [s4u_torus_multicpu/INFO] I got a 'Hello, I'm alive and running on A-cpu-0'.
+> [A-cpu-1:receiver-A-cpu-1:(3) 0.003247] [s4u_torus_multicpu/INFO] I got a 'Hello, I'm alive and running on A-cpu-0'.
+> [A-cpu-0:sender:(1) 0.003247] [s4u_torus_multicpu/INFO] Goodbye now!
+> [A-cpu-0:receiver-A-cpu-0:(2) 4.000103] [s4u_torus_multicpu/INFO] Wrote 4000000 bytes on 'disk-A-cpu-0'
+> [B-cpu-1:receiver-B-cpu-1:(5) 4.003247] [s4u_torus_multicpu/INFO] Wrote 4000000 bytes on 'disk-B-cpu-1'
+> [B-cpu-0:receiver-B-cpu-0:(4) 4.003247] [s4u_torus_multicpu/INFO] Wrote 4000000 bytes on 'disk-B-cpu-0'
+> [A-cpu-1:receiver-A-cpu-1:(3) 4.003247] [s4u_torus_multicpu/INFO] Wrote 4000000 bytes on 'disk-A-cpu-1'