+ elapsed_time = surf_solve(how_long > 0 ? surf_get_clock() + how_long : -1.0);
+ DEBUG1("surf_solve() returns %f", elapsed_time);
+ if (elapsed_time > 0.0)
+ total_time += elapsed_time;
+
+ /* let's see which tasks are done */
+ xbt_dynar_foreach(model_list, iter, model) {
+ while ((action = xbt_swag_extract(model->states.done_action_set))) {
+ task = action->data;
+ task->start_time =
+ surf_workstation_model->
+ action_get_start_time(task->surf_action);
+ task->finish_time = surf_get_clock();
+ VERB1("Task '%s' done", SD_task_get_name(task));
+ DEBUG0("Calling __SD_task_just_done");
+ __SD_task_just_done(task);
+ DEBUG1("__SD_task_just_done called on task '%s'",
+ SD_task_get_name(task));
+
+ /* the state has changed */
+ if (!xbt_dynar_member(changed_tasks, &task))
+ xbt_dynar_push(changed_tasks, &task);
+
+ /* remove the dependencies after this task */
+ xbt_dynar_foreach(task->tasks_after, depcnt, dependency) {
+ dst = dependency->dst;
+ if (dst->unsatisfied_dependencies > 0)
+ dst->unsatisfied_dependencies--;
+ if (dst->is_not_ready > 0)
+ dst->is_not_ready--;
+
+ if (!(dst->unsatisfied_dependencies)) {
+ if (__SD_task_is_scheduled(dst))
+ __SD_task_set_state(dst, SD_RUNNABLE);
+ else
+ __SD_task_set_state(dst, SD_SCHEDULABLE);
+ }
+
+ if (SD_task_get_kind(dst) == SD_TASK_COMM_E2E) {
+ SD_dependency_t comm_dep;
+ SD_task_t comm_dst;
+ xbt_dynar_get_cpy(dst->tasks_after, 0, &comm_dep);
+ comm_dst = comm_dep->dst;
+ if (__SD_task_is_not_scheduled(comm_dst) &&
+ comm_dst->is_not_ready > 0) {
+ comm_dst->is_not_ready--;
+
+ if (!(comm_dst->is_not_ready)) {
+ __SD_task_set_state(comm_dst, SD_SCHEDULABLE);
+ }
+ }
+ }
+
+ /* is dst runnable now? */
+ if (__SD_task_is_runnable(dst)
+ && !sd_global->watch_point_reached) {
+ VERB1("Executing task '%s'", SD_task_get_name(dst));
+ if (__SD_task_try_to_run(dst) &&
+ !xbt_dynar_member(changed_tasks, &task))
+ xbt_dynar_push(changed_tasks, &task);
+ }
+ }
+ }
+
+ /* let's see which tasks have just failed */
+ while ((action = xbt_swag_extract(model->states.failed_action_set))) {
+ task = action->data;
+ task->start_time =
+ surf_workstation_model->
+ action_get_start_time(task->surf_action);
+ task->finish_time = surf_get_clock();
+ VERB1("Task '%s' failed", SD_task_get_name(task));
+ __SD_task_set_state(task, SD_FAILED);
+ surf_workstation_model->action_unref(action);
+ task->surf_action = NULL;
+
+ if (!xbt_dynar_member(changed_tasks, &task))
+ xbt_dynar_push(changed_tasks, &task);
+ }
+ }
+ }
+
+ if (!sd_global->watch_point_reached && how_long<0){
+ if (xbt_swag_size(sd_global->done_task_set) < sd_global->task_number){
+ WARN0("Simulation is finished but some tasks are still not done");
+ xbt_swag_foreach_safe (task, task_safe,sd_global->not_scheduled_task_set){
+ WARN1("%s is in SD_NOT_SCHEDULED state", SD_task_get_name(task));
+ }
+ xbt_swag_foreach_safe (task, task_safe,sd_global->schedulable_task_set){
+ WARN1("%s is in SD_SCHEDULABLE state", SD_task_get_name(task));
+ }
+ xbt_swag_foreach_safe (task, task_safe,sd_global->scheduled_task_set){
+ WARN1("%s is in SD_SCHEDULED state", SD_task_get_name(task));
+ }
+ }
+ }
+
+ DEBUG3("elapsed_time = %f, total_time = %f, watch_point_reached = %d",
+ elapsed_time, total_time, sd_global->watch_point_reached);
+ DEBUG1("current time = %f", surf_get_clock());
+
+ return changed_tasks;
+}
+
+/**
+ * \brief Returns the current clock
+ *
+ * \return the current clock, in second
+ */
+double SD_get_clock(void)
+{
+ SD_CHECK_INIT_DONE();
+
+ return surf_get_clock();
+}
+
+/**
+ * \brief Destroys all SD internal data
+ *
+ * This function should be called when the simulation is over. Don't forget also to destroy
+ * the tasks.
+ *
+ * \see SD_init(), SD_task_destroy()
+ */
+void SD_exit(void)
+{
+#ifdef HAVE_TRACING
+ TRACE_surf_release();
+#endif
+ if (SD_INITIALISED()) {
+ DEBUG0("Destroying workstation and link dictionaries...");
+ xbt_dict_free(&sd_global->workstations);
+ xbt_dict_free(&sd_global->links);
+
+ DEBUG0("Destroying workstation and link arrays if necessary...");
+ if (sd_global->workstation_list != NULL)
+ xbt_free(sd_global->workstation_list);
+
+ if (sd_global->link_list != NULL)
+ xbt_free(sd_global->link_list);
+
+ if (sd_global->recyclable_route != NULL)
+ xbt_free(sd_global->recyclable_route);
+
+ DEBUG0("Destroying the swags...");
+ xbt_swag_free(sd_global->not_scheduled_task_set);
+ xbt_swag_free(sd_global->schedulable_task_set);
+ xbt_swag_free(sd_global->scheduled_task_set);
+ xbt_swag_free(sd_global->runnable_task_set);
+ xbt_swag_free(sd_global->in_fifo_task_set);
+ xbt_swag_free(sd_global->running_task_set);
+ xbt_swag_free(sd_global->done_task_set);
+ xbt_swag_free(sd_global->failed_task_set);
+
+ xbt_free(sd_global);
+ sd_global = NULL;
+
+#ifdef HAVE_TRACING
+ TRACE_end();
+#endif
+
+ DEBUG0("Exiting Surf...");
+ surf_exit();
+ } else {
+ WARN0("SD_exit() called, but SimDag is not running");
+ /* we cannot use exceptions here because xbt is not running! */
+ }
+}
+
+/**
+ * \bried load script file