Logo AND Algorithmique Numérique Distribuée

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