From 526747a744ea55946618ab192e053cd508947259 Mon Sep 17 00:00:00 2001 From: navarrop Date: Thu, 24 Mar 2011 10:35:49 +0000 Subject: [PATCH 1/1] Remove xbt_dict_t workstations from SD_global. git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/simgrid/simgrid/trunk@9833 48e7efb5-ca39-0410-a469-dd3cf9ba447f --- src/simdag/private.h | 3 --- src/simdag/sd_dotloader.c | 2 +- src/simdag/sd_global.c | 20 +++++++--------- src/simdag/sd_workstation.c | 19 +++++++-------- src/simix/smx_environment.c | 10 ++++---- src/surf/cpu.c | 3 +-- src/surf/cpu_im.c | 40 ++++++++++++++++++-------------- src/surf/cpu_ti.c | 20 +++++++++------- src/surf/workstation.c | 13 +++++------ src/surf/workstation_ptask_L07.c | 3 +-- 10 files changed, 65 insertions(+), 68 deletions(-) diff --git a/src/simdag/private.h b/src/simdag/private.h index 27cef90ff7..dce5fd6535 100644 --- a/src/simdag/private.h +++ b/src/simdag/private.h @@ -21,11 +21,8 @@ /* Global variables */ typedef struct SD_global { - xbt_dict_t workstations; /* workstation dictionary */ - int workstation_count; /* number of workstations */ SD_workstation_t *workstation_list; /* array of workstations, created only if necessary in SD_workstation_get_list */ - SD_link_t *link_list; /* array of links, created only if necessary in SD_link_get_list */ SD_link_t *recyclable_route; /* array returned by SD_route_get_list diff --git a/src/simdag/sd_dotloader.c b/src/simdag/sd_dotloader.c index 9da658effd..f2ee1a694b 100644 --- a/src/simdag/sd_dotloader.c +++ b/src/simdag/sd_dotloader.c @@ -309,7 +309,7 @@ void dot_add_task(Agnode_t * dag_node) computer = xbt_dynar_new(sizeof(SD_task_t), NULL); xbt_dict_set(computers, char_performer, computer, NULL); } - if(performer < sd_global->workstation_count){ + if(performer < host_lib->count){ // the wanted computer is available SD_task_t *task_test = NULL; if(order < computer->used) diff --git a/src/simdag/sd_global.c b/src/simdag/sd_global.c index 5378f89f35..30f5d47ca7 100644 --- a/src/simdag/sd_global.c +++ b/src/simdag/sd_global.c @@ -61,8 +61,6 @@ void SD_init(int *argc, char **argv) sd_global = xbt_new(s_SD_global_t, 1); - sd_global->workstations = xbt_dict_new(); - sd_global->workstation_count = 0; sd_global->workstation_list = NULL; sd_global->link_list = NULL; sd_global->recyclable_route = NULL; @@ -182,10 +180,10 @@ void SD_application_reinit(void) */ void SD_create_environment(const char *platform_file) { - xbt_dict_cursor_t cursor = NULL; + xbt_lib_cursor_t cursor = NULL; char *name = NULL; - void *surf_workstation = NULL; - void *surf_link = NULL; + void **surf_workstation = NULL; + void **surf_link = NULL; platform_filename = bprintf("%s",platform_file); @@ -198,14 +196,13 @@ void SD_create_environment(const char *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_lib_foreach(host_lib, cursor, name, surf_workstation){ + if(surf_workstation[SURF_WKS_LEVEL]) + __SD_workstation_create(surf_workstation[SURF_WKS_LEVEL], NULL); } - xbt_dict_foreach(surf_model_resource_set(surf_network_model), cursor, - name, surf_link) { - __SD_link_create(surf_link, NULL); + xbt_lib_foreach(link_lib, cursor, name, surf_link) { + __SD_link_create(surf_link[SURF_LINK_LEVEL], NULL); } XBT_DEBUG("Workstation number: %d, link number: %d", @@ -402,7 +399,6 @@ void SD_exit(void) #endif if (SD_INITIALISED()) { XBT_DEBUG("Destroying workstation and link dictionaries..."); - xbt_dict_free(&sd_global->workstations); XBT_DEBUG("Destroying workstation and link arrays if necessary..."); if (sd_global->workstation_list != NULL) diff --git a/src/simdag/sd_workstation.c b/src/simdag/sd_workstation.c index 0a8c3ee7f5..1044c91020 100644 --- a/src/simdag/sd_workstation.c +++ b/src/simdag/sd_workstation.c @@ -32,9 +32,7 @@ SD_workstation_t __SD_workstation_create(void *surf_workstation, workstation->current_task = NULL; name = SD_workstation_get_name(workstation); - xbt_dict_set(sd_global->workstations, name, workstation, __SD_workstation_destroy); /* add the workstation to the dictionary */ - sd_global->workstation_count++; - + xbt_lib_set(host_lib,name,SD_HOST_LEVEL,workstation); return workstation; } @@ -52,7 +50,7 @@ SD_workstation_t SD_workstation_get_by_name(const char *name) xbt_assert0(name != NULL, "Invalid parameter"); - return xbt_dict_get_or_null(sd_global->workstations, name); + return xbt_lib_get_or_null(host_lib, name, SD_HOST_LEVEL); } /** @@ -66,9 +64,9 @@ SD_workstation_t SD_workstation_get_by_name(const char *name) const SD_workstation_t *SD_workstation_get_list(void) { - xbt_dict_cursor_t cursor; + xbt_lib_cursor_t cursor; char *key; - void *data; + void **data; int i; SD_CHECK_INIT_DONE(); @@ -76,11 +74,12 @@ const SD_workstation_t *SD_workstation_get_list(void) if (sd_global->workstation_list == NULL) { /* this is the first time the function is called */ sd_global->workstation_list = - xbt_new(SD_workstation_t, sd_global->workstation_count); + xbt_new(SD_workstation_t, host_lib->count); i = 0; - xbt_dict_foreach(sd_global->workstations, cursor, key, data) { - sd_global->workstation_list[i++] = (SD_workstation_t) data; + xbt_lib_foreach(host_lib, cursor, key, data) { + if(data[SD_HOST_LEVEL]) + sd_global->workstation_list[i++] = (SD_workstation_t) data[SD_HOST_LEVEL]; } } return sd_global->workstation_list; @@ -95,7 +94,7 @@ const SD_workstation_t *SD_workstation_get_list(void) int SD_workstation_get_number(void) { SD_CHECK_INIT_DONE(); - return sd_global->workstation_count; + return host_lib->count; } /** diff --git a/src/simix/smx_environment.c b/src/simix/smx_environment.c index ba8f2e2845..600d6da7b8 100644 --- a/src/simix/smx_environment.c +++ b/src/simix/smx_environment.c @@ -33,9 +33,9 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(simix_environment, simix, */ void SIMIX_create_environment(const char *file) { - xbt_dict_cursor_t cursor = NULL; + xbt_lib_cursor_t cursor = NULL; char *name = NULL; - void *workstation = NULL; + void **workstation = NULL; double start, end; @@ -54,9 +54,9 @@ void SIMIX_create_environment(const char *file) end = xbt_os_time(); XBT_DEBUG("PARSE TIME: %lg", (end - start)); - xbt_dict_foreach(surf_model_resource_set(surf_workstation_model), cursor, - name, workstation) { - SIMIX_host_create(name, workstation, NULL); + xbt_lib_foreach(host_lib, cursor, name, workstation) { + if(workstation[SURF_WKS_LEVEL]) + SIMIX_host_create(name, workstation[SURF_WKS_LEVEL], NULL); } surf_presolve(); } diff --git a/src/surf/cpu.c b/src/surf/cpu.c index d25b8bacdf..2b7f6020e0 100644 --- a/src/surf/cpu.c +++ b/src/surf/cpu.c @@ -65,8 +65,7 @@ static cpu_Cas01_t cpu_new(char *name, double power_peak, lmm_constraint_new(cpu_maxmin_system, cpu, cpu->core * cpu->power_scale * cpu->power_peak); - xbt_dict_set(surf_model_resource_set(surf_cpu_model), name, cpu, - surf_resource_free); + xbt_lib_set(host_lib, name, SURF_CPU_LEVEL, cpu); return cpu; } diff --git a/src/surf/cpu_im.c b/src/surf/cpu_im.c index 42d7988d18..492191bddd 100644 --- a/src/surf/cpu_im.c +++ b/src/surf/cpu_im.c @@ -83,8 +83,7 @@ static cpu_Cas01_im_t cpu_im_new(char *name, double power_peak, lmm_constraint_new(cpu_im_maxmin_system, cpu, cpu->core * cpu->power_scale * cpu->power_peak); - xbt_dict_set(surf_model_resource_set(surf_cpu_model), name, cpu, - surf_resource_free); + xbt_lib_set(host_lib, name, SURF_CPU_LEVEL, cpu); cpu->action_set = xbt_swag_new(xbt_swag_offset(action, cpu_list_hookup)); return cpu; @@ -344,19 +343,23 @@ static void cpu_im_update_actions_state(double now, double delta) { //defining the last timestamp that we can safely dump to trace file //without losing the event ascending order (considering all CPU's) + void **data; cpu_Cas01_im_t cpu; xbt_dict_cursor_t cursor; char *key; double smaller = -1; - xbt_dict_foreach(surf_model_resource_set(surf_cpu_model), cursor, key, cpu){ - if (smaller < 0){ - smaller = cpu->last_update; - continue; - } - if (cpu->last_update < smaller){ - smaller = cpu->last_update; - } - } + xbt_lib_foreach(host_lib, cursor, key, data){ + if(data[SURF_CPU_LEVEL]){ + cpu = data[SURF_CPU_LEVEL]; + if (smaller < 0){ + smaller = cpu->last_update; + continue; + } + if (cpu->last_update < smaller){ + smaller = cpu->last_update; + } + } + } if (smaller > 0) { TRACE_last_timestamp_to_dump = smaller; } @@ -589,13 +592,16 @@ static void cpu_im_create_resource(char *name, double power_peak, static void cpu_im_finalize(void) { - void *cpu; - xbt_dict_cursor_t cursor; + void **cpu; + xbt_lib_cursor_t cursor; char *key; - xbt_dict_foreach(surf_model_resource_set(surf_cpu_model), cursor, key, - cpu) { - cpu_Cas01_im_t CPU = cpu; - xbt_swag_free(CPU->action_set); + + xbt_lib_foreach(host_lib, cursor, key, cpu){ + if(cpu[SURF_CPU_LEVEL]) + { + cpu_Cas01_im_t CPU = cpu[SURF_CPU_LEVEL]; + xbt_swag_free(CPU->action_set); + } } lmm_system_free(cpu_im_maxmin_system); diff --git a/src/surf/cpu_ti.c b/src/surf/cpu_ti.c index 5714ff051e..dd169796e1 100644 --- a/src/surf/cpu_ti.c +++ b/src/surf/cpu_ti.c @@ -185,8 +185,7 @@ static cpu_ti_t cpu_ti_new(char *name, double power_peak, cpu->avail_trace->last_time, 0, cpu); } } - xbt_dict_set(surf_model_resource_set(surf_cpu_model), name, cpu, - surf_resource_free); + xbt_lib_set(host_lib, name, SURF_CPU_LEVEL, cpu); return cpu; } @@ -762,14 +761,17 @@ static void cpu_ti_create_resource(char *name, double power_peak, static void cpu_ti_finalize(void) { - void *cpu; - xbt_dict_cursor_t cursor; + void **cpu; + xbt_lib_cursor_t cursor; char *key; - xbt_dict_foreach(surf_model_resource_set(surf_cpu_model), cursor, key, - cpu) { - cpu_ti_t CPU = cpu; - xbt_swag_free(CPU->action_set); - surf_cpu_ti_free_tmgr(CPU->avail_trace); + + xbt_lib_foreach(host_lib, cursor, key, cpu){ + if(cpu[SURF_CPU_LEVEL]) + { + cpu_ti_t CPU = cpu[SURF_CPU_LEVEL]; + xbt_swag_free(CPU->action_set); + surf_cpu_ti_free_tmgr(CPU->avail_trace); + } } surf_model_exit(surf_cpu_model); diff --git a/src/surf/workstation.c b/src/surf/workstation.c index 457cfe30c0..5e494826d7 100644 --- a/src/surf/workstation.c +++ b/src/surf/workstation.c @@ -27,21 +27,20 @@ static workstation_CLM03_t workstation_new(const char *name, void *cpu) workstation->generic_resource.name = xbt_strdup(name); workstation->cpu = cpu; - xbt_dict_set(surf_model_resource_set(surf_workstation_model), name, - workstation, surf_resource_free); + xbt_lib_set(host_lib, name, SURF_WKS_LEVEL, workstation); return workstation; } void create_workstations(void) { - xbt_dict_cursor_t cursor = NULL; + xbt_lib_cursor_t cursor = NULL; char *name = NULL; - void *cpu = NULL; + void **cpu = NULL; - xbt_dict_foreach(surf_model_resource_set(surf_cpu_model), cursor, name, - cpu) { - workstation_new(name, cpu); + xbt_lib_foreach(host_lib, cursor, name, cpu) { + if(cpu[SURF_CPU_LEVEL]) + workstation_new(name, cpu[SURF_CPU_LEVEL]); } } diff --git a/src/surf/workstation_ptask_L07.c b/src/surf/workstation_ptask_L07.c index 595001eb7d..315dc66278 100644 --- a/src/surf/workstation_ptask_L07.c +++ b/src/surf/workstation_ptask_L07.c @@ -649,8 +649,7 @@ static cpu_L07_t ptask_cpu_new(const char *name, double power_scale, lmm_constraint_new(ptask_maxmin_system, cpu, cpu->power_current * cpu->power_scale); - xbt_dict_set(surf_model_resource_set(surf_workstation_model), name, cpu, - surf_resource_free); + xbt_lib_set(host_lib, name, SURF_WKS_LEVEL, cpu); return cpu; } -- 2.20.1