+double SD_task_get_execution_time(SD_task_t task,
+ int workstation_nb,
+ const SD_workstation_t *
+ workstation_list,
+ const double *computation_amount,
+ const double *communication_amount)
+{
+ double time, max_time = 0.0;
+ int i, j;
+ xbt_assert(workstation_nb > 0, "Invalid parameter");
+
+ /* the task execution time is the maximum execution time of the parallel tasks */
+
+ for (i = 0; i < workstation_nb; i++) {
+ time = 0.0;
+ if (computation_amount != NULL)
+ time =
+ SD_workstation_get_computation_time(workstation_list[i],
+ computation_amount[i]);
+
+ if (communication_amount != NULL)
+ for (j = 0; j < workstation_nb; j++) {
+ time +=
+ SD_route_get_communication_time(workstation_list[i],
+ workstation_list[j],
+ communication_amount[i *
+ workstation_nb
+ + j]);
+ }
+
+ if (time > max_time) {
+ max_time = time;
+ }
+ }
+ return max_time;
+}
+
+static XBT_INLINE void SD_task_do_schedule(SD_task_t task)
+{
+ if (!__SD_task_is_not_scheduled(task) && !__SD_task_is_schedulable(task))
+ THROWF(arg_error, 0, "Task '%s' has already been scheduled",
+ SD_task_get_name(task));
+
+ /* update the task state */
+ if (task->unsatisfied_dependencies == 0)
+ __SD_task_set_state(task, SD_RUNNABLE);
+ else
+ __SD_task_set_state(task, SD_SCHEDULED);
+}
+
+/**
+ * \brief Schedules a task
+ *
+ * The task state must be #SD_NOT_SCHEDULED.
+ * Once scheduled, a task will be executed as soon as possible in SD_simulate(),
+ * i.e. when its dependencies are satisfied.
+ *
+ * \param task the task you want to schedule
+ * \param workstation_count number of workstations on which the task will be executed
+ * \param workstation_list the workstations on which the task will be executed
+ * \param computation_amount computation amount for each workstation
+ * \param communication_amount communication amount between each pair of workstations
+ * \param rate task execution speed rate
+ * \see SD_task_unschedule()
+ */
+void SD_task_schedule(SD_task_t task, int workstation_count,
+ const SD_workstation_t * workstation_list,
+ const double *computation_amount,
+ const double *communication_amount, double rate)
+{
+ int communication_nb;
+ task->workstation_nb = 0;
+ task->rate = -1;
+ xbt_assert(workstation_count > 0, "workstation_nb must be positive");
+
+ task->workstation_nb = workstation_count;
+ task->rate = rate;
+
+ if (computation_amount) {
+ task->computation_amount = xbt_realloc(task->computation_amount,
+ sizeof(double) * workstation_count);
+ memcpy(task->computation_amount, computation_amount,
+ sizeof(double) * workstation_count);
+ } else {
+ xbt_free(task->computation_amount);
+ task->computation_amount = NULL;
+ }
+
+ communication_nb = workstation_count * workstation_count;
+ if (communication_amount) {
+ task->communication_amount = xbt_realloc(task->communication_amount,
+ sizeof(double) * communication_nb);
+ memcpy(task->communication_amount, communication_amount,
+ sizeof(double) * communication_nb);
+ } else {
+ xbt_free(task->communication_amount);
+ task->communication_amount = NULL;
+ }
+
+ task->workstation_list =
+ xbt_realloc(task->workstation_list,
+ sizeof(SD_workstation_t) * workstation_count);
+ memcpy(task->workstation_list, workstation_list,
+ sizeof(SD_workstation_t) * workstation_count);
+
+ SD_task_do_schedule(task);
+}
+
+/**
+ * \brief Unschedules a task
+ *
+ * The task state must be #SD_SCHEDULED, #SD_RUNNABLE, #SD_RUNNING or #SD_FAILED.
+ * If you call this function, the task state becomes #SD_NOT_SCHEDULED.
+ * Call SD_task_schedule() to schedule it again.
+ *
+ * \param task the task you want to unschedule
+ * \see SD_task_schedule()
+ */
+void SD_task_unschedule(SD_task_t task)
+{
+ if (task->state_set != sd_global->scheduled_task_set &&
+ task->state_set != sd_global->runnable_task_set &&
+ task->state_set != sd_global->running_task_set &&
+ task->state_set != sd_global->failed_task_set)
+ THROWF(arg_error, 0,
+ "Task %s: the state must be SD_SCHEDULED, SD_RUNNABLE, SD_RUNNING or SD_FAILED",
+ SD_task_get_name(task));
+
+ if (__SD_task_is_scheduled_or_runnable(task) /* if the task is scheduled or runnable */
+ &&task->kind == SD_TASK_NOT_TYPED) /* Don't free scheduling data for typed tasks */
+ __SD_task_destroy_scheduling_data(task);
+
+ if (__SD_task_is_running(task)) /* the task should become SD_FAILED */
+ surf_workstation_model->action_cancel(task->surf_action);
+ else {
+ if (task->unsatisfied_dependencies == 0)
+ __SD_task_set_state(task, SD_SCHEDULABLE);
+ else
+ __SD_task_set_state(task, SD_NOT_SCHEDULED);
+ }
+ task->remains = task->amount;
+ task->start_time = -1.0;
+}
+
+/* Destroys the data memorized by SD_task_schedule. Task state must be SD_SCHEDULED or SD_RUNNABLE.
+ */
+static void __SD_task_destroy_scheduling_data(SD_task_t task)
+{
+ if (!__SD_task_is_scheduled_or_runnable(task)
+ && !__SD_task_is_in_fifo(task))
+ THROWF(arg_error, 0,
+ "Task '%s' must be SD_SCHEDULED, SD_RUNNABLE or SD_IN_FIFO",
+ SD_task_get_name(task));
+