Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Declaration of the variables at the beginning of the functions
[simgrid.git] / src / surf / workstation_KCCFLN05.c
1 /*      $Id$     */
2
3 /* Copyright (c) 2005 Arnaud Legrand. All rights reserved.                  */
4
5 /* This program is free software; you can redistribute it and/or modify it
6  * under the terms of the license (GNU LGPL) which comes with this package. */
7
8 #include "xbt/ex.h"
9 #include "xbt/dict.h"
10 #include "surf_private.h"
11
12 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_workstation, surf,
13                                 "Logging specific to the SURF workstation module (KCCFLN05)");
14
15 typedef enum {
16   SURF_WORKSTATION_RESOURCE_CPU,
17   SURF_WORKSTATION_RESOURCE_LINK,
18 } e_surf_workstation_model_type_t;
19
20
21 /**************************************/
22 /********* router object **************/
23 /**************************************/
24 typedef struct router_KCCFLN05 {
25   char *name;           
26   unsigned int id;
27 } s_router_KCCFLN05_t, *router_KCCFLN05_t;
28
29
30 /**************************************/
31 /********* cpu object *****************/
32 /**************************************/
33 typedef struct cpu_KCCFLN05 {
34   surf_model_t model;
35   e_surf_workstation_model_type_t type; /* Do not move this field */
36   char *name;                                   /* Do not move this field */
37   lmm_constraint_t constraint;
38   lmm_constraint_t bus;
39   double power_scale;
40   double power_current;
41   double interference_send;
42   double interference_recv;
43   double interference_send_recv;
44   tmgr_trace_event_t power_event;
45   e_surf_cpu_state_t state_current;
46   tmgr_trace_event_t state_event;
47   int id;                       /* cpu and network card are a single object... */
48   xbt_dynar_t incomming_communications;
49   xbt_dynar_t outgoing_communications;
50 } s_cpu_KCCFLN05_t, *cpu_KCCFLN05_t;
51
52 /**************************************/
53 /*********** network object ***********/
54 /**************************************/
55
56 typedef struct network_link_KCCFLN05 {
57   surf_model_t model;
58   e_surf_workstation_model_type_t type; /* Do not move this field */
59   char *name;                                   /* Do not move this field */
60   lmm_constraint_t constraint;
61   double lat_current;
62   tmgr_trace_event_t lat_event;
63   double bw_current;
64   tmgr_trace_event_t bw_event;
65   e_surf_network_link_state_t state_current;
66   tmgr_trace_event_t state_event;
67 } s_network_link_KCCFLN05_t, *network_link_KCCFLN05_t;
68
69
70 typedef struct s_route_KCCFLN05 {
71   double impact_on_src;
72   double impact_on_dst;
73   double impact_on_src_with_other_recv;
74   double impact_on_dst_with_other_send;
75   network_link_KCCFLN05_t *links;
76   int size;
77 } s_route_KCCFLN05_t, *route_KCCFLN05_t;
78
79 /**************************************/
80 /*************** actions **************/
81 /**************************************/
82 typedef struct surf_action_workstation_KCCFLN05 {
83   s_surf_action_t generic_action;
84   double latency;
85   double lat_current;
86   lmm_variable_t variable;
87   double rate;
88   int suspended;
89   cpu_KCCFLN05_t src;           /* could be avoided */
90   cpu_KCCFLN05_t dst;           /* could be avoided */
91 } s_surf_action_workstation_KCCFLN05_t,
92   *surf_action_workstation_KCCFLN05_t;
93
94
95
96 static int nb_workstation = 0;
97 static s_route_KCCFLN05_t *routing_table = NULL;
98 #define ROUTE(i,j) routing_table[(i)+(j)*nb_workstation]
99 static network_link_KCCFLN05_t loopback = NULL;
100 static xbt_dict_t parallel_task_network_link_set = NULL;
101 //added to work with GTNETS
102 static xbt_dict_t router_set = NULL;
103 static lmm_system_t maxmin_system = NULL;
104 /*xbt_dict_t network_link_set = NULL;*/
105
106
107 /* convenient function */
108 static void __update_cpu_usage(cpu_KCCFLN05_t cpu)
109 {
110   int cpt;
111   surf_action_workstation_KCCFLN05_t action = NULL;
112   if ((!xbt_dynar_length(cpu->incomming_communications)) &&
113       (!xbt_dynar_length(cpu->outgoing_communications))) {
114     /* No communications */
115     lmm_update_constraint_bound(maxmin_system, cpu->constraint,
116                                 cpu->power_current * cpu->power_scale);
117   } else if ((!xbt_dynar_length(cpu->incomming_communications))
118              && (xbt_dynar_length(cpu->outgoing_communications))) {
119     /* Emission */
120     lmm_update_constraint_bound(maxmin_system, cpu->constraint,
121                                 cpu->power_current * cpu->power_scale *
122                                 cpu->interference_send);
123     xbt_dynar_foreach(cpu->outgoing_communications, cpt, action)
124         lmm_elem_set_value(maxmin_system, cpu->constraint,
125                            action->variable,
126                            cpu->power_current * cpu->power_scale *
127                            ROUTE(action->src->id,
128                                  action->dst->id).impact_on_src);
129   } else if ((xbt_dynar_length(cpu->incomming_communications))
130              && (!xbt_dynar_length(cpu->outgoing_communications))) {
131     /* Reception */
132     lmm_update_constraint_bound(maxmin_system, cpu->constraint,
133                                 cpu->power_current * cpu->power_scale *
134                                 cpu->interference_recv);
135     xbt_dynar_foreach(cpu->incomming_communications, cpt, action)
136         lmm_elem_set_value(maxmin_system, cpu->constraint,
137                            action->variable,
138                            cpu->power_current * cpu->power_scale *
139                            ROUTE(action->src->id,
140                                  action->dst->id).impact_on_dst);
141   } else {
142     /* Emission & Reception */
143     lmm_update_constraint_bound(maxmin_system, cpu->constraint,
144                                 cpu->power_current * cpu->power_scale *
145                                 cpu->interference_send_recv);
146     xbt_dynar_foreach(cpu->outgoing_communications, cpt, action)
147         lmm_elem_set_value(maxmin_system, cpu->constraint,
148                            action->variable,
149                            cpu->power_current * cpu->power_scale *
150                            ROUTE(action->src->id,
151                                  action->dst->id).
152                            impact_on_src_with_other_recv);
153     xbt_dynar_foreach(cpu->incomming_communications, cpt, action)
154         lmm_elem_set_value(maxmin_system, cpu->constraint,
155                            action->variable,
156                            cpu->power_current * cpu->power_scale *
157                            ROUTE(action->src->id,
158                                  action->dst->id).
159                            impact_on_dst_with_other_send);
160   }
161 }
162
163 /**************************************/
164 /******* Resource Public     **********/
165 /**************************************/
166
167 static void *name_service(const char *name)
168 {
169   xbt_ex_t e;
170   void *res = NULL;
171
172   TRY {
173     res = xbt_dict_get(workstation_set, name);
174   } CATCH(e) {
175     if (e.category != not_found_error)
176       RETHROW;
177     WARN1("Host '%s' not found, verifing if it is a router", name);
178     res = NULL;
179     xbt_ex_free(e);
180   }
181
182   return res;
183 }
184
185 static const char *get_resource_name(void *resource_id)
186 {
187   /* We can freely cast as a cpu_KCCFLN05_t because it has the same
188      prefix as network_link_KCCFLN05_t. However, only cpu_KCCFLN05_t
189      will theoretically be given as an argument here. */
190   return ((cpu_KCCFLN05_t) resource_id)->name;
191 }
192
193 /* action_get_state is inherited from the surf module */
194
195 static void action_use(surf_action_t action)
196 {
197   action->using++;
198   return;
199 }
200
201 static int action_free(surf_action_t action)
202 {
203   int cpt;
204   surf_action_t act = NULL;
205   cpu_KCCFLN05_t src = ((surf_action_workstation_KCCFLN05_t) action)->src;
206   cpu_KCCFLN05_t dst = ((surf_action_workstation_KCCFLN05_t) action)->dst;
207
208   action->using--;
209   if (!action->using) {
210     xbt_swag_remove(action, action->state_set);
211     if (((surf_action_workstation_KCCFLN05_t) action)->variable)
212       lmm_variable_free(maxmin_system,
213                         ((surf_action_workstation_KCCFLN05_t) action)->
214                         variable);
215     if (src)
216       xbt_dynar_foreach(src->outgoing_communications, cpt, act)
217           if (act == action) {
218         xbt_dynar_remove_at(src->outgoing_communications, cpt, &act);
219         break;
220       }
221
222     if (dst)
223       xbt_dynar_foreach(dst->incomming_communications, cpt, act)
224           if (act == action) {
225         xbt_dynar_remove_at(dst->incomming_communications, cpt, &act);
226         break;
227       }
228
229     if (src && (!xbt_dynar_length(src->outgoing_communications)))
230       __update_cpu_usage(src);
231     if (dst && (!xbt_dynar_length(dst->incomming_communications)))
232       __update_cpu_usage(dst);
233
234     free(action);
235     return 1;
236   }
237   return 0;
238 }
239
240 static void action_cancel(surf_action_t action)
241 {
242   surf_action_change_state(action, SURF_ACTION_FAILED);
243   return;
244 }
245
246 static void action_recycle(surf_action_t action)
247 {
248   DIE_IMPOSSIBLE;
249   return;
250 }
251
252 /* action_change_state is inherited from the surf module */
253 /* action_set_data is inherited from the surf module */
254
255 static void action_suspend(surf_action_t action)
256 {
257   XBT_IN1("(%p))", action);
258   if (((surf_action_workstation_KCCFLN05_t) action)->suspended != 2) {
259     ((surf_action_workstation_KCCFLN05_t) action)->suspended = 1;
260     lmm_update_variable_weight(maxmin_system,
261                                ((surf_action_workstation_KCCFLN05_t)
262                                 action)->variable, 0.0);
263   }
264   XBT_OUT;
265 }
266
267 static void action_resume(surf_action_t action)
268 {
269   XBT_IN1("(%p)", action);
270   if (((surf_action_workstation_KCCFLN05_t) action)->suspended != 2) {
271     if (((surf_action_workstation_KCCFLN05_t) action)->lat_current == 0.0)
272       lmm_update_variable_weight(maxmin_system,
273                                  ((surf_action_workstation_KCCFLN05_t)
274                                   action)->variable, action->priority);
275     else
276       lmm_update_variable_weight(maxmin_system,
277                                  ((surf_action_workstation_KCCFLN05_t)
278                                   action)->variable,
279                                  ((surf_action_workstation_KCCFLN05_t)
280                                   action)->lat_current);
281
282     ((surf_action_workstation_KCCFLN05_t) action)->suspended = 0;
283   }
284   XBT_OUT;
285 }
286
287 static int action_is_suspended(surf_action_t action)
288 {
289   return (((surf_action_workstation_KCCFLN05_t) action)->suspended == 1);
290 }
291
292 static void action_set_max_duration(surf_action_t action, double duration)
293 {                               /* FIXME: should inherit */
294   XBT_IN2("(%p,%g)", action, duration);
295   action->max_duration = duration;
296   XBT_OUT;
297 }
298
299
300 static void action_set_priority(surf_action_t action, double priority)
301 {
302   XBT_IN2("(%p,%g)", action, priority);
303   action->priority = priority;
304   lmm_update_variable_weight(maxmin_system, ((surf_action_workstation_KCCFLN05_t) action)->variable, priority);
305
306   XBT_OUT;
307 }
308
309 /**************************************/
310 /******* Resource Private    **********/
311 /**************************************/
312
313 static int resource_used(void *resource_id)
314 {
315   /* We can freely cast as a network_link_KCCFLN05_t because it has
316      the same prefix as cpu_KCCFLN05_t */
317   if (((cpu_KCCFLN05_t) resource_id)->type ==
318       SURF_WORKSTATION_RESOURCE_CPU)
319     return (lmm_constraint_used
320             (maxmin_system, ((cpu_KCCFLN05_t) resource_id)->constraint)
321             || ((((cpu_KCCFLN05_t) resource_id)->bus) ?
322                 lmm_constraint_used(maxmin_system,
323                                     ((cpu_KCCFLN05_t) resource_id)->
324                                     bus) : 0));
325   else
326     return lmm_constraint_used(maxmin_system,
327                                ((network_link_KCCFLN05_t) resource_id)->
328                                constraint);
329
330 }
331
332 static double share_resources(double now)
333 {
334   s_surf_action_workstation_KCCFLN05_t s_action;
335   surf_action_workstation_KCCFLN05_t action = NULL;
336
337   xbt_swag_t running_actions =
338       surf_workstation_model->common_public->states.running_action_set;
339   double min = generic_maxmin_share_resources(running_actions,
340                                               xbt_swag_offset(s_action,
341                                                               variable),
342                                               maxmin_system,
343                                               lmm_solve);
344
345   xbt_swag_foreach(action, running_actions) {
346     if (action->latency > 0) {
347       if (min < 0) {
348         min = action->latency;
349         DEBUG3("Updating min (value) with %p (start %f): %f", action,
350                action->generic_action.start, min);
351       } else if (action->latency < min) {
352         min = action->latency;
353         DEBUG3("Updating min (latency) with %p (start %f): %f", action,
354                action->generic_action.start, min);
355       }
356     }
357   }
358
359   DEBUG1("min value : %f", min);
360
361   return min;
362 }
363
364 static void update_actions_state(double now, double delta)
365 {
366   double deltap = 0.0;
367   surf_action_workstation_KCCFLN05_t action = NULL;
368   surf_action_workstation_KCCFLN05_t next_action = NULL;
369   xbt_swag_t running_actions =
370       surf_workstation_model->common_public->states.running_action_set;
371
372   xbt_swag_foreach_safe(action, next_action, running_actions) {
373     deltap = delta;
374     if (action->latency > 0) {
375       if (action->latency > deltap) {
376         double_update(&(action->latency), deltap);
377         deltap = 0.0;
378       } else {
379         double_update(&(deltap), action->latency);
380         action->latency = 0.0;
381       }
382       if ((action->latency == 0.0) && (action->suspended == 0)) {
383         if ((action)->lat_current == 0.0)
384           lmm_update_variable_weight(maxmin_system, action->variable, 1.0);
385         else
386           lmm_update_variable_weight(maxmin_system, action->variable,
387                                      action->lat_current);
388       }
389     }
390     DEBUG3("Action (%p) : remains (%g) updated by %g.",
391            action, action->generic_action.remains,
392            lmm_variable_getvalue(action->variable) * deltap);
393     double_update(&(action->generic_action.remains),
394                   lmm_variable_getvalue(action->variable) * deltap);
395
396     if (action->generic_action.max_duration != NO_MAX_DURATION)
397       double_update(&(action->generic_action.max_duration), delta);
398
399     if ((action->generic_action.remains <= 0) &&
400         (lmm_get_variable_weight(action->variable) > 0)) {
401       action->generic_action.finish = surf_get_clock();
402       surf_action_change_state((surf_action_t) action, SURF_ACTION_DONE);
403     } else if ((action->generic_action.max_duration != NO_MAX_DURATION) &&
404                (action->generic_action.max_duration <= 0)) {
405       action->generic_action.finish = surf_get_clock();
406       surf_action_change_state((surf_action_t) action, SURF_ACTION_DONE);
407     } else {
408       /* Need to check that none of the resource has failed */
409       lmm_constraint_t cnst = NULL;
410       int i = 0;
411       void *constraint_id = NULL;
412
413       while ((cnst =
414               lmm_get_cnst_from_var(maxmin_system, action->variable,
415                                     i++))) {
416         constraint_id = lmm_constraint_id(cnst);
417
418 /*      if(((network_link_KCCFLN05_t)constraint_id)->type== */
419 /*         SURF_WORKSTATION_RESOURCE_LINK) { */
420 /*        DEBUG2("Checking for link %s (%p)", */
421 /*               ((network_link_KCCFLN05_t)constraint_id)->name, */
422 /*               ((network_link_KCCFLN05_t)constraint_id)); */
423 /*      } */
424 /*      if(((cpu_KCCFLN05_t)constraint_id)->type== */
425 /*         SURF_WORKSTATION_RESOURCE_CPU) { */
426 /*        DEBUG3("Checking for cpu %s (%p) : %s", */
427 /*               ((cpu_KCCFLN05_t)constraint_id)->name, */
428 /*               ((cpu_KCCFLN05_t)constraint_id), */
429 /*               ((cpu_KCCFLN05_t)constraint_id)->state_current==SURF_CPU_OFF?"Off":"On"); */
430 /*      } */
431
432         if (((((network_link_KCCFLN05_t) constraint_id)->type ==
433               SURF_WORKSTATION_RESOURCE_LINK) &&
434              (((network_link_KCCFLN05_t) constraint_id)->state_current ==
435               SURF_NETWORK_LINK_OFF)) ||
436             ((((cpu_KCCFLN05_t) constraint_id)->type ==
437               SURF_WORKSTATION_RESOURCE_CPU) &&
438              (((cpu_KCCFLN05_t) constraint_id)->state_current ==
439               SURF_CPU_OFF))) {
440           DEBUG1("Action (%p) Failed!!", action);
441           action->generic_action.finish = surf_get_clock();
442           surf_action_change_state((surf_action_t) action,
443                                    SURF_ACTION_FAILED);
444           break;
445         }
446       }
447     }
448   }
449   return;
450 }
451
452 static void update_resource_state(void *id,
453                                   tmgr_trace_event_t event_type,
454                                   double value)
455 {
456   cpu_KCCFLN05_t cpu = id;
457   network_link_KCCFLN05_t nw_link = id;
458
459   if (nw_link->type == SURF_WORKSTATION_RESOURCE_LINK) {
460     DEBUG2("Updating link %s (%p)", nw_link->name, nw_link);
461     if (event_type == nw_link->bw_event) {
462       nw_link->bw_current = value;
463       lmm_update_constraint_bound(maxmin_system, nw_link->constraint,
464                                   nw_link->bw_current);
465     } else if (event_type == nw_link->lat_event) {
466       double delta = value - nw_link->lat_current;
467       lmm_variable_t var = NULL;
468       surf_action_workstation_KCCFLN05_t action = NULL;
469
470       nw_link->lat_current = value;
471       while (lmm_get_var_from_cnst
472              (maxmin_system, nw_link->constraint, &var)) {
473         action = lmm_variable_id(var);
474         action->lat_current += delta;
475         if (action->rate < 0)
476           lmm_update_variable_bound(maxmin_system, action->variable,
477                                     SG_TCP_CTE_GAMMA / (2.0 *
478                                                         action->
479                                                         lat_current));
480         else
481           lmm_update_variable_bound(maxmin_system, action->variable,
482                                     min(action->rate,
483                                         SG_TCP_CTE_GAMMA / (2.0 *
484                                                             action->
485                                                             lat_current)));
486         if (action->suspended == 0)
487           lmm_update_variable_weight(maxmin_system, action->variable,
488                                      action->lat_current);
489         lmm_update_variable_latency(maxmin_system, action->variable,
490                                     delta);
491
492
493       }
494     } else if (event_type == nw_link->state_event) {
495       if (value > 0)
496         nw_link->state_current = SURF_NETWORK_LINK_ON;
497       else
498         nw_link->state_current = SURF_NETWORK_LINK_OFF;
499     } else {
500       CRITICAL0("Unknown event ! \n");
501       xbt_abort();
502     }
503     return;
504   } else if (cpu->type == SURF_WORKSTATION_RESOURCE_CPU) {
505     DEBUG3("Updating cpu %s (%p) with value %g", cpu->name, cpu, value);
506     if (event_type == cpu->power_event) {
507       cpu->power_current = value;
508       __update_cpu_usage(cpu);
509     } else if (event_type == cpu->state_event) {
510       if (value > 0)
511         cpu->state_current = SURF_CPU_ON;
512       else
513         cpu->state_current = SURF_CPU_OFF;
514     } else {
515       CRITICAL0("Unknown event ! \n");
516       xbt_abort();
517     }
518     return;
519   } else {
520     DIE_IMPOSSIBLE;
521   }
522   return;
523 }
524
525 static void finalize(void)
526 {
527   int i, j;
528
529   xbt_dict_free(&network_link_set);
530   xbt_dict_free(&workstation_set);
531   xbt_dict_free(&router_set);
532   if (parallel_task_network_link_set != NULL) {
533     xbt_dict_free(&parallel_task_network_link_set);
534   }
535   xbt_swag_free(surf_workstation_model->common_public->states.
536                 ready_action_set);
537   xbt_swag_free(surf_workstation_model->common_public->states.
538                 running_action_set);
539   xbt_swag_free(surf_workstation_model->common_public->states.
540                 failed_action_set);
541   xbt_swag_free(surf_workstation_model->common_public->states.
542                 done_action_set);
543
544   free(surf_workstation_model->common_public);
545   free(surf_workstation_model->common_private);
546   free(surf_workstation_model->extension_public);
547
548   free(surf_workstation_model);
549   surf_workstation_model = NULL;
550
551   for (i = 0; i < nb_workstation; i++)
552     for (j = 0; j < nb_workstation; j++)
553       free(ROUTE(i, j).links);
554   free(routing_table);
555   routing_table = NULL;
556   nb_workstation = 0;
557
558   if (maxmin_system) {
559     lmm_system_free(maxmin_system);
560     maxmin_system = NULL;
561   }
562 }
563
564 /**************************************/
565 /******* Resource Private    **********/
566 /**************************************/
567
568 static surf_action_t execute(void *cpu, double size)
569 {
570   surf_action_workstation_KCCFLN05_t action = NULL;
571   cpu_KCCFLN05_t CPU = cpu;
572
573   XBT_IN2("(%s,%g)", CPU->name, size);
574   action = xbt_new0(s_surf_action_workstation_KCCFLN05_t, 1);
575
576   action->generic_action.using = 1;
577   action->generic_action.cost = size;
578   action->generic_action.remains = size;
579   action->generic_action.priority = 1.0;
580   action->generic_action.max_duration = NO_MAX_DURATION;
581   action->generic_action.start = surf_get_clock();
582   action->generic_action.finish = -1.0;
583   action->generic_action.model_type =
584       (surf_model_t) surf_workstation_model;
585   action->suspended = 0;
586
587   if (CPU->state_current == SURF_CPU_ON)
588     action->generic_action.state_set =
589         surf_workstation_model->common_public->states.
590         running_action_set;
591   else
592     action->generic_action.state_set =
593         surf_workstation_model->common_public->states.failed_action_set;
594   xbt_swag_insert(action, action->generic_action.state_set);
595
596   action->variable = lmm_variable_new(maxmin_system, action,
597                                       action->generic_action.priority,
598                                       -1.0, 1);
599   lmm_expand(maxmin_system, CPU->constraint, action->variable, 1.0);
600   XBT_OUT;
601   return (surf_action_t) action;
602 }
603
604 static surf_action_t action_sleep(void *cpu, double duration)
605 {
606   surf_action_workstation_KCCFLN05_t action = NULL;
607
608   XBT_IN2("(%s,%g)", ((cpu_KCCFLN05_t) cpu)->name, duration);
609
610   action = (surf_action_workstation_KCCFLN05_t) execute(cpu, 1.0);
611   action->generic_action.max_duration = duration;
612   action->suspended = 2;
613   lmm_update_variable_weight(maxmin_system, action->variable, 0.0);
614
615   XBT_OUT;
616   return (surf_action_t) action;
617 }
618
619 static e_surf_cpu_state_t resource_get_state(void *cpu)
620 {
621   return ((cpu_KCCFLN05_t) cpu)->state_current;
622 }
623
624 static double get_speed(void *cpu, double load)
625 {
626   return load * (((cpu_KCCFLN05_t) cpu)->power_scale);
627 }
628
629 static double get_available_speed(void *cpu)
630 {
631   return ((cpu_KCCFLN05_t) cpu)->power_current;
632 }
633
634
635 static surf_action_t communicate(void *src, void *dst, double size,
636                                  double rate)
637 {
638   surf_action_workstation_KCCFLN05_t action = NULL;
639   cpu_KCCFLN05_t card_src = src;
640   cpu_KCCFLN05_t card_dst = dst;
641   route_KCCFLN05_t route = &(ROUTE(card_src->id, card_dst->id));
642   int route_size = route->size;
643   int i;
644
645   XBT_IN4("(%s,%s,%g,%g)", card_src->name, card_dst->name, size, rate);
646   xbt_assert2(route_size,
647               "You're trying to send data from %s to %s but there is no connexion between these two cards.",
648               card_src->name, card_dst->name);
649
650   action = xbt_new0(s_surf_action_workstation_KCCFLN05_t, 1);
651
652   action->generic_action.using = 1;
653   action->generic_action.cost = size;
654   action->generic_action.remains = size;
655   action->generic_action.max_duration = NO_MAX_DURATION;
656   action->generic_action.start = surf_get_clock();
657   action->generic_action.finish = -1.0;
658   action->src = src;
659   action->dst = dst;
660   action->generic_action.model_type =
661       (surf_model_t) surf_workstation_model;
662   action->suspended = 0;        /* Should be useless because of the 
663                                    calloc but it seems to help valgrind... */
664   action->generic_action.state_set =
665       surf_workstation_model->common_public->states.running_action_set;
666
667   xbt_dynar_push(card_src->outgoing_communications, &action);
668   xbt_dynar_push(card_dst->incomming_communications, &action);
669
670   xbt_swag_insert(action, action->generic_action.state_set);
671   action->rate = rate;
672
673   action->latency = 0.0;
674   for (i = 0; i < route_size; i++)
675     action->latency += route->links[i]->lat_current;
676   action->lat_current = action->latency;
677
678   if (action->latency > 0)
679     action->variable = lmm_variable_new(maxmin_system, action, 0.0, -1.0, route_size + 4);      /* +1 for the src bus
680                                                                                                    +1 for the dst bus
681                                                                                                    +1 for the src cpu
682                                                                                                    +1 for the dst cpu */
683   else
684     action->variable = lmm_variable_new(maxmin_system, action, 1.0, -1.0,
685                                         route_size + 4);
686
687   if (action->rate < 0) {
688     if (action->lat_current > 0)
689       lmm_update_variable_bound(maxmin_system, action->variable,
690                                 SG_TCP_CTE_GAMMA / (2.0 *
691                                                     action->lat_current));
692     else
693       lmm_update_variable_bound(maxmin_system, action->variable, -1.0);
694   } else {
695     if (action->lat_current > 0)
696       lmm_update_variable_bound(maxmin_system, action->variable,
697                                 min(action->rate,
698                                     SG_TCP_CTE_GAMMA / (2.0 *
699                                                         action->
700                                                         lat_current)));
701     else
702       lmm_update_variable_bound(maxmin_system, action->variable,
703                                 action->rate);
704   }
705
706   lmm_update_variable_latency(maxmin_system, action->variable,
707                               action->latency); /* Should be useless */
708
709   for (i = 0; i < route_size; i++)
710     lmm_expand(maxmin_system, route->links[i]->constraint,
711                action->variable, 1.0);
712   if (card_src->bus)
713     lmm_expand(maxmin_system, card_src->bus, action->variable, 1.0);
714   if (card_dst->bus)
715     lmm_expand(maxmin_system, card_dst->bus, action->variable, 1.0);
716   lmm_expand(maxmin_system, card_src->constraint, action->variable, 0.0);
717   lmm_expand(maxmin_system, card_dst->constraint, action->variable, 0.0);
718
719   XBT_OUT;
720   return (surf_action_t) action;
721 }
722
723 static surf_action_t execute_parallel_task(int workstation_nb,
724                                            void **workstation_list,
725                                            double *computation_amount,
726                                            double *communication_amount,
727                                            double amount, double rate)
728 {
729   surf_action_workstation_KCCFLN05_t action = NULL;
730   int i, j, k;
731   int nb_link = 0;
732   int nb_host = 0;
733
734   if (parallel_task_network_link_set == NULL) {
735     parallel_task_network_link_set =
736         xbt_dict_new_ext(workstation_nb * workstation_nb * 10);
737   }
738
739   /* Compute the number of affected resources... */
740   for (i = 0; i < workstation_nb; i++) {
741     for (j = 0; j < workstation_nb; j++) {
742       cpu_KCCFLN05_t card_src = workstation_list[i];
743       cpu_KCCFLN05_t card_dst = workstation_list[j];
744       int route_size = ROUTE(card_src->id, card_dst->id).size;
745       network_link_KCCFLN05_t *route =
746           ROUTE(card_src->id, card_dst->id).links;
747
748       if (communication_amount[i * workstation_nb + j] > 0)
749         for (k = 0; k < route_size; k++) {
750           xbt_dict_set(parallel_task_network_link_set, route[k]->name,
751                        route[k], NULL);
752         }
753     }
754   }
755   nb_link = xbt_dict_length(parallel_task_network_link_set);
756   xbt_dict_reset(parallel_task_network_link_set);
757
758
759   for (i = 0; i < workstation_nb; i++)
760     if (computation_amount[i] > 0)
761       nb_host++;
762
763   action = xbt_new0(s_surf_action_workstation_KCCFLN05_t, 1);
764   DEBUG3("Creating a parallel task (%p) with %d cpus and %d links.",
765          action, nb_host, nb_link);
766   action->generic_action.using = 1;
767   action->generic_action.cost = amount;
768   action->generic_action.remains = amount;
769   action->generic_action.max_duration = NO_MAX_DURATION;
770   action->generic_action.start = surf_get_clock();
771   action->generic_action.finish = -1.0;
772   action->generic_action.model_type =
773       (surf_model_t) surf_workstation_model;
774   action->suspended = 0;        /* Should be useless because of the
775                                    calloc but it seems to help valgrind... */
776   action->generic_action.state_set =
777       surf_workstation_model->common_public->states.running_action_set;
778
779   xbt_swag_insert(action, action->generic_action.state_set);
780   action->rate = rate;
781
782   if (action->rate > 0)
783     action->variable = lmm_variable_new(maxmin_system, action, 1.0, -1.0,
784                                         nb_host + nb_link);
785   else
786     action->variable =
787         lmm_variable_new(maxmin_system, action, 1.0, action->rate,
788                          nb_host + nb_link);
789
790   for (i = 0; i < workstation_nb; i++)
791     if (computation_amount[i] > 0)
792       lmm_expand(maxmin_system,
793                  ((cpu_KCCFLN05_t) workstation_list[i])->constraint,
794                  action->variable, computation_amount[i]);
795
796   for (i = 0; i < workstation_nb; i++) {
797     for (j = 0; j < workstation_nb; j++) {
798       cpu_KCCFLN05_t card_src = workstation_list[i];
799       cpu_KCCFLN05_t card_dst = workstation_list[j];
800       int route_size = ROUTE(card_src->id, card_dst->id).size;
801       network_link_KCCFLN05_t *route =
802           ROUTE(card_src->id, card_dst->id).links;
803
804       for (k = 0; k < route_size; k++) {
805         if (communication_amount[i * workstation_nb + j] > 0) {
806           lmm_expand_add(maxmin_system, route[k]->constraint,
807                          action->variable,
808                          communication_amount[i * workstation_nb + j]);
809         }
810       }
811     }
812   }
813
814   if (nb_link + nb_host == 0) {
815     action->generic_action.cost = 1.0;
816     action->generic_action.remains = 0.0;
817   }
818
819   return (surf_action_t) action;
820 }
821
822 /* returns an array of network_link_KCCFLN05_t */
823 static const void **get_route(void *src, void *dst)
824 {
825   cpu_KCCFLN05_t card_src = src;
826   cpu_KCCFLN05_t card_dst = dst;
827   route_KCCFLN05_t route = &(ROUTE(card_src->id, card_dst->id));
828
829   return (const void **) route->links;
830 }
831
832 static int get_route_size(void *src, void *dst)
833 {
834   cpu_KCCFLN05_t card_src = src;
835   cpu_KCCFLN05_t card_dst = dst;
836   route_KCCFLN05_t route = &(ROUTE(card_src->id, card_dst->id));
837   return route->size;
838 }
839
840 static const char *get_link_name(const void *link)
841 {
842   return ((network_link_KCCFLN05_t) link)->name;
843 }
844
845 static double get_link_bandwidth(const void *link)
846 {
847   return ((network_link_KCCFLN05_t) link)->bw_current;
848 }
849
850 static double get_link_latency(const void *link)
851 {
852   return ((network_link_KCCFLN05_t) link)->lat_current;
853 }
854
855 /**************************************/
856 /*** Resource Creation & Destruction **/
857 /**************************************/
858
859
860 static void router_free(void *router)
861 {
862   free(((router_KCCFLN05_t) router)->name);
863 }
864
865 static void router_new(const char *name)
866 {
867   static unsigned int nb_routers = 0;
868
869   INFO1("Creating a router %s", name);
870
871   router_KCCFLN05_t router;
872   router = xbt_new0(s_router_KCCFLN05_t, 1);
873
874   router->name = xbt_strdup(name);
875   router->id = nb_routers++;
876   xbt_dict_set(router_set, name, router, router_free);
877 }
878
879 static void parse_routers(void)
880 {
881   //add a dumb router just to be GTNETS compatible
882   router_new(A_surfxml_router_name);
883 }
884
885 static void cpu_free(void *cpu)
886 {
887   free(((cpu_KCCFLN05_t) cpu)->name);
888   xbt_dynar_free(&(((cpu_KCCFLN05_t) cpu)->incomming_communications));
889   xbt_dynar_free(&(((cpu_KCCFLN05_t) cpu)->outgoing_communications));
890   free(cpu);
891 }
892
893 static cpu_KCCFLN05_t cpu_new(const char *name, double power_scale,
894                               double power_initial,
895                               tmgr_trace_t power_trace,
896                               e_surf_cpu_state_t state_initial,
897                               tmgr_trace_t state_trace,
898                               double interference_send,
899                               double interference_recv,
900                               double interference_send_recv,
901                               double max_outgoing_rate)
902 {
903   cpu_KCCFLN05_t cpu = xbt_new0(s_cpu_KCCFLN05_t, 1);
904
905   cpu->model = (surf_model_t) surf_workstation_model;
906   cpu->type = SURF_WORKSTATION_RESOURCE_CPU;
907   cpu->name = xbt_strdup(name);
908   cpu->id = nb_workstation++;
909
910   cpu->power_scale = power_scale;
911   xbt_assert0(cpu->power_scale > 0, "Power has to be >0");
912
913   cpu->power_current = power_initial;
914   if (power_trace)
915     cpu->power_event =
916         tmgr_history_add_trace(history, power_trace, 0.0, 0, cpu);
917
918   cpu->state_current = state_initial;
919   if (state_trace)
920     cpu->state_event =
921         tmgr_history_add_trace(history, state_trace, 0.0, 0, cpu);
922
923   cpu->interference_send = interference_send;
924   cpu->interference_recv = interference_recv;
925   cpu->interference_send_recv = interference_send_recv;
926
927   cpu->constraint =
928       lmm_constraint_new(maxmin_system, cpu,
929                          cpu->power_current * cpu->power_scale);
930   if (max_outgoing_rate > 0)
931     cpu->bus = lmm_constraint_new(maxmin_system, cpu, max_outgoing_rate);
932
933   cpu->incomming_communications =
934       xbt_dynar_new(sizeof(surf_action_workstation_KCCFLN05_t), NULL);
935   cpu->outgoing_communications =
936       xbt_dynar_new(sizeof(surf_action_workstation_KCCFLN05_t), NULL);
937
938   xbt_dict_set(workstation_set, name, cpu, cpu_free);
939
940   return cpu;
941 }
942
943 static void parse_cpu(void)
944 {
945   double power_scale = 0.0;
946   double power_initial = 0.0;
947   tmgr_trace_t power_trace = NULL;
948   e_surf_cpu_state_t state_initial = SURF_CPU_OFF;
949   tmgr_trace_t state_trace = NULL;
950   double interference_send = 0.0;
951   double interference_recv = 0.0;
952   double interference_send_recv = 0.0;
953   double max_outgoing_rate = -1.0;
954
955   surf_parse_get_double(&power_scale, A_surfxml_cpu_power);
956   surf_parse_get_double(&power_initial, A_surfxml_cpu_availability);
957   surf_parse_get_trace(&power_trace, A_surfxml_cpu_availability_file);
958
959   xbt_assert0((A_surfxml_cpu_state == A_surfxml_cpu_state_ON) ||
960               (A_surfxml_cpu_state == A_surfxml_cpu_state_OFF),
961               "Invalid state");
962   if (A_surfxml_cpu_state == A_surfxml_cpu_state_ON)
963     state_initial = SURF_CPU_ON;
964   if (A_surfxml_cpu_state == A_surfxml_cpu_state_OFF)
965     state_initial = SURF_CPU_OFF;
966   surf_parse_get_trace(&state_trace, A_surfxml_cpu_state_file);
967
968   surf_parse_get_double(&interference_send,
969                         A_surfxml_cpu_interference_send);
970   surf_parse_get_double(&interference_recv,
971                         A_surfxml_cpu_interference_recv);
972   surf_parse_get_double(&interference_send_recv,
973                         A_surfxml_cpu_interference_send_recv);
974   surf_parse_get_double(&max_outgoing_rate,
975                         A_surfxml_cpu_max_outgoing_rate);
976
977   cpu_new(A_surfxml_cpu_name, power_scale, power_initial, power_trace,
978           state_initial, state_trace, interference_send, interference_recv,
979           interference_send_recv, max_outgoing_rate);
980 }
981
982 static void create_routing_table(void)
983 {
984   routing_table =
985       xbt_new0(s_route_KCCFLN05_t, nb_workstation * nb_workstation);
986 }
987
988 static void network_link_free(void *nw_link)
989 {
990   free(((network_link_KCCFLN05_t) nw_link)->name);
991   free(nw_link);
992 }
993
994 static network_link_KCCFLN05_t network_link_new(char *name,
995                                                 double bw_initial,
996                                                 tmgr_trace_t bw_trace,
997                                                 double lat_initial,
998                                                 tmgr_trace_t lat_trace,
999                                                 e_surf_network_link_state_t
1000                                                 state_initial,
1001                                                 tmgr_trace_t state_trace,
1002                                                 e_surf_network_link_sharing_policy_t
1003                                                 policy)
1004 {
1005   network_link_KCCFLN05_t nw_link = xbt_new0(s_network_link_KCCFLN05_t, 1);
1006
1007
1008   nw_link->model = (surf_model_t) surf_workstation_model;
1009   nw_link->type = SURF_WORKSTATION_RESOURCE_LINK;
1010   nw_link->name = name;
1011   nw_link->bw_current = bw_initial;
1012   if (bw_trace)
1013     nw_link->bw_event =
1014         tmgr_history_add_trace(history, bw_trace, 0.0, 0, nw_link);
1015   nw_link->state_current = state_initial;
1016   nw_link->lat_current = lat_initial;
1017   if (lat_trace)
1018     nw_link->lat_event =
1019         tmgr_history_add_trace(history, lat_trace, 0.0, 0, nw_link);
1020   if (state_trace)
1021     nw_link->state_event =
1022         tmgr_history_add_trace(history, state_trace, 0.0, 0, nw_link);
1023
1024   nw_link->constraint =
1025       lmm_constraint_new(maxmin_system, nw_link, nw_link->bw_current);
1026
1027   if (policy == SURF_NETWORK_LINK_FATPIPE)
1028     lmm_constraint_shared(nw_link->constraint);
1029
1030   xbt_dict_set(network_link_set, name, nw_link, network_link_free);
1031
1032   return nw_link;
1033 }
1034
1035 static void parse_network_link(void)
1036 {
1037   char *name;
1038   double bw_initial;
1039   tmgr_trace_t bw_trace;
1040   double lat_initial;
1041   tmgr_trace_t lat_trace;
1042   e_surf_network_link_state_t state_initial = SURF_NETWORK_LINK_ON;
1043   e_surf_network_link_sharing_policy_t policy_initial =
1044       SURF_NETWORK_LINK_SHARED;
1045   tmgr_trace_t state_trace;
1046
1047   name = xbt_strdup(A_surfxml_network_link_name);
1048   surf_parse_get_double(&bw_initial, A_surfxml_network_link_bandwidth);
1049   surf_parse_get_trace(&bw_trace, A_surfxml_network_link_bandwidth_file);
1050   surf_parse_get_double(&lat_initial, A_surfxml_network_link_latency);
1051   surf_parse_get_trace(&lat_trace, A_surfxml_network_link_latency_file);
1052
1053   xbt_assert0((A_surfxml_network_link_state ==
1054                A_surfxml_network_link_state_ON)
1055               || (A_surfxml_network_link_state ==
1056                   A_surfxml_network_link_state_OFF), "Invalid state");
1057   if (A_surfxml_network_link_state == A_surfxml_network_link_state_ON)
1058     state_initial = SURF_NETWORK_LINK_ON;
1059   else if (A_surfxml_network_link_state ==
1060            A_surfxml_network_link_state_OFF)
1061     state_initial = SURF_NETWORK_LINK_OFF;
1062
1063   if (A_surfxml_network_link_sharing_policy ==
1064       A_surfxml_network_link_sharing_policy_SHARED)
1065     policy_initial = SURF_NETWORK_LINK_SHARED;
1066   else if (A_surfxml_network_link_sharing_policy ==
1067            A_surfxml_network_link_sharing_policy_FATPIPE)
1068     policy_initial = SURF_NETWORK_LINK_FATPIPE;
1069
1070   surf_parse_get_trace(&state_trace, A_surfxml_network_link_state_file);
1071
1072   network_link_new(name, bw_initial, bw_trace,
1073                    lat_initial, lat_trace, state_initial, state_trace,
1074                    policy_initial);
1075 }
1076
1077 static void route_new(int src_id, int dst_id,
1078                       network_link_KCCFLN05_t * link_list, int nb_link,
1079                       double impact_on_src, double impact_on_dst,
1080                       double impact_on_src_with_other_recv,
1081                       double impact_on_dst_with_other_send)
1082 {
1083   route_KCCFLN05_t route = &(ROUTE(src_id, dst_id));
1084
1085   route->size = nb_link;
1086   route->links = link_list =
1087       xbt_realloc(link_list, sizeof(network_link_KCCFLN05_t) * nb_link);
1088   route->impact_on_src = impact_on_src;
1089   route->impact_on_dst = impact_on_src;
1090   route->impact_on_src_with_other_recv = impact_on_src_with_other_recv;
1091   route->impact_on_dst_with_other_send = impact_on_dst_with_other_send;
1092 }
1093
1094 static int nb_link;
1095 static int link_list_capacity;
1096 static network_link_KCCFLN05_t *link_list = NULL;
1097 static int src_id = -1;
1098 static int dst_id = -1;
1099 static double impact_on_src;
1100 static double impact_on_dst;
1101 static double impact_on_src_with_other_recv;
1102 static double impact_on_dst_with_other_send;
1103
1104 static void parse_route_set_endpoints(void)
1105 {
1106   cpu_KCCFLN05_t cpu_tmp = NULL;
1107
1108   cpu_tmp = (cpu_KCCFLN05_t) name_service(A_surfxml_route_src);
1109   if (cpu_tmp != NULL) {
1110     src_id = cpu_tmp->id;
1111   } else {
1112     xbt_assert1(xbt_dict_get_or_null(router_set, A_surfxml_route_src),
1113                 "Invalid name '%s': neither a cpu nor a router!",
1114                 A_surfxml_route_src);
1115     src_id = -1;
1116     return;
1117   }
1118
1119   cpu_tmp = (cpu_KCCFLN05_t) name_service(A_surfxml_route_dst);
1120   if (cpu_tmp != NULL) {
1121     dst_id = cpu_tmp->id;
1122   } else {
1123     xbt_assert1(xbt_dict_get_or_null(router_set, A_surfxml_route_dst),
1124                 "Invalid name '%s': neither a cpu nor a router!",
1125                 A_surfxml_route_dst);
1126     dst_id = -1;
1127     return;
1128   }
1129
1130   surf_parse_get_double(&impact_on_src, A_surfxml_route_impact_on_src);
1131   surf_parse_get_double(&impact_on_dst, A_surfxml_route_impact_on_dst);
1132   surf_parse_get_double(&impact_on_src_with_other_recv,
1133                         A_surfxml_route_impact_on_src_with_other_recv);
1134   surf_parse_get_double(&impact_on_dst_with_other_send,
1135                         A_surfxml_route_impact_on_dst_with_other_send);
1136
1137   nb_link = 0;
1138   link_list_capacity = 1;
1139   link_list = xbt_new(network_link_KCCFLN05_t, link_list_capacity);
1140
1141 }
1142
1143 static void parse_route_elem(void)
1144 {
1145   xbt_ex_t e;
1146   if (nb_link == link_list_capacity) {
1147     link_list_capacity *= 2;
1148     link_list =
1149         xbt_realloc(link_list,
1150                     (link_list_capacity) *
1151                     sizeof(network_link_KCCFLN05_t));
1152   }
1153   TRY {
1154     link_list[nb_link++] =
1155         xbt_dict_get(network_link_set, A_surfxml_route_element_name);
1156   }
1157   CATCH(e) {
1158     RETHROW1("Link %s not found (dict raised this exception: %s)",
1159              A_surfxml_route_element_name);
1160   }
1161 }
1162
1163 static void parse_route_set_route(void)
1164 {
1165   if (src_id != -1 && dst_id != -1)
1166     route_new(src_id, dst_id, link_list, nb_link, impact_on_src,
1167               impact_on_dst, impact_on_src_with_other_recv,
1168               impact_on_dst_with_other_send);
1169 }
1170
1171 static void parse_file(const char *file)
1172 {
1173   int i;
1174
1175   /* Figuring out the cpus */
1176   surf_parse_reset_parser();
1177   ETag_surfxml_cpu_fun = parse_cpu;
1178   surf_parse_open(file);
1179   xbt_assert1((!surf_parse()), "Parse error in %s", file);
1180   surf_parse_close();
1181
1182   create_routing_table();
1183
1184   /* Figuring out the router (added after GTNETS) */
1185   surf_parse_reset_parser();
1186   STag_surfxml_router_fun = parse_routers;
1187   surf_parse_open(file);
1188   xbt_assert1((!surf_parse()), "Parse error in %s", file);
1189   surf_parse_close();
1190
1191   /* Figuring out the network links */
1192   surf_parse_reset_parser();
1193   ETag_surfxml_network_link_fun = parse_network_link;
1194   surf_parse_open(file);
1195   xbt_assert1((!surf_parse()), "Parse error in %s", file);
1196   surf_parse_close();
1197
1198   /* Building the routes */
1199   surf_parse_reset_parser();
1200   STag_surfxml_route_fun = parse_route_set_endpoints;
1201   ETag_surfxml_route_element_fun = parse_route_elem;
1202   ETag_surfxml_route_fun = parse_route_set_route;
1203   surf_parse_open(file);
1204   xbt_assert1((!surf_parse()), "Parse error in %s", file);
1205   surf_parse_close();
1206
1207   /* Adding loopback if needed */
1208   for (i = 0; i < nb_workstation; i++)
1209     if (!ROUTE(i, i).size) {
1210       if (!loopback)
1211         loopback = network_link_new(xbt_strdup("__MSG_loopback__"),
1212                                     498000000, NULL, 0.000015, NULL,
1213                                     SURF_NETWORK_LINK_ON, NULL,
1214                                     SURF_NETWORK_LINK_FATPIPE);
1215       ROUTE(i, i).size = 1;
1216       ROUTE(i, i).links = xbt_new0(network_link_KCCFLN05_t, 1);
1217       ROUTE(i, i).links[0] = loopback;
1218     }
1219
1220 }
1221
1222 /**************************************/
1223 /********* Module  creation ***********/
1224 /**************************************/
1225
1226 static void model_init_internal(void)
1227 {
1228   s_surf_action_t action;
1229
1230   surf_workstation_model = xbt_new0(s_surf_workstation_model_t, 1);
1231
1232   surf_workstation_model->common_private =
1233       xbt_new0(s_surf_model_private_t, 1);
1234   surf_workstation_model->common_public =
1235       xbt_new0(s_surf_model_public_t, 1);
1236   surf_workstation_model->extension_public =
1237       xbt_new0(s_surf_workstation_model_extension_public_t, 1);
1238
1239   surf_workstation_model->common_public->states.ready_action_set =
1240       xbt_swag_new(xbt_swag_offset(action, state_hookup));
1241   surf_workstation_model->common_public->states.running_action_set =
1242       xbt_swag_new(xbt_swag_offset(action, state_hookup));
1243   surf_workstation_model->common_public->states.failed_action_set =
1244       xbt_swag_new(xbt_swag_offset(action, state_hookup));
1245   surf_workstation_model->common_public->states.done_action_set =
1246       xbt_swag_new(xbt_swag_offset(action, state_hookup));
1247
1248   surf_workstation_model->common_public->name_service = name_service;
1249   surf_workstation_model->common_public->get_resource_name =
1250       get_resource_name;
1251   surf_workstation_model->common_public->action_get_state =
1252       surf_action_get_state;
1253   surf_workstation_model->common_public->action_get_start_time =
1254       surf_action_get_start_time;
1255   surf_workstation_model->common_public->action_get_finish_time =
1256       surf_action_get_finish_time;
1257   surf_workstation_model->common_public->action_use = action_use;
1258   surf_workstation_model->common_public->action_free = action_free;
1259   surf_workstation_model->common_public->action_cancel = action_cancel;
1260   surf_workstation_model->common_public->action_recycle =
1261       action_recycle;
1262   surf_workstation_model->common_public->action_change_state =
1263       surf_action_change_state;
1264   surf_workstation_model->common_public->action_set_data =
1265       surf_action_set_data;
1266   surf_workstation_model->common_public->suspend = action_suspend;
1267   surf_workstation_model->common_public->resume = action_resume;
1268   surf_workstation_model->common_public->is_suspended =
1269       action_is_suspended;
1270   surf_workstation_model->common_public->set_max_duration =
1271       action_set_max_duration;
1272   surf_workstation_model->common_public->set_priority =
1273       action_set_priority;
1274   surf_workstation_model->common_public->name = "Workstation KCCFLN05";
1275
1276   surf_workstation_model->common_private->resource_used = resource_used;
1277   surf_workstation_model->common_private->share_resources =
1278       share_resources;
1279   surf_workstation_model->common_private->update_actions_state =
1280       update_actions_state;
1281   surf_workstation_model->common_private->update_resource_state =
1282       update_resource_state;
1283   surf_workstation_model->common_private->finalize = finalize;
1284
1285   surf_workstation_model->extension_public->execute = execute;
1286   surf_workstation_model->extension_public->sleep = action_sleep;
1287   surf_workstation_model->extension_public->get_state =
1288       resource_get_state;
1289   surf_workstation_model->extension_public->get_speed = get_speed;
1290   surf_workstation_model->extension_public->get_available_speed =
1291       get_available_speed;
1292   surf_workstation_model->extension_public->communicate = communicate;
1293   surf_workstation_model->extension_public->execute_parallel_task =
1294       execute_parallel_task;
1295   surf_workstation_model->extension_public->get_route = get_route;
1296   surf_workstation_model->extension_public->get_route_size =
1297       get_route_size;
1298   surf_workstation_model->extension_public->get_link_name =
1299       get_link_name;
1300   surf_workstation_model->extension_public->get_link_bandwidth =
1301       get_link_bandwidth;
1302   surf_workstation_model->extension_public->get_link_latency =
1303       get_link_latency;
1304
1305   workstation_set = xbt_dict_new();
1306   router_set = xbt_dict_new();
1307   network_link_set = xbt_dict_new(); 
1308   if (!maxmin_system)
1309     maxmin_system = lmm_system_new();
1310 }
1311
1312 /**************************************/
1313 /*************** Generic **************/
1314 /**************************************/
1315 void surf_workstation_model_init_KCCFLN05(const char *filename)
1316 {
1317   xbt_assert0(!surf_cpu_model, "CPU model type already defined");
1318   xbt_assert0(!surf_network_model,
1319               "network model type already defined");
1320   model_init_internal();
1321   parse_file(filename);
1322
1323   xbt_dynar_push(model_list, &surf_workstation_model);
1324 }