Logo AND Algorithmique Numérique Distribuée

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