Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Try to please sonar
authorBruno Donassolo <bruno.donassolo@inria.fr>
Mon, 26 Apr 2021 16:51:22 +0000 (18:51 +0200)
committerBruno Donassolo <bruno.donassolo@inria.fr>
Mon, 26 Apr 2021 16:51:22 +0000 (18:51 +0200)
examples/cpp/torus-multicpu/s4u-torus-multicpu.cpp
include/simgrid/s4u/NetZone.hpp
src/kernel/routing/TorusZone.cpp
src/kernel/routing/TorusZone_test.cpp

index 6aa306b..65d192e 100644 (file)
@@ -56,7 +56,7 @@ public:
 /* Receiver actor: wait for 1 message on the mailbox identified by the hostname */
 class Receiver {
 public:
-  void operator()()
+  void operator()() const
   {
     auto mbox     = sg4::Mailbox::by_name(sg4::this_actor::get_host()->get_name());
     auto received = mbox->get_unique<std::string>();
@@ -88,7 +88,7 @@ public:
  * @return netpoint, gateway: the netpoint to the StarZone and CPU0 as gateway
  */
 static std::pair<simgrid::kernel::routing::NetPoint*, simgrid::kernel::routing::NetPoint*>
-create_hostzone(sg4::NetZone* zone, const std::vector<unsigned int>& coord, int id)
+create_hostzone(const sg4::NetZone* zone, const std::vector<unsigned int>& /*coord*/, int id)
 {
   constexpr int num_cpus    = 8;     //!< Number of CPUs in the zone
   constexpr double speed    = 1e9;   //!< Speed of each CPU
@@ -101,7 +101,7 @@ create_hostzone(sg4::NetZone* zone, const std::vector<unsigned int>& coord, int
   /* setting my Torus parent zone */
   host_zone->set_parent(zone);
 
-  sg4::Host* gateway = nullptr;
+  const sg4::Host* gateway = nullptr;
   /* create CPUs */
   for (int i = 0; i < num_cpus; i++) {
     std::string cpu_name = hostname + "-cpu" + std::to_string(i);
@@ -157,7 +157,7 @@ create_hostzone(sg4::NetZone* zone, const std::vector<unsigned int>& coord, int
 static void create_torus_cluster()
 {
   // Callback to create limiter link (1Gbs) for each host
-  auto create_limiter = [](sg4::NetZone* zone, const std::vector<unsigned int>& coord, int id) -> sg4::Link* {
+  auto create_limiter = [](sg4::NetZone* zone, const std::vector<unsigned int>& /*coord*/, int id) -> sg4::Link* {
     return zone->create_link("limiter-" + std::to_string(id), 1e9)->seal();
   };
 
index eef4025..0ed4bfc 100644 (file)
@@ -164,8 +164,8 @@ XBT_PUBLIC NetZone* create_floyd_zone(const std::string& name);
  * @param id: Internal identifier of the element
  * @return pair<NetPoint*, NetPoint*>: returns a pair of netpoint and gateway.
  */
-typedef std::pair<kernel::routing::NetPoint*, kernel::routing::NetPoint*>
-TorusNetPointCb(NetZone* zone, const std::vector<unsigned int>& coord, int id);
+using TorusNetPointCb = std::pair<kernel::routing::NetPoint*, kernel::routing::NetPoint*>(
+    NetZone* zone, const std::vector<unsigned int>& coord, int id);
 /**
  * @brief Callback used to set the links for some leaf of the torus
  *
@@ -174,7 +174,7 @@ TorusNetPointCb(NetZone* zone, const std::vector<unsigned int>& coord, int id);
  * @param id: Internal identifier of the element
  * @return Pointer to the Link
  */
-typedef Link* TorusLinkCb(NetZone* zone, const std::vector<unsigned int>& coord, int id);
+using TorusLinkCb = Link*(NetZone* zone, const std::vector<unsigned int>& coord, int id);
 /**
  * @brief Create a torus zone
  *
index 4aa65f7..f11a739 100644 (file)
@@ -193,20 +193,20 @@ void TorusZone::get_local_route(NetPoint* src, NetPoint* dst, RouteCreationArgs*
 /** @brief Auxiliary function to create hosts */
 static std::pair<kernel::routing::NetPoint*, kernel::routing::NetPoint*>
 create_torus_host(const kernel::routing::ClusterCreationArgs* cluster, s4u::NetZone* zone,
-                  const std::vector<unsigned int>& coord, int id)
+                  const std::vector<unsigned int>& /*coord*/, int id)
 {
   std::string host_id = std::string(cluster->prefix) + std::to_string(id) + cluster->suffix;
   XBT_DEBUG("TorusCluster: creating host=%s speed=%f", host_id.c_str(), cluster->speeds.front());
-  s4u::Host* host = zone->create_host(host_id, cluster->speeds)
-                        ->set_core_count(cluster->core_amount)
-                        ->set_properties(cluster->properties)
-                        ->seal();
+  const s4u::Host* host = zone->create_host(host_id, cluster->speeds)
+                              ->set_core_count(cluster->core_amount)
+                              ->set_properties(cluster->properties)
+                              ->seal();
   return std::make_pair(host->get_netpoint(), nullptr);
 }
 
 /** @brief Auxiliary function to create loopback links */
 static s4u::Link* create_torus_loopback(const kernel::routing::ClusterCreationArgs* cluster, s4u::NetZone* zone,
-                                        const std::vector<unsigned int>& coord, int id)
+                                        const std::vector<unsigned int>& /*coord*/, int id)
 {
   std::string link_id = std::string(cluster->id) + "_link_" + std::to_string(id) + "_loopback";
   XBT_DEBUG("TorusCluster: creating loopback link=%s bw=%f", link_id.c_str(), cluster->loopback_bw);
@@ -220,7 +220,7 @@ static s4u::Link* create_torus_loopback(const kernel::routing::ClusterCreationAr
 
 /** @brief Auxiliary function to create limiter links */
 static s4u::Link* create_torus_limiter(const kernel::routing::ClusterCreationArgs* cluster, s4u::NetZone* zone,
-                                       const std::vector<unsigned int>& coord, int id)
+                                       const std::vector<unsigned int>& /*coord*/, int id)
 {
   std::string link_id = std::string(cluster->id) + "_link_" + std::to_string(id) + "_limiter";
   XBT_DEBUG("TorusCluster: creating limiter link=%s bw=%f", link_id.c_str(), cluster->limiter_link);
@@ -274,10 +274,13 @@ NetZone* create_torus_zone(const std::string& name, const NetZone* parent, const
   // auxiliary function to get dims from index
   auto index_to_dims = [&dimensions](int index) {
     std::vector<unsigned int> dims_array(dimensions.size());
-    for (int i = dimensions.size() - 1; i >= 0 && index > 0; --i) {
+    for (unsigned long i = dimensions.size() - 1; i != 0; --i) {
+      if (index <= 0) {
+        break;
+      }
       unsigned int value = index % dimensions[i];
       dims_array[i]      = value;
-      index              = ((index / dimensions[i]));
+      index              = (index / dimensions[i]);
     }
     return dims_array;
   };
@@ -288,9 +291,10 @@ NetZone* create_torus_zone(const std::string& name, const NetZone* parent, const
     zone->set_parent(parent->get_impl());
 
   for (int i = 0; i < tot_elements; i++) {
-    kernel::routing::NetPoint *netpoint = nullptr, *gw = nullptr;
-    auto dims              = index_to_dims(i);
-    std::tie(netpoint, gw) = set_netpoint(zone->get_iface(), dims, i);
+    kernel::routing::NetPoint* netpoint = nullptr;
+    kernel::routing::NetPoint* gw       = nullptr;
+    auto dims                           = index_to_dims(i);
+    std::tie(netpoint, gw)              = set_netpoint(zone->get_iface(), dims, i);
     xbt_assert(netpoint, "TorusZone::set_netpoint(elem=%d): Invalid netpoint (nullptr)", i);
     if (netpoint->is_netzone()) {
       xbt_assert(gw && not gw->is_netzone(),
@@ -303,14 +307,14 @@ NetZone* create_torus_zone(const std::string& name, const NetZone* parent, const
     zone->set_gateway(i, gw);
 
     if (set_loopback) {
-      Link* loopback = set_loopback(zone->get_iface(), dims, i);
+      const Link* loopback = set_loopback(zone->get_iface(), dims, i);
       xbt_assert(loopback, "TorusZone::set_loopback: Invalid loopback link (nullptr) for element %d", i);
       zone->set_loopback();
       zone->add_private_link_at(zone->node_pos(netpoint->id()), {loopback->get_impl(), loopback->get_impl()});
     }
 
     if (set_limiter) {
-      Link* limiter = set_limiter(zone->get_iface(), dims, i);
+      const Link* limiter = set_limiter(zone->get_iface(), dims, i);
       xbt_assert(limiter, "TorusZone::set_limiter: Invalid limiter link (nullptr) for element %d", i);
       zone->set_limiter();
       zone->add_private_link_at(zone->node_pos_with_loopback(netpoint->id()),
index c741931..4bc09ca 100644 (file)
 #include "simgrid/s4u/Engine.hpp"
 #include "simgrid/s4u/Host.hpp"
 #include "simgrid/s4u/NetZone.hpp"
-#include "src/surf/network_interface.hpp"
-#include "src/surf/xml/platf_private.hpp" // RouteCreationArgs and friends
 
 namespace {
 class EngineWrapper {
+public:
+  explicit EngineWrapper(std::string name) : argv(&name[0]), e(&argc, &argv) {}
   int argc = 1;
   char* argv;
-
-public:
   simgrid::s4u::Engine e;
-  explicit EngineWrapper(std::string name) : argv(&name[0]), e(&argc, &argv) {}
 };
 
 std::pair<simgrid::kernel::routing::NetPoint*, simgrid::kernel::routing::NetPoint*>
-create_host(simgrid::s4u::NetZone* zone, const std::vector<unsigned int>& coord, int id)
+create_host(simgrid::s4u::NetZone* zone, const std::vector<unsigned int>& /*coord*/, int id)
 {
-  simgrid::s4u::Host* host = zone->create_host(std::to_string(id), 1e9)->seal();
+  const simgrid::s4u::Host* host = zone->create_host(std::to_string(id), 1e9)->seal();
   return std::make_pair(host->get_netpoint(), nullptr);
 }
 } // namespace
@@ -35,11 +32,6 @@ TEST_CASE("kernel::routing::TorusZone: Creating Zone", "")
 {
   using namespace simgrid::s4u;
   EngineWrapper e("test");
-  auto create_host = [](NetZone* zone, const std::vector<unsigned int>& coord,
-                        int id) -> std::pair<simgrid::kernel::routing::NetPoint*, simgrid::kernel::routing::NetPoint*> {
-    Host* host = zone->create_host(std::to_string(id), 1e9)->seal();
-    return std::make_pair(host->get_netpoint(), nullptr);
-  };
   REQUIRE(create_torus_zone("test", e.e.get_netzone_root(), {3, 3, 3}, 1e9, 10,
                             simgrid::s4u::Link::SharingPolicy::SHARED, create_host));
 }