Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Allow to set the network factors callback from userland w/o relying on NetworkModelIntf
authorMartin Quinson <martin.quinson@ens-rennes.fr>
Sun, 23 Oct 2022 19:57:59 +0000 (21:57 +0200)
committerMartin Quinson <martin.quinson@ens-rennes.fr>
Sun, 23 Oct 2022 19:58:04 +0000 (21:58 +0200)
- this file is soon private, as the other kernel headers
- this was missing a simcall anyway

examples/cpp/network-factors/s4u-network-factors.cpp
include/simgrid/s4u/NetZone.hpp
src/s4u/s4u_Netzone.cpp

index 4eca7b8..abeeab7 100644 (file)
@@ -3,20 +3,18 @@
 /* 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. */
 
-/* This example shows how to build set customized communication factors
+/* This example shows how to build set custom communication factors
  *
- * It uses the interface provided by NetworkModelIntf to register 2 callbacks that
- * are called everytime a communication occurs.
+ * It uses the netzone interface to register 2 callbacks that are called for every communications.
  *
  * These factors are used to change the communication time depending on the message size
  * and destination.
  *
  * This example uses factors obtained by some experiments on dahu cluster in Grid'5000.
- * You must change the values according to the calibration of your enviroment.
+ * You should change the values according to the calibration of your enviroment.
  */
 
 #include <map>
-#include <simgrid/kernel/resource/NetworkModelIntf.hpp>
 #include <simgrid/s4u.hpp>
 namespace sg4 = simgrid::s4u;
 
@@ -232,9 +230,8 @@ int main(int argc, char* argv[])
   /* create platform */
   load_platform();
   /* setting network factors callbacks */
-  simgrid::kernel::resource::NetworkModelIntf* model = e.get_netzone_root()->get_network_model();
-  model->set_lat_factor_cb(latency_factor_cb);
-  model->set_bw_factor_cb(bandwidth_factor_cb);
+  e.get_netzone_root()->set_latency_factor_cb(latency_factor_cb);
+  e.get_netzone_root()->set_bandwidth_factor_cb(bandwidth_factor_cb);
 
   sg4::Host* host        = e.host_by_name("dahu-1.grid5000.fr");
   sg4::Host* host_remote = e.host_by_name("dahu-10.grid5000.fr");
index e974320..361cf4f 100644 (file)
@@ -14,6 +14,7 @@
 #include <map>
 #include <string>
 #include <unordered_map>
+#include <unordered_set>
 #include <utility>
 #include <vector>
 
@@ -153,6 +154,13 @@ public:
 
   /** @brief Seal this netzone configuration */
   NetZone* seal();
+
+  void set_latency_factor_cb(std::function<double(double size, const s4u::Host* src, const s4u::Host* dst,
+                                                  const std::vector<s4u::Link*>& /*links*/,
+                                                  const std::unordered_set<s4u::NetZone*>& /*netzones*/)> const& cb);
+  void set_bandwidth_factor_cb(std::function<double(double size, const s4u::Host* src, const s4u::Host* dst,
+                                                    const std::vector<s4u::Link*>& /*links*/,
+                                                    const std::unordered_set<s4u::NetZone*>& /*netzones*/)> const& cb);
 };
 
 // External constructors so that the types (and the types of their content) remain hidden
index bd00dc9..ec5b427 100644 (file)
@@ -113,6 +113,20 @@ NetZone* NetZone::seal()
   kernel::actor::simcall_answered([this] { pimpl_->seal(); });
   return this;
 }
+void NetZone::set_latency_factor_cb(
+    std::function<double(double size, const s4u::Host* src, const s4u::Host* dst,
+                         const std::vector<s4u::Link*>& /*links*/,
+                         const std::unordered_set<s4u::NetZone*>& /*netzones*/)> const& cb)
+{
+  kernel::actor::simcall_answered([this, &cb]() { pimpl_->get_network_model()->set_lat_factor_cb(cb); });
+}
+void NetZone::set_bandwidth_factor_cb(
+    std::function<double(double size, const s4u::Host* src, const s4u::Host* dst,
+                         const std::vector<s4u::Link*>& /*links*/,
+                         const std::unordered_set<s4u::NetZone*>& /*netzones*/)> const& cb)
+{
+  kernel::actor::simcall_answered([this, &cb]() { pimpl_->get_network_model()->set_bw_factor_cb(cb); });
+}
 
 s4u::Host* NetZone::create_host(const std::string& name, double speed)
 {