Logo AND Algorithmique Numérique Distribuée

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