Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Comment unused function parameters.
[simgrid.git] / src / surf / network_constant.cpp
1 /* Copyright (c) 2013-2018. The SimGrid Team. All rights reserved.          */
2
3 /* This program is free software; you can redistribute it and/or modify it
4  * under the terms of the license (GNU LGPL) which comes with this package. */
5
6 #include "network_constant.hpp"
7 #include "src/surf/surf_interface.hpp"
8 #include "surf/surf.hpp"
9
10 XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(surf_network);
11
12 /*********
13  * Model *
14  *********/
15 void surf_network_model_init_Constant()
16 {
17   xbt_assert(surf_network_model == nullptr);
18   surf_network_model = new simgrid::kernel::resource::NetworkConstantModel();
19   all_existing_models->push_back(surf_network_model);
20 }
21
22 namespace simgrid {
23 namespace kernel {
24 namespace resource {
25 LinkImpl* NetworkConstantModel::createLink(const std::string& name, double bw, double lat,
26                                            s4u::Link::SharingPolicy policy)
27 {
28
29   xbt_die("Refusing to create the link %s: there is no link in the Constant network model. "
30           "Please remove any link from your platform (and switch to routing='None')",
31           name.c_str());
32   return nullptr;
33 }
34
35 double NetworkConstantModel::next_occuring_event(double /*now*/)
36 {
37   double min = -1.0;
38   for (kernel::resource::Action const& action : *get_started_action_set()) {
39     const NetworkConstantAction& net_action = static_cast<const NetworkConstantAction&>(action);
40     if (net_action.latency_ > 0 && (min < 0 || net_action.latency_ < min))
41       min = net_action.latency_;
42   }
43   return min;
44 }
45
46 void NetworkConstantModel::update_actions_state(double /*now*/, double delta)
47 {
48   for (auto it = std::begin(*get_started_action_set()); it != std::end(*get_started_action_set());) {
49     NetworkConstantAction& action = static_cast<NetworkConstantAction&>(*it);
50     ++it; // increment iterator here since the following calls to action.finish() may invalidate it
51     if (action.latency_ > 0) {
52       if (action.latency_ > delta) {
53         double_update(&action.latency_, delta, sg_surf_precision);
54       } else {
55         action.latency_ = 0.0;
56       }
57     }
58     action.update_remains(action.get_cost() * delta / action.initialLatency_);
59     if (action.get_max_duration() != NO_MAX_DURATION)
60       action.update_max_duration(delta);
61
62     if ((action.get_remains_no_update() <= 0) ||
63         ((action.get_max_duration() != NO_MAX_DURATION) && (action.get_max_duration() <= 0))) {
64       action.finish(kernel::resource::Action::State::FINISHED);
65     }
66   }
67 }
68
69 kernel::resource::Action* NetworkConstantModel::communicate(s4u::Host* src, s4u::Host* dst, double size, double rate)
70 {
71   NetworkConstantAction* action = new NetworkConstantAction(this, size, sg_latency_factor);
72
73   simgrid::s4u::Link::on_communicate(action, src, dst);
74   return action;
75 }
76
77 /**********
78  * Action *
79  **********/
80 NetworkConstantAction::NetworkConstantAction(NetworkConstantModel* model_, double size, double latency)
81     : NetworkAction(model_, size, false), initialLatency_(latency)
82 {
83   latency_ = latency;
84   if (latency_ <= 0.0)
85     NetworkConstantAction::set_state(Action::State::FINISHED);
86 };
87
88 NetworkConstantAction::~NetworkConstantAction() = default;
89
90 void NetworkConstantAction::update_remains_lazy(double /*now*/)
91 {
92   THROW_IMPOSSIBLE;
93 }
94 }
95 } // namespace kernel
96 }