Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
pull up another (useless) method in the surf::Host hierarchy
[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 #include "surf/random_mgr.h"
9
10 #include "host_interface.hpp"
11
12 XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(surf_network);
13 static int host_number_int = 0;
14
15 static void netcste_parse_nolink(sg_platf_link_cbarg_t link){
16         xbt_die("There is no link in the Constant network model. "
17                         "Please remove any link from your platform (and switch to routing='None')");
18 }
19
20 /*********
21  * Model *
22  *********/
23 void surf_network_model_init_Constant()
24 {
25   xbt_assert(surf_network_model == NULL);
26   surf_network_model = new simgrid::surf::NetworkConstantModel();
27
28   routing_model_create(NULL);
29
30   simgrid::surf::Host::onCreation.connect([](simgrid::surf::Host*) {
31     host_number_int++;
32   });
33   sg_platf_link_add_cb(netcste_parse_nolink);
34
35   simgrid::surf::Model *model = surf_network_model;
36   xbt_dynar_push(all_existing_models, &model);
37 }
38
39 namespace simgrid {
40 namespace surf {
41
42 double NetworkConstantModel::shareResources(double /*now*/)
43 {
44   NetworkConstantAction *action = NULL;
45   double min = -1.0;
46
47   ActionList *actionSet = getRunningActionSet();
48   for(ActionList::iterator it(actionSet->begin()), itend(actionSet->end())
49          ; it != itend ; ++it) {
50         action = static_cast<NetworkConstantAction*>(&*it);
51         if (action->m_latency > 0 && (min < 0 || action->m_latency < min))
52             min = action->m_latency;
53   }
54
55   return min;
56 }
57
58 void NetworkConstantModel::updateActionsState(double /*now*/, double delta)
59 {
60   NetworkConstantAction *action = NULL;
61   ActionList *actionSet = getRunningActionSet();
62   for(ActionList::iterator it(actionSet->begin()), itNext=it, itend(actionSet->end())
63      ; it != itend ; it=itNext) {
64     ++itNext;
65         action = static_cast<NetworkConstantAction*>(&*it);
66     if (action->m_latency > 0) {
67       if (action->m_latency > delta) {
68         double_update(&(action->m_latency), delta, sg_surf_precision);
69       } else {
70         action->m_latency = 0.0;
71       }
72     }
73     action->updateRemains(action->getCost() * delta / action->m_latInit);
74     if (action->getMaxDuration() != NO_MAX_DURATION)
75       action->updateMaxDuration(delta);
76
77     if (action->getRemainsNoUpdate() <= 0) {
78       action->finish();
79       action->setState(SURF_ACTION_DONE);
80     } else if ((action->getMaxDuration() != NO_MAX_DURATION)
81                && (action->getMaxDuration() <= 0)) {
82       action->finish();
83       action->setState(SURF_ACTION_DONE);
84     }
85   }
86 }
87
88 Action *NetworkConstantModel::communicate(RoutingEdge *src, RoutingEdge *dst,
89                                          double size, double rate)
90 {
91   char *src_name = src->getName();
92   char *dst_name = dst->getName();
93
94   XBT_IN("(%s,%s,%g,%g)", src_name, dst_name, size, rate);
95   NetworkConstantAction *action = new NetworkConstantAction(this, size, sg_latency_factor);
96   XBT_OUT();
97
98   networkCommunicateCallbacks(action, src, dst, size, rate);
99   return action;
100 }
101
102 /**********
103  * Action *
104  **********/
105
106 int NetworkConstantAction::unref()
107 {
108   m_refcount--;
109   if (!m_refcount) {
110         if (action_hook.is_linked())
111           p_stateSet->erase(p_stateSet->iterator_to(*this));
112     delete this;
113   return 1;
114   }
115   return 0;
116 }
117
118 void NetworkConstantAction::cancel()
119 {
120   return;
121 }
122
123 void NetworkConstantAction::setCategory(const char * /*category*/)
124 {
125   //ignore completely the categories in constant model, they are not traced
126 }
127
128 void NetworkConstantAction::suspend()
129 {
130   m_suspended = true;
131 }
132
133 void NetworkConstantAction::resume()
134 {
135   if (m_suspended)
136         m_suspended = false;
137 }
138
139 bool NetworkConstantAction::isSuspended()
140 {
141   return m_suspended;
142 }
143
144 }
145 }