X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/bff077b4621c68455a86e60292cb0bf872a879d5..ed0538958d148f641416687454e0eae197607d65:/src/simdag/sd_global.c diff --git a/src/simdag/sd_global.c b/src/simdag/sd_global.c index 27e445f363..2341fc0f4f 100644 --- a/src/simdag/sd_global.c +++ b/src/simdag/sd_global.c @@ -35,9 +35,7 @@ static void _sd_cfg_cb__workstation_model(const char *name, int pos) "Cannot change the model after the initialization"); val = xbt_cfg_get_string(_sd_cfg_set, name); - find_model_description(surf_workstation_model_description, - surf_workstation_model_description_size, - val); + find_model_description(surf_workstation_model_description, val); } /* callback of the cpu_model variable */ @@ -49,8 +47,7 @@ static void _sd_cfg_cb__cpu_model(const char *name, int pos) "Cannot change the model after the initialization"); val = xbt_cfg_get_string(_sd_cfg_set, name); - find_model_description(surf_cpu_model_description, - surf_cpu_model_description_size, val); + find_model_description(surf_cpu_model_description, val); } /* callback of the workstation_model variable */ @@ -62,10 +59,13 @@ static void _sd_cfg_cb__network_model(const char *name, int pos) "Cannot change the model after the initialization"); val = xbt_cfg_get_string(_sd_cfg_set, name); - find_model_description(surf_network_model_description, - surf_network_model_description_size, val); + find_model_description(surf_network_model_description, val); } +XBT_LOG_EXTERNAL_CATEGORY(sd_kernel); +XBT_LOG_EXTERNAL_CATEGORY(sd_task); +XBT_LOG_EXTERNAL_CATEGORY(sd_workstation); + /* create the config set and register what should be */ static void sd_config_init(void) { @@ -286,7 +286,7 @@ void SD_application_reinit(void) { * * The XML file follows this DTD: * - * \include surfxml.dtd + * \include simgrid.dtd * * Here is a small example of such a platform: * @@ -313,8 +313,7 @@ void SD_create_environment(const char *platform_file) { DEBUG1("Model : %s", workstation_model_name); workstation_id = find_model_description(surf_workstation_model_description, - surf_workstation_model_description_size, - workstation_model_name); + workstation_model_name); if (!strcmp(workstation_model_name, "compound")) { xbt_ex_t e; char *network_model_name = NULL; @@ -350,12 +349,10 @@ void SD_create_environment(const char *platform_file) { network_id = find_model_description(surf_network_model_description, - surf_network_model_description_size, - network_model_name); + network_model_name); cpu_id = find_model_description(surf_cpu_model_description, - surf_cpu_model_description_size, - cpu_model_name); + cpu_model_name); surf_cpu_model_description[cpu_id].model_init(platform_file); surf_network_model_description[network_id].model_init(platform_file); @@ -400,9 +397,8 @@ SD_task_t* SD_simulate(double how_long) SD_task_t task, task_safe, dst; SD_dependency_t dependency; surf_action_t action; - SD_task_t *changed_tasks = NULL; - int changed_task_number = 0; - int changed_task_capacity = sd_global->task_number + 1; + SD_task_t *res=NULL; + xbt_dynar_t changed_tasks = xbt_dynar_new (sizeof(SD_task_t), NULL); unsigned int iter; static int first_time = 1; @@ -410,12 +406,8 @@ SD_task_t* SD_simulate(double how_long) INFO0("Starting simulation..."); - /* create the array that will be returned */ - changed_tasks = xbt_new(SD_task_t, changed_task_capacity); - changed_tasks[0] = NULL; - if (first_time) { - surf_solve(); /* Takes traces into account. Returns 0.0 */ + surf_presolve(); /* Takes traces into account */ first_time = 0; } @@ -428,16 +420,9 @@ SD_task_t* SD_simulate(double how_long) /* explore the ready tasks */ xbt_swag_foreach_safe(task, task_safe, sd_global->ready_task_set) { INFO1("Executing task '%s'", SD_task_get_name(task)); - if ((task->state_changed = __SD_task_try_to_run(task))) { - changed_tasks[changed_task_number++] = task; /* replace NULL by the task */ - /* - if (changed_task_number == changed_task_capacity) { - changed_task_capacity *= 2; - changed_tasks = xbt_realloc(changed_tasks, sizeof(SD_task_t) * changed_task_capacity); - } - */ - changed_tasks[changed_task_number] = NULL; - } + if(__SD_task_try_to_run(task) && + !xbt_dynar_member(changed_tasks,&task)) + xbt_dynar_push (changed_tasks, &task); } /* main loop */ @@ -469,17 +454,8 @@ SD_task_t* SD_simulate(double how_long) DEBUG1("__SD_task_just_done called on task '%s'", SD_task_get_name(task)); /* the state has changed */ - if (!task->state_changed) { - task->state_changed = 1; - changed_tasks[changed_task_number++] = task; - /* - if (changed_task_number == changed_task_capacity) { - changed_task_capacity *= 2; - changed_tasks = xbt_realloc(changed_tasks, sizeof(SD_task_t) * changed_task_capacity); - } - */ - changed_tasks[changed_task_number] = NULL; - } + if(!xbt_dynar_member(changed_tasks,&task)) + xbt_dynar_push (changed_tasks, &task); /* remove the dependencies after this task */ while (xbt_dynar_length(task->tasks_after) > 0) { @@ -490,16 +466,9 @@ SD_task_t* SD_simulate(double how_long) /* is dst ready now? */ if (__SD_task_is_ready(dst) && !sd_global->watch_point_reached) { INFO1("Executing task '%s'", SD_task_get_name(dst)); - if (__SD_task_try_to_run(dst)) { - changed_tasks[changed_task_number++] = dst; - /* - if (changed_task_number == changed_task_capacity) { - changed_task_capacity *= 2; - changed_tasks = xbt_realloc(changed_tasks, sizeof(SD_task_t) * changed_task_capacity); - } - */ - changed_tasks[changed_task_number] = NULL; - } + if (__SD_task_try_to_run(dst) && + !xbt_dynar_member(changed_tasks,&task)) + xbt_dynar_push(changed_tasks, &task); } } } @@ -512,17 +481,8 @@ SD_task_t* SD_simulate(double how_long) surf_workstation_model->common_public->action_free(action); task->surf_action = NULL; - if (!task->state_changed) { - task->state_changed = 1; - changed_tasks[changed_task_number++] = task; - /* - if (changed_task_number == changed_task_capacity) { - changed_task_capacity *= 2; - changed_tasks = xbt_realloc(changed_tasks, sizeof(SD_task_t) * changed_task_capacity); - } - */ - changed_tasks[changed_task_number] = NULL; - } + if(!xbt_dynar_member(changed_tasks,&task)) + xbt_dynar_push (changed_tasks, &task); } } @@ -530,18 +490,18 @@ SD_task_t* SD_simulate(double how_long) } } - /* we must reset every task->state_changed */ - iter = 0; - while (changed_tasks[iter] != NULL) { - changed_tasks[iter]->state_changed = 0; - iter++; + res = xbt_new0(SD_task_t,(xbt_dynar_length(changed_tasks)+1)); + + xbt_dynar_foreach(changed_tasks,iter,task) { + res[iter]=task; } + xbt_dynar_free(&changed_tasks); INFO0("Simulation finished"); 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; + return res; } /**