- 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;
-
- 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! */
+#ifdef HAVE_TRACING
+ TRACE_surf_resource_utilization_release();
+#endif
+
+ xbt_mallocator_free(sd_global->task_mallocator);
+
+ XBT_DEBUG("Destroying workstation and link arrays...");
+ xbt_free(sd_global->workstation_list);
+ xbt_free(sd_global->link_list);
+ xbt_free(sd_global->recyclable_route);
+
+ XBT_DEBUG("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_swag_free(sd_global->return_set);
+
+#ifdef HAVE_TRACING
+ TRACE_end();
+#endif
+
+ XBT_DEBUG("Exiting Surf...");
+ surf_exit();
+
+ xbt_free(sd_global);
+ sd_global = NULL;
+
+#ifdef HAVE_JEDULE
+ jedule_sd_dump();
+ jedule_sd_cleanup();
+#endif
+}
+
+/**
+ * \brief load script file
+ */
+
+void SD_load_environment_script(const char *script_file)
+{
+#ifdef HAVE_LUA
+ lua_State *L = lua_open();
+ luaL_openlibs(L);
+
+ if (luaL_loadfile(L, script_file) || lua_pcall(L, 0, 0, 0)) {
+ printf("error: %s\n", lua_tostring(L, -1));
+ return;