Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
237483a671b4631751cd71a1eac8f69271a992da
[simgrid.git] / src / simdag / sd_task.c
1 #include "private.h"
2 #include "simdag/simdag.h"
3 #include "xbt/sysdep.h"
4 #include "xbt/dynar.h"
5
6 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(sd_task,sd,
7                                 "Logging specific to SimDag (task)");
8
9 static void __SD_task_remove_dependencies(SD_task_t task);
10 static void __SD_task_destroy_scheduling_data(SD_task_t task);
11
12 /**
13  * \brief Creates a new task.
14  *
15  * \param name the name of the task (can be \c NULL)
16  * \param data the user data you want to associate with the task (can be \c NULL)
17  * \param amount amount of the task
18  * \return the new task
19  * \see SD_task_destroy()
20  */
21 SD_task_t SD_task_create(const char *name, void *data, double amount) {
22   SD_CHECK_INIT_DONE();
23
24   SD_task_t task = xbt_new0(s_SD_task_t, 1);
25
26   /* general information */
27   task->data = data; /* user data */
28   if (name != NULL)
29     task->name = xbt_strdup(name);
30   else
31     task->name = NULL;
32
33   task->state_set = sd_global->not_scheduled_task_set;
34   xbt_swag_insert(task,task->state_set);
35
36   task->amount = amount;
37   task->remains = amount;
38   task->start_time = -1.0;
39   task->finish_time = -1.0;
40   task->surf_action = NULL;
41   task->watch_points = 0;
42   task->state_changed = 0;
43
44   /* dependencies */
45   task->tasks_before = xbt_dynar_new(sizeof(SD_dependency_t), NULL);
46   task->tasks_after = xbt_dynar_new(sizeof(SD_dependency_t), NULL);
47
48   /* scheduling parameters */
49   task->workstation_nb = 0;
50   task->workstation_list = NULL;
51   task->computation_amount = NULL;
52   task->communication_amount = NULL;
53   task->rate = 0;
54
55   return task;
56 }
57
58 /**
59  * \brief Returns the user data of a task
60  *
61  * \param task a task
62  * \return the user data associated with this task (can be \c NULL)
63  * \see SD_task_set_data()
64  */
65 void* SD_task_get_data(SD_task_t task) {
66   SD_CHECK_INIT_DONE();
67   xbt_assert0(task != NULL, "Invalid parameter");
68   return task->data;
69 }
70
71 /**
72  * \brief Sets the user data of a task
73  *
74  * The new data can be \c NULL. The old data should have been freed first
75  * if it was not \c NULL.
76  *
77  * \param task a task
78  * \param data the new data you want to associate with this task
79  * \see SD_task_get_data()
80  */
81 void SD_task_set_data(SD_task_t task, void *data) {
82   SD_CHECK_INIT_DONE();
83   xbt_assert0(task != NULL, "Invalid parameter");
84   task->data = data;
85 }
86
87 /**
88  * \brief Returns the state of a task
89  *
90  * \param task a task
91  * \return the current \ref e_SD_task_state_t "state" of this task:
92  * #SD_NOT_SCHEDULED, #SD_SCHEDULED, #SD_READY, #SD_RUNNING, #SD_DONE or #SD_FAILED
93  * \see e_SD_task_state_t
94  */
95 e_SD_task_state_t SD_task_get_state(SD_task_t task) {
96   SD_CHECK_INIT_DONE();
97   xbt_assert0(task != NULL, "Invalid parameter");
98
99   if (task->state_set == sd_global->scheduled_task_set)
100     return SD_SCHEDULED;
101   if (task->state_set == sd_global->done_task_set)
102     return SD_DONE;
103   if (task->state_set == sd_global->running_task_set)
104     return SD_RUNNING;
105   if (task->state_set == sd_global->ready_task_set)
106     return SD_READY;
107   if (task->state_set == sd_global->not_scheduled_task_set)
108     return SD_NOT_SCHEDULED;
109   return SD_FAILED;
110 }
111
112 /* Changes the state of a task. Updates the swags and the flag sd_global->watch_point_reached.
113  */
114 void __SD_task_set_state(SD_task_t task, e_SD_task_state_t new_state) {
115   xbt_swag_remove(task, task->state_set);
116   switch (new_state) {
117   case SD_NOT_SCHEDULED:
118     task->state_set = sd_global->not_scheduled_task_set;
119     break;
120   case SD_SCHEDULED:
121     task->state_set = sd_global->scheduled_task_set;
122     break;
123   case SD_READY:
124     task->state_set = sd_global->ready_task_set;
125     break;
126   case SD_RUNNING:
127     task->state_set = sd_global->running_task_set;
128     task->start_time = surf_workstation_resource->common_public->
129       action_get_start_time(task->surf_action);
130     break;
131   case SD_DONE:
132     task->state_set = sd_global->done_task_set;
133     task->finish_time = surf_workstation_resource->common_public->
134       action_get_finish_time(task->surf_action);
135     task->remains = 0;
136     break;
137   case SD_FAILED:
138     task->state_set = sd_global->failed_task_set;
139     break;
140   default:
141     xbt_assert0(0, "Invalid state");
142   }
143   xbt_swag_insert(task, task->state_set);
144
145   if (task->watch_points & new_state) {
146     INFO1("Watch point reached with task '%s'!", SD_task_get_name(task));
147     sd_global->watch_point_reached = 1;
148     SD_task_unwatch(task, new_state); /* remove the watch point */
149   }
150 }
151
152 /**
153  * \brief Returns the name of a task
154  *
155  * \param task a task
156  * \return the name of this task (can be \c NULL)
157  */
158 const char* SD_task_get_name(SD_task_t task) {
159   SD_CHECK_INIT_DONE();
160   xbt_assert0(task != NULL, "Invalid parameter");
161   return task->name;
162 }
163
164 /**
165  * \brief Returns the total amount of a task
166  *
167  * \param task a task
168  * \return the total amount of this task
169  * \see SD_task_get_remaining_amount()
170  */
171 double SD_task_get_amount(SD_task_t task) {
172   SD_CHECK_INIT_DONE();
173   xbt_assert0(task != NULL, "Invalid parameter");
174   return task->amount;
175 }
176
177 /**
178  * \brief Returns the remaining amount of a task
179  *
180  * \param task a task
181  * \return the remaining amount of this task
182  * \see SD_task_get_amount()
183  */
184 double SD_task_get_remaining_amount(SD_task_t task) {
185   SD_CHECK_INIT_DONE();
186   xbt_assert0(task != NULL, "Invalid parameter");
187
188   if (task->surf_action)
189     return task->surf_action->remains;
190   else
191     return task->remains;
192 }
193
194 /* temporary function for debbuging */
195 static void __SD_print_dependencies(SD_task_t task) {
196   INFO1("The following tasks must be executed before %s:", SD_task_get_name(task));
197   xbt_dynar_t dynar = task->tasks_before;
198   int length = xbt_dynar_length(dynar);
199   int i;
200   SD_dependency_t dependency;
201   for (i = 0; i < length; i++) {
202     xbt_dynar_get_cpy(dynar, i, &dependency);
203     INFO1(" %s", SD_task_get_name(dependency->src));
204   }
205
206   INFO1("The following tasks must be executed after %s:", SD_task_get_name(task));
207
208   dynar = task->tasks_after;
209   length = xbt_dynar_length(dynar);
210   for (i = 0; i < length; i++) {
211     xbt_dynar_get_cpy(dynar, i, &dependency);
212     INFO1(" %s", SD_task_get_name(dependency->dst));
213   }
214   INFO0("----------------------------");
215 }
216
217 /* Destroys a dependency between two tasks.
218  */
219 static void __SD_task_dependency_destroy(void *dependency) {
220   if (((SD_dependency_t) dependency)->name != NULL)
221     xbt_free(((SD_dependency_t) dependency)->name);
222   xbt_free(dependency);
223 }
224
225 /**
226  * \brief Adds a dependency between two tasks
227  *
228  * \a dst will depend on \a src, ie \a dst will not start before \a src is finished.
229  * Their \ref e_SD_task_state_t "state" must be #SD_NOT_SCHEDULED, #SD_SCHEDULED or #SD_READY.
230  *
231  * \param name the name of the new dependency (can be \c NULL)
232  * \param data the user data you want to associate with this dependency (can be \c NULL)
233  * \param src the task which must be executed first
234  * \param dst the task you want to make depend on \a src
235  * \see SD_task_dependency_remove()
236  */
237 void SD_task_dependency_add(const char *name, void *data, SD_task_t src, SD_task_t dst) {
238   SD_CHECK_INIT_DONE();
239   xbt_assert0(src != NULL && dst != NULL, "Invalid parameter");
240
241   xbt_dynar_t dynar = src->tasks_after;
242   int length = xbt_dynar_length(dynar);
243   int found = 0;
244   int i;
245   SD_dependency_t dependency;
246
247   if (src == dst) 
248     THROW1(arg_error, 0, "Cannot add a dependency between task '%s' and itself",
249            SD_task_get_name(src));
250
251   if (!__SD_task_is_not_scheduled(src) && !__SD_task_is_scheduled_or_ready(src))
252     THROW1(arg_error, 0, "Task '%s' must be SD_NOT_SCHEDULED, SD_SCHEDULED or SD_READY", SD_task_get_name(src));
253
254   if (!__SD_task_is_not_scheduled(dst) && !__SD_task_is_scheduled_or_ready(dst))
255     THROW1(arg_error, 0, "Task '%s' must be SD_NOT_SCHEDULED, SD_SCHEDULED or SD_READY", SD_task_get_name(dst));
256
257   DEBUG2("SD_task_dependency_add: src = %s, dst = %s", SD_task_get_name(src), SD_task_get_name(dst));
258   for (i = 0; i < length && !found; i++) {
259     xbt_dynar_get_cpy(dynar, i, &dependency);
260     found = (dependency->dst == dst);
261     DEBUG2("Dependency %d: dependency->dst = %s", i, SD_task_get_name(dependency->dst));
262   }
263
264   if (found)
265     THROW2(arg_error, 0, "A dependency already exists between task '%s' and task '%s'",
266            SD_task_get_name(src), SD_task_get_name(dst));
267
268   dependency = xbt_new0(s_SD_dependency_t, 1);
269
270   if (name != NULL)
271     dependency->name = xbt_strdup(name);
272   else
273     dependency->name = NULL;
274
275   dependency->data = data;
276   dependency->src = src;
277   dependency->dst = dst;
278
279   /* src must be executed before dst */
280   xbt_dynar_push(src->tasks_after, &dependency);
281   xbt_dynar_push(dst->tasks_before, &dependency);
282
283   /* if the task was ready, then dst->tasks_before is not empty anymore,
284      so we must go back to state SD_SCHEDULED */
285   if (__SD_task_is_ready(dst)) {
286     DEBUG1("SD_task_dependency_add: %s was ready and becomes scheduled!", SD_task_get_name(dst));
287     __SD_task_set_state(dst, SD_SCHEDULED);
288   }
289
290   /*  __SD_print_dependencies(src);
291       __SD_print_dependencies(dst); */
292 }
293
294 /**
295  * \brief Remove a dependency between two tasks
296  *
297  * \param src a task
298  * \param dst a task depending on \a src
299  * \see SD_task_dependency_add()
300  */
301 void SD_task_dependency_remove(SD_task_t src, SD_task_t dst) {
302   SD_CHECK_INIT_DONE();
303   xbt_assert0(src != NULL && dst != NULL, "Invalid parameter");
304
305   /* remove the dependency from src->tasks_after */
306   xbt_dynar_t dynar = src->tasks_after;
307   int length = xbt_dynar_length(dynar);
308   int found = 0;
309   int i;
310   SD_dependency_t dependency;
311   for (i = 0; i < length && !found; i++) {
312     xbt_dynar_get_cpy(dynar, i, &dependency);
313     if (dependency->dst == dst) {
314       xbt_dynar_remove_at(dynar, i, NULL);
315       found = 1;
316     }
317   }
318   if (!found)
319     THROW4(arg_error, 0,
320            "No dependency found between task '%s' and '%s': task '%s' is not a successor of task '%s'",
321            SD_task_get_name(src), SD_task_get_name(dst), SD_task_get_name(dst), SD_task_get_name(src));
322
323   /* remove the dependency from dst->tasks_before */
324   dynar = dst->tasks_before;
325   length = xbt_dynar_length(dynar);
326   found = 0;
327   
328   for (i = 0; i < length && !found; i++) {
329     xbt_dynar_get_cpy(dynar, i, &dependency);
330     if (dependency->src == src) {
331       xbt_dynar_remove_at(dynar, i, NULL);
332       __SD_task_dependency_destroy(dependency);
333       found = 1;
334     }
335   }
336   /* should never happen... */
337   xbt_assert4(found, "SimDag error: task '%s' is a successor of '%s' but task '%s' is not a predecessor of task '%s'",
338               SD_task_get_name(dst), SD_task_get_name(src), SD_task_get_name(src), SD_task_get_name(dst));
339
340   /* if the task was scheduled and dst->tasks_before is empty now, we can make it ready */
341   if (xbt_dynar_length(dst->tasks_before) == 0 && __SD_task_is_scheduled(dst))
342     __SD_task_set_state(dst, SD_READY);
343
344   /*  __SD_print_dependencies(src); 
345       __SD_print_dependencies(dst);*/
346 }
347
348 /**
349  * \brief Returns the user data associated with a dependency between two tasks
350  *
351  * \param src a task
352  * \param dst a task depending on \a src
353  * \return the user data associated with this dependency (can be \c NULL)
354  * \see SD_task_dependency_add()
355  */
356 void *SD_task_dependency_get_data(SD_task_t src, SD_task_t dst) {
357   SD_CHECK_INIT_DONE();
358   xbt_assert0(src != NULL && dst != NULL, "Invalid parameter");
359
360   xbt_dynar_t dynar = src->tasks_after;
361   int length = xbt_dynar_length(dynar);
362   int found = 0;
363   int i;
364   SD_dependency_t dependency;
365   for (i = 0; i < length && !found; i++) {
366     xbt_dynar_get_cpy(dynar, i, &dependency);
367     found = (dependency->dst == dst);
368   }
369   if (!found)
370     THROW2(arg_error, 0, "No dependency found between task '%s' and '%s'", SD_task_get_name(src), SD_task_get_name(dst));
371   return dependency->data;
372 }
373
374 /* temporary function for debugging */
375 static void __SD_print_watch_points(SD_task_t task) {
376   static const int state_masks[] = {SD_SCHEDULED, SD_RUNNING, SD_READY, SD_DONE, SD_FAILED};
377   static const char* state_names[] = {"scheduled", "running", "ready", "done", "failed"};
378
379   INFO2("Task '%s' watch points (%x): ", SD_task_get_name(task), task->watch_points);
380
381   int i;
382   for (i = 0; i < 5; i++) {
383     if (task->watch_points & state_masks[i])
384       INFO1("%s ", state_names[i]);
385   }
386 }
387
388 /**
389  * \brief Adds a watch point to a task
390  *
391  * SD_simulate() will stop as soon as the \ref e_SD_task_state_t "state" of this
392  * task becomes the one given in argument. The
393  * watch point is then automatically removed.
394  * 
395  * \param task a task
396  * \param state the \ref e_SD_task_state_t "state" you want to watch
397  * (cannot be #SD_NOT_SCHEDULED)
398  * \see SD_task_unwatch()
399  */
400 void SD_task_watch(SD_task_t task, e_SD_task_state_t state) {
401   SD_CHECK_INIT_DONE();
402   xbt_assert0(task != NULL, "Invalid parameter");
403
404   if (state & SD_NOT_SCHEDULED)
405     THROW0(arg_error, 0, "Cannot add a watch point for state SD_NOT_SCHEDULED");
406
407   task->watch_points = task->watch_points | state;
408   /*  __SD_print_watch_points(task);*/
409 }
410
411 /**
412  * \brief Removes a watch point from a task
413  * 
414  * \param task a task
415  * \param state the \ref e_SD_task_state_t "state" you no longer want to watch
416  * \see SD_task_watch()
417  */
418 void SD_task_unwatch(SD_task_t task, e_SD_task_state_t state) {
419   SD_CHECK_INIT_DONE();
420   xbt_assert0(task != NULL, "Invalid parameter");
421   xbt_assert0(state != SD_NOT_SCHEDULED,
422               "SimDag error: Cannot have a watch point for state SD_NOT_SCHEDULED");
423   
424   task->watch_points = task->watch_points & ~state;
425   /*  __SD_print_watch_points(task);*/
426 }
427
428 /**
429  * \brief Returns an approximative estimation of the execution time of a task.
430  * 
431  * The estimation is very approximative because the value returned is the time
432  * the task would take if it was executed now and if it was the only task.
433  * 
434  * \param task the task to evaluate
435  * \param workstation_nb number of workstations on which the task would be executed
436  * \param workstation_list the workstations on which the task would be executed
437  * \param computation_amount computation amount for each workstation
438  * \param communication_amount communication amount between each pair of workstations
439  * \param rate task execution speed rate
440  * \see SD_schedule()
441  */
442 double SD_task_get_execution_time(SD_task_t task,
443                                   int workstation_nb,
444                                   const SD_workstation_t *workstation_list,
445                                   const double *computation_amount,
446                                   const double *communication_amount,
447                                   double rate) {
448   SD_CHECK_INIT_DONE();
449   xbt_assert0(task != NULL && workstation_nb > 0 && workstation_list != NULL &&
450               computation_amount != NULL && communication_amount != NULL,
451               "Invalid parameter");
452
453   /* the task execution time is the maximum execution time of the parallel tasks */
454   double time, max_time = 0.0;
455   int i, j;
456   for (i = 0; i < workstation_nb; i++) {
457     time = SD_workstation_get_computation_time(workstation_list[i], computation_amount[i]);
458     
459     for (j = 0; j < workstation_nb; j++) {
460       time += SD_route_get_communication_time(workstation_list[i], workstation_list[j],
461                                               communication_amount[i * workstation_nb + j]);
462     }
463
464     if (time > max_time) {
465       max_time = time;
466     }
467   }
468   return max_time * SD_task_get_amount(task);
469 }
470
471 /**
472  * \brief Schedules a task
473  *
474  * The task state must be #SD_NOT_SCHEDULED.
475  * Once scheduled, a task will be executed as soon as possible in SD_simulate(),
476  * i.e. when its dependencies are satisfied.
477  * 
478  * \param task the task you want to schedule
479  * \param workstation_nb number of workstations on which the task will be executed
480  * \param workstation_list the workstations on which the task will be executed
481  * \param computation_amount computation amount for each workstation
482  * \param communication_amount communication amount between each pair of workstations
483  * \param rate task execution speed rate
484  * \see SD_task_unschedule()
485  */
486 void SD_task_schedule(SD_task_t task, int workstation_nb,
487                      const SD_workstation_t *workstation_list, const double *computation_amount,
488                      const double *communication_amount, double rate) {
489   SD_CHECK_INIT_DONE();
490   xbt_assert0(task != NULL, "Invalid parameter");
491   xbt_assert0(workstation_nb > 0, "workstation_nb must be positive");
492
493   if (!__SD_task_is_not_scheduled(task))
494     THROW1(arg_error, 0, "Task '%s' has already been scheduled", SD_task_get_name(task));
495
496   task->workstation_nb = workstation_nb;
497   task->rate = rate;
498
499   task->computation_amount = xbt_new0(double, workstation_nb);
500   memcpy(task->computation_amount, computation_amount, sizeof(double) * workstation_nb);
501
502   int communication_nb = workstation_nb * workstation_nb;
503   task->communication_amount = xbt_new0(double, communication_nb);
504   memcpy(task->communication_amount, communication_amount, sizeof(double) * communication_nb);
505
506   /* we have to create a Surf workstation array instead of the SimDag workstation array */
507   task->workstation_list = xbt_new0(void*, workstation_nb);
508   int i;
509   for (i = 0; i < workstation_nb; i++) {
510     task->workstation_list[i] = workstation_list[i]->surf_workstation;
511   }
512
513   /* update the task state */
514   if (xbt_dynar_length(task->tasks_before) == 0)
515     __SD_task_set_state(task, SD_READY);
516   else
517     __SD_task_set_state(task, SD_SCHEDULED);
518 }
519
520 /**
521  * \brief Unschedules a task
522  *
523  * The task state must be #SD_SCHEDULED, #SD_READY, #SD_RUNNING or #SD_FAILED.
524  * If you call this function, the task state becomes #SD_NOT_SCHEDULED.
525  * Call SD_task_schedule() to schedule it again.
526  *
527  * \param task the task you want to unschedule
528  * \see SD_task_schedule()
529  */
530 void SD_task_unschedule(SD_task_t task) {
531   SD_CHECK_INIT_DONE();
532   xbt_assert0(task != NULL, "Invalid parameter");
533
534   if (task->state_set != sd_global->scheduled_task_set &&
535       task->state_set != sd_global->ready_task_set &&
536       task->state_set != sd_global->running_task_set &&
537       task->state_set != sd_global->failed_task_set)
538     THROW1(arg_error, 0, "Task %s: the state must be SD_SCHEDULED, SD_READY, SD_RUNNING or SD_FAILED",
539            SD_task_get_name(task));
540
541   if (__SD_task_is_scheduled_or_ready(task)) /* if the task is scheduled or ready */
542     __SD_task_destroy_scheduling_data(task);
543
544   if (__SD_task_is_running(task)) /* the task should become SD_FAILED */
545     surf_workstation_resource->common_public->action_cancel(task->surf_action);
546   else
547     __SD_task_set_state(task, SD_NOT_SCHEDULED);
548   task->remains = task->amount;
549   task->start_time = -1.0;
550 }
551
552 /* Destroys the data memorised by SD_task_schedule. Task state must be SD_SCHEDULED or SD_READY.
553  */
554 static void __SD_task_destroy_scheduling_data(SD_task_t task) {
555   SD_CHECK_INIT_DONE();
556   if (!__SD_task_is_scheduled_or_ready(task))
557     THROW1(arg_error, 0, "Task '%s' must be SD_SCHEDULED or SD_READY", SD_task_get_name(task));
558
559   xbt_free(task->workstation_list);
560   xbt_free(task->computation_amount);
561   xbt_free(task->communication_amount);
562 }
563
564 /* Runs a task. This function is called by SD_simulate() when a scheduled task can start
565  * (ie when its dependencies are satisfied).
566  */
567 surf_action_t __SD_task_run(SD_task_t task) {
568   SD_CHECK_INIT_DONE();
569   xbt_assert0(task != NULL, "Invalid parameter");
570
571   if (!__SD_task_is_ready(task))
572     THROW2(arg_error, 0, "Task '%s' is not ready! Task state: %d",
573            SD_task_get_name(task), SD_task_get_state(task));
574
575   task->surf_action = surf_workstation_resource->extension_public->
576     execute_parallel_task(task->workstation_nb,
577                           task->workstation_list,
578                           task->computation_amount,
579                           task->communication_amount,
580                           task->amount,
581                           task->rate);
582
583   DEBUG1("surf_action = %p",  task->surf_action);
584
585   __SD_task_destroy_scheduling_data(task); /* now the scheduling data are not useful anymore */
586   __SD_task_set_state(task, SD_RUNNING);
587
588   return task->surf_action;
589 }
590 /* Remove all dependencies associated with a task. This function is called when the task is destroyed.
591  */
592 static void __SD_task_remove_dependencies(SD_task_t task) {
593   /* we must destroy the dependencies carefuly (with SD_dependency_remove)
594      because each one is stored twice */
595   SD_dependency_t dependency;
596   while (xbt_dynar_length(task->tasks_before) > 0) {
597     xbt_dynar_get_cpy(task->tasks_before, 0, &dependency);
598     SD_task_dependency_remove(dependency->src, dependency->dst);
599   }
600
601   while (xbt_dynar_length(task->tasks_after) > 0) {
602     xbt_dynar_get_cpy(task->tasks_after, 0, &dependency);
603     SD_task_dependency_remove(dependency->src, dependency->dst);
604   }
605 }
606
607 /**
608  * \brief Returns the start time of a task
609  *
610  * The task state must be SD_RUNNING, SD_DONE or SD_FAILED.
611  *
612  * \param task: a task
613  * \return the start time of this task
614  */
615 double SD_task_get_start_time(SD_task_t task) {
616   SD_CHECK_INIT_DONE();
617   xbt_assert0(task != NULL, "Invalid parameter");
618   if(task->surf_action)
619     return surf_workstation_resource->common_public->action_get_start_time(task->surf_action);
620   else 
621     return task->start_time;
622 }
623
624 /**
625  * \brief Returns the finish time of a task
626  *
627  * The task state must be SD_RUNNING, SD_DONE or SD_FAILED.
628  * If the state is not completed yet, the returned value is an
629  * estimation of the task finish time. This value can fluctuate 
630  * until the task is completed.
631  *
632  * \param task: a task
633  * \return the start time of this task
634  */
635 double SD_task_get_finish_time(SD_task_t task) {
636   SD_CHECK_INIT_DONE();
637   xbt_assert0(task != NULL, "Invalid parameter");
638
639   if(task->surf_action) /* should never happen as actions are destroyed right after their completion */
640     return surf_workstation_resource->common_public->action_get_finish_time(task->surf_action);
641   else 
642     return task->finish_time;
643 }
644
645 /**
646  * \brief Destroys a task.
647  *
648  * The user data (if any) should have been destroyed first.
649  *
650  * \param task the task you want to destroy
651  * \see SD_task_create()
652  */
653 void SD_task_destroy(SD_task_t task) {
654   SD_CHECK_INIT_DONE();
655   xbt_assert0(task != NULL, "Invalid parameter");
656
657   DEBUG1("Destroying task %s...", SD_task_get_name(task));
658
659   __SD_task_remove_dependencies(task);
660
661   /* if the task was scheduled or ready we have to free the scheduling parameters */
662   if (__SD_task_is_scheduled_or_ready(task))
663     __SD_task_destroy_scheduling_data(task);
664
665   if (task->name != NULL)
666     xbt_free(task->name);
667
668   if (task->surf_action != NULL)
669     surf_workstation_resource->common_public->action_free(task->surf_action);
670
671   xbt_dynar_free(&task->tasks_before);
672   xbt_dynar_free(&task->tasks_after);
673   xbt_free(task);
674
675   DEBUG0("Task destroyed.");
676 }