Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
d16860c062859ecf6cc2bda3bd24d1b9ade00b42
[simgrid.git] / src / surf / workstation.c
1 /*      $Id$     */
2
3 /* Copyright (c) 2004 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 "gras_config.h"
11 #include "workstation_private.h"
12 #include "cpu_private.h"
13 #include "network_private.h"
14
15 #ifdef USE_GTNETS
16 #include "network_gtnets_private.h"
17 #endif
18
19 surf_workstation_resource_t surf_workstation_resource = NULL;
20 xbt_dict_t workstation_set = NULL;
21 static xbt_dict_t parallel_task_network_link_set = NULL;
22
23 static workstation_CLM03_t workstation_new(const char *name,
24                                      void *cpu, void *card)
25 {
26   workstation_CLM03_t workstation = xbt_new0(s_workstation_CLM03_t, 1);
27
28   workstation->resource = (surf_resource_t) surf_workstation_resource;
29   workstation->name = xbt_strdup(name);
30   workstation->cpu = cpu;
31   workstation->network_card = card;
32
33   return workstation;
34 }
35
36 static void workstation_free(void *workstation)
37 {
38   free(((workstation_CLM03_t)workstation)->name);
39   free(workstation);
40 }
41
42 static void create_workstations(void)
43 {
44   xbt_dict_cursor_t cursor = NULL;
45   char *name = NULL;
46   void *cpu = NULL;
47   void *nw_card = NULL;
48
49   xbt_dict_foreach(cpu_set, cursor, name, cpu) {
50     nw_card = xbt_dict_get_or_null(network_card_set, name);
51     xbt_assert1(nw_card,
52                 "No corresponding card found for %s",name);
53
54     xbt_dict_set(workstation_set, name,
55                  workstation_new(name, cpu, nw_card), workstation_free);
56   }
57 }
58
59 static void *name_service(const char *name)
60 {
61   return xbt_dict_get_or_null(workstation_set, name);
62 }
63
64 static const char *get_resource_name(void *resource_id)
65 {
66   return ((workstation_CLM03_t) resource_id)->name;
67 }
68
69 static int resource_used(void *resource_id)
70 {
71   xbt_assert0(0,
72               "Workstation is a virtual resource. I should not be there!");
73   return 0;
74 }
75
76 static int parallel_action_free(surf_action_t action)
77 {
78   action->using--;
79   if(!action->using) {
80     xbt_swag_remove(action, action->state_set);
81     if(((surf_action_parallel_task_CSL05_t)action)->variable)
82       lmm_variable_free(maxmin_system, ((surf_action_parallel_task_CSL05_t)action)->variable);
83     free(action);
84     return 1;
85   }
86   return 0;
87 }
88
89 static void parallel_action_use(surf_action_t action)
90 {
91   action->using++;
92 }
93
94 static int action_free(surf_action_t action)
95 {
96   if(action->resource_type==(surf_resource_t)surf_network_resource) 
97     return surf_network_resource->common_public->action_free(action);
98   else if(action->resource_type==(surf_resource_t)surf_cpu_resource) 
99     return surf_cpu_resource->common_public->action_free(action);
100   else if(action->resource_type==(surf_resource_t)surf_workstation_resource)
101     return parallel_action_free(action);
102   else DIE_IMPOSSIBLE;
103   return 0;
104 }
105
106 static void action_use(surf_action_t action)
107 {
108   if(action->resource_type==(surf_resource_t)surf_network_resource) 
109     surf_network_resource->common_public->action_use(action);
110   else if(action->resource_type==(surf_resource_t)surf_cpu_resource) 
111     surf_cpu_resource->common_public->action_use(action);
112   else if(action->resource_type==(surf_resource_t)surf_workstation_resource)
113     parallel_action_use(action);
114   else DIE_IMPOSSIBLE;
115   return;
116 }
117
118 static void action_cancel(surf_action_t action)
119 {
120   if(action->resource_type==(surf_resource_t)surf_network_resource) 
121     surf_network_resource->common_public->action_cancel(action);
122   else if(action->resource_type==(surf_resource_t)surf_cpu_resource) 
123     surf_cpu_resource->common_public->action_cancel(action);
124   else if(action->resource_type==(surf_resource_t)surf_workstation_resource)
125     parallel_action_use(action);
126   else DIE_IMPOSSIBLE;
127   return;
128 }
129
130 static void action_recycle(surf_action_t action)
131 {
132   DIE_IMPOSSIBLE;
133   return;
134 }
135
136 static void action_change_state(surf_action_t action,
137                                 e_surf_action_state_t state)
138 {
139   if(action->resource_type==(surf_resource_t)surf_network_resource) 
140     surf_network_resource->common_public->action_change_state(action,state);
141   else if(action->resource_type==(surf_resource_t)surf_cpu_resource) 
142     surf_cpu_resource->common_public->action_change_state(action,state);
143   else if(action->resource_type==(surf_resource_t)surf_workstation_resource)
144     surf_action_change_state(action, state);
145   else DIE_IMPOSSIBLE;
146   return;
147 }
148
149 static double share_resources(double now)
150 {
151   s_surf_action_parallel_task_CSL05_t action;
152   return generic_maxmin_share_resources(surf_workstation_resource->common_public->
153                                         states.running_action_set,
154                                         xbt_swag_offset(action, variable));
155 }
156
157 static void update_actions_state(double now, double delta)
158 {
159   surf_action_parallel_task_CSL05_t action = NULL;
160   surf_action_parallel_task_CSL05_t next_action = NULL;
161   xbt_swag_t running_actions =
162       surf_workstation_resource->common_public->states.running_action_set;
163   /* FIXME: unused
164   xbt_swag_t failed_actions =
165       surf_workstation_resource->common_public->states.failed_action_set;
166   */
167
168   xbt_swag_foreach_safe(action, next_action, running_actions) {
169     double_update(&(action->generic_action.remains),
170         lmm_variable_getvalue(action->variable) * delta);
171     if (action->generic_action.max_duration != NO_MAX_DURATION)
172       double_update(&(action->generic_action.max_duration), delta);
173     if ((action->generic_action.remains <= 0) && 
174         (lmm_get_variable_weight(action->variable)>0)) {
175       action->generic_action.finish = surf_get_clock();
176       action_change_state((surf_action_t) action, SURF_ACTION_DONE);
177     } else if ((action->generic_action.max_duration != NO_MAX_DURATION) &&
178                (action->generic_action.max_duration <= 0)) {
179       action->generic_action.finish = surf_get_clock();
180       action_change_state((surf_action_t) action, SURF_ACTION_DONE);
181     } else {                    /* Need to check that none of the resource has failed */
182       lmm_constraint_t cnst = NULL;
183       int i = 0;
184       surf_resource_t resource = NULL;
185
186       while ((cnst =
187               lmm_get_cnst_from_var(maxmin_system, action->variable,
188                                     i++))) {
189         resource = (surf_resource_t) lmm_constraint_id(cnst);
190         if(resource== (surf_resource_t) surf_cpu_resource) {
191           cpu_Cas01_t cpu = lmm_constraint_id(cnst);
192           if (cpu->state_current == SURF_CPU_OFF) {
193             action->generic_action.finish = surf_get_clock();
194             action_change_state((surf_action_t) action, SURF_ACTION_FAILED);
195             break;
196           }
197         } else if (resource== (surf_resource_t) surf_network_resource) {
198           network_link_CM02_t nw_link = lmm_constraint_id(cnst);
199
200           if (nw_link->state_current == SURF_NETWORK_LINK_OFF) {
201             action->generic_action.finish = surf_get_clock();
202             action_change_state((surf_action_t) action, SURF_ACTION_FAILED);
203             break;
204           }
205         } 
206       }
207     }
208   }
209
210   return;
211 }
212
213 #ifdef USE_GTNETS
214 /* KF. For GTNetS. This is the same as surf_actions_state_gtnets except for 
215    the network resource update.
216 */
217 static void update_actions_state_gtnets(double now, double delta)
218 {
219   surf_action_parallel_task_CSL05_t action = NULL;
220   surf_action_parallel_task_CSL05_t next_action = NULL;
221   xbt_swag_t running_actions =
222       surf_workstation_resource->common_public->states.running_action_set;
223   /* FIXME: unused
224   xbt_swag_t failed_actions =
225       surf_workstation_resource->common_public->states.failed_action_set;
226   */
227
228   xbt_swag_foreach_safe(action, next_action, running_actions) {
229     double_update(&(action->generic_action.remains),
230         lmm_variable_getvalue(action->variable) * delta);
231     if (action->generic_action.max_duration != NO_MAX_DURATION)
232       double_update(&(action->generic_action.max_duration), delta);
233     if ((action->generic_action.remains <= 0) && 
234         (lmm_get_variable_weight(action->variable)>0)) {
235       action->generic_action.finish = surf_get_clock();
236       action_change_state((surf_action_t) action, SURF_ACTION_DONE);
237     } else if ((action->generic_action.max_duration != NO_MAX_DURATION) &&
238                (action->generic_action.max_duration <= 0)) {
239       action->generic_action.finish = surf_get_clock();
240       action_change_state((surf_action_t) action, SURF_ACTION_DONE);
241     } else {                    /* Need to check that none of the resource has failed */
242       lmm_constraint_t cnst = NULL;
243       int i = 0;
244       surf_resource_t resource = NULL;
245
246       while ((cnst =
247               lmm_get_cnst_from_var(maxmin_system, action->variable,
248                                     i++))) {
249         resource = (surf_resource_t) lmm_constraint_id(cnst);
250         if(resource== (surf_resource_t) surf_cpu_resource) {
251           cpu_Cas01_t cpu = lmm_constraint_id(cnst);
252           if (cpu->state_current == SURF_CPU_OFF) {
253             action->generic_action.finish = surf_get_clock();
254             action_change_state((surf_action_t) action, SURF_ACTION_FAILED);
255             break;
256           }
257         } else if (resource== (surf_resource_t) surf_network_resource) {
258           /**
259           network_link_GTNETS_t nw_link = lmm_constraint_id(cnst);
260
261           if (nw_link->state_current == SURF_NETWORK_LINK_OFF) {
262             action->generic_action.finish = surf_get_clock();
263             action_change_state((surf_action_t) action, SURF_ACTION_FAILED);
264             break;
265           }
266           **/
267         } 
268       }
269     }
270   }
271
272   return;
273 }
274 #endif
275
276 static void update_resource_state(void *id,
277                                   tmgr_trace_event_t event_type,
278                                   double value)
279 {
280   return;
281 }
282
283 static surf_action_t execute(void *workstation, double size)
284 {
285   return surf_cpu_resource->extension_public->
286       execute(((workstation_CLM03_t) workstation)->cpu, size);
287 }
288
289 static surf_action_t action_sleep(void *workstation, double duration)
290 {
291   return surf_cpu_resource->extension_public->
292       sleep(((workstation_CLM03_t) workstation)->cpu, duration);
293 }
294
295 static void action_suspend(surf_action_t action)
296 {
297   if(action->resource_type==(surf_resource_t)surf_network_resource) 
298     surf_network_resource->common_public->suspend(action);
299   else if(action->resource_type==(surf_resource_t)surf_cpu_resource) 
300     surf_cpu_resource->common_public->suspend(action);
301   else DIE_IMPOSSIBLE;
302 }
303
304 static void action_resume(surf_action_t action)
305 {
306   if(action->resource_type==(surf_resource_t)surf_network_resource)
307     surf_network_resource->common_public->resume(action);
308   else if(action->resource_type==(surf_resource_t)surf_cpu_resource)
309     surf_cpu_resource->common_public->resume(action);
310   else DIE_IMPOSSIBLE;
311 }
312
313 static int action_is_suspended(surf_action_t action)
314 {
315   if(action->resource_type==(surf_resource_t)surf_network_resource) 
316     return surf_network_resource->common_public->is_suspended(action);
317   if(action->resource_type==(surf_resource_t)surf_cpu_resource) 
318     return surf_cpu_resource->common_public->is_suspended(action);
319   DIE_IMPOSSIBLE;
320 }
321
322 static void action_set_max_duration(surf_action_t action, double duration)
323 {
324   if(action->resource_type==(surf_resource_t)surf_network_resource)
325     surf_network_resource->common_public->set_max_duration(action,duration);
326   else if(action->resource_type==(surf_resource_t)surf_cpu_resource) 
327     surf_cpu_resource->common_public->set_max_duration(action,duration);
328   else  DIE_IMPOSSIBLE;
329 }
330  
331 static void action_set_priority(surf_action_t action, double priority)
332 {
333   if(action->resource_type==(surf_resource_t)surf_network_resource)
334     surf_network_resource->common_public->set_priority(action,priority);
335   else if(action->resource_type==(surf_resource_t)surf_cpu_resource) 
336     surf_cpu_resource->common_public->set_priority(action,priority);
337   else  DIE_IMPOSSIBLE;
338 }
339
340 static surf_action_t communicate(void *workstation_src,
341                                  void *workstation_dst, double size,
342                                  double rate)
343 {
344   return surf_network_resource->extension_public->
345       communicate(((workstation_CLM03_t) workstation_src)->network_card,
346                   ((workstation_CLM03_t) workstation_dst)->network_card, size, rate);
347 }
348
349 static e_surf_cpu_state_t get_state(void *workstation)
350 {
351   return surf_cpu_resource->extension_public->
352       get_state(((workstation_CLM03_t) workstation)->cpu);
353 }
354
355 static double get_speed(void *workstation, double load)
356 {
357   return surf_cpu_resource->extension_public->
358       get_speed(((workstation_CLM03_t) workstation)->cpu, load);
359 }
360
361 static double get_available_speed(void *workstation)
362 {
363   return surf_cpu_resource->extension_public->
364       get_available_speed(((workstation_CLM03_t) workstation)->cpu);
365 }
366
367 static surf_action_t execute_parallel_task (int workstation_nb,
368                                             void **workstation_list,
369                                             double *computation_amount,
370                                             double *communication_amount,
371                                             double amount,
372                                             double rate)
373 {
374   surf_action_parallel_task_CSL05_t action = NULL;
375   int i, j, k;
376   int nb_link = 0;
377   int nb_host = 0;
378
379   if (parallel_task_network_link_set == NULL) {
380     parallel_task_network_link_set = xbt_dict_new_ext(workstation_nb * workstation_nb * 10);
381   }
382
383   /* Compute the number of affected resources... */
384   for(i=0; i< workstation_nb; i++) {
385     for(j=0; j< workstation_nb; j++) {
386       network_card_CM02_t card_src = ((workstation_CLM03_t*)workstation_list)[i]->network_card;
387       network_card_CM02_t card_dst = ((workstation_CLM03_t*)workstation_list)[j]->network_card;
388       int route_size = ROUTE_SIZE(card_src->id, card_dst->id);
389       network_link_CM02_t *route = ROUTE(card_src->id, card_dst->id);
390       
391       if(communication_amount[i*workstation_nb+j]>0)
392         for(k=0; k< route_size; k++) {
393           xbt_dict_set(parallel_task_network_link_set, route[k]->name, route[k], NULL);
394         }
395     }
396   }
397
398   nb_link = xbt_dict_length(parallel_task_network_link_set);
399   xbt_dict_reset(parallel_task_network_link_set);
400
401   for (i = 0; i<workstation_nb; i++)
402     if(computation_amount[i]>0) nb_host++;
403  
404   if(nb_link + workstation_nb == 0)
405     return NULL;
406
407   action = xbt_new0(s_surf_action_parallel_task_CSL05_t, 1);
408   action->generic_action.using = 1;
409   action->generic_action.cost = amount;
410   action->generic_action.remains = amount;
411   action->generic_action.max_duration = NO_MAX_DURATION;
412   action->generic_action.start = surf_get_clock();
413   action->generic_action.finish = -1.0;
414   action->generic_action.resource_type =
415       (surf_resource_t) surf_workstation_resource;
416   action->suspended = 0;  /* Should be useless because of the
417                              calloc but it seems to help valgrind... */
418   action->generic_action.state_set =
419       surf_workstation_resource->common_public->states.running_action_set;
420
421   xbt_swag_insert(action, action->generic_action.state_set);
422   action->rate = rate;
423
424   if(action->rate>0)
425     action->variable = lmm_variable_new(maxmin_system, action, 1.0, -1.0,
426                                         nb_host + nb_link);
427   else   
428     action->variable = lmm_variable_new(maxmin_system, action, 1.0, action->rate,
429                                         nb_host + nb_link);
430
431   for (i = 0; i<workstation_nb; i++)
432     if(computation_amount[i]>0)
433       lmm_expand(maxmin_system, ((cpu_Cas01_t) ((workstation_CLM03_t) workstation_list[i])->cpu)->constraint, 
434                  action->variable, computation_amount[i]);
435
436   for (i=0; i<workstation_nb; i++) {
437     for(j=0; j< workstation_nb; j++) {
438       network_card_CM02_t card_src = ((workstation_CLM03_t*)workstation_list)[i]->network_card;
439       network_card_CM02_t card_dst = ((workstation_CLM03_t*)workstation_list)[j]->network_card;
440       int route_size = ROUTE_SIZE(card_src->id, card_dst->id);
441       network_link_CM02_t *route = ROUTE(card_src->id, card_dst->id);
442       
443       for(k=0; k< route_size; k++) {
444         if(communication_amount[i*workstation_nb+j]>0) {
445           lmm_expand_add(maxmin_system, route[k]->constraint, 
446                        action->variable, communication_amount[i*workstation_nb+j]);
447         }
448       }
449     }
450   }
451   
452   return (surf_action_t) action;
453 }
454
455 #ifdef USE_GTNETS
456 /* KF. We don't support this for GTNetS.
457 */
458 static surf_action_t execute_parallel_task_gtnets (int workstation_nb,
459                                             void **workstation_list,
460                                             double *computation_amount,
461                                             double *communication_amount,
462                                             double amount,
463                                             double rate)
464 {
465   xbt_assert0(0,"Cannot execute parallel task");
466   return 0;
467 #if 0
468   surf_action_parallel_task_CSL05_t action = NULL;
469   int i, j, k;
470   int nb_link = 0;
471   int nb_host = 0;
472
473   if (parallel_task_network_link_set == NULL) {
474     parallel_task_network_link_set = xbt_dict_new_ext(workstation_nb * workstation_nb * 10);
475   }
476
477   for(i=0; i< workstation_nb; i++) {
478     for(j=0; j< workstation_nb; j++) {
479       network_card_GTNETS_t card_src = ((workstation_CLM03_t*)workstation_list)[i]->network_card;
480       network_card_GTNETS_t card_dst = ((workstation_CLM03_t*)workstation_list)[j]->network_card;
481       int route_size = ROUTE_SIZE(card_src->id, card_dst->id);
482       network_link_GTNETS_t *route = ROUTE(card_src->id, card_dst->id);
483       
484       if(communication_amount[i*workstation_nb+j]>0)
485         for(k=0; k< route_size; k++) {
486           xbt_dict_set(parallel_task_network_link_set, route[k]->name, route[k], NULL);
487         }
488     }
489   }
490
491   nb_link = xbt_dict_length(parallel_task_network_link_set);
492   xbt_dict_reset(parallel_task_network_link_set);
493
494   for (i = 0; i<workstation_nb; i++)
495     if(computation_amount[i]>0) nb_host++;
496  
497   if(nb_link + workstation_nb == 0)
498     return NULL;
499
500   action = xbt_new0(s_surf_action_parallel_task_CSL05_t, 1);
501   action->generic_action.using = 1;
502   action->generic_action.cost = amount;
503   action->generic_action.remains = amount;
504   action->generic_action.max_duration = NO_MAX_DURATION;
505   action->generic_action.start = surf_get_clock();
506   action->generic_action.finish = -1.0;
507   action->generic_action.resource_type =
508       (surf_resource_t) surf_workstation_resource;
509   action->suspended = 0;  /* Should be useless because of the
510                              calloc but it seems to help valgrind... */
511   action->generic_action.state_set =
512       surf_workstation_resource->common_public->states.running_action_set;
513
514   xbt_swag_insert(action, action->generic_action.state_set);
515   action->rate = rate;
516
517   if(action->rate>0)
518     action->variable = lmm_variable_new(maxmin_system, action, 1.0, -1.0,
519                                         nb_host + nb_link);
520   else   
521     action->variable = lmm_variable_new(maxmin_system, action, 1.0, action->rate,
522                                         nb_host + nb_link);
523
524   for (i = 0; i<workstation_nb; i++)
525     if(computation_amount[i]>0)
526       lmm_expand(maxmin_system, ((cpu_Cas01_t) ((workstation_CLM03_t) workstation_list[i])->cpu)->constraint, 
527                  action->variable, computation_amount[i]);
528
529   for (i=0; i<workstation_nb; i++) {
530     for(j=0; j< workstation_nb; j++) {
531       network_card_GTNETS_t card_src = ((workstation_CLM03_t*)workstation_list)[i]->network_card;
532       network_card_GTNETS_t card_dst = ((workstation_CLM03_t*)workstation_list)[j]->network_card;
533       int route_size = ROUTE_SIZE(card_src->id, card_dst->id);
534       network_link_GTNETS_t *route = ROUTE(card_src->id, card_dst->id);
535       
536       for(k=0; k< route_size; k++) {
537         if(communication_amount[i*workstation_nb+j]>0) {
538           lmm_expand_add(maxmin_system, route[k]->constraint, 
539                        action->variable, communication_amount[i*workstation_nb+j]);
540         }
541       }
542     }
543   }
544   
545   return (surf_action_t) action;
546 #endif
547 }
548 #endif
549
550 /* returns an array of network_link_CM02_t */
551 static const void** get_route(void *src, void *dst) {
552   workstation_CLM03_t workstation_src = (workstation_CLM03_t) src;
553   workstation_CLM03_t workstation_dst = (workstation_CLM03_t) dst;
554   return surf_network_resource->extension_public->get_route(workstation_src->network_card, workstation_dst->network_card);
555 }
556
557 static int get_route_size(void *src, void *dst) {
558   workstation_CLM03_t workstation_src = (workstation_CLM03_t) src;
559   workstation_CLM03_t workstation_dst = (workstation_CLM03_t) dst;
560   return surf_network_resource->extension_public->get_route_size(workstation_src->network_card, workstation_dst->network_card);
561 }
562
563 static const char *get_link_name(const void *link) {
564   return surf_network_resource->extension_public->get_link_name(link);
565 }
566
567 static double get_link_bandwidth(const void *link) {
568   return surf_network_resource->extension_public->get_link_bandwidth(link);
569 }
570
571 static double get_link_latency(const void *link) {
572   return surf_network_resource->extension_public->get_link_latency(link); 
573 }
574
575 static void finalize(void)
576 {
577   xbt_dict_free(&workstation_set);
578   xbt_swag_free(surf_workstation_resource->common_public->states.ready_action_set);
579   xbt_swag_free(surf_workstation_resource->common_public->states.
580                 running_action_set);
581   xbt_swag_free(surf_workstation_resource->common_public->states.
582                 failed_action_set);
583   xbt_swag_free(surf_workstation_resource->common_public->states.done_action_set);
584
585   free(surf_workstation_resource->common_public);
586   free(surf_workstation_resource->common_private);
587   free(surf_workstation_resource->extension_public);
588
589   free(surf_workstation_resource);
590   surf_workstation_resource = NULL;
591 }
592
593 static void surf_workstation_resource_init_internal(void)
594 {
595   s_surf_action_t action;
596
597   surf_workstation_resource = xbt_new0(s_surf_workstation_resource_t, 1);
598
599   surf_workstation_resource->common_private =
600       xbt_new0(s_surf_resource_private_t, 1);
601   surf_workstation_resource->common_public =
602       xbt_new0(s_surf_resource_public_t, 1);
603 /*   surf_workstation_resource->extension_private = xbt_new0(s_surf_workstation_resource_extension_private_t,1); */
604   surf_workstation_resource->extension_public =
605       xbt_new0(s_surf_workstation_resource_extension_public_t, 1);
606
607   surf_workstation_resource->common_public->states.ready_action_set =
608       xbt_swag_new(xbt_swag_offset(action, state_hookup));
609   surf_workstation_resource->common_public->states.running_action_set =
610       xbt_swag_new(xbt_swag_offset(action, state_hookup));
611   surf_workstation_resource->common_public->states.failed_action_set =
612       xbt_swag_new(xbt_swag_offset(action, state_hookup));
613   surf_workstation_resource->common_public->states.done_action_set =
614       xbt_swag_new(xbt_swag_offset(action, state_hookup));
615
616   surf_workstation_resource->common_public->name_service = name_service;
617   surf_workstation_resource->common_public->get_resource_name =
618       get_resource_name;
619   surf_workstation_resource->common_public->action_get_state =
620       surf_action_get_state;
621   surf_workstation_resource->common_public->action_get_start_time =
622       surf_action_get_start_time;
623   surf_workstation_resource->common_public->action_get_finish_time =
624       surf_action_get_finish_time;
625   surf_workstation_resource->common_public->action_free = action_free;
626   surf_workstation_resource->common_public->action_use = action_use;
627   surf_workstation_resource->common_public->action_cancel = action_cancel;
628   surf_workstation_resource->common_public->action_recycle =
629       action_recycle;
630   surf_workstation_resource->common_public->action_change_state =
631       action_change_state;
632   surf_workstation_resource->common_public->action_set_data = surf_action_set_data;
633   surf_workstation_resource->common_public->name = "Workstation";
634
635   surf_workstation_resource->common_private->resource_used = resource_used;
636   surf_workstation_resource->common_private->share_resources =
637       share_resources;
638   surf_workstation_resource->common_private->update_actions_state =
639       update_actions_state;
640   surf_workstation_resource->common_private->update_resource_state =
641       update_resource_state;
642   surf_workstation_resource->common_private->finalize = finalize;
643
644   surf_workstation_resource->common_public->suspend = action_suspend;
645   surf_workstation_resource->common_public->resume = action_resume;
646   surf_workstation_resource->common_public->is_suspended = action_is_suspended;
647   surf_workstation_resource->common_public->set_max_duration = action_set_max_duration;
648   surf_workstation_resource->common_public->set_priority = action_set_priority;
649
650   surf_workstation_resource->extension_public->execute = execute;
651   surf_workstation_resource->extension_public->sleep = action_sleep;
652   surf_workstation_resource->extension_public->get_state = get_state;
653   surf_workstation_resource->extension_public->get_speed = get_speed;
654   surf_workstation_resource->extension_public->get_available_speed = get_available_speed;
655   surf_workstation_resource->extension_public->communicate = communicate;
656   surf_workstation_resource->extension_public->execute_parallel_task = 
657     execute_parallel_task;
658   surf_workstation_resource->extension_public->get_route = get_route;
659   surf_workstation_resource->extension_public->get_route_size = get_route_size;
660   surf_workstation_resource->extension_public->get_link_name = get_link_name;
661   surf_workstation_resource->extension_public->get_link_bandwidth = get_link_bandwidth;
662   surf_workstation_resource->extension_public->get_link_latency = get_link_latency;
663   workstation_set = xbt_dict_new();
664
665   xbt_assert0(maxmin_system, "surf_init has to be called first!");
666 }
667
668 #ifdef USE_GTNETS
669 /* KF. For GTNetS. This is the same as surf_workstation_resource_init_internal
670        except for 
671   - surf_workstation_resource->common_private->update_actions_state =
672       update_actions_state_gtnets;
673   -  surf_workstation_resource->extension_public->execute_parallel_task = 
674     execute_parallel_task_gtnets;
675 */
676 static void surf_workstation_resource_init_internal_gtnets(void)
677 {
678   s_surf_action_t action;
679
680   surf_workstation_resource = xbt_new0(s_surf_workstation_resource_t, 1);
681
682   surf_workstation_resource->common_private =
683       xbt_new0(s_surf_resource_private_t, 1);
684   surf_workstation_resource->common_public =
685       xbt_new0(s_surf_resource_public_t, 1);
686 /*   surf_workstation_resource->extension_private = xbt_new0(s_surf_workstation_resource_extension_private_t,1); */
687   surf_workstation_resource->extension_public =
688       xbt_new0(s_surf_workstation_resource_extension_public_t, 1);
689
690   surf_workstation_resource->common_public->states.ready_action_set =
691       xbt_swag_new(xbt_swag_offset(action, state_hookup));
692   surf_workstation_resource->common_public->states.running_action_set =
693       xbt_swag_new(xbt_swag_offset(action, state_hookup));
694   surf_workstation_resource->common_public->states.failed_action_set =
695       xbt_swag_new(xbt_swag_offset(action, state_hookup));
696   surf_workstation_resource->common_public->states.done_action_set =
697       xbt_swag_new(xbt_swag_offset(action, state_hookup));
698
699   surf_workstation_resource->common_public->name_service = name_service;
700   surf_workstation_resource->common_public->get_resource_name =
701       get_resource_name;
702   surf_workstation_resource->common_public->action_get_state =
703       surf_action_get_state;
704   surf_workstation_resource->common_public->action_get_start_time =
705       surf_action_get_start_time;
706   surf_workstation_resource->common_public->action_get_finish_time =
707       surf_action_get_finish_time;
708   surf_workstation_resource->common_public->action_free = action_free;
709   surf_workstation_resource->common_public->action_use = action_use;
710   surf_workstation_resource->common_public->action_cancel = action_cancel;
711   surf_workstation_resource->common_public->action_recycle =
712       action_recycle;
713   surf_workstation_resource->common_public->action_change_state =
714       action_change_state;
715   surf_workstation_resource->common_public->action_set_data = surf_action_set_data;
716   surf_workstation_resource->common_public->name = "Workstation";
717
718   surf_workstation_resource->common_private->resource_used = resource_used;
719   surf_workstation_resource->common_private->share_resources =
720       share_resources;
721   surf_workstation_resource->common_private->update_actions_state =
722       update_actions_state_gtnets;
723   surf_workstation_resource->common_private->update_resource_state =
724       update_resource_state;
725   surf_workstation_resource->common_private->finalize = finalize;
726
727   surf_workstation_resource->common_public->suspend = action_suspend;
728   surf_workstation_resource->common_public->resume = action_resume;
729   surf_workstation_resource->common_public->is_suspended = action_is_suspended;
730   surf_workstation_resource->common_public->set_max_duration = action_set_max_duration;
731   surf_workstation_resource->common_public->set_priority = action_set_priority;
732
733   surf_workstation_resource->extension_public->execute = execute;
734   surf_workstation_resource->extension_public->sleep = action_sleep;
735   surf_workstation_resource->extension_public->get_state = get_state;
736   surf_workstation_resource->extension_public->get_speed = get_speed;
737   surf_workstation_resource->extension_public->get_available_speed = get_available_speed;
738   surf_workstation_resource->extension_public->communicate = communicate;
739   surf_workstation_resource->extension_public->execute_parallel_task = 
740     execute_parallel_task_gtnets;
741   surf_workstation_resource->extension_public->get_route = get_route;
742   surf_workstation_resource->extension_public->get_route_size = get_route_size;
743   surf_workstation_resource->extension_public->get_link_name = get_link_name;
744   surf_workstation_resource->extension_public->get_link_bandwidth = get_link_bandwidth;
745   surf_workstation_resource->extension_public->get_link_latency = get_link_latency;
746   workstation_set = xbt_dict_new();
747
748   xbt_assert0(maxmin_system, "surf_init has to be called first!");
749 }
750 #endif
751
752 /********************************************************************/
753 /* The model used in MSG and presented at CCGrid03                  */
754 /********************************************************************/
755 /* @InProceedings{Casanova.CLM_03, */
756 /*   author = {Henri Casanova and Arnaud Legrand and Loris Marchal}, */
757 /*   title = {Scheduling Distributed Applications: the SimGrid Simulation Framework}, */
758 /*   booktitle = {Proceedings of the third IEEE International Symposium on Cluster Computing and the Grid (CCGrid'03)}, */
759 /*   publisher = {"IEEE Computer Society Press"}, */
760 /*   month = {may}, */
761 /*   year = {2003} */
762 /* } */
763 void surf_workstation_resource_init_CLM03(const char *filename)
764 {
765 /*   int i ; */
766 /*   surf_resource_t resource =  NULL; */
767
768   surf_workstation_resource_init_internal();
769   surf_cpu_resource_init_Cas01(filename);
770   surf_network_resource_init_CM02(filename);
771   create_workstations();
772   xbt_dynar_push(resource_list, &surf_workstation_resource);
773 /*   xbt_dynar_foreach(resource_list, i, resource) { */
774 /*     if(resource==surf_cpu_resource) { */
775 /*       xbt_dynar_remove_at(resource_list, i, NULL); */
776 /*       i--;  */
777 /*       continue; */
778 /*     } */
779 /*     if(resource==surf_network_resource) { */
780 /*       xbt_dynar_remove_at(resource_list, i, NULL); */
781 /*       i--;  */
782 /*       continue; */
783 /*     } */
784 /*   } */
785 }
786
787 #ifdef USE_GTNETS
788 /* KF. Use GTNetS for the network. */
789 void surf_workstation_resource_init_GTNETS(const char *filename)
790 {
791   surf_workstation_resource_init_internal_gtnets();
792   surf_cpu_resource_init_Cas01(filename);
793   surf_network_resource_init_GTNETS(filename);
794   create_workstations();
795   xbt_dynar_push(resource_list, &surf_workstation_resource);
796 }
797 #endif