Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Delete the temporary route table for model Full.
[simgrid.git] / src / surf / workstation.c
1 /* Copyright (c) 2004, 2005, 2006, 2007, 2008, 2009, 2010. The SimGrid Team.
2  * All rights reserved.                                                     */
3
4 /* This program is free software; you can redistribute it and/or modify it
5  * under the terms of the license (GNU LGPL) which comes with this package. */
6
7 #include "xbt/ex.h"
8 #include "xbt/dict.h"
9 #include "portable.h"
10 #include "surf_private.h"
11
12 typedef struct workstation_CLM03 {
13   s_surf_resource_t generic_resource;   /* Must remain first to add this to a trace */
14   void *cpu;
15 } s_workstation_CLM03_t, *workstation_CLM03_t;
16
17 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_workstation, surf,
18                                 "Logging specific to the SURF workstation module");
19
20 surf_model_t surf_workstation_model = NULL;
21
22 static workstation_CLM03_t workstation_new(const char *name, void *cpu)
23 {
24   workstation_CLM03_t workstation = xbt_new0(s_workstation_CLM03_t, 1);
25
26   workstation->generic_resource.model = surf_workstation_model;
27   workstation->generic_resource.name = xbt_strdup(name);
28   workstation->cpu = cpu;
29
30   xbt_dict_set(surf_model_resource_set(surf_workstation_model), name,
31                workstation, surf_resource_free);
32
33   return workstation;
34 }
35
36 void create_workstations(void)
37 {
38   xbt_dict_cursor_t cursor = NULL;
39   char *name = NULL;
40   void *cpu = NULL;
41
42   xbt_dict_foreach(surf_model_resource_set(surf_cpu_model), cursor, name,
43                    cpu) {
44     workstation_new(name, cpu);
45   }
46 }
47
48 static int ws_resource_used(void *resource_id)
49 {
50   THROW_IMPOSSIBLE;             /* This model does not implement parallel tasks */
51 }
52
53 static void ws_parallel_action_cancel(surf_action_t action)
54 {
55   THROW_UNIMPLEMENTED;          /* This model does not implement parallel tasks */
56 }
57
58 static int ws_parallel_action_free(surf_action_t action)
59 {
60   THROW_UNIMPLEMENTED;          /* This model does not implement parallel tasks */
61 }
62
63 static int ws_action_unref(surf_action_t action)
64 {
65   if (action->model_type == surf_network_model)
66     return surf_network_model->action_unref(action);
67   else if (action->model_type == surf_cpu_model)
68     return surf_cpu_model->action_unref(action);
69   else if (action->model_type == surf_workstation_model)
70     return ws_parallel_action_free(action);
71   else
72     DIE_IMPOSSIBLE;
73   return 0;
74 }
75
76 static void ws_action_cancel(surf_action_t action)
77 {
78   if (action->model_type == surf_network_model)
79     surf_network_model->action_cancel(action);
80   else if (action->model_type == surf_cpu_model)
81     surf_cpu_model->action_cancel(action);
82   else if (action->model_type == surf_workstation_model)
83     ws_parallel_action_cancel(action);
84   else
85     DIE_IMPOSSIBLE;
86   return;
87 }
88
89 static void ws_action_state_set(surf_action_t action,
90                                 e_surf_action_state_t state)
91 {
92   if (action->model_type == surf_network_model)
93     surf_network_model->action_state_set(action, state);
94   else if (action->model_type == surf_cpu_model)
95     surf_cpu_model->action_state_set(action, state);
96   else if (action->model_type == surf_workstation_model)
97     surf_action_state_set(action, state);
98   else
99     DIE_IMPOSSIBLE;
100   return;
101 }
102
103 static double ws_share_resources(double now)
104 {
105   return -1.0;
106 }
107
108 static void ws_update_actions_state(double now, double delta)
109 {
110   return;
111 }
112
113 static void ws_update_resource_state(void *id,
114                                      tmgr_trace_event_t event_type,
115                                      double value, double date)
116 {
117   THROW_IMPOSSIBLE;             /* This model does not implement parallel tasks */
118 }
119
120 static surf_action_t ws_execute(void *workstation, double size)
121 {
122   return surf_cpu_model->extension.cpu.
123       execute(((workstation_CLM03_t) workstation)->cpu, size);
124 }
125
126 static surf_action_t ws_action_sleep(void *workstation, double duration)
127 {
128   return surf_cpu_model->extension.cpu.
129       sleep(((workstation_CLM03_t) workstation)->cpu, duration);
130 }
131
132 static void ws_action_suspend(surf_action_t action)
133 {
134   if (action->model_type == surf_network_model)
135     surf_network_model->suspend(action);
136   else if (action->model_type == surf_cpu_model)
137     surf_cpu_model->suspend(action);
138   else
139     DIE_IMPOSSIBLE;
140 }
141
142 static void ws_action_resume(surf_action_t action)
143 {
144   if (action->model_type == surf_network_model)
145     surf_network_model->resume(action);
146   else if (action->model_type == surf_cpu_model)
147     surf_cpu_model->resume(action);
148   else
149     DIE_IMPOSSIBLE;
150 }
151
152 static int ws_action_is_suspended(surf_action_t action)
153 {
154   if (action->model_type == surf_network_model)
155     return surf_network_model->is_suspended(action);
156   if (action->model_type == surf_cpu_model)
157     return surf_cpu_model->is_suspended(action);
158   DIE_IMPOSSIBLE;
159 }
160
161 static void ws_action_set_max_duration(surf_action_t action,
162                                        double duration)
163 {
164   if (action->model_type == surf_network_model)
165     surf_network_model->set_max_duration(action, duration);
166   else if (action->model_type == surf_cpu_model)
167     surf_cpu_model->set_max_duration(action, duration);
168   else
169     DIE_IMPOSSIBLE;
170 }
171
172 static void ws_action_set_priority(surf_action_t action, double priority)
173 {
174   if (action->model_type == surf_network_model)
175     surf_network_model->set_priority(action, priority);
176   else if (action->model_type == surf_cpu_model)
177     surf_cpu_model->set_priority(action, priority);
178   else
179     DIE_IMPOSSIBLE;
180 }
181
182 #ifdef HAVE_LATENCY_BOUND_TRACKING
183 static int ws_get_latency_limited(surf_action_t action)
184 {
185   if (action->model_type == surf_network_model)
186     return surf_network_model->get_latency_limited(action);
187   INFO0
188       ("You tried to ask if a non network action is limited by latency, aborting...");
189   DIE_IMPOSSIBLE;
190 }
191 #endif
192
193 static double ws_action_get_remains(surf_action_t action)
194 {
195   if (action->model_type == surf_network_model)
196     return surf_network_model->get_remains(action);
197   if (action->model_type == surf_cpu_model)
198     return surf_cpu_model->get_remains(action);
199   DIE_IMPOSSIBLE;
200 }
201
202 static surf_action_t ws_communicate(void *workstation_src,
203                                     void *workstation_dst, double size,
204                                     double rate)
205 {
206   workstation_CLM03_t src = (workstation_CLM03_t) workstation_src;
207   workstation_CLM03_t dst = (workstation_CLM03_t) workstation_dst;
208   return surf_network_model->extension.network.
209       communicate(surf_resource_name(src->cpu),
210                   surf_resource_name(dst->cpu), size, rate);
211 }
212
213 static e_surf_resource_state_t ws_get_state(void *workstation)
214 {
215   return surf_cpu_model->extension.cpu.
216       get_state(((workstation_CLM03_t) workstation)->cpu);
217 }
218
219 static double ws_get_speed(void *workstation, double load)
220 {
221   return surf_cpu_model->extension.cpu.
222       get_speed(((workstation_CLM03_t) workstation)->cpu, load);
223 }
224
225 static double ws_get_available_speed(void *workstation)
226 {
227   return surf_cpu_model->extension.cpu.
228       get_available_speed(((workstation_CLM03_t)
229                            workstation)->cpu);
230 }
231
232 static surf_action_t ws_execute_parallel_task(int workstation_nb,
233                                               void **workstation_list,
234                                               double *computation_amount,
235                                               double *communication_amount,
236                                               double amount, double rate)
237 {
238   THROW_UNIMPLEMENTED;          /* This model does not implement parallel tasks */
239 }
240
241
242 /* returns an array of network_link_CM02_t */
243 static xbt_dynar_t ws_get_route(void *src, void *dst)
244 {
245   return surf_network_model->extension.
246       network.get_route(surf_resource_name(src), surf_resource_name(src));
247 }
248
249 static double ws_get_link_bandwidth(const void *link)
250 {
251   return surf_network_model->extension.network.get_link_bandwidth(link);
252 }
253
254 static double ws_get_link_latency(const void *link)
255 {
256   return surf_network_model->extension.network.get_link_latency(link);
257 }
258
259 static int ws_link_shared(const void *link)
260 {
261   return surf_network_model->extension.network.get_link_latency(link);
262 }
263
264 static void ws_finalize(void)
265 {
266   surf_model_exit(surf_workstation_model);
267   surf_workstation_model = NULL;
268 }
269
270 static xbt_dict_t ws_get_properties(const void *ws)
271 {
272   return surf_resource_properties(((workstation_CLM03_t) ws)->cpu);
273 }
274
275 static void surf_workstation_model_init_internal(void)
276 {
277   surf_workstation_model = surf_model_init();
278
279   surf_workstation_model->name = "Workstation";
280   surf_workstation_model->action_unref = ws_action_unref;
281   surf_workstation_model->action_cancel = ws_action_cancel;
282   surf_workstation_model->action_state_set = ws_action_state_set;
283
284   surf_workstation_model->model_private->resource_used = ws_resource_used;
285   surf_workstation_model->model_private->share_resources =
286       ws_share_resources;
287   surf_workstation_model->model_private->update_actions_state =
288       ws_update_actions_state;
289   surf_workstation_model->model_private->update_resource_state =
290       ws_update_resource_state;
291   surf_workstation_model->model_private->finalize = ws_finalize;
292
293   surf_workstation_model->suspend = ws_action_suspend;
294   surf_workstation_model->resume = ws_action_resume;
295   surf_workstation_model->is_suspended = ws_action_is_suspended;
296   surf_workstation_model->set_max_duration = ws_action_set_max_duration;
297   surf_workstation_model->set_priority = ws_action_set_priority;
298   surf_workstation_model->get_remains = ws_action_get_remains;
299 #ifdef HAVE_LATENCY_BOUND_TRACKING
300   surf_workstation_model->get_latency_limited = ws_get_latency_limited;
301 #endif
302
303   surf_workstation_model->extension.workstation.execute = ws_execute;
304   surf_workstation_model->extension.workstation.sleep = ws_action_sleep;
305   surf_workstation_model->extension.workstation.get_state = ws_get_state;
306   surf_workstation_model->extension.workstation.get_speed = ws_get_speed;
307   surf_workstation_model->extension.workstation.get_available_speed =
308       ws_get_available_speed;
309
310   surf_workstation_model->extension.workstation.communicate =
311       ws_communicate;
312   surf_workstation_model->extension.workstation.get_route = ws_get_route;
313   surf_workstation_model->extension.workstation.execute_parallel_task =
314       ws_execute_parallel_task;
315   surf_workstation_model->extension.workstation.get_link_bandwidth =
316       ws_get_link_bandwidth;
317   surf_workstation_model->extension.workstation.get_link_latency =
318       ws_get_link_latency;
319   surf_workstation_model->extension.workstation.link_shared =
320       ws_link_shared;
321   surf_workstation_model->extension.workstation.get_properties =
322       ws_get_properties;
323
324 }
325
326 /********************************************************************/
327 /* The model used in MSG and presented at CCGrid03                  */
328 /********************************************************************/
329 /* @InProceedings{Casanova.CLM_03, */
330 /*   author = {Henri Casanova and Arnaud Legrand and Loris Marchal}, */
331 /*   title = {Scheduling Distributed Applications: the SimGrid Simulation Framework}, */
332 /*   booktitle = {Proceedings of the third IEEE International Symposium on Cluster Computing and the Grid (CCGrid'03)}, */
333 /*   publisher = {"IEEE Computer Society Press"}, */
334 /*   month = {may}, */
335 /*   year = {2003} */
336 /* } */
337 void surf_workstation_model_init_CLM03(const char *filename)
338 {
339   surf_workstation_model_init_internal();
340   surf_cpu_model_init_Cas01_im(filename);
341   surf_network_model_init_LegrandVelho(filename);
342   update_model_description(surf_workstation_model_description,
343                            "CLM03", surf_workstation_model);
344   xbt_dynar_push(model_list, &surf_workstation_model);
345 }
346
347 void surf_workstation_model_init_compound(const char *filename)
348 {
349
350   xbt_assert0(surf_cpu_model, "No CPU model defined yet!");
351   xbt_assert0(surf_network_model, "No network model defined yet!");
352   surf_workstation_model_init_internal();
353
354   update_model_description(surf_workstation_model_description,
355                            "compound", surf_workstation_model);
356
357   xbt_dynar_push(model_list, &surf_workstation_model);
358 }