Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Fix bug #17132 (surf.c:366: The Impossible Did Happen (yet again)).
[simgrid.git] / src / surf / network_constant.cpp
1 /* Copyright (c) 2013-2014. 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 #include "surf/random_mgr.h"
9
10 XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(surf_network);
11 static int host_number_int = 0;
12
13 static void netcste_count_hosts(sg_platf_host_cbarg_t /*h*/) {
14   host_number_int++;
15 }
16
17 /*********
18  * Model *
19  *********/
20 void surf_network_model_init_Constant()
21 {
22   xbt_assert(surf_network_model == NULL);
23   surf_network_model = new NetworkConstantModel();
24
25   sg_platf_host_add_cb(netcste_count_hosts);
26
27   ModelPtr model = static_cast<ModelPtr>(surf_network_model);
28   xbt_dynar_push(model_list, &model);
29 }
30
31 double NetworkConstantModel::shareResources(double /*now*/)
32 {
33   NetworkConstantActionPtr action = NULL;
34   double min = -1.0;
35
36   ActionListPtr actionSet = getRunningActionSet();
37   for(ActionList::iterator it(actionSet->begin()), itend(actionSet->end())
38          ; it != itend ; ++it) {
39         action = static_cast<NetworkConstantActionPtr>(&*it);
40     if (action->m_latency > 0) {
41       if (min < 0)
42         min = action->m_latency;
43       else if (action->m_latency < min)
44         min = action->m_latency;
45     }
46   }
47
48   return min;
49 }
50
51 void NetworkConstantModel::updateActionsState(double /*now*/, double delta)
52 {
53   NetworkConstantActionPtr action = NULL;
54   ActionListPtr actionSet = getRunningActionSet();
55   for(ActionList::iterator it(actionSet->begin()), itNext=it, itend(actionSet->end())
56      ; it != itend ; it=itNext) {
57     ++itNext;
58         action = static_cast<NetworkConstantActionPtr>(&*it);
59     if (action->m_latency > 0) {
60       if (action->m_latency > delta) {
61         double_update(&(action->m_latency), delta);
62       } else {
63         action->m_latency = 0.0;
64       }
65     }
66     action->updateRemains(action->getCost() * delta / action->m_latInit);
67     if (action->getMaxDuration() != NO_MAX_DURATION)
68       action->updateMaxDuration(delta);
69
70     if (action->getRemainsNoUpdate() <= 0) {
71       action->finish();
72       action->setState(SURF_ACTION_DONE);
73     } else if ((action->getMaxDuration() != NO_MAX_DURATION)
74                && (action->getMaxDuration() <= 0)) {
75       action->finish();
76       action->setState(SURF_ACTION_DONE);
77     }
78   }
79 }
80
81 ActionPtr NetworkConstantModel::communicate(RoutingEdgePtr src, RoutingEdgePtr dst,
82                                          double size, double rate)
83 {
84   char *src_name = src->getName();
85   char *dst_name = dst->getName();
86
87   XBT_IN("(%s,%s,%g,%g)", src_name, dst_name, size, rate);
88   NetworkConstantActionPtr action = new NetworkConstantAction(this, size, sg_latency_factor);
89   XBT_OUT();
90
91   surf_callback_emit(networkCommunicateCallbacks, action, src, dst, size, rate);
92   return action;
93 }
94
95 /************
96  * Resource *
97  ************/
98 bool NetworkConstantLink::isUsed()
99 {
100   return 0;
101 }
102
103 void NetworkConstantLink::updateState(tmgr_trace_event_t /*event_type*/,
104                                          double /*value*/, double /*time*/)
105 {
106   DIE_IMPOSSIBLE;
107 }
108
109 double NetworkConstantLink::getBandwidth()
110 {
111   DIE_IMPOSSIBLE;
112   return -1.0; /* useless since DIE actually abort(), but eclipse prefer to have a useless and harmless return */
113 }
114
115 double NetworkConstantLink::getLatency()
116 {
117   DIE_IMPOSSIBLE;
118   return -1.0; /* useless since DIE actually abort(), but eclipse prefer to have a useless and harmless return */
119 }
120
121 bool NetworkConstantLink::isShared()
122 {
123   DIE_IMPOSSIBLE;
124   return -1; /* useless since DIE actually abort(), but eclipse prefer to have a useless and harmless return */
125 }
126
127 /**********
128  * Action *
129  **********/
130
131 int NetworkConstantAction::unref()
132 {
133   m_refcount--;
134   if (!m_refcount) {
135         if (actionHook::is_linked())
136           p_stateSet->erase(p_stateSet->iterator_to(*this));
137     delete this;
138   return 1;
139   }
140   return 0;
141 }
142
143 void NetworkConstantAction::cancel()
144 {
145   return;
146 }
147
148 #ifdef HAVE_TRACING
149 void NetworkConstantAction::setCategory(const char */*category*/)
150 {
151   //ignore completely the categories in constant model, they are not traced
152 }
153 #endif
154
155 void NetworkConstantAction::suspend()
156 {
157   m_suspended = true;
158 }
159
160 void NetworkConstantAction::resume()
161 {
162   if (m_suspended)
163         m_suspended = false;
164 }
165
166 void NetworkConstantAction::recycle()
167 {
168   return;
169 }
170
171 bool NetworkConstantAction::isSuspended()
172 {
173   return m_suspended;
174 }
175