From: Martin Quinson Date: Fri, 14 Oct 2016 21:23:57 +0000 (+0200) Subject: Sanitize the network_model->communicate() API X-Git-Tag: v3_14~336 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/6aff24ba47ceab30e29e122dc36c33995e6fc2dd Sanitize the network_model->communicate() API - use s4u::Host instead of netcards in the API - kill remaining C bits - (+ clang-format in action) --- diff --git a/src/include/surf/surf.h b/src/include/surf/surf.h index ea2b4bdcfa..0370873e62 100644 --- a/src/include/surf/surf.h +++ b/src/include/surf/surf.h @@ -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); diff --git a/src/simix/smx_network.cpp b/src/simix/smx_network.cpp index 0edf57d08f..70ad4acab0 100644 --- a/src/simix/smx_network.cpp +++ b/src/simix/smx_network.cpp @@ -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; diff --git a/src/surf/HostImpl.cpp b/src/surf/HostImpl.cpp index cb08a983fe..31763746b6 100644 --- a/src/surf/HostImpl.cpp +++ b/src/surf/HostImpl.cpp @@ -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 { diff --git a/src/surf/network_cm02.cpp b/src/surf/network_cm02.cpp index 91a4622f8d..8dc9d2bd3c 100644 --- a/src/surf/network_cm02.cpp +++ b/src/surf/network_cm02.cpp @@ -6,8 +6,9 @@ #include -#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 *route = new std::vector(); - 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(); - 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(); diff --git a/src/surf/network_cm02.hpp b/src/surf/network_cm02.hpp index 346b1abbf3..41a679ee6f 100644 --- a/src/surf/network_cm02.hpp +++ b/src/surf/network_cm02.hpp @@ -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) diff --git a/src/surf/network_constant.cpp b/src/surf/network_constant.cpp index 74c1678609..2da4340862 100644 --- a/src/surf/network_constant.cpp +++ b/src/surf/network_constant.cpp @@ -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); diff --git a/src/surf/network_constant.hpp b/src/surf/network_constant.hpp index e0d7d7d63d..36782df5d6 100644 --- a/src/surf/network_constant.hpp +++ b/src/surf/network_constant.hpp @@ -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; diff --git a/src/surf/network_ib.cpp b/src/surf/network_ib.cpp index 2c170bbd9d..1d84616753 100644 --- a/src/surf/network_ib.cpp +++ b/src/surf/network_ib.cpp @@ -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); diff --git a/src/surf/network_interface.cpp b/src/surf/network_interface.cpp index 9100fea993..b1b8495c6b 100644 --- a/src/surf/network_interface.cpp +++ b/src/surf/network_interface.cpp @@ -96,8 +96,7 @@ namespace simgrid { simgrid::xbt::signal Link::onStateChange; simgrid::xbt::signal networkActionStateChangedCallbacks; - simgrid::xbt::signal Link::onCommunicate; - + simgrid::xbt::signal Link::onCommunicate; } } diff --git a/src/surf/network_interface.hpp b/src/surf/network_interface.hpp index c84b48fc12..40fe146e85 100644 --- a/src/surf/network_interface.hpp +++ b/src/surf/network_interface.hpp @@ -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 onStateChange; /** @brief Callback signal fired when a communication starts - * Signature: `void(NetworkAction *action, RoutingEdge *src, RoutingEdge *dst)` */ - static simgrid::xbt::signal onCommunicate; - - + * Signature: `void(NetworkAction *action, host *src, host *dst)` */ + static simgrid::xbt::signal onCommunicate; /** @brief Get the bandwidth in bytes per second of current Link */ virtual double getBandwidth(); diff --git a/src/surf/ptask_L07.cpp b/src/surf/ptask_L07.cpp index 20810848f3..048d55dafe 100644 --- a/src/surf/ptask_L07.cpp +++ b/src/surf/ptask_L07.cpp @@ -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); diff --git a/src/surf/ptask_L07.hpp b/src/surf/ptask_L07.hpp index c03c0b1266..e1aa4bb755 100644 --- a/src/surf/ptask_L07.hpp +++ b/src/surf/ptask_L07.hpp @@ -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_; }; diff --git a/src/surf/surf_c_bindings.cpp b/src/surf/surf_c_bindings.cpp index a18cf79650..5ff85aa899 100644 --- a/src/surf/surf_c_bindings.cpp +++ b/src/surf/surf_c_bindings.cpp @@ -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); } diff --git a/teshsuite/surf/surf_usage/surf_usage.cpp b/teshsuite/surf/surf_usage/surf_usage.cpp index 75ffa7ca29..6a2fd3f6ca 100644 --- a/teshsuite/surf/surf_usage/surf_usage.cpp +++ b/teshsuite/surf/surf_usage/surf_usage.cpp @@ -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 -#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 #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 { diff --git a/teshsuite/surf/surf_usage2/surf_usage2.cpp b/teshsuite/surf/surf_usage2/surf_usage2.cpp index f849953e4f..b4467d24fb 100644 --- a/teshsuite/surf/surf_usage2/surf_usage2.cpp +++ b/teshsuite/surf/surf_usage2/surf_usage2.cpp @@ -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 {