Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Sanitize the network_model->communicate() API
authorMartin Quinson <martin.quinson@loria.fr>
Fri, 14 Oct 2016 21:23:57 +0000 (23:23 +0200)
committerMartin Quinson <martin.quinson@loria.fr>
Fri, 14 Oct 2016 21:23:57 +0000 (23:23 +0200)
- use s4u::Host instead of netcards in the API
- kill remaining C bits
- (+ clang-format in action)

15 files changed:
src/include/surf/surf.h
src/simix/smx_network.cpp
src/surf/HostImpl.cpp
src/surf/network_cm02.cpp
src/surf/network_cm02.hpp
src/surf/network_constant.cpp
src/surf/network_constant.hpp
src/surf/network_ib.cpp
src/surf/network_interface.cpp
src/surf/network_interface.hpp
src/surf/ptask_L07.cpp
src/surf/ptask_L07.hpp
src/surf/surf_c_bindings.cpp
teshsuite/surf/surf_usage/surf_usage.cpp
teshsuite/surf/surf_usage2/surf_usage2.cpp

index ea2b4bd..0370873 100644 (file)
@@ -192,17 +192,6 @@ XBT_PUBLIC(surf_action_t) surf_model_extract_failed_action_set(surf_model_t mode
  */
 XBT_PUBLIC(int) surf_model_running_action_set_size(surf_model_t model);
 
-/** @brief Create a communication between two hosts
- *
- * @param model The model which handle the communication
- * @param src The source host
- * @param dst The destination host
- * @param size The amount of data (in bytes) needed to transfer
- * @param rate [description]
- * @return The action corresponding to the communication
- */
-XBT_PUBLIC(surf_action_t) surf_network_model_communicate(surf_network_model_t model, sg_host_t src, sg_host_t dst, double size, double rate);
-
 /** @brief Create a sleep action on the given host */
 XBT_PUBLIC(surf_action_t) surf_host_sleep(sg_host_t host, double duration);
 
index 0edf57d..70ad4ac 100644 (file)
@@ -20,6 +20,7 @@
 #include "simgrid/s4u/Mailbox.hpp"
 
 #include "src/kernel/activity/SynchroComm.hpp"
+#include "src/surf/network_interface.hpp"
 
 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(simix_network, simix, "SIMIX network-related synchronization");
 
@@ -546,7 +547,7 @@ static inline void SIMIX_comm_start(smx_activity_t synchro)
 
     XBT_DEBUG("Starting communication %p from '%s' to '%s'", synchro, sg_host_get_name(sender), sg_host_get_name(receiver));
 
-    comm->surf_comm = surf_network_model_communicate(surf_network_model, sender, receiver, comm->task_size, comm->rate);
+    comm->surf_comm = surf_network_model->communicate(sender, receiver, comm->task_size, comm->rate);
     comm->surf_comm->setData(synchro);
     comm->state = SIMIX_RUNNING;
 
index cb08a98..3176374 100644 (file)
@@ -80,9 +80,7 @@ Action *HostModel::executeParallelTask(int host_nb,
     action = host_list[0]->pimpl_cpu->execution_start(flops_amount[0]);
   } else if ((host_nb == 1)
            && (cost_or_zero(flops_amount, 0) == 0.0)) {
-    action = surf_network_model->communicate(host_list[0]->pimpl_netcard,
-                                         host_list[0]->pimpl_netcard,
-                       bytes_amount[0], rate);
+    action = surf_network_model->communicate(host_list[0], host_list[0], bytes_amount[0], rate);
   } else if ((host_nb == 2)
              && (cost_or_zero(flops_amount, 0) == 0.0)
              && (cost_or_zero(flops_amount, 1) == 0.0)) {
@@ -96,7 +94,7 @@ Action *HostModel::executeParallelTask(int host_nb,
       }
     }
     if (nb == 1) {
-      action = surf_network_model->communicate(host_list[0]->pimpl_netcard, host_list[1]->pimpl_netcard, value, rate);
+      action = surf_network_model->communicate(host_list[0], host_list[1], value, rate);
     } else if (nb == 0) {
        xbt_die("Cannot have a communication with no flop to exchange in this model. You should consider using the ptask model");
     } else {       
index 91a4622..8dc9d2b 100644 (file)
@@ -6,8 +6,9 @@
 
 #include <algorithm>
 
-#include "network_cm02.hpp"
 #include "maxmin_private.hpp"
+#include "network_cm02.hpp"
+#include "simgrid/s4u/host.hpp"
 #include "simgrid/sg_config.h"
 #include "src/instr/instr_private.h" // TRACE_is_enabled(). FIXME: remove by subscribing tracing to the surf signals
 
@@ -285,8 +286,7 @@ void NetworkCm02Model::updateActionsStateFull(double now, double delta)
   }
 }
 
