+ /* __SD_print_watch_points(task); */
+}
+
+/**
+ * \brief Returns an approximative estimation of the execution time of a task.
+ *
+ * The estimation is very approximative because the value returned is the time
+ * the task would take if it was executed now and if it was the only task.
+ *
+ * \param task the task to evaluate
+ * \param workstation_nb number of workstations on which the task would be executed
+ * \param workstation_list the workstations on which the task would 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_schedule()
+ */
+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 rate)
+{
+ double time, max_time = 0.0;
+ int i, j;
+ SD_CHECK_INIT_DONE();
+ xbt_assert0(task != NULL && workstation_nb > 0 && workstation_list != NULL
+ && computation_amount != NULL
+ && communication_amount != NULL, "Invalid parameter");
+
+ /* the task execution time is the maximum execution time of the parallel tasks */
+
+ for (i = 0; i < workstation_nb; i++) {
+ time =
+ SD_workstation_get_computation_time(workstation_list[i],
+ computation_amount[i]);
+
+ 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 * SD_task_get_amount(task);
+}
+static inline void SD_task_do_schedule(SD_task_t task) {
+ SD_CHECK_INIT_DONE();
+
+ if (!__SD_task_is_not_scheduled(task))
+ THROW1(arg_error, 0, "Task '%s' has already been scheduled",
+ SD_task_get_name(task));
+
+ /* update the task state */
+ if (xbt_dynar_length(task->tasks_before) == 0)
+ __SD_task_set_state(task, SD_READY);
+ 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_nb 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)
+{
+ xbt_assert0(workstation_count > 0, "workstation_nb must be positive");
+
+ int communication_nb;
+
+ task->workstation_nb = workstation_count;
+ task->rate = rate;
+
+ task->computation_amount = xbt_new(double, workstation_count);
+ memcpy(task->computation_amount, computation_amount,
+ sizeof(double) * workstation_count);
+
+ communication_nb = workstation_count * workstation_count;
+ task->communication_amount = xbt_new(double, communication_nb);
+ memcpy(task->communication_amount, communication_amount,
+ sizeof(double) * communication_nb);
+
+ task->workstation_list = xbt_new(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_READY, #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)
+{
+ SD_CHECK_INIT_DONE();
+ xbt_assert0(task != NULL, "Invalid parameter");
+
+ if (task->state_set != sd_global->scheduled_task_set &&
+ task->state_set != sd_global->ready_task_set &&
+ task->state_set != sd_global->running_task_set &&
+ task->state_set != sd_global->failed_task_set)
+ THROW1(arg_error, 0,
+ "Task %s: the state must be SD_SCHEDULED, SD_READY, SD_RUNNING or SD_FAILED",
+ SD_task_get_name(task));
+
+ if (__SD_task_is_scheduled_or_ready(task)) /* if the task is scheduled or ready */
+ __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
+ __SD_task_set_state(task, SD_NOT_SCHEDULED);
+ task->remains = task->amount;
+ task->start_time = -1.0;