X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/8750e7f378b5d48477e1b0b2796a437366a3ea2b..fde322aea2fa9ee1dc887875f4719f8a818bb6d4:/src/simdag/sd_global.c diff --git a/src/simdag/sd_global.c b/src/simdag/sd_global.c index 52c35d5395..7c153b4845 100644 --- a/src/simdag/sd_global.c +++ b/src/simdag/sd_global.c @@ -1,9 +1,12 @@ #include "simdag/simdag.h" #include "private.h" -#include "xbt/asserts.h" #include "xbt/sysdep.h" +#include "xbt/dynar.h" #include "surf/surf.h" +XBT_LOG_NEW_DEFAULT_SUBCATEGORY(sd_kernel, msg, + "Logging specific to SimDag (kernel)"); + SD_global_t sd_global = NULL; /* Initialises SD internal data. This function should be called before any other SD function. @@ -14,8 +17,15 @@ void SD_init(int *argc, char **argv) { sd_global = xbt_new0(s_SD_global_t, 1); sd_global->workstations = xbt_dict_new(); sd_global->workstation_count = 0; - /*sd_global->links = xbt_dynar_new(sizeof(s_SD_link_t), __SD_link_destroy);*/ sd_global->links = xbt_dict_new(); + sd_global->watch_point_reached = 0; + + s_SD_task_t task; + sd_global->not_scheduled_task_set = xbt_swag_new(xbt_swag_offset(task, state_hookup)); + sd_global->scheduled_task_set = xbt_swag_new(xbt_swag_offset(task, state_hookup)); + sd_global->running_task_set = xbt_swag_new(xbt_swag_offset(task, state_hookup)); + sd_global->done_task_set = xbt_swag_new(xbt_swag_offset(task, state_hookup)); + sd_global->failed_task_set = xbt_swag_new(xbt_swag_offset(task, state_hookup)); surf_init(argc, argv); } @@ -28,7 +38,7 @@ void SD_create_environment(const char *platform_file) { void *surf_workstation = NULL; void *surf_link = NULL; - CHECK_INIT_DONE(); + SD_CHECK_INIT_DONE(); surf_timer_resource_init(platform_file); /* tell Surf to create the environnement */ @@ -36,8 +46,8 @@ void SD_create_environment(const char *platform_file) { /*printf("surf_workstation_resource = %p, workstation_set = %p\n", surf_workstation_resource, workstation_set); printf("surf_network_resource = %p, network_link_set = %p\n", surf_network_resource, network_link_set);*/ - surf_workstation_resource_init_KCCFLN05(platform_file); - /*surf_workstation_resource_init_CLM03(platform_file);*/ + /*surf_workstation_resource_init_KCCFLN05(platform_file);*/ + surf_workstation_resource_init_CLM03(platform_file); /*printf("surf_workstation_resource = %p, workstation_set = %p\n", surf_workstation_resource, workstation_set); printf("surf_network_resource = %p, network_link_set = %p\n", surf_network_resource, network_link_set);*/ @@ -49,7 +59,7 @@ void SD_create_environment(const char *platform_file) { } xbt_dict_foreach(network_link_set, cursor, name, surf_link) { - __SD_link_create(surf_link, name, NULL); + __SD_link_create(surf_link, NULL); } } @@ -59,6 +69,74 @@ SD_task_t* SD_simulate(double how_long) { /* TODO */ + double total_time = 0.0; /* we stop the simulation when total_time >= how_long */ + double elapsed_time = 0.0; + SD_task_t task; + surf_action_t action; + + /* create the array that will be returned */ + const int task_number = xbt_swag_size(sd_global->scheduled_task_set) + xbt_swag_size(sd_global->running_task_set); + SD_task_t *changed_tasks = xbt_new0(SD_task_t, task_number + 1); + changed_tasks[task_number] = NULL; + int changed_task_number = 0; + + surf_solve(); /* Takes traces into account. Returns 0.0 */ + + sd_global->watch_point_reached = 0; + + /* main loop */ + while (elapsed_time >= 0.0 && total_time < how_long && !sd_global->watch_point_reached) { + + /* explore the scheduled tasks */ + xbt_swag_foreach(task, sd_global->scheduled_task_set) { + INFO1("Examining task '%s'...", SD_task_get_name(task)); + task->state_changed = 0; + if (xbt_dynar_length(task->tasks_before) == 0) { + INFO1("The dependencies are satisfied. Executing task '%s'", SD_task_get_name(task)); + action = __SD_task_run(task); + surf_workstation_resource->common_public->action_set_data(action, task); + task->state_changed = 1; + changed_tasks[changed_task_number++] = task; + } + else { + INFO1("Cannot execute task '%s' now because some depencies are not satisfied.", SD_task_get_name(task)); + } + } + + elapsed_time = surf_solve(); + if (elapsed_time > 0.0) + total_time += elapsed_time; + /* INFO1("Total time: %f", total_time);*/ + + while ((action = xbt_swag_extract(surf_workstation_resource->common_public->states.done_action_set))) { + task = action->data; + INFO1("Task '%s' done", SD_task_get_name(task)); + __SD_task_set_state(task, SD_DONE); + __SD_task_remove_dependencies(task); + if (!task->state_changed) { + task->state_changed = 1; + changed_tasks[changed_task_number++] = task; + } + } + + while ((action = xbt_swag_extract(surf_workstation_resource->common_public->states.failed_action_set))) { + task = action->data; + INFO1("Task '%s' failed", SD_task_get_name(task)); + __SD_task_set_state(task, SD_FAILED); + if (!task->state_changed) { + task->state_changed = 1; + changed_tasks[changed_task_number++] = task; + } + } + } + + INFO0("Simulation finished"); + + INFO1("Number of tasks whose state has changed: %d", changed_task_number); + return changed_tasks; +} + +void SD_test() { /* temporary test to explore the workstations and the links */ xbt_dict_cursor_t cursor = NULL; char *name = NULL; @@ -77,7 +155,7 @@ SD_task_t* SD_simulate(double how_long) xbt_dict_foreach(sd_global->links, cursor, name, link) { bandwidth = SD_link_get_current_bandwidth(link); latency = SD_link_get_current_latency(link); - printf("Link name: %s, bandwidth: %f, latency; %f\n", name, bandwidth, latency); + printf("Link name: %s, bandwidth: %f, latency: %f\n", name, bandwidth, latency); } /* test the route between two workstations */ @@ -97,18 +175,23 @@ SD_task_t* SD_simulate(double how_long) printf("%s ", SD_link_get_name(route[i])); } printf("\n"); - - return NULL; } -/* Destroys all SD data. This function should be called when the simulation is over. +/* Destroys all SD internal data. This function should be called when the simulation is over. + * The tasks should have been destroyed first. */ -void SD_clean() { +void SD_exit() { if (sd_global != NULL) { xbt_dict_free(&sd_global->workstations); xbt_dict_free(&sd_global->links); xbt_free(sd_global); + + xbt_swag_free(sd_global->not_scheduled_task_set); + xbt_swag_free(sd_global->scheduled_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); + surf_exit(); - /* TODO: destroy the tasks */ } }