Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
9b677f8866569edb4d58a2c93bca5d55ea9b30a8
[simgrid.git] / src / simdag / sd_task.cpp
1 /* Copyright (c) 2006-2016. 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 "src/surf/HostImpl.hpp"
8 #include "src/surf/surf_interface.hpp"
9 #include "src/simdag/simdag_private.h"
10 #include "simgrid/simdag.h"
11 #include "src/instr/instr_private.h"
12
13 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(sd_task, sd, "Logging specific to SimDag (task)");
14
15 /* Destroys the data memorized by SD_task_schedule. Task state must be SD_SCHEDULED or SD_RUNNABLE. */
16 static void __SD_task_destroy_scheduling_data(SD_task_t task)
17 {
18   if (task->state != SD_SCHEDULED && task->state != SD_RUNNABLE)
19     THROWF(arg_error, 0, "Task '%s' must be SD_SCHEDULED or SD_RUNNABLE", SD_task_get_name(task));
20
21   xbt_free(task->flops_amount);
22   xbt_free(task->bytes_amount);
23   task->flops_amount = nullptr;
24   task->bytes_amount = nullptr;
25 }
26
27 void* SD_task_new_f()
28 {
29   SD_task_t task = xbt_new0(s_SD_task_t, 1);
30
31   task->inputs = new std::set<SD_task_t>();
32   task->outputs = new std::set<SD_task_t>();
33   task->predecessors = new std::set<SD_task_t>();
34   task->successors = new std::set<SD_task_t>();
35   return task;
36 }
37
38 void SD_task_recycle_f(void *t)
39 {
40   SD_task_t task = static_cast<SD_task_t>(t);
41
42   /* Reset the content */
43   task->kind = SD_TASK_NOT_TYPED;
44   task->state= SD_NOT_SCHEDULED;
45   sd_global->initial_tasks->insert(task);
46
47   task->marked = 0;
48
49   task->start_time = -1.0;
50   task->finish_time = -1.0;
51   task->surf_action = nullptr;
52   task->watch_points = 0;
53
54   /* dependencies */
55   task->unsatisfied_dependencies = 0;
56   task->is_not_ready = 0;
57
58   task->inputs->clear();
59   task->outputs->clear();
60   task->predecessors->clear();
61   task->successors->clear();
62
63   /* scheduling parameters */
64   task->host_count = 0;
65   task->host_list = nullptr;
66   task->flops_amount = nullptr;
67   task->bytes_amount = nullptr;
68   task->rate = -1;
69 }
70
71 void SD_task_free_f(void *t)
72 {
73   SD_task_t task = static_cast<SD_task_t>(t);
74
75   delete task->inputs;
76   delete task->outputs;
77   delete task->predecessors;
78   delete task->successors;
79
80   xbt_free(task);
81 }
82
83 /**
84  * \brief Creates a new task.
85  *
86  * \param name the name of the task (can be \c nullptr)
87  * \param data the user data you want to associate with the task (can be \c nullptr)
88  * \param amount amount of the task
89  * \return the new task
90  * \see SD_task_destroy()
91  */
92 SD_task_t SD_task_create(const char *name, void *data, double amount)
93 {
94   SD_task_t task = static_cast<SD_task_t>(xbt_mallocator_get(sd_global->task_mallocator));
95
96   /* general information */
97   task->data = data;            /* user data */
98   task->name = xbt_strdup(name);
99   task->amount = amount;
100   task->remains = amount;
101
102   return task;
103 }
104
105 static inline SD_task_t SD_task_create_sized(const char *name, void *data, double amount, int ws_count)
106 {
107   SD_task_t task = SD_task_create(name, data, amount);
108   task->bytes_amount = xbt_new0(double, ws_count * ws_count);
109   task->flops_amount = xbt_new0(double, ws_count);
110   task->host_count = ws_count;
111   task->host_list = xbt_new0(sg_host_t, ws_count);
112   return task;
113 }
114
115 /** @brief create a end-to-end communication task that can then be auto-scheduled
116  *
117  * Auto-scheduling mean that the task can be used with SD_task_schedulev(). This allows to specify the task costs at
118  * creation, and decouple them from the scheduling process where you just specify which resource should deliver the
119  * mandatory power.
120  *
121  * A end-to-end communication must be scheduled on 2 hosts, and the amount specified at creation is sent from hosts[0]
122  * to hosts[1].
123  */
124 SD_task_t SD_task_create_comm_e2e(const char *name, void *data, double amount)
125 {
126   SD_task_t res = SD_task_create_sized(name, data, amount, 2);
127   res->bytes_amount[2] = amount;
128   res->kind = SD_TASK_COMM_E2E;
129
130   return res;
131 }
132
133 /** @brief create a sequential computation task that can then be auto-scheduled
134  *
135  * Auto-scheduling mean that the task can be used with SD_task_schedulev(). This allows to specify the task costs at
136  * creation, and decouple them from the scheduling process where you just specify which resource should deliver the
137  * mandatory power.
138  *
139  * A sequential computation must be scheduled on 1 host, and the amount specified at creation to be run on hosts[0].
140  *
141  * \param name the name of the task (can be \c nullptr)
142  * \param data the user data you want to associate with the task (can be \c nullptr)
143  * \param flops_amount amount of compute work to be done by the task
144  * \return the new SD_TASK_COMP_SEQ typed task
145  */
146 SD_task_t SD_task_create_comp_seq(const char *name, void *data, double flops_amount)
147 {
148   SD_task_t res = SD_task_create_sized(name, data, flops_amount, 1);
149   res->flops_amount[0] = flops_amount;
150   res->kind = SD_TASK_COMP_SEQ;
151
152   return res;
153 }
154
155 /** @brief create a parallel computation task that can then be auto-scheduled
156  *
157  * Auto-scheduling mean that the task can be used with SD_task_schedulev(). This allows to specify the task costs at
158  * creation, and decouple them from the scheduling process where you just specify which resource should deliver the
159  * mandatory power.
160  *
161  * A parallel computation can be scheduled on any number of host.
162  * The underlying speedup model is Amdahl's law.
163  * To be auto-scheduled, \see SD_task_distribute_comp_amdahl has to be called first.
164  * \param name the name of the task (can be \c nullptr)
165  * \param data the user data you want to associate with the task (can be \c nullptr)
166  * \param flops_amount amount of compute work to be done by the task
167  * \param alpha purely serial fraction of the work to be done (in [0.;1.[)
168  * \return the new task
169  */
170 SD_task_t SD_task_create_comp_par_amdahl(const char *name, void *data, double flops_amount, double alpha)
171 {
172   xbt_assert(alpha < 1. && alpha >= 0., "Invalid parameter: alpha must be in [0.;1.[");
173
174   SD_task_t res = SD_task_create(name, data, flops_amount);
175   res->alpha = alpha;
176   res->kind = SD_TASK_COMP_PAR_AMDAHL;
177
178   return res;
179 }
180
181 /** @brief create a complex data redistribution task that can then be  auto-scheduled
182  *
183  * Auto-scheduling mean that the task can be used with SD_task_schedulev(). 
184  * This allows to specify the task costs at creation, and decouple them from the scheduling process where you just
185  * specify which resource should communicate.
186  *
187  * A data redistribution can be scheduled on any number of host.
188  * The assumed distribution is a 1D block distribution. Each host owns the same share of the \see amount.
189  * To be auto-scheduled, \see SD_task_distribute_comm_mxn_1d_block has to be  called first.
190  * \param name the name of the task (can be \c nullptr)
191  * \param data the user data you want to associate with the task (can be \c nullptr)
192  * \param amount amount of data to redistribute by the task
193  * \return the new task
194  */
195 SD_task_t SD_task_create_comm_par_mxn_1d_block(const char *name, void *data, double amount)
196 {
197   SD_task_t res = SD_task_create(name, data, amount);
198   res->host_list=nullptr;
199   res->kind = SD_TASK_COMM_PAR_MXN_1D_BLOCK;
200
201   return res;
202 }
203
204 /**
205  * \brief Destroys a task.
206  *
207  * The user data (if any) should have been destroyed first.
208  *
209  * \param task the task you want to destroy
210  * \see SD_task_create()
211  */
212 void SD_task_destroy(SD_task_t task)
213 {
214   XBT_DEBUG("Destroying task %s...", SD_task_get_name(task));
215
216   /* First Remove all dependencies associated with the task. */
217   while (!task->predecessors->empty())
218     SD_task_dependency_remove(*(task->predecessors->begin()), task);
219   while (!task->inputs->empty())
220     SD_task_dependency_remove(*(task->inputs->begin()), task);
221   while (!task->successors->empty())
222     SD_task_dependency_remove(task, *(task->successors->begin()));
223   while (!task->outputs->empty())
224    SD_task_dependency_remove(task, *(task->outputs->begin()));
225
226   if (task->state == SD_SCHEDULED || task->state == SD_RUNNABLE)
227     __SD_task_destroy_scheduling_data(task);
228
229   int idx = xbt_dynar_search_or_negative(sd_global->return_set, &task);
230   if (idx >=0) {
231     xbt_dynar_remove_at(sd_global->return_set, idx, nullptr);
232   }
233
234   xbt_free(task->name);
235
236   if (task->surf_action != nullptr)
237     task->surf_action->unref();
238
239   xbt_free(task->host_list);
240   xbt_free(task->bytes_amount);
241   xbt_free(task->flops_amount);
242
243   xbt_mallocator_release(sd_global->task_mallocator,task);
244
245   XBT_DEBUG("Task destroyed.");
246 }
247
248 /**
249  * \brief Returns the user data of a task
250  *
251  * \param task a task
252  * \return the user data associated with this task (can be \c nullptr)
253  * \see SD_task_set_data()
254  */
255 void *SD_task_get_data(SD_task_t task)
256 {
257   return task->data;
258 }
259
260 /**
261  * \brief Sets the user data of a task
262  *
263  * The new data can be \c nullptr. The old data should have been freed first
264  * if it was not \c nullptr.
265  *
266  * \param task a task
267  * \param data the new data you want to associate with this task
268  * \see SD_task_get_data()
269  */
270 void SD_task_set_data(SD_task_t task, void *data)
271 {
272   task->data = data;
273 }
274
275 /**
276  * \brief Sets the rate of a task
277  *
278  * This will change the network bandwidth a task can use. This rate  cannot be dynamically changed. Once the task has
279  * started, this call is ineffective. This rate depends on both the nominal bandwidth on the route onto which the task
280  * is scheduled (\see SD_task_get_current_bandwidth) and the amount of data to transfer.
281  *
282  * To divide the nominal bandwidth by 2, the rate then has to be :
283  *    rate = bandwidth/(2*amount)
284  *
285  * \param task a \see SD_TASK_COMM_E2E task (end-to-end communication)
286  * \param rate the new rate you want to associate with this task.
287  */
288 void SD_task_set_rate(SD_task_t task, double rate)
289 {
290   xbt_assert(task->kind == SD_TASK_COMM_E2E, "The rate can be modified for end-to-end communications only.");
291   if(task->start_time<0) {
292     task->rate = rate;
293   } else {
294     XBT_WARN("Task %p has started. Changing rate is ineffective.", task);
295   }
296 }
297
298 /**
299  * \brief Returns the state of a task
300  *
301  * \param task a task
302  * \return the current \ref e_SD_task_state_t "state" of this task:
303  * #SD_NOT_SCHEDULED, #SD_SCHEDULED, #SD_RUNNABLE, #SD_RUNNING, #SD_DONE or #SD_FAILED
304  * \see e_SD_task_state_t
305  */
306 e_SD_task_state_t SD_task_get_state(SD_task_t task)
307 {
308   return task->state;
309 }
310
311 /* Changes the state of a task. Updates the sd_global->watch_point_reached flag.
312  */
313 void SD_task_set_state(SD_task_t task, e_SD_task_state_t new_state)
314 {
315   std::set<SD_task_t>::iterator idx;
316   switch (new_state) {
317   case SD_NOT_SCHEDULED:
318   case SD_SCHEDULABLE:
319     if (SD_task_get_state(task) == SD_FAILED){
320       sd_global->completed_tasks->erase(task);
321       sd_global->initial_tasks->insert(task);
322     }
323     break;
324   case SD_SCHEDULED:
325     if (SD_task_get_state(task) == SD_RUNNABLE){
326       sd_global->initial_tasks->insert(task);
327       sd_global->executable_tasks->erase(task);
328     }
329     break;
330   case SD_RUNNABLE:
331     idx = sd_global->initial_tasks->find(task);
332     if (idx != sd_global->initial_tasks->end()) {
333       sd_global->executable_tasks->insert(*idx);
334       sd_global->initial_tasks->erase(idx);
335     }
336     break;
337   case SD_RUNNING:
338     sd_global->executable_tasks->erase(task);
339     break;
340   case SD_DONE:
341     sd_global->completed_tasks->insert(task);
342     task->finish_time = task->surf_action->getFinishTime();
343     task->remains = 0;
344 #if HAVE_JEDULE
345     jedule_log_sd_event(task);
346 #endif
347     break;
348   case SD_FAILED:
349     sd_global->completed_tasks->insert(task);
350     break;
351   default:
352     xbt_die( "Invalid state");
353   }
354
355   task->state = new_state;
356
357   if (task->watch_points & new_state) {
358     XBT_VERB("Watch point reached with task '%s'!", SD_task_get_name(task));
359     sd_global->watch_point_reached = 1;
360     SD_task_unwatch(task, new_state);   /* remove the watch point */
361   }
362 }
363
364 /**
365  * \brief Returns the name of a task
366  *
367  * \param task a task
368  * \return the name of this task (can be \c nullptr)
369  */
370 const char *SD_task_get_name(SD_task_t task)
371 {
372   return task->name;
373 }
374
375 /** @brief Allows to change the name of a task */
376 void SD_task_set_name(SD_task_t task, const char *name)
377 {
378   xbt_free(task->name);
379   task->name = xbt_strdup(name);
380 }
381
382 /** @brief Returns the dynar of the parents of a task
383  *
384  * \param task a task
385  * \return a newly allocated dynar comprising the parents of this task
386  */
387
388 xbt_dynar_t SD_task_get_parents(SD_task_t task)
389 {
390   xbt_dynar_t parents = xbt_dynar_new(sizeof(SD_task_t), nullptr);
391
392   for (std::set<SD_task_t>::iterator it=task->predecessors->begin(); it!=task->predecessors->end(); ++it)
393     xbt_dynar_push(parents, &(*it));
394   for (std::set<SD_task_t>::iterator it=task->inputs->begin(); it!=task->inputs->end(); ++it)
395     xbt_dynar_push(parents, &(*it));
396
397   return parents;
398 }
399
400 /** @brief Returns the dynar of the parents of a task
401  *
402  * \param task a task
403  * \return a newly allocated dynar comprising the parents of this task
404  */
405 xbt_dynar_t SD_task_get_children(SD_task_t task)
406 {
407   xbt_dynar_t children = xbt_dynar_new(sizeof(SD_task_t), nullptr);
408
409   for (std::set<SD_task_t>::iterator it=task->successors->begin(); it!=task->successors->end(); ++it)
410     xbt_dynar_push(children, &(*it));
411   for (std::set<SD_task_t>::iterator it=task->outputs->begin(); it!=task->outputs->end(); ++it)
412     xbt_dynar_push(children, &(*it));
413
414   return children;
415 }
416
417 /**
418  * \brief Returns the number of workstations involved in a task
419  *
420  * Only call this on already scheduled tasks!
421  * \param task a task
422  */
423 int SD_task_get_workstation_count(SD_task_t task)
424 {
425   return task->host_count;
426 }
427
428 /**
429  * \brief Returns the list of workstations involved in a task
430  *
431  * Only call this on already scheduled tasks!
432  * \param task a task
433  */
434 sg_host_t *SD_task_get_workstation_list(SD_task_t task)
435 {
436   return task->host_list;
437 }
438
439 /**
440  * \brief Returns the total amount of work contained in a task
441  *
442  * \param task a task
443  * \return the total amount of work (computation or data transfer) for this task
444  * \see SD_task_get_remaining_amount()
445  */
446 double SD_task_get_amount(SD_task_t task)
447 {
448   return task->amount;
449 }
450
451 /** @brief Sets the total amount of work of a task
452  * For sequential typed tasks (COMP_SEQ and COMM_E2E), it also sets the appropriate values in the flops_amount and
453  * bytes_amount arrays respectively. Nothing more than modifying task->amount is done for parallel  typed tasks
454  * (COMP_PAR_AMDAHL and COMM_PAR_MXN_1D_BLOCK) as the distribution of the amount of work is done at scheduling time.
455  *
456  * \param task a task
457  * \param amount the new amount of work to execute
458  */
459 void SD_task_set_amount(SD_task_t task, double amount)
460 {
461   task->amount = amount;
462   if (task->kind == SD_TASK_COMP_SEQ)
463     task->flops_amount[0] = amount;
464   if (task->kind == SD_TASK_COMM_E2E)
465     task->bytes_amount[2] = amount;
466 }
467
468 /**
469  * \brief Returns the alpha parameter of a SD_TASK_COMP_PAR_AMDAHL task
470  *
471  * \param task a parallel task assuming Amdahl's law as speedup model
472  * \return the alpha parameter (serial part of a task in percent) for this task
473  */
474 double SD_task_get_alpha(SD_task_t task)
475 {
476   xbt_assert(SD_task_get_kind(task) == SD_TASK_COMP_PAR_AMDAHL, "Alpha parameter is not defined for this kind of task");
477   return task->alpha;
478 }
479
480 /**
481  * \brief Returns the remaining amount work to do till the completion of a task
482  *
483  * \param task a task
484  * \return the remaining amount of work (computation or data transfer) of this task
485  * \see SD_task_get_amount()
486  */
487 double SD_task_get_remaining_amount(SD_task_t task)
488 {
489   if (task->surf_action)
490     return task->surf_action->getRemains();
491   else
492     return task->remains;
493 }
494
495 e_SD_task_kind_t SD_task_get_kind(SD_task_t task)
496 {
497   return task->kind;
498 }
499
500 /** @brief Displays debugging information about a task */
501 void SD_task_dump(SD_task_t task)
502 {
503   XBT_INFO("Displaying task %s", SD_task_get_name(task));
504   char *statename = bprintf("%s%s%s%s%s%s%s",
505                       (task->state == SD_NOT_SCHEDULED ? " not scheduled" : ""),
506                       (task->state == SD_SCHEDULABLE ? " schedulable" : ""),
507                       (task->state == SD_SCHEDULED ? " scheduled" : ""),
508                       (task->state == SD_RUNNABLE ? " runnable" : " not runnable"),
509                       (task->state == SD_RUNNING ? " running" : ""),
510                       (task->state == SD_DONE ? " done" : ""),
511                       (task->state == SD_FAILED ? " failed" : ""));
512   XBT_INFO("  - state:%s", statename);
513   free(statename);
514
515   if (task->kind != 0) {
516     switch (task->kind) {
517     case SD_TASK_COMM_E2E:
518       XBT_INFO("  - kind: end-to-end communication");
519       break;
520     case SD_TASK_COMP_SEQ:
521       XBT_INFO("  - kind: sequential computation");
522       break;
523     case SD_TASK_COMP_PAR_AMDAHL:
524       XBT_INFO("  - kind: parallel computation following Amdahl's law");
525       break;
526     case SD_TASK_COMM_PAR_MXN_1D_BLOCK:
527       XBT_INFO("  - kind: MxN data redistribution assuming 1D block distribution");
528       break;
529     default:
530       XBT_INFO("  - (unknown kind %d)", task->kind);
531     }
532   }
533
534   if (task->category)
535     XBT_INFO("  - tracing category: %s", task->category);
536
537   XBT_INFO("  - amount: %.0f", SD_task_get_amount(task));
538   if (task->kind == SD_TASK_COMP_PAR_AMDAHL)
539     XBT_INFO("  - alpha: %.2f", task->alpha);
540   XBT_INFO("  - Dependencies to satisfy: %d", task->unsatisfied_dependencies);
541   if ((task->inputs->size()+ task->predecessors->size()) > 0) {
542     XBT_INFO("  - pre-dependencies:");
543     for (std::set<SD_task_t>::iterator it=task->predecessors->begin(); it!=task->predecessors->end(); ++it)
544       XBT_INFO("    %s", SD_task_get_name(*it));
545
546     for (std::set<SD_task_t>::iterator it=task->inputs->begin(); it!=task->inputs->end(); ++it)
547       XBT_INFO("    %s", SD_task_get_name(*it));
548   }
549   if ((task->outputs->size() + task->successors->size()) > 0) {
550     XBT_INFO("  - post-dependencies:");
551
552     for (std::set<SD_task_t>::iterator it=task->successors->begin(); it!=task->successors->end(); ++it)
553       XBT_INFO("    %s", SD_task_get_name(*it));
554     for (std::set<SD_task_t>::iterator it=task->outputs->begin(); it!=task->outputs->end(); ++it)
555       XBT_INFO("    %s", SD_task_get_name(*it));
556   }
557 }
558
559 /** @brief Dumps the task in dotty formalism into the FILE* passed as second argument */
560 void SD_task_dotty(SD_task_t task, void *out)
561 {
562   FILE *fout = static_cast<FILE*>(out);
563   fprintf(fout, "  T%p [label=\"%.20s\"", task, task->name);
564   switch (task->kind) {
565   case SD_TASK_COMM_E2E:
566   case SD_TASK_COMM_PAR_MXN_1D_BLOCK:
567     fprintf(fout, ", shape=box");
568     break;
569   case SD_TASK_COMP_SEQ:
570   case SD_TASK_COMP_PAR_AMDAHL:
571     fprintf(fout, ", shape=circle");
572     break;
573   default:
574     xbt_die("Unknown task type!");
575   }
576   fprintf(fout, "];\n");
577   for (std::set<SD_task_t>::iterator it=task->predecessors->begin(); it!=task->predecessors->end(); ++it)
578     fprintf(fout, " T%p -> T%p;\n", (*it), task);
579   for (std::set<SD_task_t>::iterator it=task->inputs->begin(); it!=task->inputs->end(); ++it)
580     fprintf(fout, " T%p -> T%p;\n", (*it), task);
581 }
582
583 /**
584  * \brief Adds a dependency between two tasks
585  *
586  * \a dst will depend on \a src, ie \a dst will not start before \a src is finished.
587  * Their \ref e_SD_task_state_t "state" must be #SD_NOT_SCHEDULED, #SD_SCHEDULED or #SD_RUNNABLE.
588  *
589  * \param name the name of the new dependency (can be \c nullptr)
590  * \param data the user data you want to associate with this dependency (can be \c nullptr)
591  * \param src the task which must be executed first
592  * \param dst the task you want to make depend on \a src
593  * \see SD_task_dependency_remove()
594  */
595 void SD_task_dependency_add(const char *name, void *data, SD_task_t src, SD_task_t dst)
596 {
597
598   if (src == dst)
599     THROWF(arg_error, 0, "Cannot add a dependency between task '%s' and itself", SD_task_get_name(src));
600
601   e_SD_task_state_t state = SD_task_get_state(src);
602   if (state == SD_DONE || state == SD_FAILED)
603     THROWF(arg_error, 0, "Task '%s' must be SD_NOT_SCHEDULED, SD_SCHEDULABLE, SD_SCHEDULED, SD_RUNNABLE, or SD_RUNNING",
604            SD_task_get_name(src));
605
606   state = SD_task_get_state(dst);
607   if (state == SD_DONE || state == SD_FAILED || state == SD_RUNNING)
608     THROWF(arg_error, 0, "Task '%s' must be SD_NOT_SCHEDULED, SD_SCHEDULABLE, SD_SCHEDULED, or SD_RUNNABLE",
609            SD_task_get_name(dst));
610
611   if (src->successors->find(dst) != src->successors->end() ||
612       dst->predecessors->find(src) != dst->predecessors->end() ||
613       dst->inputs->find(src) != dst->inputs->end() ||
614       src->outputs->find(dst) != src->outputs->end())
615     THROWF(arg_error, 0, "A dependency already exists between task '%s' and task '%s'",
616            SD_task_get_name(src), SD_task_get_name(dst));
617
618   XBT_DEBUG("SD_task_dependency_add: src = %s, dst = %s", SD_task_get_name(src), SD_task_get_name(dst));
619
620   e_SD_task_kind_t src_kind = SD_task_get_kind(src);
621   e_SD_task_kind_t dst_kind = SD_task_get_kind(dst);
622
623   if (src_kind == SD_TASK_COMM_E2E || src_kind == SD_TASK_COMM_PAR_MXN_1D_BLOCK){
624     if (dst_kind == SD_TASK_COMP_SEQ || dst_kind == SD_TASK_COMP_PAR_AMDAHL){
625         dst->inputs->insert(src);
626     } else {
627       dst->predecessors->insert(src);
628     }
629     src->successors->insert(dst);
630   } else {
631     if (dst_kind == SD_TASK_COMM_E2E|| dst_kind == SD_TASK_COMM_PAR_MXN_1D_BLOCK){
632       src->outputs->insert(dst);
633     } else {
634       src->successors->insert(dst);
635     }
636     dst->predecessors->insert(src);
637   }
638
639   dst->unsatisfied_dependencies++;
640   dst->is_not_ready++;
641
642   /* if the task was runnable, the task goes back to SD_SCHEDULED because of the new dependency*/
643   if (SD_task_get_state(dst) == SD_RUNNABLE) {
644     XBT_DEBUG("SD_task_dependency_add: %s was runnable and becomes scheduled!", SD_task_get_name(dst));
645     SD_task_set_state(dst, SD_SCHEDULED);
646   }
647 }
648
649 /**
650  * \brief Indicates whether there is a dependency between two tasks.
651  *
652  * \param src a task
653  * \param dst a task depending on \a src
654  *
655  * If src is nullptr, checks whether dst has any pre-dependency.
656  * If dst is nullptr, checks whether src has any post-dependency.
657  */
658 int SD_task_dependency_exists(SD_task_t src, SD_task_t dst)
659 {
660   xbt_assert(src != nullptr || dst != nullptr, "Invalid parameter: both src and dst are nullptr");
661
662   if (src) {
663     if (dst) {
664       return (src->successors->find(dst) != src->successors->end() || src->outputs->find(dst) != src->outputs->end());
665     } else {
666       return src->successors->size() + src->outputs->size();
667     }
668   } else {
669     return dst->predecessors->size() + dst->inputs->size();
670   }
671   return 0;
672 }
673
674 /**
675  * \brief Remove a dependency between two tasks
676  *
677  * \param src a task
678  * \param dst a task depending on \a src
679  * \see SD_task_dependency_add()
680  */
681 void SD_task_dependency_remove(SD_task_t src, SD_task_t dst)
682 {
683
684   XBT_DEBUG("SD_task_dependency_remove: src = %s, dst = %s", SD_task_get_name(src), SD_task_get_name(dst));
685
686   if (src->successors->find(dst) == src->successors->end() &&
687       src->outputs->find(dst) == src->outputs->end())
688     THROWF(arg_error, 0, "No dependency found between task '%s' and '%s': task '%s' is not a successor of task '%s'",
689            SD_task_get_name(src), SD_task_get_name(dst), SD_task_get_name(dst), SD_task_get_name(src));
690
691   if (dst->predecessors->find(src) != dst->predecessors->end() ||
692       dst->inputs->find(src) != dst->inputs->end()){
693     dst->unsatisfied_dependencies--;
694     dst->is_not_ready--;
695   }
696
697   e_SD_task_kind_t src_kind = SD_task_get_kind(src);
698   e_SD_task_kind_t dst_kind = SD_task_get_kind(dst);
699   if (src_kind == SD_TASK_COMM_E2E || src_kind == SD_TASK_COMM_PAR_MXN_1D_BLOCK){
700     if (dst_kind == SD_TASK_COMP_SEQ || dst_kind == SD_TASK_COMP_PAR_AMDAHL){
701       dst->inputs->erase(src);
702     } else {
703       dst->predecessors->erase(src);
704     }
705     src->successors->erase(dst);
706   } else {
707     if (dst_kind == SD_TASK_COMM_E2E|| dst_kind == SD_TASK_COMM_PAR_MXN_1D_BLOCK){
708       src->outputs->erase(dst);
709     } else {
710       src->successors->erase(dst);
711     }
712     dst->predecessors->erase(src);
713   }
714
715   /* if the task was scheduled and dependencies are satisfied, we can make it runnable */
716   if (dst->unsatisfied_dependencies == 0) {
717     if (SD_task_get_state(dst) == SD_SCHEDULED)
718       SD_task_set_state(dst, SD_RUNNABLE);
719     else
720       SD_task_set_state(dst, SD_SCHEDULABLE);
721   }
722
723   if (dst->is_not_ready == 0)
724     SD_task_set_state(dst, SD_SCHEDULABLE);
725 }
726
727 /**
728  * \brief Adds a watch point to a task
729  *
730  * SD_simulate() will stop as soon as the \ref e_SD_task_state_t "state" of this task becomes the one given in argument.
731  * The watch point is then automatically removed.
732  *
733  * \param task a task
734  * \param state the \ref e_SD_task_state_t "state" you want to watch (cannot be #SD_NOT_SCHEDULED)
735  * \see SD_task_unwatch()
736  */
737 void SD_task_watch(SD_task_t task, e_SD_task_state_t state)
738 {
739   if (state & SD_NOT_SCHEDULED)
740     THROWF(arg_error, 0, "Cannot add a watch point for state SD_NOT_SCHEDULED");
741
742   task->watch_points = task->watch_points | state;
743 }
744
745 /**
746  * \brief Removes a watch point from a task
747  *
748  * \param task a task
749  * \param state the \ref e_SD_task_state_t "state" you no longer want to watch
750  * \see SD_task_watch()
751  */
752 void SD_task_unwatch(SD_task_t task, e_SD_task_state_t state)
753 {
754   xbt_assert(state != SD_NOT_SCHEDULED, "SimDag error: Cannot have a watch point for state SD_NOT_SCHEDULED");
755   task->watch_points = task->watch_points & ~state;
756 }
757
758 /**
759  * \brief Returns an approximative estimation of the execution time of a task.
760  *
761  * The estimation is very approximative because the value returned is the time the task would take if it was executed
762  * now and if it was the only task.
763  *
764  * \param task the task to evaluate
765  * \param workstation_nb number of workstations on which the task would be executed
766  * \param workstation_list the workstations on which the task would be executed
767  * \param flops_amount computation amount for each workstation (i.e., an array of workstation_nb doubles)
768  * \param bytes_amount communication amount between each pair of workstations (i.e., a matrix of
769  *        workstation_nb*workstation_nb doubles)
770  * \see SD_schedule()
771  */
772 double SD_task_get_execution_time(SD_task_t task, int workstation_nb, const sg_host_t *workstation_list,
773                                   const double *flops_amount, const double *bytes_amount)
774 {
775   xbt_assert(workstation_nb > 0, "Invalid parameter");
776   double max_time = 0.0;
777
778   /* the task execution time is the maximum execution time of the parallel tasks */
779   for (int i = 0; i < workstation_nb; i++) {
780     double time = 0.0;
781     if (flops_amount != nullptr)
782       time = flops_amount[i] / workstation_list[i]->speed();
783
784     if (bytes_amount != nullptr)
785       for (int j = 0; j < workstation_nb; j++) {
786         if (bytes_amount[i * workstation_nb + j] !=0 ) {
787           time += (SD_route_get_latency(workstation_list[i], workstation_list[j]) +
788                    bytes_amount[i * workstation_nb + j] /
789                    SD_route_get_bandwidth(workstation_list[i], workstation_list[j]));
790         }
791       }
792
793     if (time > max_time) {
794       max_time = time;
795     }
796   }
797   return max_time;
798 }
799
800 static inline void SD_task_do_schedule(SD_task_t task)
801 {
802   if (SD_task_get_state(task) > SD_SCHEDULABLE)
803     THROWF(arg_error, 0, "Task '%s' has already been scheduled", SD_task_get_name(task));
804
805   if (task->unsatisfied_dependencies == 0)
806     SD_task_set_state(task, SD_RUNNABLE);
807   else
808     SD_task_set_state(task, SD_SCHEDULED);
809 }
810
811 /**
812  * \brief Schedules a task
813  *
814  * The task state must be #SD_NOT_SCHEDULED.
815  * Once scheduled, a task is executed as soon as possible in \see SD_simulate, i.e. when its dependencies are satisfied.
816  *
817  * \param task the task you want to schedule
818  * \param host_count number of hosts on which the task will be executed
819  * \param workstation_list the hosts on which the task will be executed
820  * \param flops_amount computation amount for each hosts (i.e., an array of host_count doubles)
821  * \param bytes_amount communication amount between each pair of hosts (i.e., a matrix of host_count*host_count doubles)
822  * \param rate task execution speed rate
823  * \see SD_task_unschedule()
824  */
825 void SD_task_schedule(SD_task_t task, int host_count, const sg_host_t * workstation_list,
826                       const double *flops_amount, const double *bytes_amount, double rate)
827 {
828   xbt_assert(host_count > 0, "workstation_nb must be positive");
829
830   task->host_count = host_count;
831   task->rate = rate;
832
833   if (flops_amount) {
834     task->flops_amount = static_cast<double*>(xbt_realloc(task->flops_amount, sizeof(double) * host_count));
835     memcpy(task->flops_amount, flops_amount, sizeof(double) * host_count);
836   } else {
837     xbt_free(task->flops_amount);
838     task->flops_amount = nullptr;
839   }
840
841   int communication_nb = host_count * host_count;
842   if (bytes_amount) {
843     task->bytes_amount = static_cast<double*>(xbt_realloc(task->bytes_amount, sizeof(double) * communication_nb));
844     memcpy(task->bytes_amount, bytes_amount, sizeof(double) * communication_nb);
845   } else {
846     xbt_free(task->bytes_amount);
847     task->bytes_amount = nullptr;
848   }
849
850   task->host_list =  static_cast<sg_host_t*>(xbt_realloc(task->host_list, sizeof(sg_host_t) * host_count));
851   memcpy(task->host_list, workstation_list, sizeof(sg_host_t) * host_count);
852
853   SD_task_do_schedule(task);
854 }
855
856 /**
857  * \brief Unschedules a task
858  *
859  * The task state must be #SD_SCHEDULED, #SD_RUNNABLE, #SD_RUNNING or #SD_FAILED.
860  * If you call this function, the task state becomes #SD_NOT_SCHEDULED.
861  * Call SD_task_schedule() to schedule it again.
862  *
863  * \param task the task you want to unschedule
864  * \see SD_task_schedule()
865  */
866 void SD_task_unschedule(SD_task_t task)
867 {
868   if (task->state != SD_SCHEDULED && task->state != SD_RUNNABLE && task->state != SD_RUNNING &&
869       task->state != SD_FAILED)
870     THROWF(arg_error, 0, "Task %s: the state must be SD_SCHEDULED, SD_RUNNABLE, SD_RUNNING or SD_FAILED",
871            SD_task_get_name(task));
872
873   if ((task->state == SD_SCHEDULED || task->state == SD_RUNNABLE)
874       /* if the task is scheduled or runnable */
875       && ((task->kind == SD_TASK_COMP_PAR_AMDAHL) || (task->kind == SD_TASK_COMM_PAR_MXN_1D_BLOCK))) {
876           /* Don't free scheduling data for typed tasks */
877     __SD_task_destroy_scheduling_data(task);
878     xbt_free(task->host_list);
879     task->host_list=nullptr;
880     task->host_count = 0;
881   }
882
883   if (SD_task_get_state(task) == SD_RUNNING)
884     /* the task should become SD_FAILED */
885     task->surf_action->cancel();
886   else {
887     if (task->unsatisfied_dependencies == 0)
888       SD_task_set_state(task, SD_SCHEDULABLE);
889     else
890       SD_task_set_state(task, SD_NOT_SCHEDULED);
891   }
892   task->remains = task->amount;
893   task->start_time = -1.0;
894 }
895
896 /* Runs a task. */
897 void SD_task_run(SD_task_t task)
898 {
899   xbt_assert(SD_task_get_state(task) == SD_RUNNABLE, "Task '%s' is not runnable! Task state: %d",
900              SD_task_get_name(task), (int)SD_task_get_state(task));
901   xbt_assert(task->host_list != nullptr, "Task '%s': workstation_list is nullptr!", SD_task_get_name(task));
902
903   XBT_DEBUG("Running task '%s'", SD_task_get_name(task));
904
905   /* Copy the elements of the task into the action */
906   int host_nb = task->host_count;
907   sg_host_t *hosts = xbt_new(sg_host_t, host_nb);
908
909   for (int i = 0; i < host_nb; i++)
910     hosts[i] =  task->host_list[i];
911
912   double *flops_amount = xbt_new0(double, host_nb);
913   double *bytes_amount = xbt_new0(double, host_nb * host_nb);
914
915   if(task->flops_amount)
916     memcpy(flops_amount, task->flops_amount, sizeof(double) * host_nb);
917   if(task->bytes_amount)
918     memcpy(bytes_amount, task->bytes_amount, sizeof(double) * host_nb * host_nb);
919
920   task->surf_action = surf_host_model->executeParallelTask(host_nb, hosts, flops_amount, bytes_amount, task->rate);
921
922   task->surf_action->setData(task);
923
924   XBT_DEBUG("surf_action = %p", task->surf_action);
925
926   if (task->category)
927     TRACE_surf_action(task->surf_action, task->category);
928
929   __SD_task_destroy_scheduling_data(task);      /* now the scheduling data are not useful anymore */
930   SD_task_set_state(task, SD_RUNNING);
931 }
932
933 /**
934  * \brief Returns the start time of a task
935  *
936  * The task state must be SD_RUNNING, SD_DONE or SD_FAILED.
937  *
938  * \param task: a task
939  * \return the start time of this task
940  */
941 double SD_task_get_start_time(SD_task_t task)
942 {
943   if (task->surf_action)
944     return task->surf_action->getStartTime();
945   else
946     return task->start_time;
947 }
948
949 /**
950  * \brief Returns the finish time of a task
951  *
952  * The task state must be SD_RUNNING, SD_DONE or SD_FAILED.
953  * If the state is not completed yet, the returned value is an estimation of the task finish time. This value can
954  * vary until the task is completed.
955  *
956  * \param task: a task
957  * \return the start time of this task
958  */
959 double SD_task_get_finish_time(SD_task_t task)
960 {
961   if (task->surf_action)        /* should never happen as actions are destroyed right after their completion */
962     return task->surf_action->getFinishTime();
963   else
964     return task->finish_time;
965 }
966
967 void SD_task_distribute_comp_amdahl(SD_task_t task, int ws_count)
968 {
969   xbt_assert(task->kind == SD_TASK_COMP_PAR_AMDAHL, "Task %s is not a SD_TASK_COMP_PAR_AMDAHL typed task."
970               "Cannot use this function.", SD_task_get_name(task));
971   task->flops_amount = xbt_new0(double, ws_count);
972   task->bytes_amount = xbt_new0(double, ws_count * ws_count);
973   xbt_free(task->host_list);
974   task->host_count = ws_count;
975   task->host_list = xbt_new0(sg_host_t, ws_count);
976   
977   for(int i=0;i<ws_count;i++){
978     task->flops_amount[i] = (task->alpha + (1 - task->alpha)/ws_count) * task->amount;
979   }
980
981
982
983 /** @brief Auto-schedules a task.
984  *
985  * Auto-scheduling mean that the task can be used with SD_task_schedulev(). This allows to specify the task costs at
986  * creation, and decouple them from the scheduling process where you just specify which resource should deliver the
987  * mandatory power.
988  *
989  * To be auto-schedulable, a task must be type and created with one of the specialized creation functions.
990  *
991  * @todo
992  * We should create tasks kind for the following categories:
993  *  - Point to point communication (done)
994  *  - Sequential computation       (done)
995  *  - group communication (redistribution, several kinds)
996  *  - parallel tasks with no internal communication (one kind per speedup    model such as Amdahl)
997  *  - idem+ internal communication. Task type not enough since we cannot store comm cost alongside to comp one)
998  */
999 void SD_task_schedulev(SD_task_t task, int count, const sg_host_t * list)
1000 {
1001   int i;
1002   int j;
1003   xbt_assert(task->kind != 0, "Task %s is not typed. Cannot automatically schedule it.", SD_task_get_name(task));
1004   switch (task->kind) {
1005   case SD_TASK_COMP_PAR_AMDAHL:
1006     SD_task_distribute_comp_amdahl(task, count);
1007     /* no break */
1008   case SD_TASK_COMM_E2E:
1009   case SD_TASK_COMP_SEQ:
1010     xbt_assert(task->host_count == count, "Got %d locations, but were expecting %d locations", count,task->host_count);
1011     for (i = 0; i < count; i++)
1012       task->host_list[i] = list[i];
1013     if (SD_task_get_kind(task)== SD_TASK_COMP_SEQ && !task->flops_amount){
1014       /*This task has failed and is rescheduled. Reset the flops_amount*/
1015       task->flops_amount = xbt_new0(double, 1);
1016       task->flops_amount[0] = task->remains;
1017     }
1018     SD_task_do_schedule(task);
1019     break;
1020   default:
1021     xbt_die("Kind of task %s not supported by SD_task_schedulev()", SD_task_get_name(task));
1022   }
1023
1024   if (task->kind == SD_TASK_COMM_E2E) {
1025     XBT_VERB("Schedule comm task %s between %s -> %s. It costs %.f bytes", SD_task_get_name(task),
1026           sg_host_get_name(task->host_list[0]), sg_host_get_name(task->host_list[1]), task->bytes_amount[2]);
1027   }
1028
1029   /* Iterate over all inputs and outputs to say where I am located (and start them if runnable) */
1030   if (task->kind == SD_TASK_COMP_SEQ) {
1031     XBT_VERB("Schedule computation task %s on %s. It costs %.f flops", SD_task_get_name(task),
1032           sg_host_get_name(task->host_list[0]), task->flops_amount[0]);
1033
1034     for (std::set<SD_task_t>::iterator it=task->inputs->begin(); it!=task->inputs->end(); ++it){
1035       SD_task_t input = *it;
1036       input->host_list[1] = task->host_list[0];
1037       if (input->host_list[0] && (SD_task_get_state(input) < SD_SCHEDULED)) {
1038         SD_task_do_schedule(input);
1039         XBT_VERB ("Auto-Schedule comm task %s between %s -> %s. It costs %.f bytes", SD_task_get_name(input),
1040                   sg_host_get_name(input->host_list[0]), sg_host_get_name(input->host_list[1]), input->bytes_amount[2]);
1041       }
1042     }
1043
1044     for (std::set<SD_task_t>::iterator it=task->outputs->begin(); it!=task->outputs->end(); ++it){
1045       SD_task_t output = *it;
1046       output->host_list[0] = task->host_list[0];
1047       if (output->host_list[1] && (SD_task_get_state(output) < SD_SCHEDULED)) {
1048         SD_task_do_schedule(output);
1049         XBT_VERB ("Auto-Schedule comm task %s between %s -> %s. It costs %.f bytes", SD_task_get_name(output),
1050                   sg_host_get_name(output->host_list[0]), sg_host_get_name(output->host_list[1]),
1051                   output->bytes_amount[2]);
1052       }
1053     }
1054   }
1055
1056   /* Iterate over all children and parents being MXN_1D_BLOCK to say where I am located (and start them if runnable) */
1057   if (task->kind == SD_TASK_COMP_PAR_AMDAHL) {
1058     XBT_VERB("Schedule computation task %s on %d workstations. %.f flops will be distributed following Amdahl's Law",
1059           SD_task_get_name(task), task->host_count, task->flops_amount[0]);
1060     for (std::set<SD_task_t>::iterator it=task->inputs->begin(); it!=task->inputs->end(); ++it){
1061       SD_task_t input = *it;
1062       if (!input->host_list){
1063         XBT_VERB("Sender side of Task %s is not scheduled yet", SD_task_get_name(input));
1064         input->host_list = xbt_new0(sg_host_t, count);
1065         input->host_count = count;
1066         XBT_VERB("Fill the workstation list with list of Task '%s'", SD_task_get_name(task));
1067         for (i=0;i<count;i++)
1068           input->host_list[i] = task->host_list[i];
1069       } else {
1070         XBT_VERB("Build communication matrix for task '%s'", SD_task_get_name(input));
1071         int src_nb, dst_nb;
1072         double src_start, src_end, dst_start, dst_end;
1073         src_nb = input->host_count;
1074         dst_nb = count;
1075         input->host_list = static_cast<sg_host_t*>(xbt_realloc(input->host_list, (input->host_count+count)*sizeof(sg_host_t)));
1076         for(i=0; i<count; i++)
1077           input->host_list[input->host_count+i] = task->host_list[i];
1078
1079         input->host_count += count;
1080         xbt_free(input->flops_amount);
1081         xbt_free(input->bytes_amount);
1082         input->flops_amount = xbt_new0(double, input->host_count);
1083         input->bytes_amount = xbt_new0(double, input->host_count* input->host_count);
1084
1085         for(i=0;i<src_nb;i++){
1086           src_start = i*input->amount/src_nb;
1087           src_end = src_start + input->amount/src_nb;
1088           for(j=0; j<dst_nb; j++){
1089             dst_start = j*input->amount/dst_nb;
1090             dst_end = dst_start + input->amount/dst_nb;
1091             XBT_VERB("(%s->%s): (%.2f, %.2f)-> (%.2f, %.2f)", sg_host_get_name(input->host_list[i]),
1092                 sg_host_get_name(input->host_list[src_nb+j]), src_start, src_end, dst_start, dst_end);
1093             if ((src_end <= dst_start) || (dst_end <= src_start)) {
1094               input->bytes_amount[i*(src_nb+dst_nb)+src_nb+j]=0.0;
1095             } else {
1096               input->bytes_amount[i*(src_nb+dst_nb)+src_nb+j] = MIN(src_end, dst_end) - MAX(src_start, dst_start);
1097             }
1098             XBT_VERB("==> %.2f", input->bytes_amount[i*(src_nb+dst_nb)+src_nb+j]);
1099           }
1100         }
1101
1102         if (SD_task_get_state(input)< SD_SCHEDULED) {
1103           SD_task_do_schedule(input);
1104           XBT_VERB ("Auto-Schedule redistribution task %s. Send %.f bytes from %d hosts to %d hosts.",
1105                     SD_task_get_name(input),input->amount, src_nb, dst_nb);
1106         }
1107       }
1108     }
1109
1110     for (std::set<SD_task_t>::iterator it=task->outputs->begin(); it!=task->outputs->end(); ++it){
1111       SD_task_t output = *it;
1112       if (!output->host_list){
1113         XBT_VERB("Receiver side of Task '%s' is not scheduled yet", SD_task_get_name(output));
1114         output->host_list = xbt_new0(sg_host_t, count);
1115         output->host_count = count;
1116         XBT_VERB("Fill the workstation list with list of Task '%s'", SD_task_get_name(task));
1117         for (i=0;i<count;i++)
1118           output->host_list[i] = task->host_list[i];
1119       } else {
1120         int src_nb, dst_nb;
1121         double src_start, src_end, dst_start, dst_end;
1122         src_nb = count;
1123         dst_nb = output->host_count;
1124         output->host_list = static_cast<sg_host_t*>(xbt_realloc(output->host_list, (output->host_count+count)*sizeof(sg_host_t)));
1125         for(i=output->host_count - 1; i>=0; i--)
1126           output->host_list[count+i] = output->host_list[i];
1127         for(i=0; i<count; i++)
1128           output->host_list[i] = task->host_list[i];
1129
1130         output->host_count += count;
1131
1132         xbt_free(output->flops_amount);
1133         xbt_free(output->bytes_amount);
1134
1135         output->flops_amount = xbt_new0(double, output->host_count);
1136         output->bytes_amount = xbt_new0(double, output->host_count* output->host_count);
1137
1138         for(i=0;i<src_nb;i++){
1139           src_start = i*output->amount/src_nb;
1140           src_end = src_start + output->amount/src_nb;
1141           for(j=0; j<dst_nb; j++){
1142             dst_start = j*output->amount/dst_nb;
1143             dst_end = dst_start + output->amount/dst_nb;
1144             XBT_VERB("(%d->%d): (%.2f, %.2f)-> (%.2f, %.2f)", i, j, src_start, src_end, dst_start, dst_end);
1145             if ((src_end <= dst_start) || (dst_end <= src_start)) {
1146               output->bytes_amount[i*(src_nb+dst_nb)+src_nb+j]=0.0;
1147             } else {
1148               output->bytes_amount[i*(src_nb+dst_nb)+src_nb+j] = MIN(src_end, dst_end)- MAX(src_start, dst_start);
1149             }
1150             XBT_VERB("==> %.2f", output->bytes_amount[i*(src_nb+dst_nb)+src_nb+j]);
1151           }
1152         }
1153
1154         if (SD_task_get_state(output)< SD_SCHEDULED) {
1155           SD_task_do_schedule(output);
1156           XBT_VERB ("Auto-Schedule redistribution task %s. Send %.f bytes from %d hosts to %d hosts.",
1157               SD_task_get_name(output),output->amount, src_nb, dst_nb);
1158         }
1159       }
1160     }
1161   }
1162 }
1163
1164 /** @brief autoschedule a task on a list of workstations
1165  *
1166  * This function is very similar to SD_task_schedulev(), but takes the list of workstations to schedule onto as
1167  * separate parameters.
1168  * It builds a proper vector of workstations and then call SD_task_schedulev()
1169  */
1170 void SD_task_schedulel(SD_task_t task, int count, ...)
1171 {
1172   va_list ap;
1173   sg_host_t *list = xbt_new(sg_host_t, count);
1174   va_start(ap, count);
1175   for (int i = 0; i < count; i++) {
1176     list[i] = va_arg(ap, sg_host_t);
1177   }
1178   va_end(ap);
1179   SD_task_schedulev(task, count, list);
1180   free(list);
1181 }