Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[mc] Cleanup the DSO ignore list and add some entries
[simgrid.git] / src / surf / workstation_ptask_L07.cpp
1 /* Copyright (c) 2007-2010, 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 "workstation_ptask_L07.hpp"
8 #include "cpu_interface.hpp"
9 #include "surf_routing.hpp"
10
11 XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(surf_workstation);
12
13 static int ptask_host_count = 0;
14 static xbt_dict_t ptask_parallel_task_link_set = NULL;
15 lmm_system_t ptask_maxmin_system = NULL;
16
17
18 /**************************************/
19 /*** Resource Creation & Destruction **/
20 /**************************************/
21
22 static void ptask_netlink_parse_init(sg_platf_link_cbarg_t link)
23 {
24   netlink_parse_init(link);
25   current_property_set = NULL;
26 }
27
28 static void ptask_define_callbacks()
29 {
30   sg_platf_host_add_cb(cpu_parse_init);
31   sg_platf_host_add_cb(workstation_parse_init);
32   sg_platf_link_add_cb(ptask_netlink_parse_init);
33   sg_platf_postparse_add_cb(workstation_add_traces);
34 }
35
36 void surf_workstation_model_init_ptask_L07(void)
37 {
38   XBT_INFO("surf_workstation_model_init_ptask_L07");
39   xbt_assert(!surf_cpu_model_pm, "CPU model type already defined");
40   xbt_assert(!surf_network_model, "network model type already defined");
41   ptask_define_callbacks();
42   surf_workstation_model = new WorkstationL07Model();
43   ModelPtr model = surf_workstation_model;
44   xbt_dynar_push(model_list, &model);
45   xbt_dynar_push(model_list_invoke, &model);
46 }
47
48
49 WorkstationL07Model::WorkstationL07Model() : WorkstationModel("Workstation ptask_L07") {
50   if (!ptask_maxmin_system)
51         ptask_maxmin_system = lmm_system_new(1);
52   surf_workstation_model = NULL;
53   surf_network_model = new NetworkL07Model();
54   surf_cpu_model_pm = new CpuL07Model();
55   routing_model_create(surf_network_model->createNetworkLink("__loopback__",
56                                                           498000000, NULL,
57                                                           0.000015, NULL,
58                                                           SURF_RESOURCE_ON, NULL,
59                                                           SURF_LINK_FATPIPE, NULL));
60   p_cpuModel = surf_cpu_model_pm;
61 }
62
63 WorkstationL07Model::~WorkstationL07Model() {
64   xbt_dict_free(&ptask_parallel_task_link_set);
65
66   delete surf_cpu_model_pm;
67   delete surf_network_model;
68   ptask_host_count = 0;
69
70   if (ptask_maxmin_system) {
71     lmm_system_free(ptask_maxmin_system);
72     ptask_maxmin_system = NULL;
73   }
74 }
75
76 double WorkstationL07Model::shareResources(double /*now*/)
77 {
78   WorkstationL07ActionPtr action;
79
80   ActionListPtr running_actions = getRunningActionSet();
81   double min = this->shareResourcesMaxMin(running_actions,
82                                               ptask_maxmin_system,
83                                               bottleneck_solve);
84
85   for(ActionList::iterator it(running_actions->begin()), itend(running_actions->end())
86          ; it != itend ; ++it) {
87         action = static_cast<WorkstationL07ActionPtr>(&*it);
88     if (action->m_latency > 0) {
89       if (min < 0) {
90         min = action->m_latency;
91         XBT_DEBUG("Updating min (value) with %p (start %f): %f", action,
92                action->getStartTime(), min);
93       } else if (action->m_latency < min) {
94         min = action->m_latency;
95         XBT_DEBUG("Updating min (latency) with %p (start %f): %f", action,
96                action->getStartTime(), min);
97       }
98     }
99   }
100
101   XBT_DEBUG("min value : %f", min);
102
103   return min;
104 }
105
106 void WorkstationL07Model::updateActionsState(double /*now*/, double delta)
107 {
108   double deltap = 0.0;
109   WorkstationL07ActionPtr action;
110
111   ActionListPtr actionSet = getRunningActionSet();
112
113   for(ActionList::iterator it(actionSet->begin()), itNext = it, itend(actionSet->end())
114          ; it != itend ; it=itNext) {
115         ++itNext;
116     action = static_cast<WorkstationL07ActionPtr>(&*it);
117     deltap = delta;
118     if (action->m_latency > 0) {
119       if (action->m_latency > deltap) {
120         double_update(&(action->m_latency), deltap, sg_surf_precision);
121         deltap = 0.0;
122       } else {
123         double_update(&(deltap), action->m_latency, sg_surf_precision);
124         action->m_latency = 0.0;
125       }
126       if ((action->m_latency == 0.0) && (action->isSuspended() == 0)) {
127         action->updateBound();
128         lmm_update_variable_weight(ptask_maxmin_system, action->getVariable(), 1.0);
129       }
130     }
131     XBT_DEBUG("Action (%p) : remains (%g) updated by %g.",
132            action, action->getRemains(), lmm_variable_getvalue(action->getVariable()) * delta);
133     action->updateRemains(lmm_variable_getvalue(action->getVariable()) * delta);
134
135     if (action->getMaxDuration() != NO_MAX_DURATION)
136       action->updateMaxDuration(delta);
137
138     XBT_DEBUG("Action (%p) : remains (%g).",
139            action, action->getRemains());
140     if ((action->getRemains() <= 0) &&
141         (lmm_get_variable_weight(action->getVariable()) > 0)) {
142       action->finish();
143       action->setState(SURF_ACTION_DONE);
144     } else if ((action->getMaxDuration() != NO_MAX_DURATION) &&
145                (action->getMaxDuration() <= 0)) {
146       action->finish();
147      action->setState(SURF_ACTION_DONE);
148     } else {
149       /* Need to check that none of the model has failed */
150       lmm_constraint_t cnst = NULL;
151       int i = 0;
152       void *constraint_id = NULL;
153
154       while ((cnst = lmm_get_cnst_from_var(ptask_maxmin_system, action->getVariable(),
155                                     i++))) {
156         constraint_id = lmm_constraint_id(cnst);
157
158         if (static_cast<WorkstationPtr>(constraint_id)->getState() == SURF_RESOURCE_OFF) {
159           XBT_DEBUG("Action (%p) Failed!!", action);
160           action->finish();
161           action->setState(SURF_ACTION_FAILED);
162           break;
163         }
164       }
165     }
166   }
167   return;
168 }
169
170 ActionPtr WorkstationL07Model::executeParallelTask(int workstation_nb,
171                                                    void **workstation_list,
172                                                    double *flops_amount,
173                                                                                                    double *bytes_amount,
174                                                    double rate)
175 {
176   WorkstationL07ActionPtr action;
177   int i, j;
178   unsigned int cpt;
179   int nb_link = 0;
180   int nb_host = 0;
181   double latency = 0.0;
182
183   if (ptask_parallel_task_link_set == NULL)
184     ptask_parallel_task_link_set = xbt_dict_new_homogeneous(NULL);
185
186   xbt_dict_reset(ptask_parallel_task_link_set);
187
188   /* Compute the number of affected resources... */
189   for (i = 0; i < workstation_nb; i++) {
190     for (j = 0; j < workstation_nb; j++) {
191       xbt_dynar_t route=NULL;
192
193       if (bytes_amount[i * workstation_nb + j] > 0) {
194         double lat=0.0;
195         unsigned int cpt;
196         void *_link;
197         LinkL07Ptr link;
198
199         routing_platf->getRouteAndLatency(static_cast<WorkstationL07Ptr>(workstation_list[i])->p_netElm,
200                                                   static_cast<WorkstationL07Ptr>(workstation_list[j])->p_netElm,
201                                                   &route,
202                                                   &lat);
203         latency = MAX(latency, lat);
204
205         xbt_dynar_foreach(route, cpt, _link) {
206            link = static_cast<LinkL07Ptr>(_link);
207            xbt_dict_set(ptask_parallel_task_link_set, link->getName(), link, NULL);
208         }
209       }
210     }
211   }
212
213   nb_link = xbt_dict_length(ptask_parallel_task_link_set);
214   xbt_dict_reset(ptask_parallel_task_link_set);
215
216   for (i = 0; i < workstation_nb; i++)
217     if (flops_amount[i] > 0)
218       nb_host++;
219
220   action = new WorkstationL07Action(this, 1, 0);
221   XBT_DEBUG("Creating a parallel task (%p) with %d cpus and %d links.",
222          action, workstation_nb, nb_link);
223   action->m_suspended = 0;        /* Should be useless because of the
224                                    calloc but it seems to help valgrind... */
225   action->m_workstationNb = workstation_nb;
226   action->p_workstationList = (WorkstationPtr *) workstation_list;
227   action->p_computationAmount = flops_amount;
228   action->p_communicationAmount = bytes_amount;
229   action->m_latency = latency;
230   action->m_rate = rate;
231
232   action->p_variable = lmm_variable_new(ptask_maxmin_system, action, 1.0,
233                        (action->m_rate > 0) ? action->m_rate : -1.0,
234                        workstation_nb + nb_link);
235
236   if (action->m_latency > 0)
237     lmm_update_variable_weight(ptask_maxmin_system, action->getVariable(), 0.0);
238
239   for (i = 0; i < workstation_nb; i++)
240     lmm_expand(ptask_maxmin_system,
241                  static_cast<WorkstationL07Ptr>(workstation_list[i])->p_cpu->getConstraint(),
242                action->getVariable(), flops_amount[i]);
243
244   for (i = 0; i < workstation_nb; i++) {
245     for (j = 0; j < workstation_nb; j++) {
246       void *_link;
247       LinkL07Ptr link;
248
249       xbt_dynar_t route=NULL;
250       if (bytes_amount[i * workstation_nb + j] == 0.0)
251         continue;
252
253       routing_platf->getRouteAndLatency(static_cast<WorkstationL07Ptr>(workstation_list[i])->p_netElm,
254                                         static_cast<WorkstationL07Ptr>(workstation_list[j])->p_netElm,
255                                             &route, NULL);
256
257       xbt_dynar_foreach(route, cpt, _link) {
258         link = static_cast<LinkL07Ptr>(_link);
259         lmm_expand_add(ptask_maxmin_system, link->getConstraint(),
260                        action->getVariable(),
261                        bytes_amount[i * workstation_nb + j]);
262       }
263     }
264   }
265
266   if (nb_link + nb_host == 0) {
267     action->setCost(1.0);
268     action->setRemains(0.0);
269   }
270
271   return action;
272 }
273
274 WorkstationPtr WorkstationL07Model::createWorkstation(const char *name)
275 {
276   WorkstationL07Ptr wk = NULL;
277   xbt_assert(!surf_workstation_resource_priv(surf_workstation_resource_by_name(name)),
278               "Host '%s' declared several times in the platform file.",
279               name);
280
281   wk = new WorkstationL07(this, name, NULL,
282                                   static_cast<RoutingEdgePtr>(xbt_lib_get_or_null(host_lib, name, ROUTING_HOST_LEVEL)),
283                                   static_cast<CpuPtr>(xbt_lib_get_or_null(host_lib, name, SURF_CPU_LEVEL)));
284
285   xbt_lib_set(host_lib, name, SURF_WKS_LEVEL, wk);
286
287   return wk;//FIXME:xbt_lib_get_elm_or_null(host_lib, name);
288 }
289
290 ActionPtr WorkstationL07Model::communicate(WorkstationPtr src, WorkstationPtr dst,
291                                        double size, double rate)
292 {
293   void **workstation_list = xbt_new0(void *, 2);
294   double *flops_amount = xbt_new0(double, 2);
295   double *bytes_amount = xbt_new0(double, 4);
296   ActionPtr res = NULL;
297
298   workstation_list[0] = src;
299   workstation_list[1] = dst;
300   bytes_amount[1] = size;
301
302   res = executeParallelTask(2, workstation_list,
303                                     flops_amount,
304                                     bytes_amount, rate);
305
306   return res;
307 }
308
309 xbt_dynar_t WorkstationL07Model::getRoute(WorkstationPtr src, WorkstationPtr dst)
310 {
311   xbt_dynar_t route=NULL;
312   routing_platf->getRouteAndLatency(src->p_netElm, dst->p_netElm, &route, NULL);
313   return route;
314 }
315
316 CpuPtr CpuL07Model::createCpu(const char *name,  xbt_dynar_t powerPeak,
317                           int pstate, double power_scale,
318                           tmgr_trace_t power_trace, int core,
319                           e_surf_resource_state_t state_initial,
320                           tmgr_trace_t state_trace,
321                           xbt_dict_t cpu_properties)
322 {
323   double power_initial = xbt_dynar_get_as(powerPeak, pstate, double);
324   xbt_dynar_free(&powerPeak);   // kill memory leak
325
326   xbt_assert(!surf_workstation_resource_priv(surf_workstation_resource_by_name(name)),
327               "Host '%s' declared several times in the platform file.",
328               name);
329
330   CpuL07Ptr cpu = new CpuL07(this, name, cpu_properties,
331                                      power_initial, power_scale, power_trace,
332                          core, state_initial, state_trace);
333
334   xbt_lib_set(host_lib, name, SURF_CPU_LEVEL, cpu);
335
336   return cpu;
337 }
338
339 NetworkLinkPtr NetworkL07Model::createNetworkLink(const char *name,
340                                  double bw_initial,
341                                  tmgr_trace_t bw_trace,
342                                  double lat_initial,
343                                  tmgr_trace_t lat_trace,
344                                  e_surf_resource_state_t
345                                  state_initial,
346                                  tmgr_trace_t state_trace,
347                                  e_surf_link_sharing_policy_t policy,
348                                  xbt_dict_t properties)
349 {
350   xbt_assert(!xbt_lib_get_or_null(link_lib, name, SURF_LINK_LEVEL),
351                       "Link '%s' declared several times in the platform file.",
352                       name);
353
354   LinkL07Ptr nw_link = new LinkL07(this, name, properties,
355                                        bw_initial, bw_trace,
356                                        lat_initial, lat_trace,
357                                        state_initial, state_trace,
358                                        policy);
359
360   xbt_lib_set(link_lib, name, SURF_LINK_LEVEL, nw_link);
361   return nw_link;
362 }
363
364 void WorkstationL07Model::addTraces()
365 {
366   xbt_dict_cursor_t cursor = NULL;
367   char *trace_name, *elm;
368
369   if (!trace_connect_list_host_avail)
370     return;
371
372   /* Connect traces relative to cpu */
373   xbt_dict_foreach(trace_connect_list_host_avail, cursor, trace_name, elm) {
374     tmgr_trace_t trace = (tmgr_trace_t) xbt_dict_get_or_null(traces_set_list, trace_name);
375     CpuL07Ptr host = static_cast<CpuL07Ptr>(surf_cpu_resource_priv(surf_cpu_resource_by_name(elm)));
376
377     xbt_assert(host, "Host %s undefined", elm);
378     xbt_assert(trace, "Trace %s undefined", trace_name);
379
380     host->p_stateEvent = tmgr_history_add_trace(history, trace, 0.0, 0, host);
381   }
382
383   xbt_dict_foreach(trace_connect_list_power, cursor, trace_name, elm) {
384     tmgr_trace_t trace = (tmgr_trace_t) xbt_dict_get_or_null(traces_set_list, trace_name);
385     CpuL07Ptr host = static_cast<CpuL07Ptr>(surf_cpu_resource_priv(surf_cpu_resource_by_name(elm)));
386
387     xbt_assert(host, "Host %s undefined", elm);
388     xbt_assert(trace, "Trace %s undefined", trace_name);
389
390     host->p_powerEvent = tmgr_history_add_trace(history, trace, 0.0, 0, host);
391   }
392
393   /* Connect traces relative to network */
394   xbt_dict_foreach(trace_connect_list_link_avail, cursor, trace_name, elm) {
395     tmgr_trace_t trace = (tmgr_trace_t) xbt_dict_get_or_null(traces_set_list, trace_name);
396     LinkL07Ptr link = static_cast<LinkL07Ptr>(xbt_lib_get_or_null(link_lib, elm, SURF_LINK_LEVEL));
397
398     xbt_assert(link, "Link %s undefined", elm);
399     xbt_assert(trace, "Trace %s undefined", trace_name);
400
401     link->p_stateEvent = tmgr_history_add_trace(history, trace, 0.0, 0, link);
402   }
403
404   xbt_dict_foreach(trace_connect_list_bandwidth, cursor, trace_name, elm) {
405     tmgr_trace_t trace = (tmgr_trace_t) xbt_dict_get_or_null(traces_set_list, trace_name);
406     LinkL07Ptr link = static_cast<LinkL07Ptr>(xbt_lib_get_or_null(link_lib, elm, SURF_LINK_LEVEL));
407
408     xbt_assert(link, "Link %s undefined", elm);
409     xbt_assert(trace, "Trace %s undefined", trace_name);
410
411     link->p_bwEvent = tmgr_history_add_trace(history, trace, 0.0, 0, link);
412   }
413
414   xbt_dict_foreach(trace_connect_list_latency, cursor, trace_name, elm) {
415     tmgr_trace_t trace = (tmgr_trace_t) xbt_dict_get_or_null(traces_set_list, trace_name);
416     LinkL07Ptr link = static_cast<LinkL07Ptr>(xbt_lib_get_or_null(link_lib, elm, SURF_LINK_LEVEL));
417
418     xbt_assert(link, "Link %s undefined", elm);
419     xbt_assert(trace, "Trace %s undefined", trace_name);
420
421     link->p_latEvent = tmgr_history_add_trace(history, trace, 0.0, 0, link);
422   }
423 }
424
425 /************
426  * Resource *
427  ************/
428
429 WorkstationL07::WorkstationL07(WorkstationModelPtr model, const char* name, xbt_dict_t props, RoutingEdgePtr netElm, CpuPtr cpu)
430   : Workstation(model, name, props, NULL, netElm, cpu)
431 {
432 }
433
434 double WorkstationL07::getPowerPeakAt(int /*pstate_index*/)
435 {
436         THROW_UNIMPLEMENTED;
437 }
438
439 int WorkstationL07::getNbPstates()
440 {
441         THROW_UNIMPLEMENTED;
442 }
443
444 void WorkstationL07::setPstate(int /*pstate_index*/)
445 {
446         THROW_UNIMPLEMENTED;
447 }
448
449 int WorkstationL07::getPstate()
450 {
451         THROW_UNIMPLEMENTED;
452 }
453
454 double WorkstationL07::getConsumedEnergy()
455 {
456         THROW_UNIMPLEMENTED;
457 }
458
459 CpuL07::CpuL07(CpuL07ModelPtr model, const char* name, xbt_dict_t props,
460                      double power_initial, double power_scale, tmgr_trace_t power_trace,
461                            int core, e_surf_resource_state_t state_initial, tmgr_trace_t state_trace)
462  : Cpu(model, name, props, lmm_constraint_new(ptask_maxmin_system, this, power_initial * power_scale),
463            core, power_initial, power_scale)
464 {
465   xbt_assert(m_powerScale > 0, "Power has to be >0");
466
467   if (power_trace)
468     p_powerEvent = tmgr_history_add_trace(history, power_trace, 0.0, 0, this);
469   else
470     p_powerEvent = NULL;
471
472   setState(state_initial);
473   if (state_trace)
474         p_stateEvent = tmgr_history_add_trace(history, state_trace, 0.0, 0, this);
475 }
476
477 LinkL07::LinkL07(NetworkL07ModelPtr model, const char* name, xbt_dict_t props,
478                          double bw_initial,
479                          tmgr_trace_t bw_trace,
480                          double lat_initial,
481                          tmgr_trace_t lat_trace,
482                          e_surf_resource_state_t state_initial,
483                          tmgr_trace_t state_trace,
484                          e_surf_link_sharing_policy_t policy)
485  : NetworkLink(model, name, props, lmm_constraint_new(ptask_maxmin_system, this, bw_initial), history, state_trace)
486 {
487   m_bwCurrent = bw_initial;
488   if (bw_trace)
489     p_bwEvent = tmgr_history_add_trace(history, bw_trace, 0.0, 0, this);
490
491   setState(state_initial);
492   m_latCurrent = lat_initial;
493
494   if (lat_trace)
495         p_latEvent = tmgr_history_add_trace(history, lat_trace, 0.0, 0, this);
496
497   if (policy == SURF_LINK_FATPIPE)
498         lmm_constraint_shared(getConstraint());
499 }
500
501 bool CpuL07::isUsed(){
502   return lmm_constraint_used(ptask_maxmin_system, getConstraint());
503 }
504
505 bool LinkL07::isUsed(){
506   return lmm_constraint_used(ptask_maxmin_system, getConstraint());
507 }
508
509 void CpuL07::updateState(tmgr_trace_event_t event_type, double value, double /*date*/){
510   XBT_DEBUG("Updating cpu %s (%p) with value %g", getName(), this, value);
511   if (event_type == p_powerEvent) {
512           m_powerScale = value;
513     lmm_update_constraint_bound(ptask_maxmin_system, getConstraint(), m_powerPeak * m_powerScale);
514     if (tmgr_trace_event_free(event_type))
515       p_powerEvent = NULL;
516   } else if (event_type == p_stateEvent) {
517     if (value > 0)
518       setState(SURF_RESOURCE_ON);
519     else
520       setState(SURF_RESOURCE_OFF);
521     if (tmgr_trace_event_free(event_type))
522       p_stateEvent = NULL;
523   } else {
524     XBT_CRITICAL("Unknown event ! \n");
525     xbt_abort();
526   }
527   return;
528 }
529
530 void LinkL07::updateState(tmgr_trace_event_t event_type, double value, double date){
531   XBT_DEBUG("Updating link %s (%p) with value=%f for date=%g", getName(), this, value, date);
532   if (event_type == p_bwEvent) {
533     updateBandwidth(value, date);
534     if (tmgr_trace_event_free(event_type))
535       p_bwEvent = NULL;
536   } else if (event_type == p_latEvent) {
537     updateLatency(value, date);
538     if (tmgr_trace_event_free(event_type))
539       p_latEvent = NULL;
540   } else if (event_type == p_stateEvent) {
541     if (value > 0)
542       setState(SURF_RESOURCE_ON);
543     else
544       setState(SURF_RESOURCE_OFF);
545     if (tmgr_trace_event_free(event_type))
546       p_stateEvent = NULL;
547   } else {
548     XBT_CRITICAL("Unknown event ! \n");
549     xbt_abort();
550   }
551   return;
552 }
553
554 e_surf_resource_state_t WorkstationL07::getState()
555 {
556   return p_cpu->getState();
557 }
558
559 ActionPtr WorkstationL07::execute(double size)
560 {
561   void **workstation_list = xbt_new0(void *, 1);
562   double *flops_amount = xbt_new0(double, 1);
563   double *bytes_amount = xbt_new0(double, 1);
564
565   workstation_list[0] = this;
566   bytes_amount[0] = 0.0;
567   flops_amount[0] = size;
568
569   return static_cast<WorkstationL07ModelPtr>(getModel())->executeParallelTask(1, workstation_list,
570                                               flops_amount,
571                                      bytes_amount, -1);
572 }
573
574 ActionPtr WorkstationL07::sleep(double duration)
575 {
576   WorkstationL07ActionPtr action = NULL;
577
578   XBT_IN("(%s,%g)", getName(), duration);
579
580   action = static_cast<WorkstationL07ActionPtr>(execute(1.0));
581   action->m_maxDuration = duration;
582   action->m_suspended = 2;
583   lmm_update_variable_weight(ptask_maxmin_system, action->getVariable(), 0.0);
584
585   XBT_OUT();
586   return action;
587 }
588
589 double LinkL07::getBandwidth()
590 {
591   return m_bwCurrent;
592 }
593
594 void LinkL07::updateBandwidth(double value, double date)
595 {
596   m_bwCurrent = value;
597   lmm_update_constraint_bound(ptask_maxmin_system, getConstraint(), m_bwCurrent);
598 }
599
600 double LinkL07::getLatency()
601 {
602   return m_latCurrent;
603 }
604
605 void LinkL07::updateLatency(double value, double date)
606 {
607   lmm_variable_t var = NULL;
608   WorkstationL07ActionPtr action;
609   lmm_element_t elem = NULL;
610
611   m_latCurrent = value;
612   while ((var = lmm_get_var_from_cnst(ptask_maxmin_system, getConstraint(), &elem))) {
613     action = (WorkstationL07ActionPtr) lmm_variable_id(var);
614     action->updateBound();
615   }
616 }
617
618
619 bool LinkL07::isShared()
620 {
621   return lmm_constraint_is_shared(getConstraint());
622 }
623
624 /**********
625  * Action *
626  **********/
627
628 WorkstationL07Action::~WorkstationL07Action(){
629   free(p_workstationList);
630   free(p_communicationAmount);
631   free(p_computationAmount);
632 }
633
634 void WorkstationL07Action::updateBound()
635 {
636   double lat_current = 0.0;
637   double lat_bound = -1.0;
638   int i, j;
639
640   for (i = 0; i < m_workstationNb; i++) {
641     for (j = 0; j < m_workstationNb; j++) {
642       xbt_dynar_t route=NULL;
643
644       if (p_communicationAmount[i * m_workstationNb + j] > 0) {
645         double lat = 0.0;
646         routing_platf->getRouteAndLatency(static_cast<WorkstationL07Ptr>(((void**)p_workstationList)[i])->p_netElm,
647                                           static_cast<WorkstationL07Ptr>(((void**)p_workstationList)[j])->p_netElm,
648                                                           &route, &lat);
649
650         lat_current = MAX(lat_current, lat * p_communicationAmount[i * m_workstationNb + j]);
651       }
652     }
653   }
654   lat_bound = sg_tcp_gamma / (2.0 * lat_current);
655   XBT_DEBUG("action (%p) : lat_bound = %g", this, lat_bound);
656   if ((m_latency == 0.0) && (m_suspended == 0)) {
657     if (m_rate < 0)
658       lmm_update_variable_bound(ptask_maxmin_system, getVariable(), lat_bound);
659     else
660       lmm_update_variable_bound(ptask_maxmin_system, getVariable(), min(m_rate, lat_bound));
661   }
662 }
663
664 int WorkstationL07Action::unref()
665 {
666   m_refcount--;
667   if (!m_refcount) {
668     if (actionHook::is_linked())
669           p_stateSet->erase(p_stateSet->iterator_to(*this));
670     if (getVariable())
671       lmm_variable_free(ptask_maxmin_system, getVariable());
672     delete this;
673     return 1;
674   }
675   return 0;
676 }
677
678 void WorkstationL07Action::cancel()
679 {
680   setState(SURF_ACTION_FAILED);
681   return;
682 }
683
684 void WorkstationL07Action::suspend()
685 {
686   XBT_IN("(%p))", this);
687   if (m_suspended != 2) {
688     m_suspended = 1;
689     lmm_update_variable_weight(ptask_maxmin_system, getVariable(), 0.0);
690   }
691   XBT_OUT();
692 }
693
694 void WorkstationL07Action::resume()
695 {
696   XBT_IN("(%p)", this);
697   if (m_suspended != 2) {
698     lmm_update_variable_weight(ptask_maxmin_system, getVariable(), 1.0);
699     m_suspended = 0;
700   }
701   XBT_OUT();
702 }
703
704 bool WorkstationL07Action::isSuspended()
705 {
706   return m_suspended == 1;
707 }
708
709 void WorkstationL07Action::setMaxDuration(double duration)
710 {                               /* FIXME: should inherit */
711   XBT_IN("(%p,%g)", this, duration);
712   m_maxDuration = duration;
713   XBT_OUT();
714 }
715
716 void WorkstationL07Action::setPriority(double priority)
717 {                               /* FIXME: should inherit */
718   XBT_IN("(%p,%g)", this, priority);
719   m_priority = priority;
720   XBT_OUT();
721 }
722
723 double WorkstationL07Action::getRemains()
724 {
725   XBT_IN("(%p)", this);
726   XBT_OUT();
727   return m_remains;
728 }