Logo AND Algorithmique Numérique Distribuée

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