+
+static XBT_INLINE SD_task_t SD_task_create_sized(const char*name,void*data,double amount,int ws_count) {
+ SD_task_t task = SD_task_create(name,data,amount);
+ task->communication_amount = xbt_new0(double,ws_count*ws_count);
+ task->computation_amount = xbt_new0(double,ws_count);
+ task->workstation_nb = ws_count;
+ task->workstation_list = xbt_new0(SD_workstation_t,ws_count);
+ return task;
+}
+/** @brief create a end-to-end communication task that can then be auto-scheduled
+ *
+ * Auto-scheduling mean that the task can be used with SD_task_schedulev(). This
+ * allows to specify the task costs at creation, and decorelate them from the
+ * scheduling process where you just specify which resource should deliver the
+ * mandatory power.
+ *
+ * A end-to-end communication must be scheduled on 2 hosts, and the amount
+ * specified at creation is sent from hosts[0] to hosts[1].
+ */
+SD_task_t SD_task_create_comm_e2e(const char*name, void *data, double amount) {
+ SD_task_t res = SD_task_create_sized(name,data,amount,2);
+ res->communication_amount[2] = amount;
+ res->kind=SD_TASK_COMM_E2E;
+ return res;
+}
+/** @brief create a sequential computation task that can then be auto-scheduled
+ *
+ * Auto-scheduling mean that the task can be used with SD_task_schedulev(). This
+ * allows to specify the task costs at creation, and decorelate them from the
+ * scheduling process where you just specify which resource should deliver the
+ * mandatory power.
+ *
+ * A sequential computation must be scheduled on 1 host, and the amount
+ * specified at creation to be run on hosts[0].
+ */
+SD_task_t SD_task_create_comp_seq(const char*name, void *data, double amount) {
+ SD_task_t res = SD_task_create_sized(name,data,amount,1);
+ res->computation_amount[0]=amount;
+ res->kind=SD_TASK_COMP_SEQ;
+ return res;
+}
+
+/** @brief Auto-schedules a task.
+ *
+ * Auto-scheduling mean that the task can be used with SD_task_schedulev(). This
+ * allows to specify the task costs at creation, and decorelate them from the
+ * scheduling process where you just specify which resource should deliver the
+ * mandatory power.
+ *
+ * To be auto-schedulable, a task must be created with SD_task_create_comm_e2e() or
+ * SD_task_create_comp_seq(). Check their definitions for the exact semantic of each
+ * of them.
+ *
+ * @todo
+ * We should create tasks kind for the following categories:
+ * - Point to point communication (done)
+ * - Sequential computation (done)
+ * - group communication (redistribution, several kinds)
+ * - parallel tasks with no internal communication (one kind per speedup model such as amdal)
+ * - idem+ internal communication. Task type not enough since we cannot store comm cost alongside to comp one)
+ */
+void SD_task_schedulev(SD_task_t task, int count, const SD_workstation_t*list) {
+ int i;
+ SD_dependency_t dep;
+ unsigned int cpt;
+ xbt_assert1(task->kind != 0,"Task %s is not typed. Cannot automatically schedule it.",SD_task_get_name(task));
+ switch(task->kind) {
+ case SD_TASK_COMM_E2E:
+ case SD_TASK_COMP_SEQ:
+ xbt_assert(task->workstation_nb==count);
+ for (i=0;i<count;i++)
+ task->workstation_list[i]=list[i];
+ SD_task_do_schedule(task);
+ break;
+ default:
+ xbt_die(bprintf("Kind of task %s not supported by SD_task_schedulev()",
+ SD_task_get_name(task)));
+ }
+ if (task->kind == SD_TASK_COMM_E2E) {
+ VERB4("Schedule comm task %s between %s -> %s. It costs %.f bytes",
+ SD_task_get_name(task),
+ SD_workstation_get_name(task->workstation_list[0]),SD_workstation_get_name(task->workstation_list[1]),
+ task->communication_amount[2]);
+
+ }
+ /* Iterate over all childs and parent being COMM_E2E to say where I am located (and start them if runnable) */
+ if (task->kind == SD_TASK_COMP_SEQ) {
+ VERB3("Schedule computation task %s on %s. It costs %.f flops",
+ SD_task_get_name(task),SD_workstation_get_name(task->workstation_list[0]),
+ task->computation_amount[0]);
+
+ xbt_dynar_foreach(task->tasks_before,cpt,dep) {
+ SD_task_t before = dep->src;
+ if (before->kind == SD_TASK_COMM_E2E) {
+ before->workstation_list[1] = task->workstation_list[0];
+ if (before->workstation_list[0] && __SD_task_is_ready(before)) {
+ SD_task_do_schedule(before);
+ VERB4("Auto-Schedule comm task %s between %s -> %s. It costs %.f bytes",
+ SD_task_get_name(before),
+ SD_workstation_get_name(before->workstation_list[0]),SD_workstation_get_name(before->workstation_list[1]),
+ before->communication_amount[2]);
+ }
+ }
+ }
+ xbt_dynar_foreach(task->tasks_after,cpt,dep) {
+ SD_task_t after = dep->dst;
+ if (after->kind == SD_TASK_COMM_E2E) {
+ after->workstation_list[0] = task->workstation_list[0];
+ if (after->workstation_list[1] && (__SD_task_is_not_scheduled(after) ||
+ __SD_task_is_ready(after))) {
+ SD_task_do_schedule(after);
+ VERB4("Auto-Schedule comm task %s between %s -> %s. It costs %.f bytes",
+ SD_task_get_name(after),
+ SD_workstation_get_name(after->workstation_list[0]),SD_workstation_get_name(after->workstation_list[1]),
+ after->communication_amount[2]);
+
+ }
+ }
+ }
+ }
+}
+/** @brief autoschedule a task on a list of workstations
+ *
+ * This function is very similar to SD_task_schedulev(),
+ * but takes the list of workstations to schedule onto as separate parameters.
+ * It builds a proper vector of workstations and then call SD_task_schedulev()
+ */
+void SD_task_schedulel(SD_task_t task, int count, ...) {
+ va_list ap;
+ SD_workstation_t *list=xbt_new(SD_workstation_t,count);
+ int i;
+ va_start(ap,count);
+ for (i=0;i<count;i++) {
+ list[i] = va_arg(ap,SD_workstation_t);
+ }
+ va_end(ap);
+ SD_task_schedulev(task,count,list);
+ free(list);