Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
kill useless C datatypes
[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::surf::NetworkConstantModel();
19   all_existing_models->push_back(surf_network_model);
20 }
21
22 namespace simgrid {
23 namespace surf {
24 LinkImpl* NetworkConstantModel::createLink(const std::string& name, double bw, double lat,
25                                            e_surf_link_sharing_policy_t policy)
26 {
27
28   xbt_die("Refusing to create the link %s: there is no link in the Constant network model. "
29           "Please remove any link from your platform (and switch to routing='None')",
30           name.c_str());
31   return nullptr;
32 }
33
34 double NetworkConstantModel::next_occuring_event(double /*now*/)
35 {
36   double min = -1.0;
37   for (kernel::resource::Action const& action : *get_running_action_set()) {
38     const NetworkConstantAction& net_action = static_cast<const NetworkConstantAction&>(action);
39     if (net_action.latency_ > 0 && (min < 0 || net_action.latency_ < min))
40       min = net_action.latency_;
41   }
42   return min;
43 }
44
45 void NetworkConstantModel::update_actions_state(double /*now*/, double delta)
46 {
47   for (auto it = std::begin(*get_running_action_set()); it != std::end(*get_running_action_set());) {
48     NetworkConstantAction& action = static_cast<NetworkConstantAction&>(*it);
49     ++it; // increment iterator here since the following calls to action.finish() may invalidate it
50     if (action.latency_ > 0) {
51       if (action.latency_ > delta) {
52         double_update(&action.latency_, delta, sg_surf_precision);
53       } else {
54         action.latency_ = 0.0;
55       }
56     }
57     action.update_remains(action.get_cost() * delta / action.initialLatency_);
58     if (action.get_max_duration() != NO_MAX_DURATION)
59       action.update_max_duration(delta);
60
61     if ((action.get_remains_no_update() <= 0) ||
62         ((action.get_max_duration() != NO_MAX_DURATION) && (action.get_max_duration() <= 0))) {
63       action.finish(kernel::resource::Action::State::done);
64     }
65   }
66 }
67
68 kernel::resource::Action* NetworkConstantModel::communicate(s4u::Host* src, s4u::Host* dst, double size, double rate)
69 {
70   NetworkConstantAction* action = new NetworkConstantAction(this, size, sg_latency_factor);
71
72   simgrid::s4u::Link::onCommunicate(action, src, dst);
73   return action;
74 }
75
76 /**********
77  * Action *
78  **********/
79 NetworkConstantAction::NetworkConstantAction(NetworkConstantModel* model_, double size, double latency)
80     : NetworkAction(model_, size, false), initialLatency_(latency)
81 {
82   latency_ = latency;
83   if (latency_ <= 0.0)
84     NetworkConstantAction::set_state(Action::State::done);
85 };
86
87 NetworkConstantAction::~NetworkConstantAction() = default;
88
89 void NetworkConstantAction::update_remains_lazy(double /*now*/)
90 {
91   THROW_IMPOSSIBLE;
92 }
93 }
94 }