-Action *NetworkCm02Model::communicate(kernel::routing::NetCard *src, kernel::routing::NetCard *dst,
-    double size, double rate)
+Action* NetworkCm02Model::communicate(s4u::Host* src, s4u::Host* dst, double size, double rate)
 {
   int failed = 0;
   double bandwidth_bound;
@@ -296,12 +296,12 @@ Action *NetworkCm02Model::communicate(kernel::routing::NetCard *src, kernel::rou
 
   std::vector<Link*> *route = new std::vector<Link*>();
 
-  XBT_IN("(%s,%s,%g,%g)", src->name(), dst->name(), size, rate);
+  XBT_IN("(%s,%s,%g,%g)", src->name().c_str(), dst->name().c_str(), size, rate);
 
-  routing_platf->getRouteAndLatency(src, dst, route, &latency);
-  xbt_assert(! route->empty() || latency,
+  routing_platf->getRouteAndLatency(src->pimpl_netcard, dst->pimpl_netcard, route, &latency);
+  xbt_assert(!route->empty() || latency,
              "You're trying to send data from %s to %s but there is no connecting path between these two hosts.",
-             src->name(), dst->name());
+             src->name().c_str(), dst->name().c_str());
 
   for (auto link: *route)
     if (link->isOff())
@@ -309,7 +309,7 @@ Action *NetworkCm02Model::communicate(kernel::routing::NetCard *src, kernel::rou
 
   if (sg_network_crosstraffic == 1) {
     back_route = new std::vector<Link*>();
-    routing_platf->getRouteAndLatency(dst, src, back_route, nullptr);
+    routing_platf->getRouteAndLatency(dst->pimpl_netcard, src->pimpl_netcard, back_route, nullptr);
     for (auto link: *back_route)
       if (link->isOff())
         failed = 1;
@@ -342,7 +342,8 @@ Action *NetworkCm02Model::communicate(kernel::routing::NetCard *src, kernel::rou
                "Using a model with a gap (e.g., SMPI) with a platform without links (e.g. vivaldi)!!!");
 
     gapAppend(size, route->at(0), action);
-    XBT_DEBUG("Comm %p: %s -> %s gap=%f (lat=%f)", action, src->name(), dst->name(), action->senderGap_, action->latency_);
+    XBT_DEBUG("Comm %p: %s -> %s gap=%f (lat=%f)", action, src->name().c_str(), dst->name().c_str(), action->senderGap_,
+              action->latency_);
   }
 
   constraints_per_variable = route->size();
index 346b1ab..41a679e 100644 (file)
@@ -45,7 +45,7 @@ namespace simgrid {
           xbt_dict_t properties) override;
       void updateActionsStateLazy(double now, double delta) override;
       void updateActionsStateFull(double now, double delta) override;
-      Action *communicate(kernel::routing::NetCard *src, kernel::routing::NetCard *dst, double size, double rate) override;
+      Action* communicate(s4u::Host* src, s4u::Host* dst, double size, double rate) override;
       virtual void gapAppend(double size, const Link* link, NetworkAction* action);
     protected:
       bool haveGap_ = false;
@@ -72,7 +72,7 @@ namespace simgrid {
      * Action *
      **********/
     class NetworkCm02Action : public NetworkAction {
-      friend Action *NetworkCm02Model::communicate(kernel::routing::NetCard *src, kernel::routing::NetCard *dst, double size, double rate);
+      friend Action* NetworkCm02Model::communicate(s4u::Host* src, s4u::Host* dst, double size, double rate);
       friend NetworkSmpiModel;
     public:
       NetworkCm02Action(Model *model, double cost, bool failed)
index 74c1678..2da4340 100644 (file)
@@ -77,7 +77,7 @@ namespace simgrid {
       }
     }
 
-    Action *NetworkConstantModel::communicate(kernel::routing::NetCard *src, kernel::routing::NetCard *dst, double size, double rate)
+    Action* NetworkConstantModel::communicate(s4u::Host* src, s4u::Host* dst, double size, double rate)
     {
       NetworkConstantAction *action = new NetworkConstantAction(this, size, sg_latency_factor);
 
index e0d7d7d..36782df 100644 (file)
@@ -29,7 +29,7 @@ namespace simgrid {
       NetworkConstantModel()  : NetworkModel() { };
       ~NetworkConstantModel() override;
 
-      Action *communicate(kernel::routing::NetCard *src, kernel::routing::NetCard *dst, double size, double rate) override;
+      Action* communicate(simgrid::s4u::Host* src, simgrid::s4u::Host* dst, double size, double rate) override;
       double nextOccuringEvent(double now) override;
       void updateActionsState(double now, double delta) override;
 
index 2c170bb..1d84616 100644 (file)
@@ -49,16 +49,17 @@ static void IB_action_state_changed_callback(
 
 }
 
-
-static void IB_action_init_callback(
-    simgrid::surf::NetworkAction *action, simgrid::kernel::routing::NetCard *src, simgrid::kernel::routing::NetCard *dst)
+static void IB_action_init_callback(simgrid::surf::NetworkAction* action, simgrid::s4u::Host* src,
+                                    simgrid::s4u::Host* dst)
 {
   simgrid::surf::NetworkIBModel* ibModel = (simgrid::surf::NetworkIBModel*)surf_network_model;
 
-  simgrid::surf::IBNode* act_src= (simgrid::surf::IBNode*) xbt_dict_get_or_null(ibModel->active_nodes, src->name());
+  simgrid::surf::IBNode* act_src =
+      (simgrid::surf::IBNode*)xbt_dict_get_or_null(ibModel->active_nodes, src->name().c_str());
   xbt_assert(act_src, "could not find src node active comms !");
 
-  simgrid::surf::IBNode* act_dst= (simgrid::surf::IBNode*) xbt_dict_get_or_null(ibModel->active_nodes, dst->name());
+  simgrid::surf::IBNode* act_dst =
+      (simgrid::surf::IBNode*)xbt_dict_get_or_null(ibModel->active_nodes, dst->name().c_str());
   xbt_assert(act_dst, "could not find dst node active comms !");
 
   ibModel->active_comms[action]=std::make_pair(act_src, act_dst);
index 9100fea..b1b8495 100644 (file)
@@ -96,8 +96,7 @@ namespace simgrid {
     simgrid::xbt::signal<void(Link*)> Link::onStateChange;
 
     simgrid::xbt::signal<void(NetworkAction*, Action::State, Action::State)> networkActionStateChangedCallbacks;
-    simgrid::xbt::signal<void(NetworkAction*, kernel::routing::NetCard *src, kernel::routing::NetCard *dst)> Link::onCommunicate;
-
+    simgrid::xbt::signal<void(NetworkAction*, s4u::Host* src, s4u::Host* dst)> Link::onCommunicate;
   }
 }
 
index c84b48f..40fe146 100644 (file)
@@ -77,7 +77,7 @@ namespace simgrid {
        * unlimited.
        * @return The action representing the communication
        */
-      virtual Action *communicate(kernel::routing::NetCard *src, kernel::routing::NetCard *dst, double size, double rate)=0;
+      virtual Action* communicate(simgrid::s4u::Host* src, simgrid::s4u::Host* dst, double size, double rate) = 0;
 
       /** @brief Function pointer to the function to use to solve the lmm_system_t
        *
@@ -162,10 +162,8 @@ namespace simgrid {
       static simgrid::xbt::signal<void(surf::Link*)> onStateChange;
 
       /** @brief Callback signal fired when a communication starts
-       *  Signature: `void(NetworkAction *action, RoutingEdge *src, RoutingEdge *dst)` */
-      static simgrid::xbt::signal<void(surf::NetworkAction*, kernel::routing::NetCard *src, kernel::routing::NetCard *dst)> onCommunicate;
-
-
+       *  Signature: `void(NetworkAction *action, host *src, host *dst)` */
+      static simgrid::xbt::signal<void(surf::NetworkAction*, s4u::Host* src, s4u::Host* dst)> onCommunicate;
 
       /** @brief Get the bandwidth in bytes per second of current Link */
       virtual double getBandwidth();
index 2081084..048d55d 100644 (file)
@@ -239,14 +239,14 @@ L07Action::L07Action(Model *model, int host_nb, sg_host_t *host_list,
   xbt_free(host_list);
 }
 
-Action *NetworkL07Model::communicate(kernel::routing::NetCard *src, kernel::routing::NetCard *dst, double size, double rate)
+Action* NetworkL07Model::communicate(s4u::Host* src, s4u::Host* dst, double size, double rate)
 {
   sg_host_t*host_list = xbt_new0(sg_host_t, 2);
   double *flops_amount = xbt_new0(double, 2);
   double *bytes_amount = xbt_new0(double, 4);
 
-  host_list[0] = sg_host_by_name(src->name());
-  host_list[1] = sg_host_by_name(dst->name());
+  host_list[0]    = src;
+  host_list[1]    = dst;
   bytes_amount[1] = size;
 
   return hostModel_->executeParallelTask(2, host_list, flops_amount, bytes_amount, rate);
index c03c0b1..e1aa4bb 100644 (file)
@@ -62,7 +62,7 @@ public:
       e_surf_link_sharing_policy_t policy,
       xbt_dict_t properties) override;
 
-  Action *communicate(kernel::routing::NetCard *src, kernel::routing::NetCard *dst, double size, double rate) override;
+  Action* communicate(s4u::Host* src, s4u::Host* dst, double size, double rate) override;
 
   HostL07Model *hostModel_;
 };
index a18cf79..5ff85aa 100644 (file)
@@ -176,10 +176,6 @@ int surf_model_running_action_set_size(surf_model_t model){
   return model->getRunningActionSet()->size();
 }
 
-surf_action_t surf_network_model_communicate(surf_network_model_t model, sg_host_t src, sg_host_t dst, double size, double rate){
-  return model->communicate(src->pimpl_netcard, dst->pimpl_netcard, size, rate);
-}
-
 surf_action_t surf_host_sleep(sg_host_t host, double duration){
   return host->pimpl_cpu->sleep(duration);
 }
index 75ffa7c..6a2fd3f 100644 (file)
@@ -1,18 +1,17 @@
 /* A few basic tests for the surf library                                   */
 
-/* Copyright (c) 2004-2015. The SimGrid Team.
- * All rights reserved.                                                     */
+/* Copyright (c) 2004-2015. 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 <stdio.h>
-#include "simgrid/sg_config.h"
-#include "simgrid/host.h"
 #include "surf/surf.h"
-#include "src/surf/surf_interface.hpp"
+#include "simgrid/s4u/host.hpp"
+#include "simgrid/sg_config.h"
 #include "src/surf/cpu_interface.hpp"
 #include "src/surf/network_interface.hpp"
+#include "src/surf/surf_interface.hpp"
+#include <stdio.h>
 
 #include "xbt/log.h"
 XBT_LOG_NEW_DEFAULT_CATEGORY(surf_test, "Messages specific for surf example");
@@ -71,7 +70,7 @@ int main(int argc, char **argv)
 
 
   /* Let's do something on it */
-  surf_network_model_communicate(surf_network_model, hostA, hostB, 150.0, -1.0);
+  surf_network_model->communicate(hostA, hostB, 150.0, -1.0);
 
   surf_solve(-1.0);
   do {
index f849953..b4467d2 100644 (file)
@@ -1,24 +1,22 @@
 /* A few basic tests for the surf library                                   */
 
-/* Copyright (c) 2004-2015. The SimGrid Team.
- * All rights reserved.                                                     */
+/* Copyright (c) 2004-2015. 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/sg_config.h"
-#include "simgrid/host.h"
 #include "surf/surf.h"
-#include "src/surf/surf_interface.hpp"
+#include "simgrid/s4u/host.hpp"
+#include "simgrid/sg_config.h"
 #include "src/surf/cpu_interface.hpp"
+#include "src/surf/network_interface.hpp"
+#include "src/surf/surf_interface.hpp"
 
 #include "xbt/log.h"
 XBT_LOG_NEW_DEFAULT_CATEGORY(surf_test, "Messages specific for surf example");
 
 int main(int argc, char **argv)
 {
-  sg_host_t hostA = nullptr;
-  sg_host_t hostB = nullptr;
   double now = -1.0;
   int running;
 
@@ -31,8 +29,8 @@ int main(int argc, char **argv)
   parse_platform_file(argv[1]);
 
   /*********************** HOST ***********************************/
-  hostA = sg_host_by_name("Cpu A");
-  hostB = sg_host_by_name("Cpu B");
+  sg_host_t hostA = sg_host_by_name("Cpu A");
+  sg_host_t hostB = sg_host_by_name("Cpu B");
 
   /* Let's check that those two processors exist */
   XBT_DEBUG("%s : %p", sg_host_get_name(hostA), hostA);
@@ -43,7 +41,7 @@ int main(int argc, char **argv)
   hostB->pimpl_cpu->execution_start(1000.0);
   surf_host_sleep(hostB, 7.32);
 
-  surf_network_model_communicate(surf_network_model, hostA, hostB, 150.0, -1.0);
+  surf_network_model->communicate(hostA, hostB, 150.0, -1.0);
 
   surf_solve(-1.0);                 /* Takes traces into account. Returns 0.0 */
   do {