Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
properly pass the cluster's properties to the created hosts
[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 = 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 && (min < 0 || action->m_latency < min))
41             min = action->m_latency;
42   }
43
44   return min;
45 }
46
47 void NetworkConstantModel::updateActionsState(double /*now*/, double delta)
48 {
49   NetworkConstantActionPtr action = NULL;
50   ActionListPtr actionSet = getRunningActionSet();
51   for(ActionList::iterator it(actionSet->begin()), itNext=it, itend(actionSet->end())
52      ; it != itend ; it=itNext) {
53     ++itNext;
54         action = static_cast<NetworkConstantActionPtr>(&*it);
55     if (action->m_latency > 0) {
56       if (action->m_latency > delta) {
57         double_update(&(action->m_latency), delta, sg_surf_precision);
58       } else {
59         action->m_latency = 0.0;
60       }
61     }
62     action->updateRemains(action->getCost() * delta / action->m_latInit);
63     if (action->getMaxDuration() != NO_MAX_DURATION)
64       action->updateMaxDuration(delta);
65
66     if (action->getRemainsNoUpdate() <= 0) {
67       action->finish();
68       action->setState(SURF_ACTION_DONE);
69     } else if ((action->getMaxDuration() != NO_MAX_DURATION)
70                && (action->getMaxDuration() <= 0)) {
71       action->finish();
72       action->setState(SURF_ACTION_DONE);
73     }
74   }
75 }
76
77 ActionPtr NetworkConstantModel::communicate(RoutingEdgePtr src, RoutingEdgePtr dst,
78                                          double size, double rate)
79 {
80   char *src_name = src->getName();
81   char *dst_name = dst->getName();
82
83   XBT_IN("(%s,%s,%g,%g)", src_name, dst_name, size, rate);
84   NetworkConstantActionPtr action = new NetworkConstantAction(this, size, sg_latency_factor);
85   XBT_OUT();
86
87   surf_callback_emit(networkCommunicateCallbacks, action, src, dst, size, rate);
88   return action;
89 }
90
91 /************
92  * Resource *
93  ************/
94 bool NetworkConstantLink::isUsed()
95 {
96   return 0;
97 }
98
99 void NetworkConstantLink::updateState(tmgr_trace_event_t /*event_type*/,
100                                          double /*value*/, double /*time*/)
101 {
102   DIE_IMPOSSIBLE;
103 }
104
105 double NetworkConstantLink::getBandwidth()
106 {
107   DIE_IMPOSSIBLE;
108   return -1.0; /* useless since DIE actually abort(), but eclipse prefer to have a useless and harmless return */
109 }
110
111 double NetworkConstantLink::getLatency()
112 {
113   DIE_IMPOSSIBLE;
114   return -1.0; /* useless since DIE actually abort(), but eclipse prefer to have a useless and harmless return */
115 }
116
117 bool NetworkConstantLink::isShared()
118 {
119   DIE_IMPOSSIBLE;
120   return -1; /* useless since DIE actually abort(), but eclipse prefer to have a useless and harmless return */
121 }
122
123 /**********
124  * Action *
125  **********/
126
127 int NetworkConstantAction::unref()
128 {
129   m_refcount--;
130   if (!m_refcount) {
131         if (actionHook::is_linked())
132           p_stateSet->erase(p_stateSet->iterator_to(*this));
133     delete this;
134   return 1;
135   }
136   return 0;
137 }
138
139 void NetworkConstantAction::cancel()
140 {
141   return;
142 }
143
144 #ifdef HAVE_TRACING
145 void NetworkConstantAction::setCategory(const char */*category*/)
146 {
147   //ignore completely the categories in constant model, they are not traced
148 }
149 #endif
150
151 void NetworkConstantAction::suspend()
152 {
153   m_suspended = true;
154 }
155
156 void NetworkConstantAction::resume()
157 {
158   if (m_suspended)
159         m_suspended = false;
160 }
161
162 void NetworkConstantAction::recycle()
163 {
164   return;
165 }
166
167 bool NetworkConstantAction::isSuspended()
168 {
169   return m_suspended;
170 }
171