Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
sed -i -e 's/\t/ /g' [sources] Please people, stop using tabs
[simgrid.git] / src / surf / network_constant.cpp
1 /* Copyright (c) 2013-2015. The SimGrid Team.
2  * All rights reserved.                                                     */
3
4 /* This program is free software; you can redistribute it and/or modify it
5  * under the terms of the license (GNU LGPL) which comes with this package. */
6
7 #include "network_constant.hpp"
8
9 #include "host_interface.hpp"
10 #include "src/surf/platform.hpp"
11
12 XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(surf_network);
13
14 /*********
15  * Model *
16  *********/
17 void surf_network_model_init_Constant()
18 {
19   xbt_assert(surf_network_model == NULL);
20   surf_network_model = new simgrid::surf::NetworkConstantModel();
21   xbt_dynar_push(all_existing_models, &surf_network_model);
22
23   routing_model_create(NULL);
24
25   simgrid::surf::on_link.connect([](sg_platf_link_cbarg_t link){
26       xbt_die("There is no link in the Constant network model. "
27           "Please remove any link from your platform (and switch to routing='None')");
28   });
29 }
30
31 namespace simgrid {
32 namespace surf {
33
34 double NetworkConstantModel::shareResources(double /*now*/)
35 {
36   NetworkConstantAction *action = NULL;
37   double min = -1.0;
38
39   ActionList *actionSet = getRunningActionSet();
40   for(ActionList::iterator it(actionSet->begin()), itend(actionSet->end())
41    ; it != itend ; ++it) {
42   action = static_cast<NetworkConstantAction*>(&*it);
43         if (action->m_latency > 0 && (min < 0 || action->m_latency < min))
44             min = action->m_latency;
45   }
46
47   return min;
48 }
49
50 void NetworkConstantModel::updateActionsState(double /*now*/, double delta)
51 {
52   NetworkConstantAction *action = NULL;
53   ActionList *actionSet = getRunningActionSet();
54   for(ActionList::iterator it(actionSet->begin()), itNext=it, itend(actionSet->end())
55      ; it != itend ; it=itNext) {
56     ++itNext;
57   action = static_cast<NetworkConstantAction*>(&*it);
58     if (action->m_latency > 0) {
59       if (action->m_latency > delta) {
60         double_update(&(action->m_latency), delta, sg_surf_precision);
61       } else {
62         action->m_latency = 0.0;
63       }
64     }
65     action->updateRemains(action->getCost() * delta / action->m_latInit);
66     if (action->getMaxDuration() != NO_MAX_DURATION)
67       action->updateMaxDuration(delta);
68
69     if (action->getRemainsNoUpdate() <= 0) {
70       action->finish();
71       action->setState(SURF_ACTION_DONE);
72     } else if ((action->getMaxDuration() != NO_MAX_DURATION)
73                && (action->getMaxDuration() <= 0)) {
74       action->finish();
75       action->setState(SURF_ACTION_DONE);
76     }
77   }
78 }
79
80 Action *NetworkConstantModel::communicate(NetCard *src, NetCard *dst,
81                              double size, double rate)
82 {
83   char *src_name = src->getName();
84   char *dst_name = dst->getName();
85
86   XBT_IN("(%s,%s,%g,%g)", src_name, dst_name, size, rate);
87   NetworkConstantAction *action = new NetworkConstantAction(this, size, sg_latency_factor);
88   XBT_OUT();
89
90   networkCommunicateCallbacks(action, src, dst, size, rate);
91   return action;
92 }
93
94 /**********
95  * Action *
96  **********/
97
98 int NetworkConstantAction::unref()
99 {
100   m_refcount--;
101   if (!m_refcount) {
102   if (action_hook.is_linked())
103     p_stateSet->erase(p_stateSet->iterator_to(*this));
104     delete this;
105   return 1;
106   }
107   return 0;
108 }
109
110 void NetworkConstantAction::cancel()
111 {
112   return;
113 }
114
115 }
116 }