+ void *surf_workstation = NULL;
+ void *surf_link = NULL;
+
+ SD_CHECK_INIT_DONE();
+
+ DEBUG0("SD_create_environment");
+
+ surf_config_models_setup(platform_file);
+ parse_platform_file(platform_file);
+ surf_config_models_create_elms();
+
+ /* now let's create the SD wrappers for workstations and links */
+ xbt_dict_foreach(surf_model_resource_set(surf_workstation_model), cursor,
+ name, surf_workstation) {
+ __SD_workstation_create(surf_workstation, NULL);
+ }
+
+ xbt_dict_foreach(surf_model_resource_set(surf_network_model), cursor,
+ name, surf_link) {
+ __SD_link_create(surf_link, NULL);
+ }
+
+ DEBUG2("Workstation number: %d, link number: %d",
+ SD_workstation_get_number(), SD_link_get_number());
+
+#ifdef HAVE_TRACING
+ TRACE_surf_save_onelink();
+#endif
+}
+
+/**
+ * \brief Launches the simulation.
+ *
+ * The function will execute the \ref SD_RUNNABLE runnable tasks.
+ * If \a how_long is positive, then the simulation will be stopped either
+ * when time reaches \a how_long or when a watch point is reached.
+ * A nonpositive value for \a how_long means no time limit, in which case
+ * the simulation will be stopped either when a watch point is reached or
+ * when no more task can be executed.
+ * Then you can call SD_simulate() again.
+ *
+ * \param how_long maximum duration of the simulation (a negative value means no time limit)
+ * \return a NULL-terminated array of \ref SD_task_t whose state has changed.
+ * \see SD_task_schedule(), SD_task_watch()
+ */
+xbt_dynar_t SD_simulate(double how_long)
+{
+ double total_time = 0.0; /* we stop the simulation when total_time >= how_long */
+ double elapsed_time = 0.0;
+ SD_task_t task, task_safe, dst;
+ SD_dependency_t dependency;
+ surf_action_t action;
+ xbt_dynar_t changed_tasks = xbt_dynar_new(sizeof(SD_task_t), NULL);
+ unsigned int iter, depcnt;
+ static int first_time = 1;
+
+ SD_CHECK_INIT_DONE();
+
+ if (first_time) {
+ VERB0("Starting simulation...");
+
+ surf_presolve(); /* Takes traces into account */
+ first_time = 0;
+ }
+
+ if (how_long > 0) {
+ surf_timer_model->extension.timer.set(surf_get_clock() + how_long,
+ NULL, NULL);
+ }
+ sd_global->watch_point_reached = 0;
+
+ /* explore the runnable tasks */
+ xbt_swag_foreach_safe(task, task_safe, sd_global->runnable_task_set) {
+ VERB1("Executing task '%s'", SD_task_get_name(task));
+ if (__SD_task_try_to_run(task)
+ && !xbt_dynar_member(changed_tasks, &task))
+ xbt_dynar_push(changed_tasks, &task);
+ }
+
+ /* main loop */
+ elapsed_time = 0.0;
+ while (elapsed_time >= 0.0 &&
+ (how_long < 0.0 || total_time < how_long) &&
+ !sd_global->watch_point_reached) {
+ surf_model_t model = NULL;
+ /* dumb variables */
+ void *fun = NULL;
+ void *arg = NULL;
+
+
+ DEBUG1("Total time: %f", total_time);
+
+ elapsed_time = surf_solve();
+ DEBUG1("surf_solve() returns %f", elapsed_time);
+ if (elapsed_time > 0.0)
+ total_time += elapsed_time;