Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
useless cosmetics
[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
15 /*********
16  * Model *
17  *********/
18 void surf_network_model_init_Constant()
19 {
20   xbt_assert(surf_network_model == NULL);
21   surf_network_model = new simgrid::surf::NetworkConstantModel();
22   xbt_dynar_push(all_existing_models, &surf_network_model);
23
24   routing_model_create(NULL);
25
26   simgrid::surf::on_link.connect([](sg_platf_link_cbarg_t link){
27       xbt_die("There is no link in the Constant network model. "
28           "Please remove any link from your platform (and switch to routing='None')");
29   });
30 }
31
32 namespace simgrid {
33 namespace surf {
34
35 double NetworkConstantModel::shareResources(double /*now*/)
36 {
37   NetworkConstantAction *action = NULL;
38   double min = -1.0;
39
40   ActionList *actionSet = getRunningActionSet();
41   for(ActionList::iterator it(actionSet->begin()), itend(actionSet->end())
42          ; it != itend ; ++it) {
43         action = static_cast<NetworkConstantAction*>(&*it);
44         if (action->m_latency > 0 && (min < 0 || action->m_latency < min))
45             min = action->m_latency;
46   }
47
48   return min;
49 }
50
51 void NetworkConstantModel::updateActionsState(double /*now*/, double delta)
52 {
53   NetworkConstantAction *action = NULL;
54   ActionList *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<NetworkConstantAction*>(&*it);
59     if (action->m_latency > 0) {
60       if (action->m_latency > delta) {
61         double_update(&(action->m_latency), delta, sg_surf_precision);
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 Action *NetworkConstantModel::communicate(NetCard *src, NetCard *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   NetworkConstantAction *action = new NetworkConstantAction(this, size, sg_latency_factor);
89   XBT_OUT();
90
91   networkCommunicateCallbacks(action, src, dst, size, rate);
92   return action;
93 }
94
95 /**********
96  * Action *
97  **********/
98
99 int NetworkConstantAction::unref()
100 {
101   m_refcount--;
102   if (!m_refcount) {
103         if (action_hook.is_linked())
104           p_stateSet->erase(p_stateSet->iterator_to(*this));
105     delete this;
106   return 1;
107   }
108   return 0;
109 }
110
111 void NetworkConstantAction::cancel()
112 {
113   return;
114 }
115
116 }
117 }